Closed TheNeedful-DO closed 2 months ago
I think I see a solution to my problem.
There exists a variable allowed_updates
Including this variable when instantiating the bot should allow the message_reaction
event to be properly parsed instead of as an edited_message
event.
My code now looks like this:
allowed_updates = ["message",
"edited_message",
"message_reaction",
"inline_query",
"chosen_inline_result",
"callback_query"]
Telegram::Bot::Client.run(token, allowed_updates: allowed_updates, logger: Logger.new($stderr)) do |bot|
Telegram API list of allowed_update
types:
https://core.telegram.org/bots/api#getupdates
I will continue working on this tomorrow and update my results. I think it's going to work 🤞 and if so I will close this issue.
Here is my solution.
bot.listen do |message|
# ignore reactions
next if bot.api.getUpdates.map{|update| !update.message_reaction.nil?}.any?
This code works by scanning the message for a reaction which consists of two update events. The method bot.api.getUpdates
fetches the current update(s). If any of the updates is a Message Reaction, the message
is skipped by way of the next
method.
Picture shows log of the two parts to a Message Reaction Update
My solution feels a little sloppy but it seems good enough for now.
Previous solution is unreliable.
Now skipping all message edits. This is non-ideal but the only solution I see at this time.
next unless bot.api.getUpdates[0].edited_message.nil?
When a user reacts to an old message the bot interprets this as an incoming message from the original sender.
This occurs in chatrooms but not in direct message.
Reacting to recent messages does not trigger the behavior. I don't know how old the message must be. At least hours or days old maybe.
To reproduce:
In a chatroom, react to an old bot command message (i.e Thumbs Up 👍)
Screenshot shows reacting to an old bot command message and the bot logs the action as an "Incoming message"