telegramtelegram-bottelegram-api

Check if given telegram topic link is valid (Telegram Bot API)


So, I have a topic link given by a user. I want to verify if that topic link is correct or not using Telegram Bot API


Solution

  • As of now, there's no API methods in Telegram Bot API to know if the link actually leads to a existing topic in a Forum chat.


    But, a workaround I can suggest is you can try calling a send method such as sendMessage with passing the thread id. Remember, your bot must be in the specified chat (and need necessary permissions - if required) to send message.

    If the topic does not exist, you will receive a exception from Telegram Bot API as follows:

    {
      "ok": false,
      "error_code": 400,
      "description": "Bad Request: message thread not found"
    }
    

    So the workaround is something like:

    1. Send a test message
    2. If it fails with the specified exception the topic does not exist
    3. If bot is able to send message the topic exist, optionally, you can simply use the deleteMessage method to delete the test message.

    Hope this helps!