diff --git a/README.md b/README.md index 3ec1f740..9e2688df 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,28 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp). ## State -- [x] Telegram Bot API 7.2 -- [ ] [MaybeInaccessibleMessage](https://core.telegram.org/bots/api#maybeinaccessiblemessage) -- [ ] [Message->pinnedMessage](https://core.telegram.org/bots/api#message) -- [ ] [CallbackQuery->message](https://core.telegram.org/bots/api#callbackquery) +This library implements most features from **Telegram Bot API 7.2** with additional features from later versions. + +### Recently Added Features: +- [x] Message Reactions (Bot API 7.x+) + - MessageReactionUpdated event handling + - MessageReactionCountUpdated event handling +- [x] Business Account Integration (Bot API 7.x+) + - BusinessConnection updates + - Business message handling + - Deleted business messages tracking +- [x] Chat Boosts (Bot API 7.x+) + - ChatBoostUpdated events + - ChatBoostRemoved events + +### Known Limitations: +- [ ] [MaybeInaccessibleMessage](https://core.telegram.org/bots/api#maybeinaccessiblemessage) - Planned for future implementation +- [ ] [Message->pinnedMessage](https://core.telegram.org/bots/api#message) - Requires MaybeInaccessibleMessage +- [ ] [CallbackQuery->message](https://core.telegram.org/bots/api#callbackquery) - Requires MaybeInaccessibleMessage - [ ] [Deep Linking](https://core.telegram.org/bots/features#deep-linking) +**Note:** Full Bot API 8.x and 9.x support is planned. Contributions are welcome! + ## Sample diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h index 8773f353..5fc03553 100644 --- a/include/tgbot/EventBroadcaster.h +++ b/include/tgbot/EventBroadcaster.h @@ -12,6 +12,12 @@ #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/BusinessConnection.h" +#include "tgbot/types/BusinessMessagesDeleted.h" +#include "tgbot/types/ChatBoostUpdated.h" +#include "tgbot/types/ChatBoostRemoved.h" #include #include @@ -43,6 +49,12 @@ 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 BusinessConnectionListener; + typedef std::function BusinessMessagesDeletedListener; + typedef std::function ChatBoostUpdatedListener; + typedef std::function ChatBoostRemovedListener; /** * @brief Registers listener which receives new incoming message of any kind - text, photo, sticker, etc. @@ -202,6 +214,101 @@ friend EventHandler; _onChatJoinRequestListeners.push_back(listener); } + /** + * @brief Registers listener which receives message reaction updates. + * + * The bot must be an administrator in the chat and must explicitly specify + * "message_reaction" in the list of allowedUpdates to receive these updates. + * The update isn't received for reactions set by bots. + * + * @param listener Listener. + */ + inline void onMessageReaction(const MessageReactionUpdatedListener& listener){ + _onMessageReactionUpdatedListeners.push_back(listener); + } + + /** + * @brief Registers listener which receives message reaction count updates. + * + * The bot must be an administrator in the chat and must explicitly specify + * "message_reaction_count" in the list of allowedUpdates to receive these updates. + * The updates are grouped and can be sent with delay up to a few minutes. + * + * @param listener Listener. + */ + inline void onMessageReactionCount(const MessageReactionCountUpdatedListener& listener){ + _onMessageReactionCountUpdatedListeners.push_back(listener); + } + + /** + * @brief Registers listener which receives business connection updates. + * + * The bot was connected to or disconnected from a business account, + * or a user edited an existing connection with the bot. + * + * @param listener Listener. + */ + inline void onBusinessConnection(const BusinessConnectionListener& listener){ + _onBusinessConnectionListeners.push_back(listener); + } + + /** + * @brief Registers listener which receives business message updates. + * + * New non-service message from a connected business account. + * + * @param listener Listener. + */ + inline void onBusinessMessage(const MessageListener& listener){ + _onBusinessMessageListeners.push_back(listener); + } + + /** + * @brief Registers listener which receives edited business message updates. + * + * New version of a message from a connected business account. + * + * @param listener Listener. + */ + inline void onEditedBusinessMessage(const MessageListener& listener){ + _onEditedBusinessMessageListeners.push_back(listener); + } + + /** + * @brief Registers listener which receives business messages deleted updates. + * + * Messages were deleted from a connected business account. + * + * @param listener Listener. + */ + inline void onDeletedBusinessMessages(const BusinessMessagesDeletedListener& listener){ + _onDeletedBusinessMessagesListeners.push_back(listener); + } + + /** + * @brief Registers listener which receives chat boost updates. + * + * A chat boost was added or changed. The bot must be an administrator + * in the chat to receive these updates. + * + * @param listener Listener. + */ + inline void onChatBoost(const ChatBoostUpdatedListener& listener){ + _onChatBoostUpdatedListeners.push_back(listener); + } + + /** + * @brief Registers listener which receives removed chat boost updates. + * + * A boost was removed from a chat. The bot must be an administrator + * in the chat to receive these updates. + * + * @param listener Listener. + */ + inline void onRemovedChatBoost(const ChatBoostRemovedListener& listener){ + _onRemovedChatBoostListeners.push_back(listener); + } + private: template inline void broadcast(const std::vector& listeners, const ObjectType object) const { @@ -278,6 +385,38 @@ friend EventHandler; broadcast(_onChatJoinRequestListeners, result); } + inline void broadcastMessageReactionUpdated(const MessageReactionUpdated::Ptr& result) const { + broadcast(_onMessageReactionUpdatedListeners, result); + } + + inline void broadcastMessageReactionCountUpdated(const MessageReactionCountUpdated::Ptr& result) const { + broadcast(_onMessageReactionCountUpdatedListeners, result); + } + + inline void broadcastBusinessConnection(const BusinessConnection::Ptr& result) const { + broadcast(_onBusinessConnectionListeners, result); + } + + inline void broadcastBusinessMessage(const Message::Ptr& message) const { + broadcast(_onBusinessMessageListeners, message); + } + + inline void broadcastEditedBusinessMessage(const Message::Ptr& message) const { + broadcast(_onEditedBusinessMessageListeners, message); + } + + inline void broadcastDeletedBusinessMessages(const BusinessMessagesDeleted::Ptr& result) const { + broadcast(_onDeletedBusinessMessagesListeners, result); + } + + inline void broadcastChatBoostUpdated(const ChatBoostUpdated::Ptr& result) const { + broadcast(_onChatBoostUpdatedListeners, result); + } + + inline void broadcastRemovedChatBoost(const ChatBoostRemoved::Ptr& result) const { + broadcast(_onRemovedChatBoostListeners, result); + } + std::vector _onAnyMessageListeners; std::unordered_map _onCommandListeners; std::vector _onUnknownCommandListeners; @@ -293,6 +432,14 @@ friend EventHandler; std::vector _onMyChatMemberListeners; std::vector _onChatMemberListeners; std::vector _onChatJoinRequestListeners; + std::vector _onMessageReactionUpdatedListeners; + std::vector _onMessageReactionCountUpdatedListeners; + std::vector _onBusinessConnectionListeners; + std::vector _onBusinessMessageListeners; + std::vector _onEditedBusinessMessageListeners; + std::vector _onDeletedBusinessMessagesListeners; + std::vector _onChatBoostUpdatedListeners; + std::vector _onRemovedChatBoostListeners; }; } diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index 3bfb7d39..06f930f6 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -16,6 +16,24 @@ void EventHandler::handleUpdate(const Update::Ptr& update) const { if (update->editedChannelPost != nullptr) { _broadcaster->broadcastEditedMessage(update->editedChannelPost); } + if (update->businessConnection != nullptr) { + _broadcaster->broadcastBusinessConnection(update->businessConnection); + } + if (update->businessMessage != nullptr) { + _broadcaster->broadcastBusinessMessage(update->businessMessage); + } + if (update->editedBusinessMessage != nullptr) { + _broadcaster->broadcastEditedBusinessMessage(update->editedBusinessMessage); + } + if (update->deletedBusinessMessages != nullptr) { + _broadcaster->broadcastDeletedBusinessMessages(update->deletedBusinessMessages); + } + if (update->messageReaction != nullptr) { + _broadcaster->broadcastMessageReactionUpdated(update->messageReaction); + } + if (update->messageReactionCount != nullptr) { + _broadcaster->broadcastMessageReactionCountUpdated(update->messageReactionCount); + } if (update->inlineQuery != nullptr) { _broadcaster->broadcastInlineQuery(update->inlineQuery); } @@ -46,6 +64,12 @@ void EventHandler::handleUpdate(const Update::Ptr& update) const { if (update->chatJoinRequest != nullptr) { _broadcaster->broadcastChatJoinRequest(update->chatJoinRequest); } + if (update->chatBoost != nullptr) { + _broadcaster->broadcastChatBoostUpdated(update->chatBoost); + } + if (update->removedChatBoost != nullptr) { + _broadcaster->broadcastRemovedChatBoost(update->removedChatBoost); + } } void EventHandler::handleMessage(const Message::Ptr& message) const {