I want to use pyTelegramBotAPI (or any other non-async Python library) for a bot that has to monitor messages in a chat and to reply to messages that got a reaction.
For example, in 2 hours after I sent my message somebody reacts the message — my bot has to intercept it and send a reply to my message, let it be “Your messages got a reaction — ✅”.
How to do this? I am learning Python and can’t handle Telegram API documentation, may anybody give me an example how to do this?
I have found something like a documentation for handling reaction: https://core.telegram.org/bots/api#reactiontype
And I have found a decorator to the pyTelegramBotAPI:
@bot.message_reaction_handler()
But I can’t get them together.
The following 2 functions are from examples of pyTelegramBotAPI’s developer, the last one was created by me — and it doesn’t work:
bot = telebot.TeleBot(TOKEN, parse_mode=None)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
@bot.message_handler(func=lambda message: True)
def echo_all(message):
bot.reply_to(message, message.text)
@bot.message_reaction_handler(func=lambda reaction: True)
def handle_reaction(reaction):
print("I see the reaction")
chat_id = reaction.chat.id
message_id = reaction.message.message_id
bot.send_message(chat_id, f"Thank you for your reaction to message {message_id}!")
bot.infinity_polling()
Sherlock440 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.