jsontelegramtelegram-botchatbot

How to Copy Messages from Forum Topics to Users Using Telegram API?


I'm working on a messaging system where I need to copy messages from forum topics to users using the Telegram API. According to the official Telegram documentation, in CopyMessage request there's only one message_thread_id key, which seems to be working only for copying messages from users to forum topics, not the other way around. How can I use the Telegram API to copy messages from forum topics to users, given that the message_thread_id key seems to work only for user-to-topic messages? Any help or insights into this would be greatly appreciated.

Here's a sample JSON request for copying a message:

{
  "chat_id": 1106660938,
  "message_thread_id": 2,
  "from_chat_id": "-1002213908537",
  "message_id": 32
}

In this structure:

this request(if all data is correct) result in 400 stating: Bad Request: message thread not found

Additional Information:

Thank you in advance for your help!


Solution

  • Actually, you don't have to specify the message_thread_id if you are copying the message to a private chat.

    The from_chat_id and the message_id can be together used to uniquely identify the message inside the Forum topic.

    So you just need to call the copyMessage method with these parameters:

    {
      "chat_id": 1106660938,
      "from_chat_id": -1002213908537,
      "message_id": 32
    }
    

    Why did I get that error?

    It's because private chats don't have threads. The message_thread_id is considered only for the destination chat. Since, the destination chat (specified with the chat_id) is of a user's private chat with the bot it do not have threads. Hence, raising the error:

    400: Bad Request: message thread not found
    

    Hope this helps :)