Recently Telegram added support for Topics in Groups in Bot API version 6.3 and this support added into python-telegram-bot version 13.15 (please find changelog https://docs.python-telegram-bot.org/en/stable/changelog.html)
Im sending messages like this:
{
"@type": "sendMessage",
"chat_id": "-1001580394181",
"input_message_content": {
"@type": "inputMessageText","text": {
"@type": "formattedText","text": "test", "entities": []
}
}
}
and it works. They added message_thread_id parameter to define to which topic message should be sent. So i added the parameter:
{
"@type": "sendMessage",
"chat_id": "-1001580394181",
"message_thread_id": "20451426304",
"input_message_content": {
"@type": "inputMessageText","text": {
"@type": "formattedText","text": "test", "entities": []
}
}
but message goes to main topic, there’s no error or anything unless i’ll provide incorrect message_thread_id, if so i’m getting message: Code: 400, message: Invalid message thread ID specified
What i’m doing wrong? The id’s are correct i got them from catching the response from sending test message to topic channel.
2
Answers
To send messages to Telegram Forum Topic you need to reply to a message saying
π¬ "Topic" was created
So basically every message you send in telegram topic is just a reply to this original message. You can check this if you view your Forum as Messages.
I, for example, have deleted that message so I:
https://api.telegram.org/bot{token}/getUpdates
message_id
of topic created messageHere is how my message looked like:
So you can take either
message_id
ormessage_thread_id
. In my case they were the same but I am not sure if there is a difference.And now paste this
message_id
as areply_to_message_id
parameter inbot.send_message()
method.bot.send_message(-12345678, 'Message for topic', reply_to_message_id=12345)