Developing Telegram Bots for Forums
Forums are a special kind of group that is split into multiple topics. If your bot works in groups, you should verify that it handles forums correctly.
Technical perspective
A forum is simply a group with a special user interface. You can even open a forum in a regular chat view using the forum menu in the official apps.
Let's discuss how topics work technically:
- When a topic is created, a system message "Topic created" appears
- All replies to this message then fall into the topic
- The topic ID is exactly the same as the system message ID
- The General topic is where all other messages go, and its ID equals 1
Usage
If your bot works in groups, you should consider how it will behave when the group is a forum. For example, when a user sends a command, the bot should answer in the same topic, otherwise the response will appear in the General topic.
python
@dp.message()
async def handle_message(message: types.Message):
if message.chat.type == ChatType.SUPERGROUP and message.message_thread_id:
await message.answer('This is a forum!')
else:
await message.answer('This is not a forum')
Managing topics
Bots can open, edit, and close topics just like users. Depending on the forum settings this may require special admin rights.