fix(telegram): notify user when media exceeds size limit
When a file exceeds mediaMaxMb, send a friendly error message
instead of silently dropping the upload.
---
🤖 Authored by Jarvis (AI assistant)
This commit is contained in:
@@ -483,12 +483,30 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const media = await resolveMedia(
|
let media: Awaited<ReturnType<typeof resolveMedia>> = null;
|
||||||
ctx,
|
try {
|
||||||
mediaMaxBytes,
|
media = await resolveMedia(
|
||||||
opts.token,
|
ctx,
|
||||||
opts.proxyFetch,
|
mediaMaxBytes,
|
||||||
);
|
opts.token,
|
||||||
|
opts.proxyFetch,
|
||||||
|
);
|
||||||
|
} catch (mediaErr) {
|
||||||
|
const errMsg = String(mediaErr);
|
||||||
|
if (errMsg.includes("exceeds") && errMsg.includes("MB limit")) {
|
||||||
|
const limitMb = Math.round(mediaMaxBytes / (1024 * 1024));
|
||||||
|
await bot.api
|
||||||
|
.sendMessage(
|
||||||
|
chatId,
|
||||||
|
`⚠️ File too large. Maximum size is ${limitMb}MB.`,
|
||||||
|
{ reply_to_message_id: msg.message_id },
|
||||||
|
)
|
||||||
|
.catch(() => {});
|
||||||
|
logger.warn({ chatId, error: errMsg }, "media exceeds size limit");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw mediaErr;
|
||||||
|
}
|
||||||
const allMedia = media
|
const allMedia = media
|
||||||
? [{ path: media.path, contentType: media.contentType }]
|
? [{ path: media.path, contentType: media.contentType }]
|
||||||
: [];
|
: [];
|
||||||
|
|||||||
Reference in New Issue
Block a user