Skip to content

fix(telegram): improve error messages for 403 bot not member errors#48650

Closed
w-sss wants to merge 3 commits intoopenclaw:mainfrom
w-sss:fix/telegram-403-error-v2
Closed

fix(telegram): improve error messages for 403 bot not member errors#48650
w-sss wants to merge 3 commits intoopenclaw:mainfrom
w-sss:fix/telegram-403-error-v2

Conversation

@w-sss
Copy link
Copy Markdown
Contributor

@w-sss w-sss commented Mar 17, 2026

Summary

Fixes #48273 - Telegram outbound sendMessage fails with 403 error

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

Testing

  • Verified error message is clear and actionable
  • No breaking changes to existing error handling
  • Other error types unchanged

Related Issue

Fixes #48273

@openclaw-barnacle openclaw-barnacle bot added channel: telegram Channel integration: telegram size: XS labels Mar 17, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 17, 2026

Greptile Summary

This PR improves error messaging in the Telegram send.ts extension by detecting 403 "bot is not a member" and "bot was blocked" errors and surfacing a clear, actionable message instead of a generic failure. The change is small and well-scoped, but contains a regex operator-precedence bug that needs to be fixed before merging.

Key issues:

  • Logic bug (line 497): The regex /403.*bot.*not.*member|bot.*blocked/i has two alternations due to | precedence — the second branch bot.*blocked has no 403 prefix, so it can trigger the new error message for non-403 errors. This should be /403.*(bot.*not.*member|bot.*blocked)/i.
  • Style concern (lines 499–503): The error message says "bot is not a member" and suggests adding the bot to a channel/group, which is misleading for the "bot was blocked by the user" DM scenario captured by the second alternation.

Confidence Score: 3/5

  • Mostly safe but has a regex precedence bug that can cause incorrect error messages for non-403 errors.
  • The change is small and targeted, touching only error message formatting. However, the regex alternation bug means bot.*blocked can match any error containing those words regardless of HTTP status, which would misclassify unrelated errors and replace potentially more informative messages with a misleading "not a member" message. This is a real correctness issue that should be fixed before merge.
  • extensions/telegram/src/send.ts — specifically the regex on line 497.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/telegram/src/send.ts
Line: 497

Comment:
**Regex alternation precedence matches non-403 errors**

Due to how regex `|` alternation works, this pattern has two alternatives:
1. `403.*bot.*not.*member`
2. `bot.*blocked`

The second alternative has no `403` prefix requirement, meaning **any** error message that contains `"bot"` followed by `"blocked"` will match this branch — even if it's a 404, 500, or some other non-403 error. This would incorrectly return the "bot is not a member" message for unrelated errors.

The fix is to group the two alternatives and require `403` for both:

```suggestion
  if (/403.*(bot.*not.*member|bot.*blocked)/i.test(errorMsg)) {
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/telegram/src/send.ts
Line: 499-503

Comment:
**Misleading fix suggestion for "bot was blocked" case**

The regex matches two distinct Telegram 403 scenarios:
- `"bot is not a member of the channel chat"` — bot was never added to the channel/group.
- `"bot was blocked by the user"` — a user in a DM has blocked the bot.

For the second case, the error message `"bot is not a member of the chat"` and the suggestion `"Add the bot to the channel/group"` are misleading — in a blocked-by-user DM context, adding the bot to a group is not the right fix.

Consider branching the two cases, or at minimum broadening the error text to cover both scenarios, e.g.:

```suggestion
        `Telegram send failed: bot is not a member of the chat or has been blocked (chat_id=${params.chatId}).`,
        "Fix: Add the bot to the channel/group, ensure it has not been removed, or ask the user to unblock the bot.",
        `Input was: ${JSON.stringify(params.input)}.`,
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 8ef89ac

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ef89acee4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb2b52ab2d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

w-sss added 2 commits March 17, 2026 21:07
- Detect 403 'bot is not a member' errors specifically
- Provide actionable guidance for users to fix the issue
- Fixes openclaw#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
- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback
@w-sss w-sss force-pushed the fix/telegram-403-error-v2 branch from bb2b52a to e9c69ff Compare March 17, 2026 13:11
w-sss pushed a commit to w-sss/openclaw that referenced this pull request Mar 21, 2026
- Detect 403 'bot is not a member' and 'bot was blocked' errors
- Provide actionable guidance for users to fix the issue
- Group regex alternatives correctly: /403.*(bot.*not.*member|bot.*blocked)/i
- Fixes openclaw#48273

Addresses Greptile/Codex review feedback on PR openclaw#48650
- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650
w-sss pushed a commit to w-sss/openclaw that referenced this pull request Mar 23, 2026
- Detect 403 'bot is not a member' and 'bot was blocked' errors
- Provide actionable guidance for users to fix the issue
- Group regex alternatives correctly: /403.*(bot.*not.*member|bot.*blocked)/i
- Fixes openclaw#48273

Addresses Greptile/Codex review feedback on PR openclaw#48650
@w-sss
Copy link
Copy Markdown
Contributor Author

w-sss commented Mar 23, 2026

📊 CI 状态说明

当前失败: extension-fast (telegram), macos

原因分析:

  • 非本 PR 引入 - telegram 和 macos 测试失败是仓库已有问题
  • 本 PR 修复内容: 改进 Telegram 403 错误消息(bot not member/blocked)
  • check 通过 - 代码规范检查通过

建议: 可以安全合并,CI 失败与本 PR 无关。

@w-sss
Copy link
Copy Markdown
Contributor Author

w-sss commented Mar 24, 2026

🔧 CI 修复进展

已创建 PR #53245 修复仓库依赖问题:

  • 修复 pnpm 缓存过期导致的依赖缺失
  • 解决 check, channels, extensions 测试失败

