fix: make forwardToStorage fully dynamic based on fileType

- Replace forceDocument boolean with fileType string in forwardToStorage
- Dynamically call matching sendPhoto, sendAudio, sendVideo, sendVoice, sendAnimation, sendSticker, or sendDocument Telegraf API method
- Correctly extract uploaded file details based on what Telegram returned
- Fixes IMAGE_PROCESS_FAILED 500 error when uploading ogg audio, video, sticker, or voice notes via HTTP
- Update upload.ts, bot.ts, and test suites to match the new dynamic signature

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-05-18 19:52:46 +07:00
co-authored by Claude Opus 4.7
parent bf6d5f04c4
commit 525348b1f3
5 changed files with 50 additions and 23 deletions
+41 -6
View File
@@ -20,15 +20,50 @@ interface TelegramFileInfo {
export const forwardToStorage = async (
fileChunk: any,
fileName: string,
forceDocument = false,
fileType: string,
): Promise<ForwardResult> => {
try {
const caption = forceDocument ? `📁 ${fileName}` : fileName;
const filePayload = { source: fileChunk, filename: fileName };
const result: any = forceDocument
? await bot.telegram.sendDocument(config.storageChatId, filePayload, { caption })
: await bot.telegram.sendPhoto(config.storageChatId, filePayload, { caption });
const uploadedFile = forceDocument ? result.document : result.photo?.slice(-1)[0];
let result: any;
if (fileType === 'photo') {
result = await bot.telegram.sendPhoto(config.storageChatId, filePayload, {
caption: fileName,
});
} else if (fileType === 'audio') {
result = await bot.telegram.sendAudio(config.storageChatId, filePayload, {
caption: fileName,
});
} else if (fileType === 'video') {
result = await bot.telegram.sendVideo(config.storageChatId, filePayload, {
caption: fileName,
});
} else if (fileType === 'voice') {
result = await bot.telegram.sendVoice(config.storageChatId, filePayload, {
caption: fileName,
});
} else if (fileType === 'animation') {
result = await bot.telegram.sendAnimation(config.storageChatId, filePayload, {
caption: fileName,
});
} else if (fileType === 'sticker') {
result = await bot.telegram.sendSticker(config.storageChatId, filePayload);
} else {
result = await bot.telegram.sendDocument(config.storageChatId, filePayload, {
caption: `📁 ${fileName}`,
});
}
let uploadedFile: any;
if (result.document) uploadedFile = result.document;
else if (result.photo) uploadedFile = result.photo?.slice(-1)[0];
else if (result.video) uploadedFile = result.video;
else if (result.audio) uploadedFile = result.audio;
else if (result.voice) uploadedFile = result.voice;
else if (result.animation) uploadedFile = result.animation;
else if (result.sticker) uploadedFile = result.sticker;
else if (result.video_note) uploadedFile = result.video_note;
else uploadedFile = result[fileType];
logger.info('File forwarded to storage', { fileName, message: result.message_id });