fix(gateway): strip @botname suffix from Telegram slash command parsing - #3541
Closed
Kathie-yu wants to merge 1 commit into
Closed
fix(gateway): strip @botname suffix from Telegram slash command parsing#3541Kathie-yu wants to merge 1 commit into
Kathie-yu wants to merge 1 commit into
Conversation
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>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Telegram clients append the bot username to slash commands (e.g.
/model@MyBot_bot).get_command()does not strip this suffix, soresolve_command()fails to match and the command falls through to the agent as plain text.This affects both group chats and DMs:
@botnameto disambiguate between multiple bots@botnamein private chats (observed on Telegram Desktop and certain mobile client versions)All slash commands are affected — including the new
/modelscommand proposed in #3500 (#3502, #3503), which would also fail in group chats and DMs without this fix.Root cause
MessageEvent.get_command()ingateway/platforms/base.pyextracts the command withtext.split()[0][1:]— this returnsmodel@mybot_botinstead ofmodel. Sinceresolve_command("model@mybot_bot")returnsNone, the message bypasses command dispatch entirely.The
@usernamesuffix 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 inget_command()).This is safe for all platforms — only Telegram uses the
@suffixconvention, and no valid command name contains@.How to test
/model@YourBot_bot— should now be recognized as/model/help@YourBot_bot— should show help@botnamesuffix still work normally in both chat typesPlatform tested
Linux, Telegram gateway (group chats and DMs)
Related to #3500