状态: 等待维护者审核合并

合并后本 PR 的 CI 将自动变绿。

@w-sss
Copy link
Copy Markdown
Contributor Author

w-sss commented Mar 24, 2026

🔧 CI 修复更新

已创建新的 CI 修复 PR #53283(之前的 #53245 因 PR 数量限制被关闭):

  • 修复 pnpm 缓存过期导致的依赖缺失
  • 解决 check, channels, extensions 测试失败

状态: 等待维护者审核合并

合并后本 PR 的 CI 将自动变绿。

@w-sss w-sss closed this Mar 24, 2026
@w-sss w-sss deleted the fix/telegram-403-error-v2 branch March 24, 2026 10:42
w-sss added a commit to w-sss/openclaw that referenced this pull request Mar 24, 2026
- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650
obviyus pushed a commit to w-sss/openclaw that referenced this pull request Mar 25, 2026
- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650
obviyus pushed a commit to w-sss/openclaw that referenced this pull request Mar 25, 2026
- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650
obviyus added a commit that referenced this pull request Mar 25, 2026
…w-sss)

* 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

* fix(telegram): fix regex precedence for 403 error detection

- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback

* fix(telegram): correct regex alternation precedence for 403 errors

- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR #48650

* fix(telegram): add 'bot was kicked' to 403 error regex and message

* fix(telegram): preserve membership delivery errors

* fix: improve Telegram 403 membership delivery errors (#53635) (thanks @w-sss)

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
artemgetmann pushed a commit to artemgetmann/openclaw that referenced this pull request Mar 25, 2026
… (thanks @w-sss)

* 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 openclaw#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

* fix(telegram): fix regex precedence for 403 error detection

- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback

* fix(telegram): correct regex alternation precedence for 403 errors

- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650

* fix(telegram): add 'bot was kicked' to 403 error regex and message

* fix(telegram): preserve membership delivery errors

* fix: improve Telegram 403 membership delivery errors (openclaw#53635) (thanks @w-sss)

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
netandreus pushed a commit to netandreus/openclaw that referenced this pull request Mar 25, 2026
… (thanks @w-sss)

* 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 openclaw#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

* fix(telegram): fix regex precedence for 403 error detection

- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback

* fix(telegram): correct regex alternation precedence for 403 errors

- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650

* fix(telegram): add 'bot was kicked' to 403 error regex and message

* fix(telegram): preserve membership delivery errors

* fix: improve Telegram 403 membership delivery errors (openclaw#53635) (thanks @w-sss)

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
npmisantosh pushed a commit to npmisantosh/openclaw that referenced this pull request Mar 25, 2026
… (thanks @w-sss)

* 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 openclaw#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

* fix(telegram): fix regex precedence for 403 error detection

- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback

* fix(telegram): correct regex alternation precedence for 403 errors

- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650

* fix(telegram): add 'bot was kicked' to 403 error regex and message

* fix(telegram): preserve membership delivery errors

* fix: improve Telegram 403 membership delivery errors (openclaw#53635) (thanks @w-sss)

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
fuller-stack-dev pushed a commit to fuller-stack-dev/openclaw that referenced this pull request Mar 25, 2026
… (thanks @w-sss)

* 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 openclaw#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

* fix(telegram): fix regex precedence for 403 error detection

- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback

* fix(telegram): correct regex alternation precedence for 403 errors

- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650

* fix(telegram): add 'bot was kicked' to 403 error regex and message

* fix(telegram): preserve membership delivery errors

* fix: improve Telegram 403 membership delivery errors (openclaw#53635) (thanks @w-sss)

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
jacobtomlinson pushed a commit to jacobtomlinson/openclaw that referenced this pull request Mar 25, 2026
… (thanks @w-sss)

* 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 openclaw#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

* fix(telegram): fix regex precedence for 403 error detection

- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback

* fix(telegram): correct regex alternation precedence for 403 errors

- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650

* fix(telegram): add 'bot was kicked' to 403 error regex and message

* fix(telegram): preserve membership delivery errors

* fix: improve Telegram 403 membership delivery errors (openclaw#53635) (thanks @w-sss)

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
artemgetmann pushed a commit to artemgetmann/openclaw that referenced this pull request Mar 26, 2026
… (thanks @w-sss)

* 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 openclaw#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

* fix(telegram): fix regex precedence for 403 error detection

- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback

* fix(telegram): correct regex alternation precedence for 403 errors

- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650

* fix(telegram): add 'bot was kicked' to 403 error regex and message

* fix(telegram): preserve membership delivery errors

* fix: improve Telegram 403 membership delivery errors (openclaw#53635) (thanks @w-sss)

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
godlin-gh pushed a commit to YouMindInc/openclaw that referenced this pull request Mar 27, 2026
… (thanks @w-sss)

* 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 openclaw#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

* fix(telegram): fix regex precedence for 403 error detection

- Group alternatives correctly: /403.*(bot.*not.*member|bot was blocked)/i
- Require 403 for both alternatives (previously bot.*blocked matched any error)
- Update error message to cover both scenarios
- Fixes Greptile review feedback

* fix(telegram): correct regex alternation precedence for 403 errors

- Fix: /403.*(bot.*not.*member|bot was blocked)/ → /403.*(bot.*not.*member|bot.*blocked)/
- Ensures 403 requirement applies to both alternatives
- Fixes Greptile review comment on PR openclaw#48650

* fix(telegram): add 'bot was kicked' to 403 error regex and message

* fix(telegram): preserve membership delivery errors

* fix: improve Telegram 403 membership delivery errors (openclaw#53635) (thanks @w-sss)

---------

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram outbound sendMessage fails with "403 bot is not a member" despite working bot token and inbound messages working

1 participant