Replies and Topics
message.reply_to_message is not enough for production reply logic.
Valid reply semantics
In forum-enabled chats, replying to the topic starter is often not a meaningful reply target for command logic.
A practical rule:
- if there is no
reply_to_message, it is not a reply - outside forum topics, any reply is valid
- inside forum topics, ignore replies where
reply_to_message.message_id == message.message_thread_id
Use scripts/topic_aware_reply_helpers.py.
Thread id normalization
message_thread_id needs normalization because Telegram uses it in several different ways:
- real forum topics
- private-message topics
- linked discussion groups for channel comments
- pseudo-thread ids in non-forum chats when replying to a bot
Useful rules:
- in forum chats, only return
message_thread_idfor real topic messages - in linked discussion groups, keep
message_thread_idonly when it represents a real discussion thread - ignore pseudo-thread ids created by bot replies in plain chats
- when needed, prefer the current message thread and fallback to the replied message thread
Reply filters
For routers, keep reusable reply filter expressions rather than repeating raw F.reply_to_message checks everywhere.
Two useful variants:
IS_REPLY: true only for meaningful repliesFILTER_REPLY_OR_NONE: allow no reply or a topic-root reply, but exclude arbitrary reply-to-user cases