Skip to content

fix: ignore commands for other bots, end commands at line breaks, key FSM by sender chat - #47

Merged
darxnet merged 1 commit into
mainfrom
fix/command-addressing-fsm-sender
Nov 12, 2026
Merged

darxnet merged 1 commit into
mainfrom
fix/command-addressing-fsm-sender

Conversation

@darxnet

@darxnet darxnet commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Three routing/FSM bugs found while checking the issues competitors fixed this week (aiogram#1997, go-telegram/bot#304, node-telegram-bot-api#1382, python-telegram-bot#5398).

Changes

  • Commands for other bots. /start@other_bot no longer reaches HandleCommand, FilterCommand or ctx.Command(): in a group with several bots, an admin bot (or one with privacy mode off) answered commands meant for the others. The username comes from Client.Me, fetched once on the first @-addressed command; if getMe fails, the command is accepted as before. A command for another bot is an ordinary message for this one (HandleOnMessage still sees it).
  • Line breaks. A command ends at any whitespace, so /start\npayload is routed to /start; Message.Payload and CallbackQuery.Payload split at a line break or tab, as Args already did.
  • FSM key for messages sent on behalf of a chat. Anonymous group admins, users writing as a channel and automatic forwards all arrive from one service user (GroupAnonymousBot, Channel_Bot), so every such sender shared one state. The state is now keyed by sender_chat; callback queries keep the presser's id. States previously stored under those service users are no longer found.
  • FuzzEntityText guards EntityText against out-of-range entity offsets and lengths (2.6M execs, no panic).

Checked and left as is: the per-chat Throttle waits before the global WithRPS token is taken in the transport, so throttled chats do not consume global slots (the node-telegram-bot-api#1390 bug).

Testing

make lint and make test pass locally; new tests in addressing_test.go, the existing @bot tests now use a canned getMe instead of the network.

… FSM by sender chat

- "/start@other_bot" no longer reaches HandleCommand, FilterCommand or
  Context.Command: in a group with several bots an admin bot answered
  commands meant for the others. The username comes from Client.Me,
  fetched once on the first @-addressed command; if it cannot be fetched
  the command is accepted as before.
- A command ends at any whitespace: "/start\npayload" is routed to
  /start, and Message.Payload/CallbackQuery.Payload split at a line break
  or tab as Args already did.
- The FSM state of a message sent on behalf of a chat (anonymous group
  administrators, users writing as a channel, automatic forwards) is
  keyed by that chat: they all come from one service user, so every such
  sender shared one state. Callback queries keep the presser's id.
- FuzzEntityText guards EntityText against out-of-range entities.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@darxnet
darxnet force-pushed the fix/command-addressing-fsm-sender branch from 5084a24 to c1c8dd6 Compare November 12, 2026 10:51
@darxnet
darxnet merged commit 5e12e3b into main Nov 12, 2026
11 checks passed
@darxnet
darxnet deleted the fix/command-addressing-fsm-sender branch November 12, 2026 11:10
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.

1 participant