Skip to content

fix(gateway): strip @botname suffix from Telegram slash command parsing - #3541

Closed
Kathie-yu wants to merge 1 commit into
NousResearch:mainfrom
Kathie-yu:fix/telegram-botname-command-parsing
Closed

fix(gateway): strip @botname suffix from Telegram slash command parsing#3541
Kathie-yu wants to merge 1 commit into
NousResearch:mainfrom
Kathie-yu:fix/telegram-botname-command-parsing

Conversation

@Kathie-yu

@Kathie-yu Kathie-yu commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Telegram clients append the bot username to slash commands (e.g. /model@MyBot_bot). get_command() does not strip this suffix, so resolve_command() fails to match and the command falls through to the agent as plain text.

This affects both group chats and DMs:

  • Group chats / Supergroups: Telegram Bot API always appends @botname to disambiguate between multiple bots
  • DMs: Some Telegram clients also append @botname in private chats (observed on Telegram Desktop and certain mobile client versions)

All slash commands are affected — including the new /models command proposed in #3500 (#3502, #3503), which would also fail in group chats and DMs without this fix.

Root cause

MessageEvent.get_command() in gateway/platforms/base.py extracts the command with text.split()[0][1:] — this returns model@mybot_bot instead of model. Since resolve_command("model@mybot_bot") returns None, the message bypasses command dispatch entirely.

The @username suffix is a standard Telegram Bot API convention — it is guaranteed in group chats and common in DMs depending on client implementation.

Fix

gateway/platforms/base.py: Strip everything after @ in the extracted command name (3-line change in get_command()).

cmd = parts[0][1:].lower()
if cmd and "@" in cmd:
    cmd = cmd.split("@")[0]

This is safe for all platforms — only Telegram uses the @suffix convention, and no valid command name contains @.

How to test

  1. In a group chat: send /model@YourBot_bot — should now be recognized as /model
  2. In a DM: send /help@YourBot_bot — should show help
  3. Verify commands without @botname suffix still work normally in both chat types

Platform tested

Linux, Telegram gateway (group chats and DMs)

Related to #3500

Telegram clients append the bot username to slash commands in group chats
(e.g. /model@MyBot_bot). get_command() extracts the raw string including
the @suffix, so resolve_command("model@mybot_bot") returns None and the
command falls through to the agent as plain text.

Strip everything after @ in the extracted command name. This is safe for
all platforms — only Telegram uses the @suffix convention, and no valid
command name contains @.

Amp-Thread-ID: https://ampcode.com/threads/T-019d34eb-b4d4-7204-8b4d-221cc211ac9b
Co-authored-by: Amp <amp@ampcode.com>
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #3581 using #3550's implementation (which included tests). You were first to submit this fix — both contributors credited. Thanks!

@teknium1 teknium1 closed this Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants