From cbb1b33ad32b846b307120f0e22955f05b82e9d5 Mon Sep 17 00:00:00 2001 From: Legolase Date: Fri, 28 Nov 2025 14:29:34 +0300 Subject: [PATCH] feat: add message_reaction update and message_reaction_count update support --- include/tgbot/EventBroadcaster.h | 30 ++++++++++++++++++++++++++++++ src/EventHandler.cpp | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h index 2148d14c..6c609832 100644 --- a/include/tgbot/EventBroadcaster.h +++ b/include/tgbot/EventBroadcaster.h @@ -12,6 +12,8 @@ #include "tgbot/types/PollAnswer.h" #include "tgbot/types/ChatMemberUpdated.h" #include "tgbot/types/ChatJoinRequest.h" +#include "tgbot/types/MessageReactionUpdated.h" +#include "tgbot/types/MessageReactionCountUpdated.h" #include "tgbot/types/SuccessfulPayment.h" #include @@ -44,6 +46,8 @@ friend EventHandler; typedef std::function PollAnswerListener; typedef std::function ChatMemberUpdatedListener; typedef std::function ChatJoinRequestListener; + typedef std::function MessageReactionUpdatedListener; + typedef std::function MessageReactionCountUpdatedListener; typedef std::function SuccessfulPaymentListener; /** @@ -204,6 +208,22 @@ friend EventHandler; _onChatJoinRequestListeners.push_back(listener); } + /** + * @brief Registers listener which receives new incoming message reaction update event. + * @param listener Listener. + */ + inline void onMessageReaction(const MessageReactionUpdatedListener& listener) { + _onMessageReactionUpdatedListener.push_back(listener); + } + + /** + * @brief Registers listener which receives new incoming message reaction count update event. + * @param listener Listener. + */ + inline void onMessageReactionCount(const MessageReactionCountUpdatedListener& listener) { + _onMessageReactionCountUpdatedListener.push_back(listener); + } + /** * @brief Registers listener which receives information about successful payments. * This listener is triggered when a successful payment is received by the bot. @@ -293,6 +313,14 @@ friend EventHandler; broadcast(_onChatJoinRequestListeners, result); } + inline void broadcastMessageReactionUpdated(const MessageReactionUpdated::Ptr& messageReaction) const { + broadcast(_onMessageReactionUpdatedListener, messageReaction); + } + + inline void broadcastMessageReactionCountUpdated(const MessageReactionCountUpdated::Ptr& messageReactionCount) const { + broadcast(_onMessageReactionCountUpdatedListener, messageReactionCount); + } + inline void broadcastSuccessfulPayment(const Message::Ptr& message) const { if (!message || !message->successfulPayment) { return; @@ -318,6 +346,8 @@ friend EventHandler; std::vector _onMyChatMemberListeners; std::vector _onChatMemberListeners; std::vector _onChatJoinRequestListeners; + std::vector _onMessageReactionUpdatedListener; + std::vector _onMessageReactionCountUpdatedListener; std::vector _onSuccessfulPaymentListeners; }; diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index 02ad31f1..5bffce8a 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -45,6 +45,12 @@ void EventHandler::handleUpdate(const Update::Ptr& update) const { if (update->chatJoinRequest != nullptr) { _broadcaster.broadcastChatJoinRequest(update->chatJoinRequest); } + if (update->messageReaction != nullptr) { + _broadcaster.broadcastMessageReactionUpdated(update->messageReaction); + } + if (update->messageReactionCount != nullptr) { + _broadcaster.broadcastMessageReactionCountUpdated(update->messageReactionCount); + } } void EventHandler::handleMessage(const Message::Ptr& message) const {