Skip to content

Commit 8ef89ac

Browse files
committed
fix(telegram): improve error messages for 403 bot not member errors
- Detect 403 'bot is not a member' errors specifically - Provide actionable guidance for users to fix the issue - Fixes #48273 where outbound sendMessage fails with 403 Root cause: When a Telegram bot tries to send a message to a channel/group it's not a member of, the API returns 403 'bot is not a member of the channel chat'. The error message was not clear about how to fix this. Fix: 1. Detect 403 errors in wrapTelegramChatNotFoundError 2. Provide clear error message explaining the issue 3. Suggest adding the bot to the channel/group
1 parent e1f759f commit 8ef89ac

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

extensions/telegram/src/send.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,20 @@ function createTelegramRequestWithDiag(params: {
491491
}
492492

493493
function wrapTelegramChatNotFoundError(err: unknown, params: { chatId: string; input: string }) {
494-
if (!CHAT_NOT_FOUND_RE.test(formatErrorMessage(err))) {
494+
const errorMsg = formatErrorMessage(err);
495+
496+
// Check for 403 "bot is not a member" error
497+
if (/403.*bot.*not.*member|bot.*blocked/i.test(errorMsg)) {
498+
return new Error(
499+
[
500+
`Telegram send failed: bot is not a member of the chat (chat_id=${params.chatId}).`,
501+
"Fix: Add the bot to the channel/group, or ensure it has not been removed/blocked.",
502+
`Input was: ${JSON.stringify(params.input)}.`,
503+
].join(" "),
504+
);
505+
}
506+
507+
if (!CHAT_NOT_FOUND_RE.test(errorMsg)) {
495508
return err;
496509
}
497510
return new Error(

0 commit comments

Comments
 (0)