Search code examples
python-3.xtelegramtelegram-botpython-telegram-bottelebot

Is there any way to create a telegram bot with Telebot library that can drop reactions into messages users send?


Is there any way to create a Telegram Bot with Telebot library that can drop reactions into messages users send?

For example the following image:

Example

I have tried many times but it seems impossible.

I want if when I send a message the bot will drop reaction to my message, I use Telebot library.


Solution

  • I just tried out Telebot library, and it seems like the library is still in development stages, and the setMessageReaction method is not added yet. So, at this moment you cannot add reactions with Telebot library.


    But, anyway, you can still make a simple HTTP request to the following endpoint:

    https://api.telegram.org/bot<TOKEN>/setMessageReaction
    

    With the following data payload:

    {
      "chat_id": 12345,
      "message_id": 123,
      "reaction": [
        {
          "type": "emoji",
          "emoji": "💯"
        }
      ]
    }
    

    Your bot can still add the given reaction to the specified message.

    Note: Make sure to edit the chat_id, message_id and reaction.


    In other words, you can use this method:

    import requests
    
    def set_message_reaction(token: str, emoji: str, chat_id: int, message_id: int):
        url = f"https://api.telegram.org/bot{token}/setMessageReaction"
        
        payload = {
            "chat_id": chat_id,
            "message_id": message_id,
            "reaction": [
                {
                    "type": "emoji",
                    "emoji": emoji
                }
            ]
        }
        
        response = requests.post(url, json=payload)
        
        if response.status_code == 200:
            return response.json()
        else:
            return {"error": response.status_code, "message": response.text}
    
    

    Hope this helps!