From cbe762b92d57fef9585a49497767ad7c7dc7e162 Mon Sep 17 00:00:00 2001 From: alex <9151956053@mail.ru> Date: Sat, 18 Jan 2025 21:51:38 +0300 Subject: [PATCH 1/2] I noticed that the onSuccessfulPayment method is not available in the current version of the tgbot-cpp library. This makes it challenging to handle successful payment events directly using the library. Could you let me know if there are any plans to add this method in future updates? If yes, when can we expect it to be implemented? Thank you for your work on this library, and I look forward to your response! Best regards, --- CMakeLists.txt | 2 ++ include/tgbot/EventBroadcaster.h | 17 +++++++++++++++++ src/EventHandler.cpp | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 627af9c0c..e801c9344 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.10.2) project(TgBot) +set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake") + if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) # find_package() uses _ROOT variables endif() diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h index 8773f3532..be8858942 100644 --- a/include/tgbot/EventBroadcaster.h +++ b/include/tgbot/EventBroadcaster.h @@ -43,6 +43,7 @@ friend EventHandler; typedef std::function PollAnswerListener; typedef std::function ChatMemberUpdatedListener; typedef std::function ChatJoinRequestListener; + typedef std::function SuccessfulPaymentListener; /** * @brief Registers listener which receives new incoming message of any kind - text, photo, sticker, etc. @@ -202,6 +203,16 @@ friend EventHandler; _onChatJoinRequestListeners.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. + * + * @param listener Listener. + */ + inline void onSuccessfulPayment(const SuccessfulPaymentListener& listener) { + _onSuccessfulPaymentListeners.push_back(listener); + } + private: template inline void broadcast(const std::vector& listeners, const ObjectType object) const { @@ -278,6 +289,10 @@ friend EventHandler; broadcast(_onChatJoinRequestListeners, result); } + inline void broadcastSuccessfulPayment(const SuccessfulPayment::Ptr& payment) const { + broadcast(_onSuccessfulPaymentListeners, payment); + } + std::vector _onAnyMessageListeners; std::unordered_map _onCommandListeners; std::vector _onUnknownCommandListeners; @@ -293,6 +308,8 @@ friend EventHandler; std::vector _onMyChatMemberListeners; std::vector _onChatMemberListeners; std::vector _onChatJoinRequestListeners; + std::vector _onSuccessfulPaymentListeners; + }; } diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index 1a6ed400b..a19e7f4a2 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -72,6 +72,10 @@ void EventHandler::handleMessage(const Message::Ptr& message) const { } else { _broadcaster.broadcastNonCommandMessage(message); } + + if (message->successfulPayment != nullptr) { + _broadcaster.broadcastSuccessfulPayment(message->successfulPayment); + } } } From 61a691e7ed0dc620e2b8c465fd77b8e4e753d4a6 Mon Sep 17 00:00:00 2001 From: alex <9151956053@mail.ru> Date: Sat, 18 Jan 2025 22:13:50 +0300 Subject: [PATCH 2/2] I removed the extra additions in CMaleList.txt and added #include "tgbot/types/SuccessfulPayment.h" --- CMakeLists.txt | 2 -- include/tgbot/EventBroadcaster.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e801c9344..627af9c0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(TgBot) -set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake") - if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) # find_package() uses _ROOT variables endif() diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h index be8858942..98c048188 100644 --- a/include/tgbot/EventBroadcaster.h +++ b/include/tgbot/EventBroadcaster.h @@ -12,6 +12,7 @@ #include "tgbot/types/PollAnswer.h" #include "tgbot/types/ChatMemberUpdated.h" #include "tgbot/types/ChatJoinRequest.h" +#include "tgbot/types/SuccessfulPayment.h" #include #include