diff --git a/.dockerignore b/.dockerignore index e137e9268..95e66c4b6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,5 @@ !samples !src !test -!CMakeLists.txt \ No newline at end of file +!CMakeLists.txt +!CMake \ No newline at end of file diff --git a/CMake/FindJsonCppCustom.cmake b/CMake/FindJsonCppCustom.cmake new file mode 100644 index 000000000..fc43e1254 --- /dev/null +++ b/CMake/FindJsonCppCustom.cmake @@ -0,0 +1,27 @@ +# FindJsonCpp.cmake + +# Try to locate the jsoncpp package using pkg-config +find_package(PkgConfig QUIET) + +if (PKG_CONFIG_FOUND) + pkg_check_modules(JSONCPP_PKG jsoncpp) + + if (JSONCPP_PKG_FOUND) + # Create the jsoncpp imported target + if (NOT TARGET JsonCpp::JsonCpp) + add_library(JsonCpp::JsonCpp SHARED IMPORTED) + set_target_properties(JsonCpp::JsonCpp PROPERTIES + IMPORTED_LOCATION "${JSONCPP_PKG_LIBRARY_DIRS}/libjsoncpp.so" + INTERFACE_INCLUDE_DIRECTORIES "${JSONCPP_PKG_INCLUDE_DIRS}" + ) + + # Optionally, set any additional properties, such as dependencies or version + message(STATUS "Found JsonCpp: ${JSONCPP_PKG_LIBRARY_DIRS}/libjsoncpp.so") + endif() + + else() + message(FATAL_ERROR "Pkg-config found, but JsonCpp not found via pkg-config.") + endif() +else() + message(FATAL_ERROR "Pkg-config not found, cannot locate JsonCpp.") +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 627af9c0c..632b28641 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,17 +37,7 @@ set(SRC_LIST src/net/Url.cpp src/tools/FileTools.cpp src/tools/StringTools.cpp - src/types/BotCommandScope.cpp - src/types/ChatBoostSource.cpp - src/types/ChatMember.cpp - src/types/InlineQueryResult.cpp - src/types/InputFile.cpp - src/types/InputMedia.cpp - src/types/InputMessageContent.cpp - src/types/MenuButton.cpp - src/types/MessageOrigin.cpp - src/types/PassportElementError.cpp - src/types/ReactionType.cpp) + src/types/InputFile.cpp) # libs ## threads @@ -67,6 +57,22 @@ if (CURL_FOUND) add_definitions(-DHAVE_CURL) endif() +## jsoncpp +if (NOT TARGET JsonCpp::JsonCpp) + find_package(jsoncpp) + if (NOT TARGET JsonCpp::JsonCpp) + message(STATUS "Using alternative findjsoncpp") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake") + find_package(JsonCppCustom) + if (NOT TARGET JsonCpp::JsonCpp) + message(FATAL_ERROR "Jsoncpp is not available") + endif() + endif() +endif() +install(FILES CMake/FindJsonCppCustom.cmake + DESTINATION lib/cmake/tgbot-cpp +) + ## boost set(Boost_USE_MULTITHREADED ON) if (ENABLE_TESTS) @@ -86,10 +92,11 @@ set(LIB_LIST ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} + JsonCpp::JsonCpp ) if (CURL_FOUND) - set(LIB_LIST ${LIB_LIST} ${CURL_LIBRARIES}) + set(LIB_LIST ${LIB_LIST} CURL::libcurl) endif() if (WIN32) @@ -101,6 +108,7 @@ add_library(${PROJECT_NAME} ${SRC_LIST}) target_include_directories(${PROJECT_NAME} PUBLIC $ $) +target_include_directories(${PROJECT_NAME} PUBLIC ${jsoncpp_INCLUDE_DIRS} ${JSONCPP_PKG_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${LIB_LIST}) include(GNUInstallDirs) install(TARGETS ${PROJECT_NAME} diff --git a/Dockerfile b/Dockerfile index 3664680db..081cb2fd4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,14 @@ FROM debian:latest MAINTAINER Oleg Morozenkov RUN apt-get -qq update && \ - apt-get -qq install -y g++ make binutils cmake libssl-dev libboost-system-dev libcurl4-openssl-dev zlib1g-dev && \ + apt-get -qq install -y g++ make binutils cmake libssl-dev libboost-system-dev libcurl4-openssl-dev zlib1g-dev libjsoncpp-dev && \ rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/tgbot-cpp COPY include include COPY src src COPY CMakeLists.txt ./ +COPY CMake CMake RUN cmake . && \ make -j$(nproc) && \ diff --git a/Dockerfile_test b/Dockerfile_test index e28a43b2c..917a7737b 100644 --- a/Dockerfile_test +++ b/Dockerfile_test @@ -16,7 +16,9 @@ RUN apt-get -qq update && \ make \ python2.7-dev \ wget \ - zlib1g-dev && \ + zlib1g-dev \ + libjsoncpp-dev \ + pkg-config && \ rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/tgbot-cpp @@ -24,6 +26,7 @@ COPY include include COPY src src COPY test test COPY CMakeLists.txt ./ +COPY CMake CMake RUN cmake -DENABLE_TESTS=ON . && \ make -j$(nproc) && \ diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 2288f5c0b..4e68ae29b 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -1,40 +1,54 @@ #ifndef TGBOT_API_H #define TGBOT_API_H -#include "tgbot/TgException.h" -#include "tgbot/TgTypeParser.h" -#include "tgbot/net/HttpClient.h" #include "tgbot/net/HttpReqArg.h" -#include "tgbot/tools/StringTools.h" -#include "tgbot/types/User.h" -#include "tgbot/types/Message.h" -#include "tgbot/types/MessageId.h" -#include "tgbot/types/GenericReply.h" -#include "tgbot/types/InputFile.h" -#include "tgbot/types/UserProfilePhotos.h" -#include "tgbot/types/Update.h" -#include "tgbot/types/InlineQueryResult.h" -#include "tgbot/types/Venue.h" -#include "tgbot/types/WebhookInfo.h" +#include "tgbot/types/BotCommand.h" +#include "tgbot/types/BotCommandScope.h" +#include "tgbot/types/BotDescription.h" +#include "tgbot/types/BotName.h" +#include "tgbot/types/BotShortDescription.h" +#include "tgbot/types/BusinessConnection.h" +#include "tgbot/types/Chat.h" +#include "tgbot/types/ChatAdministratorRights.h" +#include "tgbot/types/ChatInviteLink.h" #include "tgbot/types/ChatMember.h" -#include "tgbot/types/Sticker.h" -#include "tgbot/types/StickerSet.h" +#include "tgbot/types/ChatPermissions.h" #include "tgbot/types/File.h" -#include "tgbot/types/InputMedia.h" +#include "tgbot/types/ForumTopic.h" #include "tgbot/types/GameHighScore.h" -#include "tgbot/types/SentWebAppMessage.h" +#include "tgbot/types/GenericReply.h" +#include "tgbot/types/GiveawayCompleted.h" +#include "tgbot/types/InlineKeyboardMarkup.h" +#include "tgbot/types/InlineQueryResult.h" +#include "tgbot/types/InlineQueryResultsButton.h" +#include "tgbot/types/InputMedia.h" +#include "tgbot/types/InputFile.h" +#include "tgbot/types/InputSticker.h" #include "tgbot/types/LabeledPrice.h" +#include "tgbot/types/LinkPreviewOptions.h" +#include "tgbot/types/MaskPosition.h" +#include "tgbot/types/MenuButton.h" +#include "tgbot/types/Message.h" +#include "tgbot/types/MessageEntity.h" +#include "tgbot/types/MessageId.h" +#include "tgbot/types/PassportElementError.h" +#include "tgbot/types/Poll.h" +#include "tgbot/types/ReactionType.h" +#include "tgbot/types/ReplyParameters.h" +#include "tgbot/types/SentWebAppMessage.h" #include "tgbot/types/ShippingOption.h" -#include "tgbot/types/BotCommand.h" -#include "tgbot/types/ForumTopic.h" - -#include +#include "tgbot/types/Sticker.h" +#include "tgbot/types/StickerSet.h" +#include "tgbot/types/Update.h" +#include "tgbot/types/User.h" +#include "tgbot/types/UserChatBoosts.h" +#include "tgbot/types/UserProfilePhotos.h" +#include "tgbot/types/WebhookInfo.h" #include #include #include #include -#include #include namespace TgBot { @@ -48,13 +62,9 @@ class Bot; */ class TGBOT_API Api { -typedef std::shared_ptr> StringArrayPtr; - -friend class Bot; - public: - Api(std::string token, const HttpClient& httpClient, const std::string& url); - + typedef std::shared_ptr> StringArrayPtr; + /** * @brief Use this method to receive incoming updates using long polling ([wiki](https://en.wikipedia.org/wiki/Push_technology#Long_polling)). * @@ -69,10 +79,10 @@ friend class Bot; * * @return Returns an Array of Update objects. */ - std::vector getUpdates(std::int32_t offset = 0, + virtual std::vector getUpdates(std::int32_t offset = 0, std::int32_t limit = 100, std::int32_t timeout = 0, - const StringArrayPtr& allowedUpdates = nullptr) const; + const StringArrayPtr& allowedUpdates = nullptr) const = 0; /** * @brief Use this method to specify a URL and receive incoming updates via an outgoing webhook. @@ -100,13 +110,13 @@ friend class Bot; * * @return Returns True on success. */ - bool setWebhook(const std::string& url, + virtual bool setWebhook(const std::string& url, InputFile::Ptr certificate = nullptr, std::int32_t maxConnections = 40, const StringArrayPtr& allowedUpdates = nullptr, const std::string& ipAddress = "", bool dropPendingUpdates = false, - const std::string& secretToken = "") const; + const std::string& secretToken = "") const = 0; /** * @brief Use this method to remove webhook integration if you decide to switch back to Api::getUpdates. @@ -115,7 +125,7 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteWebhook(bool dropPendingUpdates = false) const; + virtual bool deleteWebhook(bool dropPendingUpdates = false) const = 0; /** * @brief Use this method to get current webhook status. @@ -125,7 +135,7 @@ friend class Bot; * * @return On success, returns a WebhookInfo object. If the bot is using getUpdates, will return a nullptr. */ - WebhookInfo::Ptr getWebhookInfo() const; + virtual WebhookInfo::Ptr getWebhookInfo() const = 0; /** * @brief A simple method for testing your bot's authentication token. @@ -134,7 +144,7 @@ friend class Bot; * * @return Returns basic information about the bot in form of a User object. */ - User::Ptr getMe() const; + virtual User::Ptr getMe() const = 0; /** * @brief Use this method to log out from the cloud Bot API server before launching the bot locally. @@ -145,7 +155,7 @@ friend class Bot; * * @return Returns True on success. */ - bool logOut() const; + virtual bool logOut() const = 0; /** * @brief Use this method to close the bot instance before moving it from one local server to another. @@ -156,7 +166,7 @@ friend class Bot; * * @return Returns True on success. */ - bool close() const; + virtual bool close() const = 0; /** * @brief Use this method to send text messages. @@ -175,7 +185,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendMessage(boost::variant chatId, + virtual Message::Ptr sendMessage(boost::variant chatId, const std::string& text, LinkPreviewOptions::Ptr linkPreviewOptions = nullptr, ReplyParameters::Ptr replyParameters = nullptr, @@ -185,7 +195,7 @@ friend class Bot; const std::vector& entities = std::vector(), std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to forward messages of any kind. @@ -201,12 +211,12 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr forwardMessage(boost::variant chatId, + virtual Message::Ptr forwardMessage(boost::variant chatId, boost::variant fromChatId, std::int32_t messageId, bool disableNotification = false, bool protectContent = false, - std::int32_t messageThreadId = 0) const; + std::int32_t messageThreadId = 0) const = 0; /** * @brief Use this method to forward multiple messages of any kind. @@ -224,12 +234,12 @@ friend class Bot; * * @return On success, an array of MessageId of the sent messages is returned. */ - std::vector forwardMessages(boost::variant chatId, + virtual std::vector forwardMessages(boost::variant chatId, boost::variant fromChatId, const std::vector& messageIds, std::int32_t messageThreadId = 0, bool disableNotification = false, - bool protectContent = false) const; + bool protectContent = false) const = 0; /** * @brief Use this method to copy messages of any kind. @@ -252,7 +262,7 @@ friend class Bot; * * @return Returns the MessageId of the sent message on success. */ - MessageId::Ptr copyMessage(boost::variant chatId, + virtual MessageId::Ptr copyMessage(boost::variant chatId, boost::variant fromChatId, std::int32_t messageId, const std::string& caption = "", @@ -260,9 +270,9 @@ friend class Bot; const std::vector& captionEntities = std::vector(), bool disableNotification = false, ReplyParameters::Ptr replyParameters = nullptr, - GenericReply::Ptr replyMarkup = std::make_shared(), + GenericReply::Ptr replyMarkup = nullptr, bool protectContent = false, - std::int32_t messageThreadId = 0) const; + std::int32_t messageThreadId = 0) const = 0; /** * @brief Use this method to copy messages of any kind. @@ -283,13 +293,13 @@ friend class Bot; * * @return On success, an array of MessageId of the sent messages is returned. */ - std::vector copyMessages(boost::variant chatId, + virtual std::vector copyMessages(boost::variant chatId, boost::variant fromChatId, const std::vector& messageIds, std::int32_t messageThreadId = 0, bool disableNotification = false, bool protectContent = false, - bool removeCaption = false) const; + bool removeCaption = false) const = 0; /** * @brief Use this method to send photos. @@ -309,7 +319,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendPhoto(boost::variant chatId, + virtual Message::Ptr sendPhoto(boost::variant chatId, boost::variant photo, const std::string& caption = "", ReplyParameters::Ptr replyParameters = nullptr, @@ -320,7 +330,7 @@ friend class Bot; std::int32_t messageThreadId = 0, bool protectContent = false, bool hasSpoiler = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send audio files, if you want Telegram clients to display them in the music player. @@ -348,7 +358,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendAudio(boost::variant chatId, + virtual Message::Ptr sendAudio(boost::variant chatId, boost::variant audio, const std::string& caption = "", std::int32_t duration = 0, @@ -362,7 +372,7 @@ friend class Bot; const std::vector& captionEntities = std::vector(), std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send general files. @@ -385,7 +395,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendDocument(boost::variant chatId, + virtual Message::Ptr sendDocument(boost::variant chatId, boost::variant document, boost::variant thumbnail = "", const std::string& caption = "", @@ -397,7 +407,7 @@ friend class Bot; bool disableContentTypeDetection = false, std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). @@ -424,7 +434,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendVideo(boost::variant chatId, + virtual Message::Ptr sendVideo(boost::variant chatId, boost::variant video, bool supportsStreaming = false, std::int32_t duration = 0, @@ -440,7 +450,7 @@ friend class Bot; std::int32_t messageThreadId = 0, bool protectContent = false, bool hasSpoiler = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). @@ -466,7 +476,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendAnimation(boost::variant chatId, + virtual Message::Ptr sendAnimation(boost::variant chatId, boost::variant animation, std::int32_t duration = 0, std::int32_t width = 0, @@ -481,7 +491,7 @@ friend class Bot; std::int32_t messageThreadId = 0, bool protectContent = false, bool hasSpoiler = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. @@ -504,7 +514,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendVoice(boost::variant chatId, + virtual Message::Ptr sendVoice(boost::variant chatId, boost::variant voice, const std::string& caption = "", std::int32_t duration = 0, @@ -515,7 +525,7 @@ friend class Bot; const std::vector& captionEntities = std::vector(), std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send video messages. @@ -536,7 +546,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendVideoNote(boost::variant chatId, + virtual Message::Ptr sendVideoNote(boost::variant chatId, boost::variant videoNote, ReplyParameters::Ptr replyParameters = nullptr, bool disableNotification = false, @@ -546,7 +556,7 @@ friend class Bot; GenericReply::Ptr replyMarkup = nullptr, std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send a group of photos, videos, documents or audios as an album. @@ -563,13 +573,13 @@ friend class Bot; * * @return On success, an array of Messages that were sent is returned. */ - std::vector sendMediaGroup(boost::variant chatId, + virtual std::vector sendMediaGroup(boost::variant chatId, const std::vector& media, bool disableNotification = false, ReplyParameters::Ptr replyParameters = nullptr, std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send point on the map. @@ -590,7 +600,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendLocation(boost::variant chatId, + virtual Message::Ptr sendLocation(boost::variant chatId, float latitude, float longitude, std::int32_t livePeriod = 0, @@ -602,7 +612,7 @@ friend class Bot; std::int32_t proximityAlertRadius = 0, std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to edit live location messages. @@ -621,7 +631,7 @@ friend class Bot; * * @return On success, the edited Message is returned. */ - Message::Ptr editMessageLiveLocation(float latitude, + virtual Message::Ptr editMessageLiveLocation(float latitude, float longitude, boost::variant chatId = "", std::int32_t messageId = 0, @@ -629,7 +639,7 @@ friend class Bot; InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared(), float horizontalAccuracy = 0, std::int32_t heading = 0, - std::int32_t proximityAlertRadius = 0) const; + std::int32_t proximityAlertRadius = 0) const = 0; /** * @brief Use this method to stop updating a live location message before livePeriod expires. @@ -641,10 +651,10 @@ friend class Bot; * * @return On success, the edited Message is returned. */ - Message::Ptr stopMessageLiveLocation(boost::variant chatId = "", + virtual Message::Ptr stopMessageLiveLocation(boost::variant chatId = "", std::int32_t messageId = 0, const std::string& inlineMessageId = "", - InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared()) const; + InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared()) const = 0; /** * @brief Use this method to send information about a venue. @@ -667,7 +677,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendVenue(boost::variant chatId, + virtual Message::Ptr sendVenue(boost::variant chatId, float latitude, float longitude, const std::string& title, @@ -681,7 +691,7 @@ friend class Bot; const std::string& googlePlaceType = "", std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send phone contacts. @@ -700,7 +710,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendContact(boost::variant chatId, + virtual Message::Ptr sendContact(boost::variant chatId, const std::string& phoneNumber, const std::string& firstName, const std::string& lastName = "", @@ -710,7 +720,7 @@ friend class Bot; GenericReply::Ptr replyMarkup = nullptr, std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send a native poll. @@ -737,7 +747,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendPoll(boost::variant chatId, + virtual Message::Ptr sendPoll(boost::variant chatId, const std::string& question, const std::vector& options, bool disableNotification = false, @@ -755,7 +765,7 @@ friend class Bot; bool isClosed = false, std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to send an animated emoji that will display a random value. @@ -771,14 +781,14 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendDice(boost::variant chatId, + virtual Message::Ptr sendDice(boost::variant chatId, bool disableNotification = false, ReplyParameters::Ptr replyParameters = nullptr, GenericReply::Ptr replyMarkup = nullptr, const std::string& emoji = "", std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to change the chosen reactions on a message. @@ -793,10 +803,10 @@ friend class Bot; * * @return Returns True on success. */ - bool setMessageReaction(boost::variant chatId, + virtual bool setMessageReaction(boost::variant chatId, std::int32_t messageId = 0, const std::vector& reaction = std::vector(), - bool isBig = false) const; + bool isBig = false) const = 0; /** * @brief Use this method when you need to tell the user that something is happening on the bot's side. @@ -816,10 +826,10 @@ friend class Bot; * * @return Returns True on success. */ - bool sendChatAction(std::int64_t chatId, + virtual bool sendChatAction(std::int64_t chatId, const std::string& action, std::int32_t messageThreadId = 0, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to get a list of profile pictures for a user. @@ -830,9 +840,9 @@ friend class Bot; * * @return Returns a UserProfilePhotos object. */ - UserProfilePhotos::Ptr getUserProfilePhotos(std::int64_t userId, + virtual UserProfilePhotos::Ptr getUserProfilePhotos(std::int64_t userId, std::int32_t offset = 0, - std::int32_t limit = 100) const; + std::int32_t limit = 100) const = 0; /** * @brief Use this method to get basic information about a file and prepare it for downloading. @@ -849,7 +859,7 @@ friend class Bot; * * @return On success, a File object is returned. */ - File::Ptr getFile(const std::string& fileId) const; + virtual File::Ptr getFile(const std::string& fileId) const = 0; /** * @brief Use this method to ban a user in a group, a supergroup or a channel. @@ -864,10 +874,10 @@ friend class Bot; * * @return Returns True on success. */ - bool banChatMember(boost::variant chatId, + virtual bool banChatMember(boost::variant chatId, std::int64_t userId, std::int32_t untilDate = 0, - bool revokeMessages = true) const; + bool revokeMessages = true) const = 0; /** * @brief Use this method to unban a previously banned user in a supergroup or channel. @@ -884,9 +894,9 @@ friend class Bot; * * @return Returns True on success. */ - bool unbanChatMember(boost::variant chatId, + virtual bool unbanChatMember(boost::variant chatId, std::int64_t userId, - bool onlyIfBanned = false) const; + bool onlyIfBanned = false) const = 0; /** * @brief Use this method to restrict a user in a supergroup. @@ -902,11 +912,11 @@ friend class Bot; * * @return Returns True on success. */ - bool restrictChatMember(boost::variant chatId, + virtual bool restrictChatMember(boost::variant chatId, std::int64_t userId, ChatPermissions::Ptr permissions, std::uint32_t untilDate = 0, - bool useIndependentChatPermissions = false) const; + bool useIndependentChatPermissions = false) const = 0; /** * @brief Use this method to promote or demote a user in a supergroup or a channel. @@ -934,7 +944,7 @@ friend class Bot; * * @return Returns True on success. */ - bool promoteChatMember(boost::variant chatId, + virtual bool promoteChatMember(boost::variant chatId, std::int64_t userId, bool canChangeInfo = false, bool canPostMessages = false, @@ -950,7 +960,7 @@ friend class Bot; bool canManageTopics = false, bool canPostStories = false, bool canEditStories = false, - bool canDeleteStories = false) const; + bool canDeleteStories = false) const = 0; /** * @brief Use this method to set a custom title for an administrator in a supergroup promoted by the bot. @@ -961,9 +971,9 @@ friend class Bot; * * @return Returns True on success. */ - bool setChatAdministratorCustomTitle(boost::variant chatId, + virtual bool setChatAdministratorCustomTitle(boost::variant chatId, std::int64_t userId, - const std::string& customTitle) const; + const std::string& customTitle) const = 0; /** * @brief Use this method to ban a channel chat in a supergroup or a channel. @@ -976,8 +986,8 @@ friend class Bot; * * @return Returns True on success. */ - bool banChatSenderChat(boost::variant chatId, - std::int64_t senderChatId) const; + virtual bool banChatSenderChat(boost::variant chatId, + std::int64_t senderChatId) const = 0; /** * @brief Use this method to unban a previously banned channel chat in a supergroup or channel. @@ -989,8 +999,8 @@ friend class Bot; * * @return Returns True on success. */ - bool unbanChatSenderChat(boost::variant chatId, - std::int64_t senderChatId) const; + virtual bool unbanChatSenderChat(boost::variant chatId, + std::int64_t senderChatId) const = 0; /** * @brief Use this method to set default chat permissions for all members. @@ -1003,9 +1013,9 @@ friend class Bot; * * @return Returns True on success. */ - bool setChatPermissions(boost::variant chatId, + virtual bool setChatPermissions(boost::variant chatId, ChatPermissions::Ptr permissions, - bool useIndependentChatPermissions = false) const; + bool useIndependentChatPermissions = false) const = 0; /** * @brief Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. @@ -1021,7 +1031,7 @@ friend class Bot; * * @return Returns the new invite link as String on success. */ - std::string exportChatInviteLink(boost::variant chatId) const; + virtual std::string exportChatInviteLink(boost::variant chatId) const = 0; /** * @brief Use this method to create an additional invite link for a chat. @@ -1037,11 +1047,11 @@ friend class Bot; * * @return Returns the new invite link as ChatInviteLink object. */ - ChatInviteLink::Ptr createChatInviteLink(boost::variant chatId, + virtual ChatInviteLink::Ptr createChatInviteLink(boost::variant chatId, std::int32_t expireDate = 0, std::int32_t memberLimit = 0, const std::string& name = "", - bool createsJoinRequest = false) const; + bool createsJoinRequest = false) const = 0; /** * @brief Use this method to edit a non-primary invite link created by the bot. @@ -1057,12 +1067,12 @@ friend class Bot; * * @return Returns the edited invite link as a ChatInviteLink object. */ - ChatInviteLink::Ptr editChatInviteLink(boost::variant chatId, + virtual ChatInviteLink::Ptr editChatInviteLink(boost::variant chatId, const std::string& inviteLink, std::int32_t expireDate = 0, std::int32_t memberLimit = 0, const std::string& name = "", - bool createsJoinRequest = false) const; + bool createsJoinRequest = false) const = 0; /** * @brief Use this method to revoke an invite link created by the bot. @@ -1075,8 +1085,8 @@ friend class Bot; * * @return Returns the revoked invite link as ChatInviteLink object. */ - ChatInviteLink::Ptr revokeChatInviteLink(boost::variant chatId, - const std::string& inviteLink) const; + virtual ChatInviteLink::Ptr revokeChatInviteLink(boost::variant chatId, + const std::string& inviteLink) const = 0; /** * @brief Use this method to approve a chat join request. @@ -1088,8 +1098,8 @@ friend class Bot; * * @return Returns True on success. */ - bool approveChatJoinRequest(boost::variant chatId, - std::int64_t userId) const; + virtual bool approveChatJoinRequest(boost::variant chatId, + std::int64_t userId) const = 0; /** * @brief Use this method to decline a chat join request. @@ -1101,8 +1111,8 @@ friend class Bot; * * @return True on success. */ - bool declineChatJoinRequest(boost::variant chatId, - std::int64_t userId) const; + virtual bool declineChatJoinRequest(boost::variant chatId, + std::int64_t userId) const = 0; /** * @brief Use this method to set a new profile photo for the chat. @@ -1115,8 +1125,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setChatPhoto(boost::variant chatId, - InputFile::Ptr photo) const; + virtual bool setChatPhoto(boost::variant chatId, + InputFile::Ptr photo) const = 0; /** * @brief Use this method to delete a chat photo. @@ -1128,7 +1138,7 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteChatPhoto(boost::variant chatId) const; + virtual bool deleteChatPhoto(boost::variant chatId) const = 0; /** * @brief Use this method to change the title of a chat. @@ -1141,8 +1151,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setChatTitle(boost::variant chatId, - const std::string& title) const; + virtual bool setChatTitle(boost::variant chatId, + const std::string& title) const = 0; /** * @brief Use this method to change the description of a group, a supergroup or a channel. @@ -1154,8 +1164,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setChatDescription(boost::variant chatId, - const std::string& description = "") const; + virtual bool setChatDescription(boost::variant chatId, + const std::string& description = "") const = 0; /** * @brief Use this method to add a message to the list of pinned messages in a chat. @@ -1168,9 +1178,9 @@ friend class Bot; * * @return Returns True on success. */ - bool pinChatMessage(boost::variant chatId, + virtual bool pinChatMessage(boost::variant chatId, std::int32_t messageId, - bool disableNotification = false) const; + bool disableNotification = false) const = 0; /** * @brief Use this method to remove a message from the list of pinned messages in a chat. @@ -1182,8 +1192,8 @@ friend class Bot; * * @return Returns True on success. */ - bool unpinChatMessage(boost::variant chatId, - std::int32_t messageId = 0) const; + virtual bool unpinChatMessage(boost::variant chatId, + std::int32_t messageId = 0) const = 0; /** * @brief Use this method to clear the list of pinned messages in a chat. @@ -1194,7 +1204,7 @@ friend class Bot; * * @return Returns True on success. */ - bool unpinAllChatMessages(boost::variant chatId) const; + virtual bool unpinAllChatMessages(boost::variant chatId) const = 0; /** * @brief Use this method for your bot to leave a group, supergroup or channel. @@ -1203,7 +1213,7 @@ friend class Bot; * * @return Returns True on success. */ - bool leaveChat(boost::variant chatId) const; + virtual bool leaveChat(boost::variant chatId) const = 0; /** * @brief Use this method to get up to date information about the chat. @@ -1212,7 +1222,7 @@ friend class Bot; * * @return Returns a Chat object on success. */ - Chat::Ptr getChat(boost::variant chatId) const; + virtual Chat::Ptr getChat(boost::variant chatId) const = 0; /** * @brief Use this method to get a list of administrators in a chat, which aren't bots. @@ -1221,7 +1231,7 @@ friend class Bot; * * @return Returns an Array of ChatMember objects. */ - std::vector getChatAdministrators(boost::variant chatId) const; + virtual std::vector getChatAdministrators(boost::variant chatId) const = 0; /** * @brief Use this method to get the number of members in a chat. @@ -1230,7 +1240,7 @@ friend class Bot; * * @return Returns Int on success. */ - std::int32_t getChatMemberCount(boost::variant chatId) const; + virtual std::int32_t getChatMemberCount(boost::variant chatId) const = 0; /** * @brief Use this method to get information about a member of a chat. @@ -1242,8 +1252,8 @@ friend class Bot; * * @return Returns a ChatMember object on success. */ - ChatMember::Ptr getChatMember(boost::variant chatId, - std::int64_t userId) const; + virtual ChatMember::Ptr getChatMember(boost::variant chatId, + std::int64_t userId) const = 0; /** * @brief Use this method to set a new group sticker set for a supergroup. @@ -1256,8 +1266,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setChatStickerSet(boost::variant chatId, - const std::string& stickerSetName) const; + virtual bool setChatStickerSet(boost::variant chatId, + const std::string& stickerSetName) const = 0; /** * @brief Use this method to delete a group sticker set from a supergroup. @@ -1269,14 +1279,14 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteChatStickerSet(boost::variant chatId) const; + virtual bool deleteChatStickerSet(boost::variant chatId) const = 0; /** * @brief Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. * * @return Returns an Array of Sticker objects. */ - std::vector getForumTopicIconStickers() const; + virtual std::vector getForumTopicIconStickers() const = 0; /** * @brief Use this method to create a topic in a forum supergroup chat. @@ -1290,10 +1300,10 @@ friend class Bot; * * @return Returns information about the created topic as a ForumTopic object. */ - ForumTopic::Ptr createForumTopic(boost::variant chatId, + virtual ForumTopic::Ptr createForumTopic(boost::variant chatId, const std::string& name, std::int32_t iconColor = 0, - const std::string& iconCustomEmojiId = "") const; + const std::string& iconCustomEmojiId = "") const = 0; /** * @brief Use this method to edit name and icon of a topic in a forum supergroup chat. @@ -1307,10 +1317,10 @@ friend class Bot; * * @return Returns True on success. */ - bool editForumTopic(boost::variant chatId, + virtual bool editForumTopic(boost::variant chatId, std::int32_t messageThreadId, const std::string& name = "", - boost::variant iconCustomEmojiId = 0) const; + boost::variant iconCustomEmojiId = 0) const = 0; /** * @brief Use this method to close an open topic in a forum supergroup chat. @@ -1322,8 +1332,8 @@ friend class Bot; * * @return Returns True on success. */ - bool closeForumTopic(boost::variant chatId, - std::int32_t messageThreadId) const; + virtual bool closeForumTopic(boost::variant chatId, + std::int32_t messageThreadId) const = 0; /** * @brief Use this method to reopen a closed topic in a forum supergroup chat. @@ -1335,8 +1345,8 @@ friend class Bot; * * @return Returns True on success. */ - bool reopenForumTopic(boost::variant chatId, - std::int32_t messageThreadId) const; + virtual bool reopenForumTopic(boost::variant chatId, + std::int32_t messageThreadId) const = 0; /** * @brief Use this method to delete a forum topic along with all its messages in a forum supergroup chat. @@ -1348,8 +1358,8 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteForumTopic(boost::variant chatId, - std::int32_t messageThreadId) const; + virtual bool deleteForumTopic(boost::variant chatId, + std::int32_t messageThreadId) const = 0; /** * @brief Use this method to clear the list of pinned messages in a forum topic. @@ -1361,8 +1371,8 @@ friend class Bot; * * @return Returns True on success. */ - bool unpinAllForumTopicMessages(boost::variant chatId, - std::int32_t messageThreadId) const; + virtual bool unpinAllForumTopicMessages(boost::variant chatId, + std::int32_t messageThreadId) const = 0; /** * @brief Use this method to edit the name of the 'General' topic in a forum supergroup chat. @@ -1374,8 +1384,8 @@ friend class Bot; * * @return Returns True on success. */ - bool editGeneralForumTopic(boost::variant chatId, - std::string name) const; + virtual bool editGeneralForumTopic(boost::variant chatId, + std::string name) const = 0; /** * @brief Use this method to close an open 'General' topic in a forum supergroup chat. @@ -1386,7 +1396,7 @@ friend class Bot; * * @return Returns True on success. */ - bool closeGeneralForumTopic(boost::variant chatId) const; + virtual bool closeGeneralForumTopic(boost::variant chatId) const = 0; /** * @brief Use this method to reopen a closed 'General' topic in a forum supergroup chat. @@ -1398,7 +1408,7 @@ friend class Bot; * * @return Returns True on success. */ - bool reopenGeneralForumTopic(boost::variant chatId) const; + virtual bool reopenGeneralForumTopic(boost::variant chatId) const = 0; /** * @brief Use this method to hide the 'General' topic in a forum supergroup chat. @@ -1410,7 +1420,7 @@ friend class Bot; * * @return Returns True on success. */ - bool hideGeneralForumTopic(boost::variant chatId) const; + virtual bool hideGeneralForumTopic(boost::variant chatId) const = 0; /** * @brief Use this method to unhide the 'General' topic in a forum supergroup chat. @@ -1421,7 +1431,7 @@ friend class Bot; * * @return Returns True on success. */ - bool unhideGeneralForumTopic(boost::variant chatId) const; + virtual bool unhideGeneralForumTopic(boost::variant chatId) const = 0; /** * @brief Use this method to clear the list of pinned messages in a General forum topic. @@ -1432,7 +1442,7 @@ friend class Bot; * * @return Returns True on success. */ - bool unpinAllGeneralForumTopicMessages(boost::variant chatId) const; + virtual bool unpinAllGeneralForumTopicMessages(boost::variant chatId) const = 0; /** * @brief Use this method to send answers to callback queries sent from inline keyboards. @@ -1451,11 +1461,11 @@ friend class Bot; * * @return On success, True is returned. */ - bool answerCallbackQuery(const std::string& callbackQueryId, + virtual bool answerCallbackQuery(const std::string& callbackQueryId, const std::string& text = "", bool showAlert = false, const std::string& url = "", - std::int32_t cacheTime = 0) const; + std::int32_t cacheTime = 0) const = 0; /** * @brief Use this method to get the list of boosts added to a chat by a user. @@ -1467,8 +1477,8 @@ friend class Bot; * * @return Returns a UserChatBoosts object. */ - UserChatBoosts::Ptr getUserChatBoosts(boost::variant chatId, - std::int32_t userId) const; + virtual UserChatBoosts::Ptr getUserChatBoosts(boost::variant chatId, + std::int32_t userId) const = 0; /** * @brief Use this method to get information about the connection of the bot with a business account. @@ -1477,7 +1487,7 @@ friend class Bot; * * @return Returns a BusinessConnection object on success. */ - BusinessConnection::Ptr getBusinessConnection(const std::string& businessConnectionId) const; + virtual BusinessConnection::Ptr getBusinessConnection(const std::string& businessConnectionId) const = 0; /** * @brief Use this method to change the list of the bot's commands. @@ -1490,9 +1500,9 @@ friend class Bot; * * @return Returns True on success. */ - bool setMyCommands(const std::vector& commands, + virtual bool setMyCommands(const std::vector& commands, BotCommandScope::Ptr scope = nullptr, - const std::string& languageCode = "") const; + const std::string& languageCode = "") const = 0; /** * @brief Use this method to delete the list of the bot's commands for the given scope and user language. @@ -1504,8 +1514,8 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteMyCommands(BotCommandScope::Ptr scope = nullptr, - const std::string& languageCode = "") const; + virtual bool deleteMyCommands(BotCommandScope::Ptr scope = nullptr, + const std::string& languageCode = "") const = 0; /** * @brief Use this method to get the current list of the bot's commands for the given scope and user language. @@ -1515,8 +1525,8 @@ friend class Bot; * * @return Returns an Array of BotCommand objects. If commands aren't set, an empty list is returned. */ - std::vector getMyCommands(BotCommandScope::Ptr scope = nullptr, - const std::string& languageCode = "") const; + virtual std::vector getMyCommands(BotCommandScope::Ptr scope = nullptr, + const std::string& languageCode = "") const = 0; /** * @brief Use this method to change the bot's name. @@ -1526,8 +1536,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setMyName(const std::string& name = "", - const std::string& languageCode = "") const; + virtual bool setMyName(const std::string& name = "", + const std::string& languageCode = "") const = 0; /** * @brief Use this method to get the current bot name for the given user language. @@ -1536,7 +1546,7 @@ friend class Bot; * * @return Returns BotName on success. */ - BotName::Ptr getMyName(const std::string& languageCode = "") const; + virtual BotName::Ptr getMyName(const std::string& languageCode = "") const = 0; /** * @brief Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. @@ -1546,8 +1556,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setMyDescription(const std::string& description = "", - const std::string& languageCode = "") const; + virtual bool setMyDescription(const std::string& description = "", + const std::string& languageCode = "") const = 0; /** * @brief Use this method to get the current bot description for the given user language. @@ -1556,7 +1566,7 @@ friend class Bot; * * @return Returns BotDescription on success. */ - BotDescription::Ptr getMyDescription(const std::string& languageCode = "") const; + virtual BotDescription::Ptr getMyDescription(const std::string& languageCode = "") const = 0; /** * @brief Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. @@ -1566,8 +1576,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setMyShortDescription(const std::string& shortDescription = "", - const std::string& languageCode = "") const; + virtual bool setMyShortDescription(const std::string& shortDescription = "", + const std::string& languageCode = "") const = 0; /** * @brief Use this method to get the current bot short description for the given user language. @@ -1576,7 +1586,7 @@ friend class Bot; * * @return Returns BotShortDescription on success. */ - BotShortDescription::Ptr getMyShortDescription(const std::string& languageCode = "") const; + virtual BotShortDescription::Ptr getMyShortDescription(const std::string& languageCode = "") const = 0; /** * @brief Use this method to change the bot's menu button in a private chat, or the default menu button. @@ -1586,8 +1596,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setChatMenuButton(std::int64_t chatId = 0, - MenuButton::Ptr menuButton = nullptr) const; + virtual bool setChatMenuButton(std::int64_t chatId = 0, + MenuButton::Ptr menuButton = nullptr) const = 0; /** * @brief Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. @@ -1596,7 +1606,7 @@ friend class Bot; * * @return Returns MenuButton on success. */ - MenuButton::Ptr getChatMenuButton(std::int64_t chatId = 0) const; + virtual MenuButton::Ptr getChatMenuButton(std::int64_t chatId = 0) const = 0; /** * @brief Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. @@ -1608,8 +1618,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights = nullptr, - bool forChannels = false) const; + virtual bool setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights = nullptr, + bool forChannels = false) const = 0; /** * @brief Use this method to get the current default administrator rights of the bot. @@ -1618,7 +1628,7 @@ friend class Bot; * * @return Returns ChatAdministratorRights on success. */ - ChatAdministratorRights::Ptr getMyDefaultAdministratorRights(bool forChannels = false) const; + virtual ChatAdministratorRights::Ptr getMyDefaultAdministratorRights(bool forChannels = false) const = 0; /** * @brief Use this method to edit text and [game](https://core.telegram.org/bots/api#games) messages. @@ -1634,14 +1644,14 @@ friend class Bot; * * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned. */ - Message::Ptr editMessageText(const std::string& text, + virtual Message::Ptr editMessageText(const std::string& text, boost::variant chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", const std::string& parseMode = "", LinkPreviewOptions::Ptr linkPreviewOptions = nullptr, InlineKeyboardMarkup::Ptr replyMarkup = nullptr, - const std::vector& entities = std::vector()) const; + const std::vector& entities = std::vector()) const = 0; /** * @brief Use this method to edit captions of messages. @@ -1656,13 +1666,13 @@ friend class Bot; * * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned. */ - Message::Ptr editMessageCaption(boost::variant chatId = 0, + virtual Message::Ptr editMessageCaption(boost::variant chatId = 0, std::int32_t messageId = 0, const std::string& caption = "", const std::string& inlineMessageId = "", GenericReply::Ptr replyMarkup = nullptr, const std::string& parseMode = "", - const std::vector& captionEntities = std::vector()) const; + const std::vector& captionEntities = std::vector()) const = 0; /** * @brief Use this method to edit animation, audio, document, photo, or video messages. @@ -1678,11 +1688,11 @@ friend class Bot; * * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned. */ - Message::Ptr editMessageMedia(InputMedia::Ptr media, + virtual Message::Ptr editMessageMedia(InputMedia::Ptr media, boost::variant chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", - GenericReply::Ptr replyMarkup = nullptr) const; + GenericReply::Ptr replyMarkup = nullptr) const = 0; /** * @brief Use this method to edit only the reply markup of messages. @@ -1694,10 +1704,10 @@ friend class Bot; * * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned. */ - Message::Ptr editMessageReplyMarkup(boost::variant chatId = 0, + virtual Message::Ptr editMessageReplyMarkup(boost::variant chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", - GenericReply::Ptr replyMarkup = nullptr) const; + GenericReply::Ptr replyMarkup = nullptr) const = 0; /** * @brief Use this method to stop a poll which was sent by the bot. @@ -1708,9 +1718,9 @@ friend class Bot; * * @return On success, the stopped Poll is returned. */ - Poll::Ptr stopPoll(boost::variant chatId, + virtual Poll::Ptr stopPoll(boost::variant chatId, std::int64_t messageId, - InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared()) const; + InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared()) const = 0; /** * @brief Use this method to delete a message, including service messages, with the following limitations: @@ -1729,8 +1739,8 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteMessage(boost::variant chatId, - std::int32_t messageId) const; + virtual bool deleteMessage(boost::variant chatId, + std::int32_t messageId) const = 0; /** * @brief Use this method to delete multiple messages simultaneously. @@ -1742,8 +1752,8 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteMessages(boost::variant chatId, - const std::vector& messageIds) const; + virtual bool deleteMessages(boost::variant chatId, + const std::vector& messageIds) const = 0; /** * @brief Use this method to send static .WEBP, [animated](https://telegram.org/blog/animated-stickers) .TGS, or [video](https://telegram.org/blog/video-stickers-better-reactions) .WEBM stickers. @@ -1760,7 +1770,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendSticker(boost::variant chatId, + virtual Message::Ptr sendSticker(boost::variant chatId, boost::variant sticker, ReplyParameters::Ptr replyParameters = nullptr, GenericReply::Ptr replyMarkup = nullptr, @@ -1768,7 +1778,7 @@ friend class Bot; std::int32_t messageThreadId = 0, bool protectContent = false, const std::string& emoji = "", - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to get a sticker set. @@ -1777,7 +1787,7 @@ friend class Bot; * * @return On success, a StickerSet object is returned. */ - StickerSet::Ptr getStickerSet(const std::string& name) const; + virtual StickerSet::Ptr getStickerSet(const std::string& name) const = 0; /** * @brief Use this method to get information about custom emoji stickers by their identifiers. @@ -1786,7 +1796,7 @@ friend class Bot; * * @return Returns an Array of Sticker objects. */ - std::vector getCustomEmojiStickers(const std::vector& customEmojiIds) const; + virtual std::vector getCustomEmojiStickers(const std::vector& customEmojiIds) const = 0; /** * @brief Use this method to upload a file with a sticker for later use in the Api::createNewStickerSet, Api::addStickerToSet, or Api::replaceStickerInSet methods (the file can be used multiple times). @@ -1797,9 +1807,9 @@ friend class Bot; * * @return Returns the uploaded File on success. */ - File::Ptr uploadStickerFile(std::int64_t userId, + virtual File::Ptr uploadStickerFile(std::int64_t userId, InputFile::Ptr sticker, - const std::string& stickerFormat) const; + const std::string& stickerFormat) const = 0; /** * @brief Use this method to create a new sticker set owned by a user. @@ -1815,12 +1825,12 @@ friend class Bot; * * @return Returns True on success. */ - bool createNewStickerSet(std::int64_t userId, + virtual bool createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, const std::vector& stickers, Sticker::Type stickerType = Sticker::Type::Regular, - bool needsRepainting = false) const; + bool needsRepainting = false) const = 0; /** * @brief Use this method to add a new sticker to a set created by the bot. @@ -1834,9 +1844,9 @@ friend class Bot; * * @return Returns True on success. */ - bool addStickerToSet(std::int64_t userId, + virtual bool addStickerToSet(std::int64_t userId, const std::string& name, - InputSticker::Ptr sticker) const; + InputSticker::Ptr sticker) const = 0; /** * @brief Use this method to move a sticker in a set created by the bot to a specific position. @@ -1846,8 +1856,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setStickerPositionInSet(const std::string& sticker, - std::int32_t position) const; + virtual bool setStickerPositionInSet(const std::string& sticker, + std::int32_t position) const = 0; /** * @brief Use this method to delete a sticker from a set created by the bot. @@ -1856,7 +1866,7 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteStickerFromSet(const std::string& sticker) const; + virtual bool deleteStickerFromSet(const std::string& sticker) const = 0; /** * @brief Use this method to replace an existing sticker in a sticker set with a new one. @@ -1870,10 +1880,10 @@ friend class Bot; * * @return Returns True on success. */ - bool replaceStickerInSet(std::int64_t userId, + virtual bool replaceStickerInSet(std::int64_t userId, const std::string& name, const std::string& oldSticker, - InputSticker::Ptr sticker) const; + InputSticker::Ptr sticker) const = 0; /** * @brief Use this method to change the list of emoji assigned to a regular or custom emoji sticker. @@ -1885,8 +1895,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setStickerEmojiList(const std::string& sticker, - const std::vector& emojiList) const; + virtual bool setStickerEmojiList(const std::string& sticker, + const std::vector& emojiList) const = 0; /** * @brief Use this method to change search keywords assigned to a regular or custom emoji sticker. @@ -1898,8 +1908,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setStickerKeywords(const std::string& sticker, - const std::vector& keywords = std::vector()) const; + virtual bool setStickerKeywords(const std::string& sticker, + const std::vector& keywords = std::vector()) const = 0; /** * @brief Use this method to change the mask position of a mask sticker. @@ -1911,8 +1921,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setStickerMaskPosition(const std::string& sticker, - MaskPosition::Ptr maskPosition = nullptr) const; + virtual bool setStickerMaskPosition(const std::string& sticker, + MaskPosition::Ptr maskPosition = nullptr) const = 0; /** * @brief Use this method to set the title of a created sticker set. @@ -1922,8 +1932,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setStickerSetTitle(const std::string& name, - const std::string& title) const; + virtual bool setStickerSetTitle(const std::string& name, + const std::string& title) const = 0; /** * @brief Use this method to set the thumbnail of a regular or mask sticker set. @@ -1937,10 +1947,10 @@ friend class Bot; * * @return Returns True on success. */ - bool setStickerSetThumbnail(const std::string& name, + virtual bool setStickerSetThumbnail(const std::string& name, std::int64_t userId, const std::string& format, - boost::variant thumbnail = "") const; + boost::variant thumbnail = "") const = 0; /** * @brief Use this method to set the thumbnail of a custom emoji sticker set. @@ -1950,8 +1960,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setCustomEmojiStickerSetThumbnail(const std::string& name, - const std::string& customEmojiId = "") const; + virtual bool setCustomEmojiStickerSetThumbnail(const std::string& name, + const std::string& customEmojiId = "") const = 0; /** * @brief Use this method to delete a sticker set that was created by the bot. @@ -1960,7 +1970,7 @@ friend class Bot; * * @return Returns True on success. */ - bool deleteStickerSet(const std::string& name) const; + virtual bool deleteStickerSet(const std::string& name) const = 0; /** * @brief Use this method to send answers to an inline query. @@ -1976,12 +1986,12 @@ friend class Bot; * * @return On success, True is returned. */ - bool answerInlineQuery(const std::string& inlineQueryId, + virtual bool answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, std::int32_t cacheTime = 300, bool isPersonal = false, const std::string& nextOffset = "", - InlineQueryResultsButton::Ptr button = nullptr) const; + InlineQueryResultsButton::Ptr button = nullptr) const = 0; /** * @brief Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated. @@ -1991,8 +2001,8 @@ friend class Bot; * * @return On success, a SentWebAppMessage object is returned. */ - SentWebAppMessage::Ptr answerWebAppQuery(const std::string& webAppQueryId, - InlineQueryResult::Ptr result) const; + virtual SentWebAppMessage::Ptr answerWebAppQuery(const std::string& webAppQueryId, + InlineQueryResult::Ptr result) const = 0; /** * @brief Use this method to send invoices. @@ -2027,7 +2037,7 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendInvoice(boost::variant chatId, + virtual Message::Ptr sendInvoice(boost::variant chatId, const std::string& title, const std::string& description, const std::string& payload, @@ -2053,7 +2063,7 @@ friend class Bot; std::int32_t maxTipAmount = 0, const std::vector& suggestedTipAmounts = std::vector(), const std::string& startParameter = "", - bool protectContent = false) const; + bool protectContent = false) const = 0; /** * @brief Use this method to create a link for an invoice. @@ -2081,7 +2091,7 @@ friend class Bot; * * @return Returns the created invoice link as String on success. */ - std::string createInvoiceLink(const std::string& title, + virtual std::string createInvoiceLink(const std::string& title, const std::string& description, const std::string& payload, const std::string& providerToken, @@ -2100,7 +2110,7 @@ friend class Bot; bool needShippingAddress = false, bool sendPhoneNumberToProvider = false, bool sendEmailToProvider = false, - bool isFlexible = false) const; + bool isFlexible = false) const = 0; /** * @brief Use this method to reply to shipping queries. @@ -2114,10 +2124,10 @@ friend class Bot; * * @return On success, True is returned. */ - bool answerShippingQuery(const std::string& shippingQueryId, + virtual bool answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector& shippingOptions = std::vector(), - const std::string& errorMessage = "") const; + const std::string& errorMessage = "") const = 0; /** * @brief Use this method to respond to such pre-checkout queries. @@ -2131,9 +2141,9 @@ friend class Bot; * * @return On success, True is returned. */ - bool answerPreCheckoutQuery(const std::string& preCheckoutQueryId, + virtual bool answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, - const std::string& errorMessage = "") const; + const std::string& errorMessage = "") const = 0; /** * @brief Informs a user that some of the Telegram Passport elements they provided contains errors. @@ -2148,8 +2158,8 @@ friend class Bot; * * @return Returns True on success. */ - bool setPassportDataErrors(std::int64_t userId, - const std::vector& errors) const; + virtual bool setPassportDataErrors(std::int64_t userId, + const std::vector& errors) const = 0; /** * @brief Use this method to send a game. @@ -2165,14 +2175,14 @@ friend class Bot; * * @return On success, the sent Message is returned. */ - Message::Ptr sendGame(std::int64_t chatId, + virtual Message::Ptr sendGame(std::int64_t chatId, const std::string& gameShortName, ReplyParameters::Ptr replyParameters = nullptr, InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared(), bool disableNotification = false, std::int32_t messageThreadId = 0, bool protectContent = false, - const std::string& businessConnectionId = "") const; + const std::string& businessConnectionId = "") const = 0; /** * @brief Use this method to set the score of the specified user in a game message. @@ -2189,13 +2199,13 @@ friend class Bot; * * @return On success, if the message is not an inline message, the Message is returned, otherwise nullptr is returned. */ - Message::Ptr setGameScore(std::int64_t userId, + virtual Message::Ptr setGameScore(std::int64_t userId, std::int32_t score, bool force = false, bool disableEditMessage = false, std::int64_t chatId = 0, std::int32_t messageId = 0, - const std::string& inlineMessageId = "") const; + const std::string& inlineMessageId = "") const = 0; /** * @brief Use this method to get data for high score tables. @@ -2213,10 +2223,10 @@ friend class Bot; * * @return Returns an Array of GameHighScore objects. */ - std::vector getGameHighScores(std::int64_t userId, + virtual std::vector getGameHighScores(std::int64_t userId, std::int64_t chatId = 0, std::int32_t messageId = 0, - const std::string& inlineMessageId = "") const; + const std::string& inlineMessageId = "") const = 0; /** * @brief Download a file from Telegram and save it in memory. @@ -2226,8 +2236,8 @@ friend class Bot; * * @return File content in a string. */ - std::string downloadFile(const std::string& filePath, - const std::vector& args = std::vector()) const; + virtual std::string downloadFile(const std::string& filePath, + const std::vector& args = std::vector()) const = 0; /** * @brief Check if user has blocked the bot @@ -2236,16 +2246,9 @@ friend class Bot; * * @return Returns True if bot is blocked by user */ - bool blockedByUser(std::int64_t chatId) const; - - const HttpClient& _httpClient; - -protected: - boost::property_tree::ptree sendRequest(const std::string& method, const std::vector& args = std::vector()) const; + virtual bool blockedByUser(std::int64_t chatId) const = 0; - const std::string _token; - const TgTypeParser _tgTypeParser; - const std::string _url; + virtual ~Api() = default; }; } diff --git a/include/tgbot/ApiImpl.h b/include/tgbot/ApiImpl.h new file mode 100644 index 000000000..b549246b3 --- /dev/null +++ b/include/tgbot/ApiImpl.h @@ -0,0 +1,2220 @@ +#ifndef TGBOT_API_PRIV_H +#define TGBOT_API_PRIV_H + +#include +#include +#include +#include + +namespace TgBot { + +class Bot; + +/** + * @brief This class is a API class that implements internal logic + * + * @ingroup general + */ +class TGBOT_API ApiImpl : public Api { + friend class Bot; + +public: + ApiImpl(std::string token, std::unique_ptr httpClient, + std::string url); + ~ApiImpl() override = default; + + /** + * @brief Use this method to receive incoming updates using long polling ([wiki](https://en.wikipedia.org/wiki/Push_technology#Long_polling)). + * + * Notes + * - This method will not work if an outgoing webhook is set up. + * - In order to avoid getting duplicate updates, recalculate offset after each server response. + * + * @param offset Optional. Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as Api::getUpdates is called with an offset higher than its updateId. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will be forgotten. + * @param limit Optional. Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100. + * @param timeout Optional. Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only. + * @param allowedUpdates Optional. A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time. + * + * @return Returns an Array of Update objects. + */ + std::vector getUpdates(std::int32_t offset = 0, + std::int32_t limit = 100, + std::int32_t timeout = 0, + const StringArrayPtr& allowedUpdates = nullptr) const override; + + /** + * @brief Use this method to specify a URL and receive incoming updates via an outgoing webhook. + * + * Whenever there is an update for the bot, we will send an HTTPS POST request to the specified URL, containing a JSON-serialized Update. + * In case of an unsuccessful request, we will give up after a reasonable amount of attempts. + * + * If you'd like to make sure that the webhook was set by you, you can specify secret data in the parameter secretToken. + * If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content. + * + * Notes + * - You will not be able to receive updates using Api::getUpdates for as long as an outgoing webhook is set up. + * - To use a self-signed certificate, you need to upload your [public key certificate](https://core.telegram.org/bots/self-signed) using certificate parameter. Please upload as InputFile, sending a String will not work. + * - Ports currently supported for webhooks: 443, 80, 88, 8443. + * + * If you're having any trouble setting up webhooks, please check out [this amazing guide to webhooks](https://core.telegram.org/bots/webhooks). + * + * @param url HTTPS URL to send updates to. Use an empty string to remove webhook integration + * @param certificate Optional. Upload your public key certificate so that the root certificate in use can be checked. See our [self-signed guide](https://core.telegram.org/bots/self-signed) for details. + * @param maxConnections Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput. + * @param allowedUpdates Optional. A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time. + * @param ipAddress Optional. The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS + * @param dropPendingUpdates Optional. Pass True to drop all pending updates + * @param secretToken Optional. A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you. + * + * @return Returns True on success. + */ + bool setWebhook(const std::string& url, + InputFile::Ptr certificate = nullptr, + std::int32_t maxConnections = 40, + const StringArrayPtr& allowedUpdates = nullptr, + const std::string& ipAddress = "", + bool dropPendingUpdates = false, + const std::string& secretToken = "") const override; + + /** + * @brief Use this method to remove webhook integration if you decide to switch back to Api::getUpdates. + * + * @param dropPendingUpdates Optional. Pass True to drop all pending updates + * + * @return Returns True on success. + */ + bool deleteWebhook(bool dropPendingUpdates = false) const override; + + /** + * @brief Use this method to get current webhook status. + * + * Requires no parameters. + * If the bot is using Api::getUpdates, will return an object with the url field empty. + * + * @return On success, returns a WebhookInfo object. If the bot is using getUpdates, will return a nullptr. + */ + WebhookInfo::Ptr getWebhookInfo() const override; + + /** + * @brief A simple method for testing your bot's authentication token. + * + * Requires no parameters. + * + * @return Returns basic information about the bot in form of a User object. + */ + User::Ptr getMe() const override; + + /** + * @brief Use this method to log out from the cloud Bot API server before launching the bot locally. + * + * You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. + * After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. + * Requires no parameters. + * + * @return Returns True on success. + */ + bool logOut() const override; + + /** + * @brief Use this method to close the bot instance before moving it from one local server to another. + * + * You need to delete the webhook before calling this method to ensure that the bot isn't launched again after server restart. + * The method will return error 429 in the first 10 minutes after the bot is launched. + * Requires no parameters. + * + * @return Returns True on success. + */ + bool close() const override; + + /** + * @brief Use this method to send text messages. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param text Text of the message to be sent, 1-4096 characters after entities parsing + * @param linkPreviewOptions Optional. Link preview generation options for the message + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param parseMode Optional. Mode for parsing entities in the message text. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + * @param disableNotification Optional. Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. + * @param entities Optional. A JSON-serialized list of special entities that appear in message text, which can be specified instead of parseMode + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendMessage(boost::variant chatId, + const std::string& text, + LinkPreviewOptions::Ptr linkPreviewOptions = nullptr, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& parseMode = "", + bool disableNotification = false, + const std::vector& entities = std::vector(), + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to forward messages of any kind. + * + * Service messages and messages with protected content can't be forwarded. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) + * @param messageId Message identifier in the chat specified in fromChatId + * @param disableNotification Optional. Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. + * @param protectContent Optional. Protects the contents of the forwarded message from forwarding and saving + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * + * @return On success, the sent Message is returned. + */ + Message::Ptr forwardMessage(boost::variant chatId, + boost::variant fromChatId, + std::int32_t messageId, + bool disableNotification = false, + bool protectContent = false, + std::int32_t messageThreadId = 0) const override; + + /** + * @brief Use this method to forward multiple messages of any kind. + * + * If some of the specified messages can't be found or forwarded, they are skipped. + * Service messages and messages with protected content can't be forwarded. + * Album grouping is kept for forwarded messages. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param fromChatId Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) + * @param messageIds A JSON-serialized list of 1-100 identifiers of messages in the chat fromChatId to forward. The identifiers must be specified in a strictly increasing order. + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param disableNotification Optional. Sends the messages [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. + * @param protectContent Optional. Protects the contents of the forwarded message from forwarding and saving + * + * @return On success, an array of MessageId of the sent messages is returned. + */ + std::vector forwardMessages(boost::variant chatId, + boost::variant fromChatId, + const std::vector& messageIds, + std::int32_t messageThreadId = 0, + bool disableNotification = false, + bool protectContent = false) const override; + + /** + * @brief Use this method to copy messages of any kind. + * + * Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. + * A quiz Poll can be copied only if the value of the field correctOptionId is known to the bot. + * The method is analogous to the method Api::forwardMessage, but the copied message doesn't have a link to the original message. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) + * @param messageId Message identifier in the chat specified in fromChatId + * @param caption Optional. New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept + * @param parseMode Optional. Mode for parsing entities in the new caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of parseMode + * @param disableNotification Optional. Sends the message [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove reply keyboard or to force a reply from the user. + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * + * @return Returns the MessageId of the sent message on success. + */ + MessageId::Ptr copyMessage(boost::variant chatId, + boost::variant fromChatId, + std::int32_t messageId, + const std::string& caption = "", + const std::string& parseMode = "", + const std::vector& captionEntities = std::vector(), + bool disableNotification = false, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + bool protectContent = false, + std::int32_t messageThreadId = 0) const override; + + /** + * @brief Use this method to copy messages of any kind. + * + * If some of the specified messages can't be found or copied, they are skipped. + * Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. + * A quiz Poll can be copied only if the value of the field correctOptionId is known to the bot. + * The method is analogous to the method Api::forwardMessages, but the copied messages don't have a link to the original message. + * Album grouping is kept for copied messages. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param fromChatId Unique identifier for the chat where the original messages were sent (or channel username in the format @channelusername) + * @param messageIds A JSON-serialized list of 1-100 identifiers of messages in the chat fromChatId to copy. The identifiers must be specified in a strictly increasing order. + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param disableNotification Optional. Sends the messages [silently](https://telegram.org/blog/channels-2-0#silent-messages). Users will receive a notification with no sound. + * @param protectContent Optional. Protects the contents of the sent messages from forwarding and saving + * @param removeCaption Optional. Pass True to copy the messages without their captions + * + * @return On success, an array of MessageId of the sent messages is returned. + */ + std::vector copyMessages(boost::variant chatId, + boost::variant fromChatId, + const std::vector& messageIds, + std::int32_t messageThreadId = 0, + bool disableNotification = false, + bool protectContent = false, + bool removeCaption = false) const override; + + /** + * @brief Use this method to send photos. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param photo Photo to send. Pass a fileId as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20. https://core.telegram.org/bots/api#sending-files + * @param caption Optional. Photo caption (may also be used when resending photos by fileId), 0-1024 characters after entities parsing + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param parseMode Optional. Mode for parsing entities in the photo caption. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param hasSpoiler Optional. Pass True if the photo needs to be covered with a spoiler animation + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendPhoto(boost::variant chatId, + boost::variant photo, + const std::string& caption = "", + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& parseMode = "", + bool disableNotification = false, + const std::vector& captionEntities = std::vector(), + std::int32_t messageThreadId = 0, + bool protectContent = false, + bool hasSpoiler = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send audio files, if you want Telegram clients to display them in the music player. + * + * Your audio must be in the .MP3 or .M4A format. + * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. + * + * For sending voice messages, use the Api::sendVoice method instead. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param audio Audio file to send. Pass a fileId as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. https://core.telegram.org/bots/api#sending-files + * @param caption Optional. Audio caption, 0-1024 characters after entities parsing + * @param duration Optional. Duration of the audio in seconds + * @param performer Optional. Performer + * @param title Optional. Track name + * @param thumbnail Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . https://core.telegram.org/bots/api#sending-files + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param parseMode Optional. Mode for parsing entities in the audio caption. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendAudio(boost::variant chatId, + boost::variant audio, + const std::string& caption = "", + std::int32_t duration = 0, + const std::string& performer = "", + const std::string& title = "", + boost::variant thumbnail = "", + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& parseMode = "", + bool disableNotification = false, + const std::vector& captionEntities = std::vector(), + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send general files. + * + * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param document File to send. Pass a fileId as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. https://core.telegram.org/bots/api#sending-files + * @param thumbnail Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . https://core.telegram.org/bots/api#sending-files + * @param caption Optional. Document caption (may also be used when resending documents by fileId), 0-1024 characters after entities parsing + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param parseMode Optional. Mode for parsing entities in the document caption. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode + * @param disableContentTypeDetection Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendDocument(boost::variant chatId, + boost::variant document, + boost::variant thumbnail = "", + const std::string& caption = "", + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& parseMode = "", + bool disableNotification = false, + const std::vector& captionEntities = std::vector(), + bool disableContentTypeDetection = false, + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). + * + * Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param video Video to send. Pass a fileId as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. https://core.telegram.org/bots/api#sending-files + * @param supportsStreaming Optional. Pass True if the uploaded video is suitable for streaming + * @param duration Optional. Duration of sent video in seconds + * @param width Optional. Video width + * @param height Optional. Video height + * @param thumbnail Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . https://core.telegram.org/bots/api#sending-files + * @param caption Optional. Video caption (may also be used when resending videos by fileId), 0-1024 characters after entities parsing + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param parseMode Optional. Mode for parsing entities in the video caption. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param hasSpoiler Optional. Pass True if the video needs to be covered with a spoiler animation + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendVideo(boost::variant chatId, + boost::variant video, + bool supportsStreaming = false, + std::int32_t duration = 0, + std::int32_t width = 0, + std::int32_t height = 0, + boost::variant thumbnail = "", + const std::string& caption = "", + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& parseMode = "", + bool disableNotification = false, + const std::vector& captionEntities = std::vector(), + std::int32_t messageThreadId = 0, + bool protectContent = false, + bool hasSpoiler = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). + * + * Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param animation Animation to send. Pass a fileId as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. https://core.telegram.org/bots/api#sending-files + * @param duration Optional. Duration of sent animation in seconds + * @param width Optional. Animation width + * @param height Optional. Animation height + * @param thumbnail Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . https://core.telegram.org/bots/api#sending-files + * @param caption Optional. Animation caption (may also be used when resending animation by fileId), 0-1024 characters after entities parsing + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param parseMode Optional. Mode for parsing entities in the animation caption. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param hasSpoiler Optional. Pass True if the animation needs to be covered with a spoiler animation + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendAnimation(boost::variant chatId, + boost::variant animation, + std::int32_t duration = 0, + std::int32_t width = 0, + std::int32_t height = 0, + boost::variant thumbnail = "", + const std::string& caption = "", + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& parseMode = "", + bool disableNotification = false, + const std::vector& captionEntities = std::vector(), + std::int32_t messageThreadId = 0, + bool protectContent = false, + bool hasSpoiler = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. + * + * For this to work, your audio must be in an .OGG file encoded with OPUS (other formats may be sent as Audio or Document). + * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param voice Audio file to send. Pass a fileId as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. https://core.telegram.org/bots/api#sending-files + * @param caption Optional. Voice message caption, 0-1024 characters after entities parsing + * @param duration Optional. Duration of the voice message in seconds + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param parseMode Optional. Mode for parsing entities in the voice message caption. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendVoice(boost::variant chatId, + boost::variant voice, + const std::string& caption = "", + std::int32_t duration = 0, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& parseMode = "", + bool disableNotification = false, + const std::vector& captionEntities = std::vector(), + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send video messages. + * + * As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param videoNote Video note to send. Pass a fileId as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. https://core.telegram.org/bots/api#sending-files. Sending video notes by a URL is currently unsupported + * @param replyParameters Optional. Description of the message to reply to + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param duration Optional. Duration of sent video in seconds + * @param length Optional. Video width and height, i.e. diameter of the video message + * @param thumbnail Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . https://core.telegram.org/bots/api#sending-files + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendVideoNote(boost::variant chatId, + boost::variant videoNote, + ReplyParameters::Ptr replyParameters = nullptr, + bool disableNotification = false, + std::int32_t duration = 0, + std::int32_t length = 0, + boost::variant thumbnail = "", + GenericReply::Ptr replyMarkup = nullptr, + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send a group of photos, videos, documents or audios as an album. + * + * Documents and audio files can be only grouped in an album with messages of the same type. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param media A JSON-serialized array describing messages to be sent, must include 2-10 items + * @param disableNotification Optional. Sends messages silently. Users will receive a notification with no sound. + * @param replyParameters Optional. Description of the message to reply to + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent messages from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, an array of Messages that were sent is returned. + */ + std::vector sendMediaGroup(boost::variant chatId, + const std::vector& media, + bool disableNotification = false, + ReplyParameters::Ptr replyParameters = nullptr, + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send point on the map. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param latitude Latitude of the location + * @param longitude Longitude of the location + * @param livePeriod Optional. Period in seconds for which the location will be updated (see https://telegram.org/blog/live-locations, should be between 60 and 86400. + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param horizontalAccuracy Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + * @param heading Optional. For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. + * @param proximityAlertRadius Optional. For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendLocation(boost::variant chatId, + float latitude, + float longitude, + std::int32_t livePeriod = 0, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + bool disableNotification = false, + float horizontalAccuracy = 0, + std::int32_t heading = 0, + std::int32_t proximityAlertRadius = 0, + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to edit live location messages. + * + * A location can be edited until its livePeriod expires or editing is explicitly disabled by a call to Api::stopMessageLiveLocation. + * + * @param latitude Latitude of new location + * @param longitude Longitude of new location + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message to edit + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * @param replyMarkup Optional. A JSON-serialized object for a new inline keyboard. + * @param horizontalAccuracy Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + * @param heading Optional. Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. + * @param proximityAlertRadius Optional. The maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. + * + * @return On success, the edited Message is returned. + */ + Message::Ptr editMessageLiveLocation(float latitude, + float longitude, + boost::variant chatId = "", + std::int32_t messageId = 0, + const std::string& inlineMessageId = "", + InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared(), + float horizontalAccuracy = 0, + std::int32_t heading = 0, + std::int32_t proximityAlertRadius = 0) const override; + + /** + * @brief Use this method to stop updating a live location message before livePeriod expires. + * + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message with live location to stop + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * @param replyMarkup Optional. A JSON-serialized object for a new inline keyboard. + * + * @return On success, the edited Message is returned. + */ + Message::Ptr stopMessageLiveLocation(boost::variant chatId = "", + std::int32_t messageId = 0, + const std::string& inlineMessageId = "", + InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared()) const override; + + /** + * @brief Use this method to send information about a venue. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param latitude Latitude of the venue + * @param longitude Longitude of the venue + * @param title Name of the venue + * @param address Address of the venue + * @param foursquareId Optional. Foursquare identifier of the venue + * @param foursquareType Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param googlePlaceId Optional. Google Places identifier of the venue + * @param googlePlaceType Optional. Google Places type of the venue. (See https://developers.google.com/places/web-service/supported_types) + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendVenue(boost::variant chatId, + float latitude, + float longitude, + const std::string& title, + const std::string& address, + const std::string& foursquareId = "", + const std::string& foursquareType = "", + bool disableNotification = false, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& googlePlaceId = "", + const std::string& googlePlaceType = "", + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send phone contacts. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param phoneNumber Contact's phone number + * @param firstName Contact's first name + * @param lastName Optional. Contact's last name + * @param vcard Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendContact(boost::variant chatId, + const std::string& phoneNumber, + const std::string& firstName, + const std::string& lastName = "", + const std::string& vcard = "", + bool disableNotification = false, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send a native poll. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param question Poll question, 1-300 characters + * @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param isAnonymous Optional. True, if the poll needs to be anonymous, defaults to True + * @param type Optional. Poll type, “quiz” or “regular”, defaults to “regular” + * @param allowsMultipleAnswers Optional. True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False + * @param correctOptionId Optional. 0-based identifier of the correct answer option, required for polls in quiz mode + * @param explanation Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing + * @param explanationParseMode Optional. Mode for parsing entities in the explanation. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param explanationEntities Optional. List of special entities that appear in the poll explanation, which can be specified instead of parseMode + * @param openPeriod Optional. Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with closeDate. + * @param closeDate Optional. Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with openPeriod. + * @param isClosed Optional. Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendPoll(boost::variant chatId, + const std::string& question, + const std::vector& options, + bool disableNotification = false, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + bool isAnonymous = true, + const std::string& type = "", + bool allowsMultipleAnswers = false, + std::int32_t correctOptionId = -1, + const std::string& explanation = "", + const std::string& explanationParseMode = "", + const std::vector& explanationEntities = std::vector(), + std::int32_t openPeriod = 0, + std::int32_t closeDate = 0, + bool isClosed = false, + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to send an animated emoji that will display a random value. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param emoji Optional. Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Dice can have values 1-6 for “🎲”, “🎯” and “🎳”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲” + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendDice(boost::variant chatId, + bool disableNotification = false, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + const std::string& emoji = "", + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to change the chosen reactions on a message. + * + * Service messages can't be reacted to. + * Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead. + * @param reaction Optional. A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. + * @param isBig Optional. Pass True to set the reaction with a big animation + * + * @return Returns True on success. + */ + bool setMessageReaction(boost::variant chatId, + std::int32_t messageId = 0, + const std::vector& reaction = std::vector(), + bool isBig = false) const override; + + /** + * @brief Use this method when you need to tell the user that something is happening on the bot's side. + * + * The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). + * + * Example: The [ImageBot](https://t.me/imagebot) needs some time to process a request and upload the image. + * Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use Api::sendChatAction with action = upload_photo. + * The user will see a “sending photo” status for the bot. + * + * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, choose_sticker for stickers, find_location for location data, record_video_note or upload_video_note for video notes. + * @param messageThreadId Optional. Unique identifier for the target message thread; for supergroups only + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the action will be sent + * + * @return Returns True on success. + */ + bool sendChatAction(std::int64_t chatId, + const std::string& action, + std::int32_t messageThreadId = 0, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to get a list of profile pictures for a user. + * + * @param userId Unique identifier of the target user + * @param offset Optional. Sequential number of the first photo to be returned. By default, all photos are returned. + * @param limit Optional. Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100. + * + * @return Returns a UserProfilePhotos object. + */ + UserProfilePhotos::Ptr getUserProfilePhotos(std::int64_t userId, + std::int32_t offset = 0, + std::int32_t limit = 100) const override; + + /** + * @brief Use this method to get basic information about a file and prepare it for downloading. + * + * For the moment, bots can download files of up to 20MB in size. + * The file can then be downloaded via Api::downloadFile or via the link https://api.telegram.org/file/bot/, where filePath is taken from the response. + * It is guaranteed that the filePath will be valid for at least 1 hour. + * When the link expires, a new one can be requested by calling Api::getFile again. + * + * This function may not preserve the original file name and MIME type. + * You should save the file's MIME type and name (if available) when the File object is received. + * + * @param fileId File identifier to get information about + * + * @return On success, a File object is returned. + */ + File::Ptr getFile(const std::string& fileId) const override; + + /** + * @brief Use this method to ban a user in a group, a supergroup or a channel. + * + * In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername) + * @param userId Unique identifier of the target user + * @param untilDate Optional. Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only. + * @param revokeMessages Optional. Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels. + * + * @return Returns True on success. + */ + bool banChatMember(boost::variant chatId, + std::int64_t userId, + std::int32_t untilDate = 0, + bool revokeMessages = true) const override; + + /** + * @brief Use this method to unban a previously banned user in a supergroup or channel. + * + * The user will not return to the group or channel automatically, but will be able to join via link, etc. + * The bot must be an administrator for this to work. + * By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. + * So if the user is a member of the chat they will also be removed from the chat. + * If you don't want this, use the parameter onlyIfBanned. + * + * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername) + * @param userId Unique identifier of the target user + * @param onlyIfBanned Optional. Pass True to do nothing if the user is not banned + * + * @return Returns True on success. + */ + bool unbanChatMember(boost::variant chatId, + std::int64_t userId, + bool onlyIfBanned = false) const override; + + /** + * @brief Use this method to restrict a user in a supergroup. + * + * The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights. + * Pass True for all permissions to lift restrictions from a user. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param userId Unique identifier of the target user + * @param permissions A JSON-serialized object for new user permissions + * @param untilDate Optional. Date when restrictions will be lifted for the user; Unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever + * @param useIndependentChatPermissions Optional. Pass True if chat permissions are set independently. Otherwise, the canSendOtherMessages and canAddWebPagPreviews permissions will imply the canSendMessages, canSendAudios, canSendDocuments, canSendPhotos, canSendVideos, canSendVideoNotes, and canSendVoiceNotes permissions; the canSendPolls permission will imply the canSendMessages permission. + * + * @return Returns True on success. + */ + bool restrictChatMember(boost::variant chatId, + std::int64_t userId, + ChatPermissions::Ptr permissions, + std::uint32_t untilDate = 0, + bool useIndependentChatPermissions = false) const override; + + /** + * @brief Use this method to promote or demote a user in a supergroup or a channel. + * + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Pass False for all boolean parameters to demote a user. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param userId Unique identifier of the target user + * @param canChangeInfo Optional. Pass True if the administrator can change chat title, photo and other settings + * @param canPostMessages Optional. Pass True if the administrator can post messages in the channel, or access channel statistics; for channels only + * @param canEditMessages Optional. Pass True if the administrator can edit messages of other users and can pin messages; for channels only + * @param canDeleteMessages Optional. Pass True if the administrator can delete messages of other users + * @param canInviteUsers Optional. Pass True if the administrator can invite new users to the chat + * @param canPinMessages Optional. Pass True if the administrator can pin messages; for supergroups only + * @param canPromoteMembers Optional. Pass True if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by him) + * @param isAnonymous Optional. Pass True if the administrator's presence in the chat is hidden + * @param canManageChat Optional. Pass True if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode. Implied by any other administrator privilege. + * @param canManageVideoChats Optional. Pass True if the administrator can manage video chats + * @param canRestrictMembers Optional. Pass True if the administrator can restrict, ban or unban chat members, or access supergroup statistics + * @param canManageTopics Optional. Pass True if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only + * @param canPostStories Optional. Pass True if the administrator can post stories to the chat + * @param canEditStories Optional. Pass True if the administrator can edit stories posted by other users + * @param canDeleteStories Optional. Pass True if the administrator can delete stories posted by other users + * + * @return Returns True on success. + */ + bool promoteChatMember(boost::variant chatId, + std::int64_t userId, + bool canChangeInfo = false, + bool canPostMessages = false, + bool canEditMessages = false, + bool canDeleteMessages = false, + bool canInviteUsers = false, + bool canPinMessages = false, + bool canPromoteMembers = false, + bool isAnonymous = false, + bool canManageChat = false, + bool canManageVideoChats = false, + bool canRestrictMembers = false, + bool canManageTopics = false, + bool canPostStories = false, + bool canEditStories = false, + bool canDeleteStories = false) const override; + + /** + * @brief Use this method to set a custom title for an administrator in a supergroup promoted by the bot. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param userId Unique identifier of the target user + * @param customTitle New custom title for the administrator; 0-16 characters, emoji are not allowed + * + * @return Returns True on success. + */ + bool setChatAdministratorCustomTitle(boost::variant chatId, + std::int64_t userId, + const std::string& customTitle) const override; + + /** + * @brief Use this method to ban a channel chat in a supergroup or a channel. + * + * Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. + * The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param senderChatId Unique identifier of the target sender chat + * + * @return Returns True on success. + */ + bool banChatSenderChat(boost::variant chatId, + std::int64_t senderChatId) const override; + + /** + * @brief Use this method to unban a previously banned channel chat in a supergroup or channel. + * + * The bot must be an administrator for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param senderChatId Unique identifier of the target sender chat + * + * @return Returns True on success. + */ + bool unbanChatSenderChat(boost::variant chatId, + std::int64_t senderChatId) const override; + + /** + * @brief Use this method to set default chat permissions for all members. + * + * The bot must be an administrator in the group or a supergroup for this to work and must have the canRestrictMembers administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param permissions A JSON-serialized object for new default chat permissions + * @param useIndependentChatPermissions Optional. Pass True if chat permissions are set independently. Otherwise, the canSendOtherMessages and canAddWebPagPreviews permissions will imply the canSendMessages, canSendAudios, canSendDocuments, canSendPhotos, canSendVideos, canSendVideoNotes, and canSendVoiceNotes permissions; the canSendPolls permission will imply the canSendMessages permission. + * + * @return Returns True on success. + */ + bool setChatPermissions(boost::variant chatId, + ChatPermissions::Ptr permissions, + bool useIndependentChatPermissions = false) const override; + + /** + * @brief Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. + * + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * + * Each administrator in a chat generates their own invite links. + * Bots can't use invite links generated by other administrators. + * If you want your bot to work with invite links, it will need to generate its own link using Api::exportChatInviteLink or by calling the Api::getChat method. + * If your bot needs to generate a new primary invite link replacing its previous one, use Api::exportChatInviteLink again. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * + * @return Returns the new invite link as String on success. + */ + std::string exportChatInviteLink(boost::variant chatId) const override; + + /** + * @brief Use this method to create an additional invite link for a chat. + * + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * The link can be revoked using the method Api::revokeChatInviteLink. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param expireDate Optional. Point in time (Unix timestamp) when the link will expire + * @param memberLimit Optional. The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 + * @param name Optional. Invite link name; 0-32 characters + * @param createsJoinRequest Optional. True, if users joining the chat via the link need to be approved by chat administrators. If True, memberLimit can't be specified + * + * @return Returns the new invite link as ChatInviteLink object. + */ + ChatInviteLink::Ptr createChatInviteLink(boost::variant chatId, + std::int32_t expireDate = 0, + std::int32_t memberLimit = 0, + const std::string& name = "", + bool createsJoinRequest = false) const override; + + /** + * @brief Use this method to edit a non-primary invite link created by the bot. + * + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param inviteLink The invite link to edit + * @param expireDate Optional. Point in time (Unix timestamp) when the link will expire + * @param memberLimit Optional. Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 + * @param name Optional. Invite link name; 0-32 characters + * @param createsJoinRequest Optional. True, if users joining the chat via the link need to be approved by chat administrators. If True, memberLimit can't be specified + * + * @return Returns the edited invite link as a ChatInviteLink object. + */ + ChatInviteLink::Ptr editChatInviteLink(boost::variant chatId, + const std::string& inviteLink, + std::int32_t expireDate = 0, + std::int32_t memberLimit = 0, + const std::string& name = "", + bool createsJoinRequest = false) const override; + + /** + * @brief Use this method to revoke an invite link created by the bot. + * + * If the primary link is revoked, a new link is automatically generated. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier of the target chat or username of the target channel (in the format @channelusername) + * @param inviteLink The invite link to revoke + * + * @return Returns the revoked invite link as ChatInviteLink object. + */ + ChatInviteLink::Ptr revokeChatInviteLink(boost::variant chatId, + const std::string& inviteLink) const override; + + /** + * @brief Use this method to approve a chat join request. + * + * The bot must be an administrator in the chat for this to work and must have the canInviteUsers administrator right. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param userId Unique identifier of the target user + * + * @return Returns True on success. + */ + bool approveChatJoinRequest(boost::variant chatId, + std::int64_t userId) const override; + + /** + * @brief Use this method to decline a chat join request. + * + * The bot must be an administrator in the chat for this to work and must have the canInviteUsers administrator right. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param userId Unique identifier of the target user + * + * @return True on success. + */ + bool declineChatJoinRequest(boost::variant chatId, + std::int64_t userId) const override; + + /** + * @brief Use this method to set a new profile photo for the chat. + * + * Photos can't be changed for private chats. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param photo New chat photo, uploaded using multipart/form-data + * + * @return Returns True on success. + */ + bool setChatPhoto(boost::variant chatId, + InputFile::Ptr photo) const override; + + /** + * @brief Use this method to delete a chat photo. + * + * Photos can't be changed for private chats. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * + * @return Returns True on success. + */ + bool deleteChatPhoto(boost::variant chatId) const override; + + /** + * @brief Use this method to change the title of a chat. + * + * Titles can't be changed for private chats. + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param title New chat title, 1-255 characters + * + * @return Returns True on success. + */ + bool setChatTitle(boost::variant chatId, + const std::string& title) const override; + + /** + * @brief Use this method to change the description of a group, a supergroup or a channel. + * + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param description New chat description, 0-255 characters + * + * @return Returns True on success. + */ + bool setChatDescription(boost::variant chatId, + const std::string& description = "") const override; + + /** + * @brief Use this method to add a message to the list of pinned messages in a chat. + * + * If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'canPinMessages' administrator right in a supergroup or 'canEditMessages' administrator right in a channel. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Identifier of a message to pin + * @param disableNotification Optional. Pass True if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats. + * + * @return Returns True on success. + */ + bool pinChatMessage(boost::variant chatId, + std::int32_t messageId, + bool disableNotification = false) const override; + + /** + * @brief Use this method to remove a message from the list of pinned messages in a chat. + * + * If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'canPinMessages' administrator right in a supergroup or 'canEditMessages' administrator right in a channel. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional. Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned. + * + * @return Returns True on success. + */ + bool unpinChatMessage(boost::variant chatId, + std::int32_t messageId = 0) const override; + + /** + * @brief Use this method to clear the list of pinned messages in a chat. + * + * If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'canPinMessages' administrator right in a supergroup or 'canEditMessages' administrator right in a channel. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * + * @return Returns True on success. + */ + bool unpinAllChatMessages(boost::variant chatId) const override; + + /** + * @brief Use this method for your bot to leave a group, supergroup or channel. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * + * @return Returns True on success. + */ + bool leaveChat(boost::variant chatId) const override; + + /** + * @brief Use this method to get up to date information about the chat. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * + * @return Returns a Chat object on success. + */ + Chat::Ptr getChat(boost::variant chatId) const override; + + /** + * @brief Use this method to get a list of administrators in a chat, which aren't bots. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * + * @return Returns an Array of ChatMember objects. + */ + std::vector getChatAdministrators(boost::variant chatId) const override; + + /** + * @brief Use this method to get the number of members in a chat. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * + * @return Returns Int on success. + */ + std::int32_t getChatMemberCount(boost::variant chatId) const override; + + /** + * @brief Use this method to get information about a member of a chat. + * + * The method is only guaranteed to work for other users if the bot is an administrator in the chat. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * @param userId Unique identifier of the target user + * + * @return Returns a ChatMember object on success. + */ + ChatMember::Ptr getChatMember(boost::variant chatId, + std::int64_t userId) const override; + + /** + * @brief Use this method to set a new group sticker set for a supergroup. + * + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Use the field canSetStickerSet optionally returned in Api::getChat requests to check if the bot can use this method. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param stickerSetName Name of the sticker set to be set as the group sticker set + * + * @return Returns True on success. + */ + bool setChatStickerSet(boost::variant chatId, + const std::string& stickerSetName) const override; + + /** + * @brief Use this method to delete a group sticker set from a supergroup. + * + * The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. + * Use the field canSetSticker_set optionally returned in Api::getChat requests to check if the bot can use this method. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * + * @return Returns True on success. + */ + bool deleteChatStickerSet(boost::variant chatId) const override; + + /** + * @brief Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. + * + * @return Returns an Array of Sticker objects. + */ + std::vector getForumTopicIconStickers() const override; + + /** + * @brief Use this method to create a topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param name Topic name, 1-128 characters + * @param iconColor Optional. Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F) + * @param iconCustomEmojiId Optional. Unique identifier of the custom emoji shown as the topic icon. Use Api::getForumTopicIconStickers to get all allowed custom emoji identifiers. + * + * @return Returns information about the created topic as a ForumTopic object. + */ + ForumTopic::Ptr createForumTopic(boost::variant chatId, + const std::string& name, + std::int32_t iconColor = 0, + const std::string& iconCustomEmojiId = "") const override; + + /** + * @brief Use this method to edit name and icon of a topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have canManageTopics administrator rights, unless it is the creator of the topic. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param messageThreadId Unique identifier for the target message thread of the forum topic + * @param name Optional. New topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept + * @param iconCustomEmojiId Optional. New unique identifier of the custom emoji shown as the topic icon. Use Api::getForumTopicIconStickers to get all allowed custom emoji identifiers. Pass an empty string to remove the icon. If not specified, the current icon will be kept + * + * @return Returns True on success. + */ + bool editForumTopic(boost::variant chatId, + std::int32_t messageThreadId, + const std::string& name = "", + boost::variant iconCustomEmojiId = 0) const override; + + /** + * @brief Use this method to close an open topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights, unless it is the creator of the topic. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return Returns True on success. + */ + bool closeForumTopic(boost::variant chatId, + std::int32_t messageThreadId) const override; + + /** + * @brief Use this method to reopen a closed topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights, unless it is the creator of the topic. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return Returns True on success. + */ + bool reopenForumTopic(boost::variant chatId, + std::int32_t messageThreadId) const override; + + /** + * @brief Use this method to delete a forum topic along with all its messages in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have the canDeleteMessages administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return Returns True on success. + */ + bool deleteForumTopic(boost::variant chatId, + std::int32_t messageThreadId) const override; + + /** + * @brief Use this method to clear the list of pinned messages in a forum topic. + * + * The bot must be an administrator in the chat for this to work and must have the canPinMessages administrator right in the supergroup. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param messageThreadId Unique identifier for the target message thread of the forum topic + * + * @return Returns True on success. + */ + bool unpinAllForumTopicMessages(boost::variant chatId, + std::int32_t messageThreadId) const override; + + /** + * @brief Use this method to edit the name of the 'General' topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have canManageTopics administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * @param name New topic name, 1-128 characters + * + * @return Returns True on success. + */ + bool editGeneralForumTopic(boost::variant chatId, + std::string name) const override; + + /** + * @brief Use this method to close an open 'General' topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * + * @return Returns True on success. + */ + bool closeGeneralForumTopic(boost::variant chatId) const override; + + /** + * @brief Use this method to reopen a closed 'General' topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights. + * The topic will be automatically unhidden if it was hidden. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * + * @return Returns True on success. + */ + bool reopenGeneralForumTopic(boost::variant chatId) const override; + + /** + * @brief Use this method to hide the 'General' topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights. + * The topic will be automatically closed if it was open. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * + * @return Returns True on success. + */ + bool hideGeneralForumTopic(boost::variant chatId) const override; + + /** + * @brief Use this method to unhide the 'General' topic in a forum supergroup chat. + * + * The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * + * @return Returns True on success. + */ + bool unhideGeneralForumTopic(boost::variant chatId) const override; + + /** + * @brief Use this method to clear the list of pinned messages in a General forum topic. + * + * The bot must be an administrator in the chat for this to work and must have the canPinMessages administrator right in the supergroup. + * + * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) + * + * @return Returns True on success. + */ + bool unpinAllGeneralForumTopicMessages(boost::variant chatId) const override; + + /** + * @brief Use this method to send answers to callback queries sent from inline keyboards. + * + * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. + * + * Alternatively, the user can be redirected to the specified Game URL. + * For this option to work, you must first create a game for your bot via @BotFather and accept the terms. + * Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter. + * + * @param callbackQueryId Unique identifier for the query to be answered + * @param text Optional. Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters + * @param showAlert Optional. If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. + * @param url Optional. URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @BotFather, specify the URL that opens your game - note that this will only work if the query comes from an InlineKeyboardButton button. + * @param cacheTime Optional. The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0. + * + * @return On success, True is returned. + */ + bool answerCallbackQuery(const std::string& callbackQueryId, + const std::string& text = "", + bool showAlert = false, + const std::string& url = "", + std::int32_t cacheTime = 0) const override; + + /** + * @brief Use this method to get the list of boosts added to a chat by a user. + * + * Requires administrator rights in the chat. + * + * @param chatId Unique identifier for the chat or username of the channel (in the format @channelusername) + * @param userId Unique identifier of the target user + * + * @return Returns a UserChatBoosts object. + */ + UserChatBoosts::Ptr getUserChatBoosts(boost::variant chatId, + std::int32_t userId) const override; + + /** + * @brief Use this method to get information about the connection of the bot with a business account. + * + * @param businessConnectionId Unique identifier of the business connection + * + * @return Returns a BusinessConnection object on success. + */ + BusinessConnection::Ptr getBusinessConnection(const std::string& businessConnectionId) const override; + + /** + * @brief Use this method to change the list of the bot's commands. + * + * See https://core.telegram.org/bots#commands for more details about bot commands. + * + * @param commands A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified. + * @param scope Optional. A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault. + * @param languageCode Optional. A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands + * + * @return Returns True on success. + */ + bool setMyCommands(const std::vector& commands, + BotCommandScope::Ptr scope = nullptr, + const std::string& languageCode = "") const override; + + /** + * @brief Use this method to delete the list of the bot's commands for the given scope and user language. + * + * After deletion, higher level commands will be shown to affected users. + * + * @param scope Optional. A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault. + * @param languageCode Optional. A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands + * + * @return Returns True on success. + */ + bool deleteMyCommands(BotCommandScope::Ptr scope = nullptr, + const std::string& languageCode = "") const override; + + /** + * @brief Use this method to get the current list of the bot's commands for the given scope and user language. + * + * @param scope Optional. A JSON-serialized object, describing scope of users. Defaults to BotCommandScopeDefault. + * @param languageCode Optional. A two-letter ISO 639-1 language code or an empty string + * + * @return Returns an Array of BotCommand objects. If commands aren't set, an empty list is returned. + */ + std::vector getMyCommands(BotCommandScope::Ptr scope = nullptr, + const std::string& languageCode = "") const override; + + /** + * @brief Use this method to change the bot's name. + * + * @param name Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language. + * @param languageCode Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name. + * + * @return Returns True on success. + */ + bool setMyName(const std::string& name = "", + const std::string& languageCode = "") const override; + + /** + * @brief Use this method to get the current bot name for the given user language. + * + * @param languageCode Optional. A two-letter ISO 639-1 language code or an empty string + * + * @return Returns BotName on success. + */ + BotName::Ptr getMyName(const std::string& languageCode = "") const override; + + /** + * @brief Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. + * + * @param description Optional. New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language. + * @param languageCode Optional. A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description. + * + * @return Returns True on success. + */ + bool setMyDescription(const std::string& description = "", + const std::string& languageCode = "") const override; + + /** + * @brief Use this method to get the current bot description for the given user language. + * + * @param languageCode Optional. A two-letter ISO 639-1 language code or an empty string + * + * @return Returns BotDescription on success. + */ + BotDescription::Ptr getMyDescription(const std::string& languageCode = "") const override; + + /** + * @brief Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. + * + * @param shortDescription Optional. New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language. + * @param languageCode Optional. A two-letter ISO 639-1 language code. If empty, the short description will be applied to all users for whose language there is no dedicated short description. + * + * @return Returns True on success. + */ + bool setMyShortDescription(const std::string& shortDescription = "", + const std::string& languageCode = "") const override; + + /** + * @brief Use this method to get the current bot short description for the given user language. + * + * @param languageCode Optional. A two-letter ISO 639-1 language code or an empty string + * + * @return Returns BotShortDescription on success. + */ + BotShortDescription::Ptr getMyShortDescription(const std::string& languageCode = "") const override; + + /** + * @brief Use this method to change the bot's menu button in a private chat, or the default menu button. + * + * @param chatId Optional. Unique identifier for the target private chat. If not specified, default bot's menu button will be changed + * @param menuButton Optional. A JSON-serialized object for the bot's new menu button. Defaults to MenuButtonDefault + * + * @return Returns True on success. + */ + bool setChatMenuButton(std::int64_t chatId = 0, + MenuButton::Ptr menuButton = nullptr) const override; + + /** + * @brief Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. + * + * @param chatId Optional. Unique identifier for the target private chat. If not specified, default bot's menu button will be returned + * + * @return Returns MenuButton on success. + */ + MenuButton::Ptr getChatMenuButton(std::int64_t chatId = 0) const override; + + /** + * @brief Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. + * + * These rights will be suggested to users, but they are free to modify the list before adding the bot. + * + * @param rights Optional. A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared. + * @param forChannels Optional. Pass True to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed. + * + * @return Returns True on success. + */ + bool setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights = nullptr, + bool forChannels = false) const override; + + /** + * @brief Use this method to get the current default administrator rights of the bot. + * + * @param forChannels Optional. Pass True to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned. + * + * @return Returns ChatAdministratorRights on success. + */ + ChatAdministratorRights::Ptr getMyDefaultAdministratorRights(bool forChannels = false) const override; + + /** + * @brief Use this method to edit text and [game](https://core.telegram.org/bots/api#games) messages. + * + * @param text New text of the message, 1-4096 characters after entities parsing + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message to edit + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * @param parseMode Optional. Mode for parsing entities in the message text. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param linkPreviewOptions Optional. Link preview generation options for the message + * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. + * @param entities Optional. List of special entities that appear in message text, which can be specified instead of parseMode + * + * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned. + */ + Message::Ptr editMessageText(const std::string& text, + boost::variant chatId = 0, + std::int32_t messageId = 0, + const std::string& inlineMessageId = "", + const std::string& parseMode = "", + LinkPreviewOptions::Ptr linkPreviewOptions = nullptr, + InlineKeyboardMarkup::Ptr replyMarkup = nullptr, + const std::vector& entities = std::vector()) const override; + + /** + * @brief Use this method to edit captions of messages. + * + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message to edit + * @param caption Optional. New caption of the message, 0-1024 characters after entities parsing + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. + * @param parseMode Optional. Mode for parsing entities in the message caption. See https://core.telegram.org/bots/api#formatting-options for more details. + * @param captionEntities Optional. List of special entities that appear in the caption, which can be specified instead of parseMode + * + * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned. + */ + Message::Ptr editMessageCaption(boost::variant chatId = 0, + std::int32_t messageId = 0, + const std::string& caption = "", + const std::string& inlineMessageId = "", + GenericReply::Ptr replyMarkup = nullptr, + const std::string& parseMode = "", + const std::vector& captionEntities = std::vector()) const override; + + /** + * @brief Use this method to edit animation, audio, document, photo, or video messages. + * + * If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. + * When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its fileId or specify a URL. + * + * @param media A JSON-serialized object for a new media content of the message + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message to edit + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * @param replyMarkup Optional. A JSON-serialized object for a new inline keyboard. + * + * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned. + */ + Message::Ptr editMessageMedia(InputMedia::Ptr media, + boost::variant chatId = 0, + std::int32_t messageId = 0, + const std::string& inlineMessageId = "", + GenericReply::Ptr replyMarkup = nullptr) const override; + + /** + * @brief Use this method to edit only the reply markup of messages. + * + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the message to edit + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. + * + * @return On success, if the edited message is not an inline message, the edited Message is returned, otherwise nullptr is returned. + */ + Message::Ptr editMessageReplyMarkup(boost::variant chatId = 0, + std::int32_t messageId = 0, + const std::string& inlineMessageId = "", + GenericReply::Ptr replyMarkup = nullptr) const override; + + /** + * @brief Use this method to stop a poll which was sent by the bot. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Identifier of the original message with the poll + * @param replyMarkup Optional. A JSON-serialized object for a new message inline keyboard. + * + * @return On success, the stopped Poll is returned. + */ + Poll::Ptr stopPoll(boost::variant chatId, + std::int64_t messageId, + InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared()) const override; + + /** + * @brief Use this method to delete a message, including service messages, with the following limitations: + * + * - A message can only be deleted if it was sent less than 48 hours ago. + * - Service messages about a supergroup, channel, or forum topic creation can't be deleted. + * - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago. + * - Bots can delete outgoing messages in private chats, groups, and supergroups. + * - Bots can delete incoming messages in private chats. + * - Bots granted canPostMessages permissions can delete outgoing messages in channels. + * - If the bot is an administrator of a group, it can delete any message there. + * - If the bot has canDeleteMessages permission in a supergroup or a channel, it can delete any message there. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Identifier of the message to delete + * + * @return Returns True on success. + */ + bool deleteMessage(boost::variant chatId, + std::int32_t messageId) const override; + + /** + * @brief Use this method to delete multiple messages simultaneously. + * + * If some of the specified messages can't be found, they are skipped. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageIds A JSON-serialized list of 1-100 identifiers of messages to delete. See Api::deleteMessage for limitations on which messages can be deleted + * + * @return Returns True on success. + */ + bool deleteMessages(boost::variant chatId, + const std::vector& messageIds) const override; + + /** + * @brief Use this method to send static .WEBP, [animated](https://telegram.org/blog/animated-stickers) .TGS, or [video](https://telegram.org/blog/video-stickers-better-reactions) .WEBM stickers. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param sticker Sticker to send. Pass a fileId as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .WEBP sticker from the Internet, or upload a new .WEBP, .TGS, or .WEBM sticker using multipart/form-data. [More information on Sending Files »](https://core.telegram.org/bots/api#sending-files). Video and animated stickers can't be sent via an HTTP URL. + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards), [custom reply keyboard](https://core.telegram.org/bots/features#keyboards), instructions to remove a reply keyboard or to force a reply from the user. Not supported for messages sent on behalf of a business account + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param emoji Optional. Emoji associated with the sticker; only for just uploaded stickers + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendSticker(boost::variant chatId, + boost::variant sticker, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + bool disableNotification = false, + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& emoji = "", + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to get a sticker set. + * + * @param name Name of the sticker set + * + * @return On success, a StickerSet object is returned. + */ + StickerSet::Ptr getStickerSet(const std::string& name) const override; + + /** + * @brief Use this method to get information about custom emoji stickers by their identifiers. + * + * @param customEmojiIds A JSON-serialized list of custom emoji identifiers. At most 200 custom emoji identifiers can be specified. + * + * @return Returns an Array of Sticker objects. + */ + std::vector getCustomEmojiStickers(const std::vector& customEmojiIds) const override; + + /** + * @brief Use this method to upload a file with a sticker for later use in the Api::createNewStickerSet, Api::addStickerToSet, or Api::replaceStickerInSet methods (the file can be used multiple times). + * + * @param userId User identifier of sticker file owner + * @param sticker A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See https://core.telegram.org/stickers for technical requirements. https://core.telegram.org/bots/api#sending-files + * @param stickerFormat Format of the sticker, must be one of “static”, “animated”, “video” + * + * @return Returns the uploaded File on success. + */ + File::Ptr uploadStickerFile(std::int64_t userId, + InputFile::Ptr sticker, + const std::string& stickerFormat) const override; + + /** + * @brief Use this method to create a new sticker set owned by a user. + * + * The bot will be able to edit the sticker set thus created. + * + * @param userId User identifier of created sticker set owner + * @param name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only English letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in "_by_". is case insensitive. 1-64 characters. + * @param title Sticker set title, 1-64 characters + * @param stickers A JSON-serialized list of 1-50 initial stickers to be added to the sticker set + * @param stickerType Optional. Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created. + * @param needsRepainting Optional. Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only + * + * @return Returns True on success. + */ + bool createNewStickerSet(std::int64_t userId, + const std::string& name, + const std::string& title, + const std::vector& stickers, + Sticker::Type stickerType = Sticker::Type::Regular, + bool needsRepainting = false) const override; + + /** + * @brief Use this method to add a new sticker to a set created by the bot. + * + * Emoji sticker sets can have up to 200 stickers. + * Other sticker sets can have up to 120 stickers. + * + * @param userId User identifier of sticker set owner + * @param name Sticker set name + * @param sticker A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set isn't changed. + * + * @return Returns True on success. + */ + bool addStickerToSet(std::int64_t userId, + const std::string& name, + InputSticker::Ptr sticker) const override; + + /** + * @brief Use this method to move a sticker in a set created by the bot to a specific position. + * + * @param sticker File identifier of the sticker + * @param position New sticker position in the set, zero-based + * + * @return Returns True on success. + */ + bool setStickerPositionInSet(const std::string& sticker, + std::int32_t position) const override; + + /** + * @brief Use this method to delete a sticker from a set created by the bot. + * + * @param sticker File identifier of the sticker + * + * @return Returns True on success. + */ + bool deleteStickerFromSet(const std::string& sticker) const override; + + /** + * @brief Use this method to replace an existing sticker in a sticker set with a new one. + * + * The method is equivalent to calling Api::deleteStickerFromSet, then Api::addStickerToSet, then Api::setStickerPositionInSet. + * + * @param userId User identifier of the sticker set owner + * @param name Sticker set name + * @param oldSticker File identifier of the replaced sticker + * @param sticker A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged. + * + * @return Returns True on success. + */ + bool replaceStickerInSet(std::int64_t userId, + const std::string& name, + const std::string& oldSticker, + InputSticker::Ptr sticker) const override; + + /** + * @brief Use this method to change the list of emoji assigned to a regular or custom emoji sticker. + * + * The sticker must belong to a sticker set created by the bot. + * + * @param sticker File identifier of the sticker + * @param emojiList A JSON-serialized list of 1-20 emoji associated with the sticker + * + * @return Returns True on success. + */ + bool setStickerEmojiList(const std::string& sticker, + const std::vector& emojiList) const override; + + /** + * @brief Use this method to change search keywords assigned to a regular or custom emoji sticker. + * + * The sticker must belong to a sticker set created by the bot. + * + * @param sticker File identifier of the sticker + * @param keywords Optional. A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters + * + * @return Returns True on success. + */ + bool setStickerKeywords(const std::string& sticker, + const std::vector& keywords = std::vector()) const override; + + /** + * @brief Use this method to change the mask position of a mask sticker. + * + * The sticker must belong to a sticker set that was created by the bot. + * + * @param sticker File identifier of the sticker + * @param maskPosition A JSON-serialized object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position. + * + * @return Returns True on success. + */ + bool setStickerMaskPosition(const std::string& sticker, + MaskPosition::Ptr maskPosition = nullptr) const override; + + /** + * @brief Use this method to set the title of a created sticker set. + * + * @param name Sticker set name + * @param title Sticker set title, 1-64 characters + * + * @return Returns True on success. + */ + bool setStickerSetTitle(const std::string& name, + const std::string& title) const override; + + /** + * @brief Use this method to set the thumbnail of a regular or mask sticker set. + * + * The format of the thumbnail file must match the format of the stickers in the set. + * + * @param name Sticker set name + * @param userId User identifier of the sticker set owner + * @param format Format of the thumbnail, must be one of “static” for a .WEBP or .PNG image, “animated” for a .TGS animation, or “video” for a WEBM video + * @param thumbnail Optional. A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a fileId as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. https://core.telegram.org/bots/api#sending-files. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. + * + * @return Returns True on success. + */ + bool setStickerSetThumbnail(const std::string& name, + std::int64_t userId, + const std::string& format, + boost::variant thumbnail = "") const override; + + /** + * @brief Use this method to set the thumbnail of a custom emoji sticker set. + * + * @param name Sticker set name + * @param customEmojiId Optional. Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail. + * + * @return Returns True on success. + */ + bool setCustomEmojiStickerSetThumbnail(const std::string& name, + const std::string& customEmojiId = "") const override; + + /** + * @brief Use this method to delete a sticker set that was created by the bot. + * + * @param name Sticker set name + * + * @return Returns True on success. + */ + bool deleteStickerSet(const std::string& name) const override; + + /** + * @brief Use this method to send answers to an inline query. + * + * No more than 50 results per query are allowed. + * + * @param inlineQueryId Unique identifier for the answered query + * @param results A JSON-serialized array of results for the inline query + * @param cacheTime Optional. The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300. + * @param isPersonal Optional. Pass True if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query. + * @param nextOffset Optional. Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes. + * @param button Optional. A JSON-serialized object describing a button to be shown above inline query results + * + * @return On success, True is returned. + */ + bool answerInlineQuery(const std::string& inlineQueryId, + const std::vector& results, + std::int32_t cacheTime = 300, + bool isPersonal = false, + const std::string& nextOffset = "", + InlineQueryResultsButton::Ptr button = nullptr) const override; + + /** + * @brief Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated. + * + * @param webAppQueryId Unique identifier for the query to be answered + * @param result A JSON-serialized object describing the message to be sent + * + * @return On success, a SentWebAppMessage object is returned. + */ + SentWebAppMessage::Ptr answerWebAppQuery(const std::string& webAppQueryId, + InlineQueryResult::Ptr result) const override; + + /** + * @brief Use this method to send invoices. + * + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param title Product name, 1-32 characters + * @param description Product description, 1-255 characters + * @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. + * @param providerToken Payments provider token, obtained via Botfather + * @param currency Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies + * @param prices Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + * @param providerData Optional. A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. + * @param photoUrl Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for. + * @param photoSize Optional. Photo size + * @param photoWidth Optional. Photo width + * @param photoHeight Optional. Photo height + * @param needName Optional. Pass True, if you require the user's full name to complete the order + * @param needPhoneNumber Optional. Pass True, if you require the user's phone number to complete the order + * @param needEmail Optional. Pass True, if you require the user's email address to complete the order + * @param needShippingAddress Optional. Pass True, if you require the user's shipping address to complete the order + * @param sendPhoneNumberToProvider Optional. Pass True, if user's phone number should be sent to provider + * @param sendEmailToProvider Optional. Pass True, if user's email address should be sent to provider + * @param isFlexible Optional. Pass True, if the final price depends on the shipping method + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param maxTipAmount Optional. The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in https://core.telegram.org/bots/payments/currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0 + * @param suggestedTipAmounts Optional. A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed maxTipAmount. + * @param startParameter Optional. Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendInvoice(boost::variant chatId, + const std::string& title, + const std::string& description, + const std::string& payload, + const std::string& providerToken, + const std::string& currency, + const std::vector& prices, + const std::string& providerData = "", + const std::string& photoUrl = "", + std::int32_t photoSize = 0, + std::int32_t photoWidth = 0, + std::int32_t photoHeight = 0, + bool needName = false, + bool needPhoneNumber = false, + bool needEmail = false, + bool needShippingAddress = false, + bool sendPhoneNumberToProvider = false, + bool sendEmailToProvider = false, + bool isFlexible = false, + ReplyParameters::Ptr replyParameters = nullptr, + GenericReply::Ptr replyMarkup = nullptr, + bool disableNotification = false, + std::int32_t messageThreadId = 0, + std::int32_t maxTipAmount = 0, + const std::vector& suggestedTipAmounts = std::vector(), + const std::string& startParameter = "", + bool protectContent = false) const override; + + /** + * @brief Use this method to create a link for an invoice. + * + * @param title Product name, 1-32 characters + * @param description Product description, 1-255 characters + * @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. + * @param providerToken Payment provider token, obtained via BotFather + * @param currency Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies + * @param prices Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + * @param maxTipAmount Optional. The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass maxTipAmount = 145. See the exp parameter in https://core.telegram.org/bots/payments/currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0 + * @param suggestedTipAmounts Optional. A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed maxTipAmount. + * @param providerData Optional. JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. + * @param photoUrl Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. + * @param photoSize Optional. Photo size in bytes + * @param photoWidth Optional. Photo width + * @param photoHeight Optional. Photo height + * @param needName Optional. Pass True, if you require the user's full name to complete the order + * @param needPhoneNumber Optional. Pass True, if you require the user's phone number to complete the order + * @param needEmail Optional. Pass True, if you require the user's email address to complete the order + * @param needShippingAddress Optional. Pass True, if you require the user's shipping address to complete the order + * @param sendPhoneNumberToProvider Optional. Pass True, if the user's phone number should be sent to the provider + * @param sendEmailToProvider Optional. Pass True, if the user's email address should be sent to the provider + * @param isFlexible Optional. Pass True, if the final price depends on the shipping method + * + * @return Returns the created invoice link as String on success. + */ + std::string createInvoiceLink(const std::string& title, + const std::string& description, + const std::string& payload, + const std::string& providerToken, + const std::string& currency, + const std::vector& prices, + std::int32_t maxTipAmount = 0, + const std::vector& suggestedTipAmounts = std::vector(), + const std::string& providerData = "", + const std::string& photoUrl = "", + std::int32_t photoSize = 0, + std::int32_t photoWidth = 0, + std::int32_t photoHeight = 0, + bool needName = false, + bool needPhoneNumber = false, + bool needEmail = false, + bool needShippingAddress = false, + bool sendPhoneNumberToProvider = false, + bool sendEmailToProvider = false, + bool isFlexible = false) const override; + + /** + * @brief Use this method to reply to shipping queries. + * + * If you sent an invoice requesting a shipping address and the parameter isFlexible was specified, the Bot API will send an Update with a shippingQuery field to the bot. + * + * @param shippingQueryId Unique identifier for the query to be answered + * @param ok Pass True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible) + * @param shippingOptions Optional. Required if ok is True. A JSON-serialized array of available shipping options. + * @param errorMessage Optional. Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user. + * + * @return On success, True is returned. + */ + bool answerShippingQuery(const std::string& shippingQueryId, + bool ok, + const std::vector& shippingOptions = std::vector(), + const std::string& errorMessage = "") const override; + + /** + * @brief Use this method to respond to such pre-checkout queries. + * + * Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field preCheckoutQuery. + * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. + * + * @param preCheckoutQueryId Unique identifier for the query to be answered + * @param ok Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems. + * @param errorMessage Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user. + * + * @return On success, True is returned. + */ + bool answerPreCheckoutQuery(const std::string& preCheckoutQueryId, + bool ok, + const std::string& errorMessage = "") const override; + + /** + * @brief Informs a user that some of the Telegram Passport elements they provided contains errors. + * + * The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). + * Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. + * For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. + * Supply some details in the error message to make sure the user knows how to correct the issues. + * + * @param userId User identifier + * @param errors A JSON-serialized array describing the errors + * + * @return Returns True on success. + */ + bool setPassportDataErrors(std::int64_t userId, + const std::vector& errors) const override; + + /** + * @brief Use this method to send a game. + * + * @param chatId Unique identifier for the target chat + * @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via @BotFather. + * @param replyParameters Optional. Description of the message to reply to + * @param replyMarkup Optional. A JSON-serialized object for an [inline keyboard](https://core.telegram.org/bots/features#inline-keyboards). If empty, one 'Play gameTitle' button will be shown. If not empty, the first button must launch the game. Not supported for messages sent on behalf of a business account. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param messageThreadId Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @param protectContent Optional. Protects the contents of the sent message from forwarding and saving + * @param businessConnectionId Optional. Unique identifier of the business connection on behalf of which the message will be sent + * + * @return On success, the sent Message is returned. + */ + Message::Ptr sendGame(std::int64_t chatId, + const std::string& gameShortName, + ReplyParameters::Ptr replyParameters = nullptr, + InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared(), + bool disableNotification = false, + std::int32_t messageThreadId = 0, + bool protectContent = false, + const std::string& businessConnectionId = "") const override; + + /** + * @brief Use this method to set the score of the specified user in a game message. + * + * Returns an error, if the new score is not greater than the user's current score in the chat and force is False. + * + * @param userId User identifier + * @param score New score, must be non-negative + * @param force Optional. Pass True if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters + * @param disableEditMessage Optional. Pass True if the game message should not be automatically edited to include the current scoreboard + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * + * @return On success, if the message is not an inline message, the Message is returned, otherwise nullptr is returned. + */ + Message::Ptr setGameScore(std::int64_t userId, + std::int32_t score, + bool force = false, + bool disableEditMessage = false, + std::int64_t chatId = 0, + std::int32_t messageId = 0, + const std::string& inlineMessageId = "") const override; + + /** + * @brief Use this method to get data for high score tables. + * + * Will return the score of the specified user and several of their neighbors in a game. + * + * This method will currently return scores for the target user, plus two of their closest neighbors on each side. + * Will also return the top three users if the user and their neighbors are not among them. + * Please note that this behavior is subject to change. + * + * @param userId Target user id + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * + * @return Returns an Array of GameHighScore objects. + */ + std::vector getGameHighScores(std::int64_t userId, + std::int64_t chatId = 0, + std::int32_t messageId = 0, + const std::string& inlineMessageId = "") const override; + + /** + * @brief Download a file from Telegram and save it in memory. + * + * @param filePath Telegram file path from Api::getFile + * @param args Additional api parameters + * + * @return File content in a string. + */ + std::string downloadFile(const std::string& filePath, + const std::vector& args = std::vector()) const override; + + /** + * @brief Check if user has blocked the bot + * + * @param chatId Unique identifier for the target chat + * + * @return Returns True if bot is blocked by user + */ + bool blockedByUser(std::int64_t chatId) const override; + + std::unique_ptr _httpClient; + + protected: + Json::Value sendRequest( + const std::string& method, + const std::vector& args = std::vector()) const; + + std::string _token; + std::string _url; +}; +} // namespace TgBot +#endif \ No newline at end of file diff --git a/include/tgbot/Bot.h b/include/tgbot/Bot.h index 36d3cb42f..8ee831098 100644 --- a/include/tgbot/Bot.h +++ b/include/tgbot/Bot.h @@ -21,7 +21,7 @@ class HttpClient; class TGBOT_API Bot { public: - explicit Bot(std::string token, const HttpClient &httpClient = _getDefaultHttpClient(), const std::string& url="https://api.telegram.org"); + explicit Bot(std::string token, std::unique_ptr httpClient = _getDefaultHttpClient(), const std::string& url="https://api.telegram.org"); /** * @return Token for accessing api. @@ -34,7 +34,7 @@ class TGBOT_API Bot { * @return Object which can execute Telegram Bot API methods. */ inline const Api& getApi() const { - return _api; + return *_api; } /** @@ -52,12 +52,12 @@ class TGBOT_API Bot { } private: - static HttpClient &_getDefaultHttpClient(); + static std::unique_ptr _getDefaultHttpClient(); - const std::string _token; - const Api _api; + std::string _token; + std::unique_ptr _api; std::unique_ptr _eventBroadcaster; - const EventHandler _eventHandler; + EventHandler _eventHandler; }; } diff --git a/include/tgbot/TgException.h b/include/tgbot/TgException.h index 0fbda9391..a4e1f8cea 100644 --- a/include/tgbot/TgException.h +++ b/include/tgbot/TgException.h @@ -5,6 +5,7 @@ #include #include +#include namespace TgBot { @@ -20,11 +21,11 @@ class TGBOT_API TgException : public std::runtime_error { /** * @brief Enum of possible errors from Api requests */ - enum class ErrorCode : size_t { + enum class ErrorCode : std::int32_t { Undefined = 0, BadRequest = 400, Unauthorized = 401, Forbidden = 403, NotFound = 404, - Flood = 402, Internal = 500, + Flood = 402, Conflict = 409, Internal = 500, HtmlResponse = 100, InvalidJson = 101 }; diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 661930e01..9f10f1be8 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -1,963 +1,556 @@ #ifndef TGBOT_TGTYPEPARSER_H #define TGBOT_TGTYPEPARSER_H -#include "tgbot/export.h" -#include "tgbot/types/Update.h" -#include "tgbot/types/WebhookInfo.h" -#include "tgbot/types/User.h" -#include "tgbot/types/Chat.h" -#include "tgbot/types/Message.h" -#include "tgbot/types/MessageId.h" -#include "tgbot/types/InaccessibleMessage.h" -#include "tgbot/types/MessageEntity.h" -#include "tgbot/types/TextQuote.h" -#include "tgbot/types/ExternalReplyInfo.h" -#include "tgbot/types/ReplyParameters.h" -#include "tgbot/types/MessageOrigin.h" -#include "tgbot/types/MessageOriginUser.h" -#include "tgbot/types/MessageOriginHiddenUser.h" -#include "tgbot/types/MessageOriginChat.h" -#include "tgbot/types/MessageOriginChannel.h" -#include "tgbot/types/PhotoSize.h" +#include +#include +#include +#include +#include +#include +#include + #include "tgbot/types/Animation.h" #include "tgbot/types/Audio.h" -#include "tgbot/types/Document.h" -#include "tgbot/types/Story.h" -#include "tgbot/types/Video.h" -#include "tgbot/types/VideoNote.h" -#include "tgbot/types/Voice.h" -#include "tgbot/types/Contact.h" -#include "tgbot/types/Dice.h" -#include "tgbot/types/PollOption.h" -#include "tgbot/types/PollAnswer.h" -#include "tgbot/types/Poll.h" -#include "tgbot/types/Location.h" -#include "tgbot/types/Venue.h" -#include "tgbot/types/WebAppData.h" -#include "tgbot/types/ProximityAlertTriggered.h" -#include "tgbot/types/MessageAutoDeleteTimerChanged.h" -#include "tgbot/types/ChatBoostAdded.h" -#include "tgbot/types/ForumTopicCreated.h" -#include "tgbot/types/ForumTopicClosed.h" -#include "tgbot/types/ForumTopicEdited.h" -#include "tgbot/types/ForumTopicReopened.h" -#include "tgbot/types/GeneralForumTopicHidden.h" -#include "tgbot/types/GeneralForumTopicUnhidden.h" -#include "tgbot/types/SharedUser.h" -#include "tgbot/types/UsersShared.h" -#include "tgbot/types/ChatShared.h" -#include "tgbot/types/WriteAccessAllowed.h" -#include "tgbot/types/VideoChatScheduled.h" -#include "tgbot/types/VideoChatStarted.h" -#include "tgbot/types/VideoChatEnded.h" -#include "tgbot/types/VideoChatParticipantsInvited.h" -#include "tgbot/types/GiveawayCreated.h" -#include "tgbot/types/Giveaway.h" -#include "tgbot/types/GiveawayWinners.h" -#include "tgbot/types/GiveawayCompleted.h" -#include "tgbot/types/LinkPreviewOptions.h" -#include "tgbot/types/UserProfilePhotos.h" -#include "tgbot/types/File.h" -#include "tgbot/types/WebAppInfo.h" -#include "tgbot/types/ReplyKeyboardMarkup.h" -#include "tgbot/types/KeyboardButton.h" -#include "tgbot/types/KeyboardButtonRequestUsers.h" -#include "tgbot/types/KeyboardButtonRequestChat.h" -#include "tgbot/types/KeyboardButtonPollType.h" -#include "tgbot/types/ReplyKeyboardRemove.h" -#include "tgbot/types/InlineKeyboardMarkup.h" -#include "tgbot/types/InlineKeyboardButton.h" -#include "tgbot/types/LoginUrl.h" -#include "tgbot/types/SwitchInlineQueryChosenChat.h" -#include "tgbot/types/CallbackQuery.h" -#include "tgbot/types/ForceReply.h" -#include "tgbot/types/ChatPhoto.h" -#include "tgbot/types/ChatInviteLink.h" -#include "tgbot/types/ChatAdministratorRights.h" -#include "tgbot/types/ChatMemberUpdated.h" -#include "tgbot/types/ChatMember.h" -#include "tgbot/types/ChatMemberOwner.h" -#include "tgbot/types/ChatMemberAdministrator.h" -#include "tgbot/types/ChatMemberMember.h" -#include "tgbot/types/ChatMemberRestricted.h" -#include "tgbot/types/ChatMemberLeft.h" -#include "tgbot/types/ChatMemberBanned.h" -#include "tgbot/types/ChatJoinRequest.h" -#include "tgbot/types/ChatPermissions.h" #include "tgbot/types/Birthdate.h" -#include "tgbot/types/BusinessIntro.h" -#include "tgbot/types/BusinessLocation.h" -#include "tgbot/types/BusinessOpeningHoursInterval.h" -#include "tgbot/types/BusinessOpeningHours.h" -#include "tgbot/types/ChatLocation.h" -#include "tgbot/types/ReactionType.h" -#include "tgbot/types/ReactionTypeEmoji.h" -#include "tgbot/types/ReactionTypeCustomEmoji.h" -#include "tgbot/types/ReactionCount.h" -#include "tgbot/types/MessageReactionUpdated.h" -#include "tgbot/types/MessageReactionCountUpdated.h" -#include "tgbot/types/ForumTopic.h" #include "tgbot/types/BotCommand.h" #include "tgbot/types/BotCommandScope.h" -#include "tgbot/types/BotCommandScopeDefault.h" -#include "tgbot/types/BotCommandScopeAllPrivateChats.h" -#include "tgbot/types/BotCommandScopeAllGroupChats.h" #include "tgbot/types/BotCommandScopeAllChatAdministrators.h" +#include "tgbot/types/BotCommandScopeAllGroupChats.h" +#include "tgbot/types/BotCommandScopeAllPrivateChats.h" #include "tgbot/types/BotCommandScopeChat.h" #include "tgbot/types/BotCommandScopeChatAdministrators.h" #include "tgbot/types/BotCommandScopeChatMember.h" -#include "tgbot/types/BotName.h" +#include "tgbot/types/BotCommandScopeDefault.h" #include "tgbot/types/BotDescription.h" +#include "tgbot/types/BotName.h" #include "tgbot/types/BotShortDescription.h" -#include "tgbot/types/MenuButton.h" -#include "tgbot/types/MenuButtonCommands.h" -#include "tgbot/types/MenuButtonWebApp.h" -#include "tgbot/types/MenuButtonDefault.h" +#include "tgbot/types/BusinessConnection.h" +#include "tgbot/types/BusinessIntro.h" +#include "tgbot/types/BusinessLocation.h" +#include "tgbot/types/BusinessMessagesDeleted.h" +#include "tgbot/types/BusinessOpeningHours.h" +#include "tgbot/types/BusinessOpeningHoursInterval.h" +#include "tgbot/types/CallbackGame.h" +#include "tgbot/types/CallbackQuery.h" +#include "tgbot/types/Chat.h" +#include "tgbot/types/ChatAdministratorRights.h" +#include "tgbot/types/ChatBoost.h" +#include "tgbot/types/ChatBoostAdded.h" +#include "tgbot/types/ChatBoostRemoved.h" #include "tgbot/types/ChatBoostSource.h" -#include "tgbot/types/ChatBoostSourcePremium.h" #include "tgbot/types/ChatBoostSourceGiftCode.h" #include "tgbot/types/ChatBoostSourceGiveaway.h" -#include "tgbot/types/ChatBoost.h" +#include "tgbot/types/ChatBoostSourcePremium.h" #include "tgbot/types/ChatBoostUpdated.h" -#include "tgbot/types/ChatBoostRemoved.h" -#include "tgbot/types/UserChatBoosts.h" -#include "tgbot/types/BusinessConnection.h" -#include "tgbot/types/BusinessMessagesDeleted.h" -#include "tgbot/types/ResponseParameters.h" -#include "tgbot/types/InputMedia.h" -#include "tgbot/types/InputMediaPhoto.h" -#include "tgbot/types/InputMediaVideo.h" -#include "tgbot/types/InputMediaAnimation.h" -#include "tgbot/types/InputMediaAudio.h" -#include "tgbot/types/InputMediaDocument.h" -#include "tgbot/types/Sticker.h" -#include "tgbot/types/StickerSet.h" -#include "tgbot/types/MaskPosition.h" -#include "tgbot/types/InputSticker.h" +#include "tgbot/types/ChatInviteLink.h" +#include "tgbot/types/ChatJoinRequest.h" +#include "tgbot/types/ChatLocation.h" +#include "tgbot/types/ChatMember.h" +#include "tgbot/types/ChatMemberAdministrator.h" +#include "tgbot/types/ChatMemberBanned.h" +#include "tgbot/types/ChatMemberLeft.h" +#include "tgbot/types/ChatMemberMember.h" +#include "tgbot/types/ChatMemberOwner.h" +#include "tgbot/types/ChatMemberRestricted.h" +#include "tgbot/types/ChatMemberUpdated.h" +#include "tgbot/types/ChatPermissions.h" +#include "tgbot/types/ChatPhoto.h" +#include "tgbot/types/ChatShared.h" +#include "tgbot/types/ChosenInlineResult.h" +#include "tgbot/types/Contact.h" +#include "tgbot/types/Dice.h" +#include "tgbot/types/Document.h" +#include "tgbot/types/EncryptedCredentials.h" +#include "tgbot/types/EncryptedPassportElement.h" +#include "tgbot/types/ExternalReplyInfo.h" +#include "tgbot/types/File.h" +#include "tgbot/types/ForceReply.h" +#include "tgbot/types/ForumTopic.h" +#include "tgbot/types/ForumTopicClosed.h" +#include "tgbot/types/ForumTopicCreated.h" +#include "tgbot/types/ForumTopicEdited.h" +#include "tgbot/types/ForumTopicReopened.h" +#include "tgbot/types/Game.h" +#include "tgbot/types/GameHighScore.h" +#include "tgbot/types/GeneralForumTopicHidden.h" +#include "tgbot/types/GeneralForumTopicUnhidden.h" +#include "tgbot/types/GenericReply.h" +#include "tgbot/types/Giveaway.h" +#include "tgbot/types/GiveawayCompleted.h" +#include "tgbot/types/GiveawayCreated.h" +#include "tgbot/types/GiveawayWinners.h" +#include "tgbot/types/InaccessibleMessage.h" +#include "tgbot/types/InlineKeyboardButton.h" +#include "tgbot/types/InlineKeyboardMarkup.h" #include "tgbot/types/InlineQuery.h" -#include "tgbot/types/InlineQueryResultsButton.h" #include "tgbot/types/InlineQueryResult.h" #include "tgbot/types/InlineQueryResultArticle.h" -#include "tgbot/types/InlineQueryResultPhoto.h" -#include "tgbot/types/InlineQueryResultGif.h" -#include "tgbot/types/InlineQueryResultMpeg4Gif.h" -#include "tgbot/types/InlineQueryResultVideo.h" #include "tgbot/types/InlineQueryResultAudio.h" -#include "tgbot/types/InlineQueryResultVoice.h" -#include "tgbot/types/InlineQueryResultDocument.h" -#include "tgbot/types/InlineQueryResultLocation.h" -#include "tgbot/types/InlineQueryResultVenue.h" -#include "tgbot/types/InlineQueryResultContact.h" -#include "tgbot/types/InlineQueryResultGame.h" -#include "tgbot/types/InlineQueryResultCachedPhoto.h" +#include "tgbot/types/InlineQueryResultCachedAudio.h" +#include "tgbot/types/InlineQueryResultCachedDocument.h" #include "tgbot/types/InlineQueryResultCachedGif.h" #include "tgbot/types/InlineQueryResultCachedMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultCachedPhoto.h" #include "tgbot/types/InlineQueryResultCachedSticker.h" -#include "tgbot/types/InlineQueryResultCachedDocument.h" #include "tgbot/types/InlineQueryResultCachedVideo.h" #include "tgbot/types/InlineQueryResultCachedVoice.h" -#include "tgbot/types/InlineQueryResultCachedAudio.h" +#include "tgbot/types/InlineQueryResultContact.h" +#include "tgbot/types/InlineQueryResultDocument.h" +#include "tgbot/types/InlineQueryResultGame.h" +#include "tgbot/types/InlineQueryResultGif.h" +#include "tgbot/types/InlineQueryResultLocation.h" +#include "tgbot/types/InlineQueryResultMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultPhoto.h" +#include "tgbot/types/InlineQueryResultVenue.h" +#include "tgbot/types/InlineQueryResultVideo.h" +#include "tgbot/types/InlineQueryResultVoice.h" +#include "tgbot/types/InlineQueryResultsButton.h" +#include "tgbot/types/InputContactMessageContent.h" +#include "tgbot/types/InputInvoiceMessageContent.h" +#include "tgbot/types/InputLocationMessageContent.h" +#include "tgbot/types/InputMedia.h" +#include "tgbot/types/InputMediaAnimation.h" +#include "tgbot/types/InputMediaAudio.h" +#include "tgbot/types/InputMediaDocument.h" +#include "tgbot/types/InputMediaPhoto.h" +#include "tgbot/types/InputMediaVideo.h" #include "tgbot/types/InputMessageContent.h" +#include "tgbot/types/InputSticker.h" #include "tgbot/types/InputTextMessageContent.h" -#include "tgbot/types/InputLocationMessageContent.h" #include "tgbot/types/InputVenueMessageContent.h" -#include "tgbot/types/InputContactMessageContent.h" -#include "tgbot/types/InputInvoiceMessageContent.h" -#include "tgbot/types/ChosenInlineResult.h" -#include "tgbot/types/SentWebAppMessage.h" -#include "tgbot/types/LabeledPrice.h" #include "tgbot/types/Invoice.h" -#include "tgbot/types/ShippingAddress.h" +#include "tgbot/types/KeyboardButton.h" +#include "tgbot/types/KeyboardButtonPollType.h" +#include "tgbot/types/KeyboardButtonRequestChat.h" +#include "tgbot/types/KeyboardButtonRequestUsers.h" +#include "tgbot/types/LabeledPrice.h" +#include "tgbot/types/LinkPreviewOptions.h" +#include "tgbot/types/Location.h" +#include "tgbot/types/LoginUrl.h" +#include "tgbot/types/MaskPosition.h" +#include "tgbot/types/MenuButton.h" +#include "tgbot/types/MenuButtonCommands.h" +#include "tgbot/types/MenuButtonDefault.h" +#include "tgbot/types/MenuButtonWebApp.h" +#include "tgbot/types/Message.h" +#include "tgbot/types/MessageAutoDeleteTimerChanged.h" +#include "tgbot/types/MessageEntity.h" +#include "tgbot/types/MessageId.h" +#include "tgbot/types/MessageOrigin.h" +#include "tgbot/types/MessageOriginChannel.h" +#include "tgbot/types/MessageOriginChat.h" +#include "tgbot/types/MessageOriginHiddenUser.h" +#include "tgbot/types/MessageOriginUser.h" +#include "tgbot/types/MessageReactionCountUpdated.h" +#include "tgbot/types/MessageReactionUpdated.h" #include "tgbot/types/OrderInfo.h" -#include "tgbot/types/ShippingOption.h" -#include "tgbot/types/SuccessfulPayment.h" -#include "tgbot/types/ShippingQuery.h" -#include "tgbot/types/PreCheckoutQuery.h" #include "tgbot/types/PassportData.h" -#include "tgbot/types/PassportFile.h" -#include "tgbot/types/EncryptedPassportElement.h" -#include "tgbot/types/EncryptedCredentials.h" #include "tgbot/types/PassportElementError.h" #include "tgbot/types/PassportElementErrorDataField.h" +#include "tgbot/types/PassportElementErrorFile.h" +#include "tgbot/types/PassportElementErrorFiles.h" #include "tgbot/types/PassportElementErrorFrontSide.h" #include "tgbot/types/PassportElementErrorReverseSide.h" #include "tgbot/types/PassportElementErrorSelfie.h" -#include "tgbot/types/PassportElementErrorFile.h" -#include "tgbot/types/PassportElementErrorFiles.h" #include "tgbot/types/PassportElementErrorTranslationFile.h" #include "tgbot/types/PassportElementErrorTranslationFiles.h" #include "tgbot/types/PassportElementErrorUnspecified.h" -#include "tgbot/types/Game.h" -#include "tgbot/types/CallbackGame.h" -#include "tgbot/types/GameHighScore.h" -#include "tgbot/types/GenericReply.h" - -#include -#include - -#include -#include -#include -#include -#include +#include "tgbot/types/PassportFile.h" +#include "tgbot/types/PhotoSize.h" +#include "tgbot/types/Poll.h" +#include "tgbot/types/PollAnswer.h" +#include "tgbot/types/PollOption.h" +#include "tgbot/types/PreCheckoutQuery.h" +#include "tgbot/types/ProximityAlertTriggered.h" +#include "tgbot/types/ReactionCount.h" +#include "tgbot/types/ReactionType.h" +#include "tgbot/types/ReactionTypeCustomEmoji.h" +#include "tgbot/types/ReactionTypeEmoji.h" +#include "tgbot/types/ReplyKeyboardMarkup.h" +#include "tgbot/types/ReplyKeyboardRemove.h" +#include "tgbot/types/ReplyParameters.h" +#include "tgbot/types/ResponseParameters.h" +#include "tgbot/types/SentWebAppMessage.h" +#include "tgbot/types/SharedUser.h" +#include "tgbot/types/ShippingAddress.h" +#include "tgbot/types/ShippingOption.h" +#include "tgbot/types/ShippingQuery.h" +#include "tgbot/types/Sticker.h" +#include "tgbot/types/StickerSet.h" +#include "tgbot/types/Story.h" +#include "tgbot/types/SuccessfulPayment.h" +#include "tgbot/types/SwitchInlineQueryChosenChat.h" +#include "tgbot/types/TextQuote.h" +#include "tgbot/types/Update.h" +#include "tgbot/types/User.h" +#include "tgbot/types/UserChatBoosts.h" +#include "tgbot/types/UserProfilePhotos.h" +#include "tgbot/types/UsersShared.h" +#include "tgbot/types/Venue.h" +#include "tgbot/types/Video.h" +#include "tgbot/types/VideoChatEnded.h" +#include "tgbot/types/VideoChatParticipantsInvited.h" +#include "tgbot/types/VideoChatScheduled.h" +#include "tgbot/types/VideoChatStarted.h" +#include "tgbot/types/VideoNote.h" +#include "tgbot/types/Voice.h" +#include "tgbot/types/WebAppData.h" +#include "tgbot/types/WebAppInfo.h" +#include "tgbot/types/WebhookInfo.h" +#include "tgbot/types/WriteAccessAllowed.h" namespace TgBot { -class TGBOT_API TgTypeParser { - -public: - template - using JsonToTgTypeFunc = std::shared_ptr (TgTypeParser::*)(const boost::property_tree::ptree&) const; - - template - using TgTypeToJsonFunc = std::string (TgTypeParser::*)(const std::shared_ptr&) const; - - Update::Ptr parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const; - std::string parseUpdate(const Update::Ptr& object) const; - - WebhookInfo::Ptr parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const; - std::string parseWebhookInfo(const WebhookInfo::Ptr& object) const; - - User::Ptr parseJsonAndGetUser(const boost::property_tree::ptree& data) const; - std::string parseUser(const User::Ptr& object) const; - - Chat::Ptr parseJsonAndGetChat(const boost::property_tree::ptree& data) const; - std::string parseChat(const Chat::Ptr& object) const; - - Message::Ptr parseJsonAndGetMessage(const boost::property_tree::ptree& data) const; - std::string parseMessage(const Message::Ptr& object) const; - - MessageId::Ptr parseJsonAndGetMessageId(const boost::property_tree::ptree& data) const; - std::string parseMessageId(const MessageId::Ptr& object) const; - - InaccessibleMessage::Ptr parseJsonAndGetInaccessibleMessage(const boost::property_tree::ptree& data) const; - std::string parseInaccessibleMessage(const InaccessibleMessage::Ptr& object) const; - - MessageEntity::Ptr parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const; - std::string parseMessageEntity(const MessageEntity::Ptr& object) const; - - TextQuote::Ptr parseJsonAndGetTextQuote(const boost::property_tree::ptree& data) const; - std::string parseTextQuote(const TextQuote::Ptr& object) const; - - ExternalReplyInfo::Ptr parseJsonAndGetExternalReplyInfo(const boost::property_tree::ptree& data) const; - std::string parseExternalReplyInfo(const ExternalReplyInfo::Ptr& object) const; - - ReplyParameters::Ptr parseJsonAndGetReplyParameters(const boost::property_tree::ptree& data) const; - std::string parseReplyParameters(const ReplyParameters::Ptr& object) const; - - MessageOrigin::Ptr parseJsonAndGetMessageOrigin(const boost::property_tree::ptree& data) const; - std::string parseMessageOrigin(const MessageOrigin::Ptr& object) const; - - MessageOriginUser::Ptr parseJsonAndGetMessageOriginUser(const boost::property_tree::ptree& data) const; - std::string parseMessageOriginUser(const MessageOriginUser::Ptr& object) const; - - MessageOriginHiddenUser::Ptr parseJsonAndGetMessageOriginHiddenUser(const boost::property_tree::ptree& data) const; - std::string parseMessageOriginHiddenUser(const MessageOriginHiddenUser::Ptr& object) const; - - MessageOriginChat::Ptr parseJsonAndGetMessageOriginChat(const boost::property_tree::ptree& data) const; - std::string parseMessageOriginChat(const MessageOriginChat::Ptr& object) const; - - MessageOriginChannel::Ptr parseJsonAndGetMessageOriginChannel(const boost::property_tree::ptree& data) const; - std::string parseMessageOriginChannel(const MessageOriginChannel::Ptr& object) const; - - PhotoSize::Ptr parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const; - std::string parsePhotoSize(const PhotoSize::Ptr& object) const; - - Animation::Ptr parseJsonAndGetAnimation(const boost::property_tree::ptree& data) const; - std::string parseAnimation(const Animation::Ptr& object) const; - - Audio::Ptr parseJsonAndGetAudio(const boost::property_tree::ptree& data) const; - std::string parseAudio(const Audio::Ptr& object) const; - - Document::Ptr parseJsonAndGetDocument(const boost::property_tree::ptree& data) const; - std::string parseDocument(const Document::Ptr& object) const; - - Story::Ptr parseJsonAndGetStory(const boost::property_tree::ptree& data) const; - std::string parseStory(const Story::Ptr& object) const; - - Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const; - std::string parseVideo(const Video::Ptr& object) const; - - VideoNote::Ptr parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const; - std::string parseVideoNote(const VideoNote::Ptr& object) const; - - Voice::Ptr parseJsonAndGetVoice(const boost::property_tree::ptree& data) const; - std::string parseVoice(const Voice::Ptr& object) const; - - Contact::Ptr parseJsonAndGetContact(const boost::property_tree::ptree& data) const; - std::string parseContact(const Contact::Ptr& object) const; - - Dice::Ptr parseJsonAndGetDice(const boost::property_tree::ptree& data) const; - std::string parseDice(const Dice::Ptr& object) const; - - PollOption::Ptr parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const; - std::string parsePollOption(const PollOption::Ptr& object) const; - - PollAnswer::Ptr parseJsonAndGetPollAnswer(const boost::property_tree::ptree& data) const; - std::string parsePollAnswer(const PollAnswer::Ptr& object) const; - - Poll::Ptr parseJsonAndGetPoll(const boost::property_tree::ptree& data) const; - std::string parsePoll(const Poll::Ptr& object) const; - - Location::Ptr parseJsonAndGetLocation(const boost::property_tree::ptree& data) const; - std::string parseLocation(const Location::Ptr& object) const; - - Venue::Ptr parseJsonAndGetVenue(const boost::property_tree::ptree& data) const; - std::string parseVenue(const Venue::Ptr& object) const; - - WebAppData::Ptr parseJsonAndGetWebAppData(const boost::property_tree::ptree& data) const; - std::string parseWebAppData(const WebAppData::Ptr& object) const; - - ProximityAlertTriggered::Ptr parseJsonAndGetProximityAlertTriggered(const boost::property_tree::ptree& data) const; - std::string parseProximityAlertTriggered(const ProximityAlertTriggered::Ptr& object) const; - - MessageAutoDeleteTimerChanged::Ptr parseJsonAndGetMessageAutoDeleteTimerChanged(const boost::property_tree::ptree& data) const; - std::string parseMessageAutoDeleteTimerChanged(const MessageAutoDeleteTimerChanged::Ptr& object) const; - - ChatBoostAdded::Ptr parseJsonAndGetChatBoostAdded(const boost::property_tree::ptree& data) const; - std::string parseChatBoostAdded(const ChatBoostAdded::Ptr& object) const; - - ForumTopicCreated::Ptr parseJsonAndGetForumTopicCreated(const boost::property_tree::ptree& data) const; - std::string parseForumTopicCreated(const ForumTopicCreated::Ptr& object) const; - - ForumTopicClosed::Ptr parseJsonAndGetForumTopicClosed(const boost::property_tree::ptree& data) const; - std::string parseForumTopicClosed(const ForumTopicClosed::Ptr& object) const; - - ForumTopicEdited::Ptr parseJsonAndGetForumTopicEdited(const boost::property_tree::ptree& data) const; - std::string parseForumTopicEdited(const ForumTopicEdited::Ptr& object) const; - - ForumTopicReopened::Ptr parseJsonAndGetForumTopicReopened(const boost::property_tree::ptree& data) const; - std::string parseForumTopicReopened(const ForumTopicReopened::Ptr& object) const; - - GeneralForumTopicHidden::Ptr parseJsonAndGetGeneralForumTopicHidden(const boost::property_tree::ptree& data) const; - std::string parseGeneralForumTopicHidden(const GeneralForumTopicHidden::Ptr& object) const; - - GeneralForumTopicUnhidden::Ptr parseJsonAndGetGeneralForumTopicUnhidden(const boost::property_tree::ptree& data) const; - std::string parseGeneralForumTopicUnhidden(const GeneralForumTopicUnhidden::Ptr& object) const; - - SharedUser::Ptr parseJsonAndGetSharedUser(const boost::property_tree::ptree& data) const; - std::string parseSharedUser(const SharedUser::Ptr& object) const; - - UsersShared::Ptr parseJsonAndGetUsersShared(const boost::property_tree::ptree& data) const; - std::string parseUsersShared(const UsersShared::Ptr& object) const; - - ChatShared::Ptr parseJsonAndGetChatShared(const boost::property_tree::ptree& data) const; - std::string parseChatShared(const ChatShared::Ptr& object) const; - - WriteAccessAllowed::Ptr parseJsonAndGetWriteAccessAllowed(const boost::property_tree::ptree& data) const; - std::string parseWriteAccessAllowed(const WriteAccessAllowed::Ptr& object) const; - - VideoChatScheduled::Ptr parseJsonAndGetVideoChatScheduled(const boost::property_tree::ptree& data) const; - std::string parseVideoChatScheduled(const VideoChatScheduled::Ptr& object) const; - - VideoChatStarted::Ptr parseJsonAndGetVideoChatStarted(const boost::property_tree::ptree& data) const; - std::string parseVideoChatStarted(const VideoChatStarted::Ptr& object) const; - - VideoChatEnded::Ptr parseJsonAndGetVideoChatEnded(const boost::property_tree::ptree& data) const; - std::string parseVideoChatEnded(const VideoChatEnded::Ptr& object) const; - - VideoChatParticipantsInvited::Ptr parseJsonAndGetVideoChatParticipantsInvited(const boost::property_tree::ptree& data) const; - std::string parseVideoChatParticipantsInvited(const VideoChatParticipantsInvited::Ptr& object) const; - - GiveawayCreated::Ptr parseJsonAndGetGiveawayCreated(const boost::property_tree::ptree& data) const; - std::string parseGiveawayCreated(const GiveawayCreated::Ptr& object) const; - - Giveaway::Ptr parseJsonAndGetGiveaway(const boost::property_tree::ptree& data) const; - std::string parseGiveaway(const Giveaway::Ptr& object) const; - - GiveawayWinners::Ptr parseJsonAndGetGiveawayWinners(const boost::property_tree::ptree& data) const; - std::string parseGiveawayWinners(const GiveawayWinners::Ptr& object) const; - - GiveawayCompleted::Ptr parseJsonAndGetGiveawayCompleted(const boost::property_tree::ptree& data) const; - std::string parseGiveawayCompleted(const GiveawayCompleted::Ptr& object) const; - - LinkPreviewOptions::Ptr parseJsonAndGetLinkPreviewOptions(const boost::property_tree::ptree& data) const; - std::string parseLinkPreviewOptions(const LinkPreviewOptions::Ptr& object) const; - - UserProfilePhotos::Ptr parseJsonAndGetUserProfilePhotos(const boost::property_tree::ptree& data) const; - std::string parseUserProfilePhotos(const UserProfilePhotos::Ptr& object) const; - - File::Ptr parseJsonAndGetFile(const boost::property_tree::ptree& data) const; - std::string parseFile(const File::Ptr& object) const; - - WebAppInfo::Ptr parseJsonAndGetWebAppInfo(const boost::property_tree::ptree& data) const; - std::string parseWebAppInfo(const WebAppInfo::Ptr& object) const; - - ReplyKeyboardMarkup::Ptr parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Ptr& object) const; - - KeyboardButton::Ptr parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButton(const KeyboardButton::Ptr& object) const; - - KeyboardButtonRequestUsers::Ptr parseJsonAndGetKeyboardButtonRequestUsers(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButtonRequestUsers(const KeyboardButtonRequestUsers::Ptr& object) const; - - KeyboardButtonRequestChat::Ptr parseJsonAndGetKeyboardButtonRequestChat(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButtonRequestChat(const KeyboardButtonRequestChat::Ptr& object) const; - - KeyboardButtonPollType::Ptr parseJsonAndGetKeyboardButtonPollType(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButtonPollType(const KeyboardButtonPollType::Ptr& object) const; - - ReplyKeyboardRemove::Ptr parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const; - - InlineKeyboardMarkup::Ptr parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const; - std::string parseInlineKeyboardMarkup(const InlineKeyboardMarkup::Ptr& object) const; - - InlineKeyboardButton::Ptr parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const; - std::string parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const; - - LoginUrl::Ptr parseJsonAndGetLoginUrl(const boost::property_tree::ptree& data) const; - std::string parseLoginUrl(const LoginUrl::Ptr& object) const; - - SwitchInlineQueryChosenChat::Ptr parseJsonAndGetSwitchInlineQueryChosenChat(const boost::property_tree::ptree& data) const; - std::string parseSwitchInlineQueryChosenChat(const SwitchInlineQueryChosenChat::Ptr& object) const; - - CallbackQuery::Ptr parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const; - std::string parseCallbackQuery(const CallbackQuery::Ptr& object) const; - - ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const; - std::string parseForceReply(const ForceReply::Ptr& object) const; - - ChatPhoto::Ptr parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const; - std::string parseChatPhoto(const ChatPhoto::Ptr& object) const; - - ChatInviteLink::Ptr parseJsonAndGetChatInviteLink(const boost::property_tree::ptree& data) const; - std::string parseChatInviteLink(const ChatInviteLink::Ptr& object) const; - - ChatAdministratorRights::Ptr parseJsonAndGetChatAdministratorRights(const boost::property_tree::ptree& data) const; - std::string parseChatAdministratorRights(const ChatAdministratorRights::Ptr& object) const; - - ChatMemberUpdated::Ptr parseJsonAndGetChatMemberUpdated(const boost::property_tree::ptree& data) const; - std::string parseChatMemberUpdated(const ChatMemberUpdated::Ptr& object) const; - - ChatMember::Ptr parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const; - std::string parseChatMember(const ChatMember::Ptr& object) const; - - ChatMemberOwner::Ptr parseJsonAndGetChatMemberOwner(const boost::property_tree::ptree& data) const; - std::string parseChatMemberOwner(const ChatMemberOwner::Ptr& object) const; - - ChatMemberAdministrator::Ptr parseJsonAndGetChatMemberAdministrator(const boost::property_tree::ptree& data) const; - std::string parseChatMemberAdministrator(const ChatMemberAdministrator::Ptr& object) const; - - ChatMemberMember::Ptr parseJsonAndGetChatMemberMember(const boost::property_tree::ptree& data) const; - std::string parseChatMemberMember(const ChatMemberMember::Ptr& object) const; - - ChatMemberRestricted::Ptr parseJsonAndGetChatMemberRestricted(const boost::property_tree::ptree& data) const; - std::string parseChatMemberRestricted(const ChatMemberRestricted::Ptr& object) const; - - ChatMemberLeft::Ptr parseJsonAndGetChatMemberLeft(const boost::property_tree::ptree& data) const; - std::string parseChatMemberLeft(const ChatMemberLeft::Ptr& object) const; - - ChatMemberBanned::Ptr parseJsonAndGetChatMemberBanned(const boost::property_tree::ptree& data) const; - std::string parseChatMemberBanned(const ChatMemberBanned::Ptr& object) const; - - ChatJoinRequest::Ptr parseJsonAndGetChatJoinRequest(const boost::property_tree::ptree& data) const; - std::string parseChatJoinRequest(const ChatJoinRequest::Ptr& object) const; +template +using Matrix = std::vector>; +namespace detail { // shared_ptr +template +struct is_shared_ptr : std::false_type {}; - ChatPermissions::Ptr parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const; - std::string parseChatPermissions(const ChatPermissions::Ptr& object) const; - - Birthdate::Ptr parseJsonAndGetBirthdate(const boost::property_tree::ptree& data) const; - std::string parseBirthdate(const Birthdate::Ptr& object) const; - - BusinessIntro::Ptr parseJsonAndGetBusinessIntro(const boost::property_tree::ptree& data) const; - std::string parseBusinessIntro(const BusinessIntro::Ptr& object) const; - - BusinessLocation::Ptr parseJsonAndGetBusinessLocation(const boost::property_tree::ptree& data) const; - std::string parseBusinessLocation(const BusinessLocation::Ptr& object) const; - - BusinessOpeningHoursInterval::Ptr parseJsonAndGetBusinessOpeningHoursInterval(const boost::property_tree::ptree& data) const; - std::string parseBusinessOpeningHoursInterval(const BusinessOpeningHoursInterval::Ptr& object) const; - - BusinessOpeningHours::Ptr parseJsonAndGetBusinessOpeningHours(const boost::property_tree::ptree& data) const; - std::string parseBusinessOpeningHours(const BusinessOpeningHours::Ptr& object) const; - - ChatLocation::Ptr parseJsonAndGetChatLocation(const boost::property_tree::ptree& data) const; - std::string parseChatLocation(const ChatLocation::Ptr& object) const; - - ReactionType::Ptr parseJsonAndGetReactionType(const boost::property_tree::ptree& data) const; - std::string parseReactionType(const ReactionType::Ptr& object) const; - - ReactionTypeEmoji::Ptr parseJsonAndGetReactionTypeEmoji(const boost::property_tree::ptree& data) const; - std::string parseReactionTypeEmoji(const ReactionTypeEmoji::Ptr& object) const; - - ReactionTypeCustomEmoji::Ptr parseJsonAndGetReactionTypeCustomEmoji(const boost::property_tree::ptree& data) const; - std::string parseReactionTypeCustomEmoji(const ReactionTypeCustomEmoji::Ptr& object) const; - - ReactionCount::Ptr parseJsonAndGetReactionCount(const boost::property_tree::ptree& data) const; - std::string parseReactionCount(const ReactionCount::Ptr& object) const; - - MessageReactionUpdated::Ptr parseJsonAndGetMessageReactionUpdated(const boost::property_tree::ptree& data) const; - std::string parseMessageReactionUpdated(const MessageReactionUpdated::Ptr& object) const; - - MessageReactionCountUpdated::Ptr parseJsonAndGetMessageReactionCountUpdated(const boost::property_tree::ptree& data) const; - std::string parseMessageReactionCountUpdated(const MessageReactionCountUpdated::Ptr& object) const; - - ForumTopic::Ptr parseJsonAndGetForumTopic(const boost::property_tree::ptree& data) const; - std::string parseForumTopic(const ForumTopic::Ptr& object) const; - - BotCommand::Ptr parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const; - std::string parseBotCommand(const BotCommand::Ptr& object) const; - - BotCommandScope::Ptr parseJsonAndGetBotCommandScope(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScope(const BotCommandScope::Ptr& object) const; - - BotCommandScopeDefault::Ptr parseJsonAndGetBotCommandScopeDefault(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeDefault(const BotCommandScopeDefault::Ptr& object) const; - - BotCommandScopeAllPrivateChats::Ptr parseJsonAndGetBotCommandScopeAllPrivateChats(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeAllPrivateChats(const BotCommandScopeAllPrivateChats::Ptr& object) const; - - BotCommandScopeAllGroupChats::Ptr parseJsonAndGetBotCommandScopeAllGroupChats(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeAllGroupChats(const BotCommandScopeAllGroupChats::Ptr& object) const; - - BotCommandScopeAllChatAdministrators::Ptr parseJsonAndGetBotCommandScopeAllChatAdministrators(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeAllChatAdministrators(const BotCommandScopeAllChatAdministrators::Ptr& object) const; - - BotCommandScopeChat::Ptr parseJsonAndGetBotCommandScopeChat(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeChat(const BotCommandScopeChat::Ptr& object) const; - - BotCommandScopeChatAdministrators::Ptr parseJsonAndGetBotCommandScopeChatAdministrators(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeChatAdministrators(const BotCommandScopeChatAdministrators::Ptr& object) const; - - BotCommandScopeChatMember::Ptr parseJsonAndGetBotCommandScopeChatMember(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeChatMember(const BotCommandScopeChatMember::Ptr& object) const; - - BotName::Ptr parseJsonAndGetBotName(const boost::property_tree::ptree& data) const; - std::string parseBotName(const BotName::Ptr& object) const; - - BotDescription::Ptr parseJsonAndGetBotDescription(const boost::property_tree::ptree& data) const; - std::string parseBotDescription(const BotDescription::Ptr& object) const; - - BotShortDescription::Ptr parseJsonAndGetBotShortDescription(const boost::property_tree::ptree& data) const; - std::string parseBotShortDescription(const BotShortDescription::Ptr& object) const; - - MenuButton::Ptr parseJsonAndGetMenuButton(const boost::property_tree::ptree& data) const; - std::string parseMenuButton(const MenuButton::Ptr& object) const; - - MenuButtonCommands::Ptr parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& data) const; - std::string parseMenuButtonCommands(const MenuButtonCommands::Ptr& object) const; - - MenuButtonWebApp::Ptr parseJsonAndGetMenuButtonWebApp(const boost::property_tree::ptree& data) const; - std::string parseMenuButtonWebApp(const MenuButtonWebApp::Ptr& object) const; - - MenuButtonDefault::Ptr parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& data) const; - std::string parseMenuButtonDefault(const MenuButtonDefault::Ptr& object) const; - - ChatBoostSource::Ptr parseJsonAndGetChatBoostSource(const boost::property_tree::ptree& data) const; - std::string parseChatBoostSource(const ChatBoostSource::Ptr& object) const; - - ChatBoostSourcePremium::Ptr parseJsonAndGetChatBoostSourcePremium(const boost::property_tree::ptree& data) const; - std::string parseChatBoostSourcePremium(const ChatBoostSourcePremium::Ptr& object) const; - - ChatBoostSourceGiftCode::Ptr parseJsonAndGetChatBoostSourceGiftCode(const boost::property_tree::ptree& data) const; - std::string parseChatBoostSourceGiftCode(const ChatBoostSourceGiftCode::Ptr& object) const; - - ChatBoostSourceGiveaway::Ptr parseJsonAndGetChatBoostSourceGiveaway(const boost::property_tree::ptree& data) const; - std::string parseChatBoostSourceGiveaway(const ChatBoostSourceGiveaway::Ptr& object) const; - - ChatBoost::Ptr parseJsonAndGetChatBoost(const boost::property_tree::ptree& data) const; - std::string parseChatBoost(const ChatBoost::Ptr& object) const; - - ChatBoostUpdated::Ptr parseJsonAndGetChatBoostUpdated(const boost::property_tree::ptree& data) const; - std::string parseChatBoostUpdated(const ChatBoostUpdated::Ptr& object) const; - - ChatBoostRemoved::Ptr parseJsonAndGetChatBoostRemoved(const boost::property_tree::ptree& data) const; - std::string parseChatBoostRemoved(const ChatBoostRemoved::Ptr& object) const; - - UserChatBoosts::Ptr parseJsonAndGetUserChatBoosts(const boost::property_tree::ptree& data) const; - std::string parseUserChatBoosts(const UserChatBoosts::Ptr& object) const; - - BusinessConnection::Ptr parseJsonAndGetBusinessConnection(const boost::property_tree::ptree& data) const; - std::string parseBusinessConnection(const BusinessConnection::Ptr& object) const; - - BusinessMessagesDeleted::Ptr parseJsonAndGetBusinessMessagesDeleted(const boost::property_tree::ptree& data) const; - std::string parseBusinessMessagesDeleted(const BusinessMessagesDeleted::Ptr& object) const; - - ResponseParameters::Ptr parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const; - std::string parseResponseParameters(const ResponseParameters::Ptr& object) const; - - InputMedia::Ptr parseJsonAndGetInputMedia(const boost::property_tree::ptree& data) const; - std::string parseInputMedia(const InputMedia::Ptr& object) const; - - InputMediaPhoto::Ptr parseJsonAndGetInputMediaPhoto(const boost::property_tree::ptree& data) const; - std::string parseInputMediaPhoto(const InputMediaPhoto::Ptr& object) const; - - InputMediaVideo::Ptr parseJsonAndGetInputMediaVideo(const boost::property_tree::ptree& data) const; - std::string parseInputMediaVideo(const InputMediaVideo::Ptr& object) const; - - InputMediaAnimation::Ptr parseJsonAndGetInputMediaAnimation(const boost::property_tree::ptree& data) const; - std::string parseInputMediaAnimation(const InputMediaAnimation::Ptr& object) const; - - InputMediaAudio::Ptr parseJsonAndGetInputMediaAudio(const boost::property_tree::ptree& data) const; - std::string parseInputMediaAudio(const InputMediaAudio::Ptr& object) const; - - InputMediaDocument::Ptr parseJsonAndGetInputMediaDocument(const boost::property_tree::ptree& data) const; - std::string parseInputMediaDocument(const InputMediaDocument::Ptr& object) const; - - Sticker::Ptr parseJsonAndGetSticker(const boost::property_tree::ptree& data) const; - std::string parseSticker(const Sticker::Ptr& object) const; - - StickerSet::Ptr parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const; - std::string parseStickerSet(const StickerSet::Ptr& object) const; - - MaskPosition::Ptr parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const; - std::string parseMaskPosition(const MaskPosition::Ptr& object) const; - - InputSticker::Ptr parseJsonAndGetInputSticker(const boost::property_tree::ptree& data) const; - std::string parseInputSticker(const InputSticker::Ptr& object) const; - - InlineQuery::Ptr parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const; - std::string parseInlineQuery(const InlineQuery::Ptr& object) const; - - InlineQueryResultsButton::Ptr parseJsonAndGetInlineQueryResultsButton(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultsButton(const InlineQueryResultsButton::Ptr& object) const; - - InlineQueryResult::Ptr parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResult(const InlineQueryResult::Ptr& object) const; - - InlineQueryResultArticle::Ptr parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const; - - InlineQueryResultPhoto::Ptr parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const; - - InlineQueryResultGif::Ptr parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const; - - InlineQueryResultMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultMpeg4Gif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultMpeg4Gif(const InlineQueryResultMpeg4Gif::Ptr& object) const; - - InlineQueryResultVideo::Ptr parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const; - - InlineQueryResultAudio::Ptr parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const; - - InlineQueryResultVoice::Ptr parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const; - - InlineQueryResultDocument::Ptr parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const; - - InlineQueryResultLocation::Ptr parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const; - - InlineQueryResultVenue::Ptr parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const; - - InlineQueryResultContact::Ptr parseJsonAndGetInlineQueryResultContact(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const; - - InlineQueryResultGame::Ptr parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const; - - InlineQueryResultCachedPhoto::Ptr parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const; - - InlineQueryResultCachedGif::Ptr parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const; - - InlineQueryResultCachedMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const; - - InlineQueryResultCachedSticker::Ptr parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const; - - InlineQueryResultCachedDocument::Ptr parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const; - - InlineQueryResultCachedVideo::Ptr parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const; - - InlineQueryResultCachedVoice::Ptr parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const; - - InlineQueryResultCachedAudio::Ptr parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const; - - InputMessageContent::Ptr parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputMessageContent(const InputMessageContent::Ptr& object) const; - - InputTextMessageContent::Ptr parseJsonAndGetInputTextMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const; - - InputLocationMessageContent::Ptr parseJsonAndGetInputLocationMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const; - - InputVenueMessageContent::Ptr parseJsonAndGetInputVenueMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const; - - InputContactMessageContent::Ptr parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const; - - InputInvoiceMessageContent::Ptr parseJsonAndGetInputInvoiceMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputInvoiceMessageContent(const InputInvoiceMessageContent::Ptr& object) const; - - ChosenInlineResult::Ptr parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const; - std::string parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const; - - SentWebAppMessage::Ptr parseJsonAndGetSentWebAppMessage(const boost::property_tree::ptree& data) const; - std::string parseSentWebAppMessage(const SentWebAppMessage::Ptr& object) const; - - LabeledPrice::Ptr parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const; - std::string parseLabeledPrice(const LabeledPrice::Ptr& object) const; - - Invoice::Ptr parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const; - std::string parseInvoice(const Invoice::Ptr& object) const; - - ShippingAddress::Ptr parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const; - std::string parseShippingAddress(const ShippingAddress::Ptr& object) const; - - OrderInfo::Ptr parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const; - std::string parseOrderInfo(const OrderInfo::Ptr& object) const; - - ShippingOption::Ptr parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const; - std::string parseShippingOption(const ShippingOption::Ptr& object) const; - - SuccessfulPayment::Ptr parseJsonAndGetSuccessfulPayment(const boost::property_tree::ptree& data) const; - std::string parseSuccessfulPayment(const SuccessfulPayment::Ptr& object) const; - - ShippingQuery::Ptr parseJsonAndGetShippingQuery(const boost::property_tree::ptree& data) const; - std::string parseShippingQuery(const ShippingQuery::Ptr& object) const; - - PreCheckoutQuery::Ptr parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const; - std::string parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const; - - PassportData::Ptr parseJsonAndGetPassportData(const boost::property_tree::ptree& data) const; - std::string parsePassportData(const PassportData::Ptr& object) const; - - PassportFile::Ptr parseJsonAndGetPassportFile(const boost::property_tree::ptree& data) const; - std::string parsePassportFile(const PassportFile::Ptr& object) const; - - EncryptedPassportElement::Ptr parseJsonAndGetEncryptedPassportElement(const boost::property_tree::ptree& data) const; - std::string parseEncryptedPassportElement(const EncryptedPassportElement::Ptr& object) const; - - EncryptedCredentials::Ptr parseJsonAndGetEncryptedCredentials(const boost::property_tree::ptree& data) const; - std::string parseEncryptedCredentials(const EncryptedCredentials::Ptr& object) const; - - PassportElementError::Ptr parseJsonAndGetPassportElementError(const boost::property_tree::ptree& data) const; - std::string parsePassportElementError(const PassportElementError::Ptr& object) const; - - PassportElementErrorDataField::Ptr parseJsonAndGetPassportElementErrorDataField(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorDataField(const PassportElementErrorDataField::Ptr& object) const; - - PassportElementErrorFrontSide::Ptr parseJsonAndGetPassportElementErrorFrontSide(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorFrontSide(const PassportElementErrorFrontSide::Ptr& object) const; - - PassportElementErrorReverseSide::Ptr parseJsonAndGetPassportElementErrorReverseSide(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorReverseSide(const PassportElementErrorReverseSide::Ptr& object) const; - - PassportElementErrorSelfie::Ptr parseJsonAndGetPassportElementErrorSelfie(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorSelfie(const PassportElementErrorSelfie::Ptr& object) const; - - PassportElementErrorFile::Ptr parseJsonAndGetPassportElementErrorFile(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorFile(const PassportElementErrorFile::Ptr& object) const; - - PassportElementErrorFiles::Ptr parseJsonAndGetPassportElementErrorFiles(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorFiles(const PassportElementErrorFiles::Ptr& object) const; - - PassportElementErrorTranslationFile::Ptr parseJsonAndGetPassportElementErrorTranslationFile(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorTranslationFile(const PassportElementErrorTranslationFile::Ptr& object) const; - - PassportElementErrorTranslationFiles::Ptr parseJsonAndGetPassportElementErrorTranslationFiles(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorTranslationFiles(const PassportElementErrorTranslationFiles::Ptr& object) const; - - PassportElementErrorUnspecified::Ptr parseJsonAndGetPassportElementErrorUnspecified(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorUnspecified(const PassportElementErrorUnspecified::Ptr& object) const; - - Game::Ptr parseJsonAndGetGame(const boost::property_tree::ptree& data) const; - std::string parseGame(const Game::Ptr& object) const; - - CallbackGame::Ptr parseJsonAndGetCallbackGame(const boost::property_tree::ptree& data) const; - std::string parseCallbackGame(const CallbackGame::Ptr& object) const; +template +struct is_shared_ptr> : std::true_type { + using type = T; +}; - GameHighScore::Ptr parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const; - std::string parseGameHighScore(const GameHighScore::Ptr& object) const; +template +constexpr bool is_shared_ptr_v = is_shared_ptr::value; - GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const; - std::string parseGenericReply(const GenericReply::Ptr& object) const; +// vector +template +struct is_vector : std::false_type {}; +template +struct is_vector> : std::true_type { + using type = T; +}; +template +constexpr bool is_vector_v = is_vector::value; + +// primitive +template +struct is_primitive : std::false_type {}; +template <> +struct is_primitive : std::true_type {}; +template <> +struct is_primitive : std::true_type {}; +template <> +struct is_primitive : std::true_type {}; + +template +constexpr bool is_primitive_v = is_primitive::value; + +// Matrix +template +struct is_matrix : std::false_type {}; +template +struct is_matrix> : std::true_type { + using type = T; +}; +template +constexpr bool is_matrix_v = is_matrix::value; - inline boost::property_tree::ptree parseJson(const std::string& json) const { - boost::property_tree::ptree tree; - std::istringstream input(json); - boost::property_tree::read_json(input, tree); - return tree; - } +} // namespace detail - template - std::shared_ptr tryParseJson(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return std::shared_ptr(); - } - return (this->*parseFunc)(treeItem->second); - } +// Parse function for shared_ptr +template +std::shared_ptr parse(const Json::Value &data) = delete; - template - std::vector> parseJsonAndGetArray(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data) const { - std::vector> result; - result.reserve(data.size()); - for (const std::pair& innerTreeItem : data) { - result.push_back((this->*parseFunc)(innerTreeItem.second)); - } - return result; - } +#define DECLARE_PARSER_FROM_JSON(TYPE) \ + template <> \ + TYPE::Ptr parse(const Json::Value &data) - template - std::vector parseJsonAndGetArray(std::function parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair& innerTreeItem : treeItem->second) { - result.push_back(parseFunc(innerTreeItem.second)); - } - return result; +// Grab array of T from JSON array. +template +std::vector> parseArray(const Json::Value &data) { + std::vector> result; + for (const auto &item : data) { + result.emplace_back(parse(item)); } + return result; +} - template - std::vector> parseJsonAndGetArray(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair& innerTreeItem : treeItem->second) { - result.push_back((this->*parseFunc)(innerTreeItem.second)); - } - return result; +// Parse array from a key. +template +std::vector> parseArray(const Json::Value &data, const std::string &key) { + if (!data.isMember(key)) { + return {}; } + return parseArray(data[key]); +} - template - std::vector>> parseJsonAndGet2DArray(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector>> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair& innerTreeItem : treeItem->second) { - std::vector> innerResult; - for (const std::pair& innerInnerTreeItem : innerTreeItem.second) { - innerResult.push_back((this->*parseFunc)(innerInnerTreeItem.second)); - } - result.push_back(innerResult); - } - return result; +// Parse 2D array of T from JSON. +template +Matrix> parseMatrix(const Json::Value &data) { + Matrix> result; + for (const auto &item : data) { + result.emplace_back(parseArray(item)); } + return result; +} - template - std::string parseArray(TgTypeToJsonFunc parseFunc, const std::vector>& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const std::shared_ptr& item : objects) { - result += (this->*parseFunc)(item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; +template +Matrix> parseMatrix(const Json::Value &data, const std::string &key) { + if (!data.isMember(key)) { + return {}; } + return parseMatrix(data[key]); +} - template - std::string parseArray(std::function parseFunc, const std::vector& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const T& item : objects) { - result += parseFunc(item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; +// Parse an array of primitive types. +template +std::vector parsePrimitiveArray(const Json::Value &data, const std::string &key) { + if (!data.isMember(key)) { + return {}; } - - template - std::string parse2DArray(TgTypeToJsonFunc parseFunc, const std::vector>>& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const std::vector>& item : objects) { - result += parseArray(parseFunc, item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; + std::vector result; + for (const auto &item : data[key]) { + result.emplace_back(item.as()); } + return result; +} -private: - inline void removeLastComma(std::string& input) const { - input.erase(input.length() - 1); - } +// Put function for objects to JSON +template +Json::Value put(const T &value) = delete; + +#define DECLARE_PARSER_TO_JSON(TYPE) \ + template <> \ + Json::Value put(const TYPE::Ptr &object) + +// Helper to put base class shared_ptr to derived T. +template && + !std::is_same_v && + std::is_base_of_v, + bool> = true> +Json::Value put(const V &data) { + return put(std::static_pointer_cast(data)); +} - template - inline void appendToJson(std::string& json, const std::string& varName, const std::shared_ptr& value) const { - if (value == nullptr) { - return; +// Put vector to JSON. +template , bool> = true> +Json::Value put(const std::vector &vector) { + Json::Value dataArray(Json::arrayValue); + for (const auto &item : vector) { + if constexpr (detail::is_primitive_v) { + dataArray.append(item); + } else { + dataArray.append(put(item)); // Recursively call put for non-primitives } - json += '"'; - json += varName; - json += R"(":)"; - json += value; - json += ','; - } - - template - inline void appendToJson(std::string& json, const std::string& varName, const T& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += value; - json += ','; - } - - template - inline void appendToJsonNumber(std::string& json, const std::string& varName, const T& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += std::to_string(value); - json += ','; - } - - inline void appendToJson(std::string &json, const std::string &varName, const int &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned long long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const float &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const double &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long double &value) const { appendToJsonNumber(json, varName, value); } - - inline void appendToJson(std::string& json, const std::string& varName, const bool& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += (value ? "true" : "false"); - json += ','; } + return dataArray; +} - inline void appendToJson(std::string& json, const std::string& varName, const char* value) const { - if (value != nullptr){ - std::string strValue(value); - appendToJson(json, varName, strValue); - } +// Put 2D array (Matrix) to JSON. +template +Json::Value put(const Matrix &matrix) { + Json::Value dataMatrix(Json::arrayValue); + for (const auto &row : matrix) { + dataMatrix.append(put(row)); // Recursively call put for each row } + return dataMatrix; +} - void appendToJson(std::string& json, const std::string& varName, const std::string& value) const; -}; +// Serialize object to JSON string. +template +std::string putJSON(const T &object) { + Json::StreamWriterBuilder writer; + return Json::writeString(writer, put(object)); } -#endif //TGBOT_TGTYPEPARSER_H + +#define IMPLEMENT_PARSERS(type) \ + DECLARE_PARSER_FROM_JSON(type); \ + DECLARE_PARSER_TO_JSON(type) +IMPLEMENT_PARSERS(Animation); +IMPLEMENT_PARSERS(Audio); +IMPLEMENT_PARSERS(Birthdate); +IMPLEMENT_PARSERS(BotCommand); +IMPLEMENT_PARSERS(BotCommandScope); +IMPLEMENT_PARSERS(BotCommandScopeAllChatAdministrators); +IMPLEMENT_PARSERS(BotCommandScopeAllGroupChats); +IMPLEMENT_PARSERS(BotCommandScopeAllPrivateChats); +IMPLEMENT_PARSERS(BotCommandScopeChat); +IMPLEMENT_PARSERS(BotCommandScopeChatAdministrators); +IMPLEMENT_PARSERS(BotCommandScopeChatMember); +IMPLEMENT_PARSERS(BotCommandScopeDefault); +IMPLEMENT_PARSERS(BotDescription); +IMPLEMENT_PARSERS(BotName); +IMPLEMENT_PARSERS(BotShortDescription); +IMPLEMENT_PARSERS(BusinessConnection); +IMPLEMENT_PARSERS(BusinessIntro); +IMPLEMENT_PARSERS(BusinessLocation); +IMPLEMENT_PARSERS(BusinessMessagesDeleted); +IMPLEMENT_PARSERS(BusinessOpeningHours); +IMPLEMENT_PARSERS(BusinessOpeningHoursInterval); +IMPLEMENT_PARSERS(CallbackGame); +IMPLEMENT_PARSERS(CallbackQuery); +IMPLEMENT_PARSERS(Chat); +IMPLEMENT_PARSERS(ChatAdministratorRights); +IMPLEMENT_PARSERS(ChatBoost); +IMPLEMENT_PARSERS(ChatBoostAdded); +IMPLEMENT_PARSERS(ChatBoostRemoved); +IMPLEMENT_PARSERS(ChatBoostSource); +IMPLEMENT_PARSERS(ChatBoostSourceGiftCode); +IMPLEMENT_PARSERS(ChatBoostSourceGiveaway); +IMPLEMENT_PARSERS(ChatBoostSourcePremium); +IMPLEMENT_PARSERS(ChatBoostUpdated); +IMPLEMENT_PARSERS(ChatInviteLink); +IMPLEMENT_PARSERS(ChatJoinRequest); +IMPLEMENT_PARSERS(ChatLocation); +IMPLEMENT_PARSERS(ChatMember); +IMPLEMENT_PARSERS(ChatMemberAdministrator); +IMPLEMENT_PARSERS(ChatMemberBanned); +IMPLEMENT_PARSERS(ChatMemberLeft); +IMPLEMENT_PARSERS(ChatMemberMember); +IMPLEMENT_PARSERS(ChatMemberOwner); +IMPLEMENT_PARSERS(ChatMemberRestricted); +IMPLEMENT_PARSERS(ChatMemberUpdated); +IMPLEMENT_PARSERS(ChatPermissions); +IMPLEMENT_PARSERS(ChatPhoto); +IMPLEMENT_PARSERS(ChatShared); +IMPLEMENT_PARSERS(ChosenInlineResult); +IMPLEMENT_PARSERS(Contact); +IMPLEMENT_PARSERS(Dice); +IMPLEMENT_PARSERS(Document); +IMPLEMENT_PARSERS(EncryptedCredentials); +IMPLEMENT_PARSERS(EncryptedPassportElement); +IMPLEMENT_PARSERS(ExternalReplyInfo); +IMPLEMENT_PARSERS(File); +IMPLEMENT_PARSERS(ForceReply); +IMPLEMENT_PARSERS(ForumTopic); +IMPLEMENT_PARSERS(ForumTopicClosed); +IMPLEMENT_PARSERS(ForumTopicCreated); +IMPLEMENT_PARSERS(ForumTopicEdited); +IMPLEMENT_PARSERS(ForumTopicReopened); +IMPLEMENT_PARSERS(Game); +IMPLEMENT_PARSERS(GameHighScore); +IMPLEMENT_PARSERS(GeneralForumTopicHidden); +IMPLEMENT_PARSERS(GeneralForumTopicUnhidden); +IMPLEMENT_PARSERS(GenericReply); +IMPLEMENT_PARSERS(Giveaway); +IMPLEMENT_PARSERS(GiveawayCompleted); +IMPLEMENT_PARSERS(GiveawayCreated); +IMPLEMENT_PARSERS(GiveawayWinners); +IMPLEMENT_PARSERS(InaccessibleMessage); +IMPLEMENT_PARSERS(InlineKeyboardButton); +IMPLEMENT_PARSERS(InlineKeyboardMarkup); +IMPLEMENT_PARSERS(InlineQuery); +IMPLEMENT_PARSERS(InlineQueryResult); +IMPLEMENT_PARSERS(InlineQueryResultArticle); +IMPLEMENT_PARSERS(InlineQueryResultAudio); +IMPLEMENT_PARSERS(InlineQueryResultCachedAudio); +IMPLEMENT_PARSERS(InlineQueryResultCachedDocument); +IMPLEMENT_PARSERS(InlineQueryResultCachedGif); +IMPLEMENT_PARSERS(InlineQueryResultCachedMpeg4Gif); +IMPLEMENT_PARSERS(InlineQueryResultCachedPhoto); +IMPLEMENT_PARSERS(InlineQueryResultCachedSticker); +IMPLEMENT_PARSERS(InlineQueryResultCachedVideo); +IMPLEMENT_PARSERS(InlineQueryResultCachedVoice); +IMPLEMENT_PARSERS(InlineQueryResultContact); +IMPLEMENT_PARSERS(InlineQueryResultDocument); +IMPLEMENT_PARSERS(InlineQueryResultGame); +IMPLEMENT_PARSERS(InlineQueryResultGif); +IMPLEMENT_PARSERS(InlineQueryResultLocation); +IMPLEMENT_PARSERS(InlineQueryResultMpeg4Gif); +IMPLEMENT_PARSERS(InlineQueryResultPhoto); +IMPLEMENT_PARSERS(InlineQueryResultVenue); +IMPLEMENT_PARSERS(InlineQueryResultVideo); +IMPLEMENT_PARSERS(InlineQueryResultVoice); +IMPLEMENT_PARSERS(InlineQueryResultsButton); +IMPLEMENT_PARSERS(InputContactMessageContent); +IMPLEMENT_PARSERS(InputInvoiceMessageContent); +IMPLEMENT_PARSERS(InputLocationMessageContent); +IMPLEMENT_PARSERS(InputMedia); +IMPLEMENT_PARSERS(InputMediaAnimation); +IMPLEMENT_PARSERS(InputMediaAudio); +IMPLEMENT_PARSERS(InputMediaDocument); +IMPLEMENT_PARSERS(InputMediaPhoto); +IMPLEMENT_PARSERS(InputMediaVideo); +IMPLEMENT_PARSERS(InputMessageContent); +IMPLEMENT_PARSERS(InputSticker); +IMPLEMENT_PARSERS(InputTextMessageContent); +IMPLEMENT_PARSERS(InputVenueMessageContent); +IMPLEMENT_PARSERS(Invoice); +IMPLEMENT_PARSERS(KeyboardButton); +IMPLEMENT_PARSERS(KeyboardButtonPollType); +IMPLEMENT_PARSERS(KeyboardButtonRequestChat); +IMPLEMENT_PARSERS(KeyboardButtonRequestUsers); +IMPLEMENT_PARSERS(LabeledPrice); +IMPLEMENT_PARSERS(LinkPreviewOptions); +IMPLEMENT_PARSERS(Location); +IMPLEMENT_PARSERS(LoginUrl); +IMPLEMENT_PARSERS(MaskPosition); +IMPLEMENT_PARSERS(MenuButton); +IMPLEMENT_PARSERS(MenuButtonCommands); +IMPLEMENT_PARSERS(MenuButtonDefault); +IMPLEMENT_PARSERS(MenuButtonWebApp); +IMPLEMENT_PARSERS(Message); +IMPLEMENT_PARSERS(MessageAutoDeleteTimerChanged); +IMPLEMENT_PARSERS(MessageEntity); +IMPLEMENT_PARSERS(MessageId); +IMPLEMENT_PARSERS(MessageOrigin); +IMPLEMENT_PARSERS(MessageOriginChannel); +IMPLEMENT_PARSERS(MessageOriginChat); +IMPLEMENT_PARSERS(MessageOriginHiddenUser); +IMPLEMENT_PARSERS(MessageOriginUser); +IMPLEMENT_PARSERS(MessageReactionCountUpdated); +IMPLEMENT_PARSERS(MessageReactionUpdated); +IMPLEMENT_PARSERS(OrderInfo); +IMPLEMENT_PARSERS(PassportData); +IMPLEMENT_PARSERS(PassportElementError); +IMPLEMENT_PARSERS(PassportElementErrorDataField); +IMPLEMENT_PARSERS(PassportElementErrorFile); +IMPLEMENT_PARSERS(PassportElementErrorFiles); +IMPLEMENT_PARSERS(PassportElementErrorFrontSide); +IMPLEMENT_PARSERS(PassportElementErrorReverseSide); +IMPLEMENT_PARSERS(PassportElementErrorSelfie); +IMPLEMENT_PARSERS(PassportElementErrorTranslationFile); +IMPLEMENT_PARSERS(PassportElementErrorTranslationFiles); +IMPLEMENT_PARSERS(PassportElementErrorUnspecified); +IMPLEMENT_PARSERS(PassportFile); +IMPLEMENT_PARSERS(PhotoSize); +IMPLEMENT_PARSERS(Poll); +IMPLEMENT_PARSERS(PollAnswer); +IMPLEMENT_PARSERS(PollOption); +IMPLEMENT_PARSERS(PreCheckoutQuery); +IMPLEMENT_PARSERS(ProximityAlertTriggered); +IMPLEMENT_PARSERS(ReactionCount); +IMPLEMENT_PARSERS(ReactionType); +IMPLEMENT_PARSERS(ReactionTypeCustomEmoji); +IMPLEMENT_PARSERS(ReactionTypeEmoji); +IMPLEMENT_PARSERS(ReplyKeyboardMarkup); +IMPLEMENT_PARSERS(ReplyKeyboardRemove); +IMPLEMENT_PARSERS(ReplyParameters); +IMPLEMENT_PARSERS(ResponseParameters); +IMPLEMENT_PARSERS(SentWebAppMessage); +IMPLEMENT_PARSERS(SharedUser); +IMPLEMENT_PARSERS(ShippingAddress); +IMPLEMENT_PARSERS(ShippingOption); +IMPLEMENT_PARSERS(ShippingQuery); +IMPLEMENT_PARSERS(Sticker); +IMPLEMENT_PARSERS(StickerSet); +IMPLEMENT_PARSERS(Story); +IMPLEMENT_PARSERS(SuccessfulPayment); +IMPLEMENT_PARSERS(SwitchInlineQueryChosenChat); +IMPLEMENT_PARSERS(TextQuote); +IMPLEMENT_PARSERS(Update); +IMPLEMENT_PARSERS(User); +IMPLEMENT_PARSERS(UserChatBoosts); +IMPLEMENT_PARSERS(UserProfilePhotos); +IMPLEMENT_PARSERS(UsersShared); +IMPLEMENT_PARSERS(Venue); +IMPLEMENT_PARSERS(Video); +IMPLEMENT_PARSERS(VideoChatEnded); +IMPLEMENT_PARSERS(VideoChatParticipantsInvited); +IMPLEMENT_PARSERS(VideoChatScheduled); +IMPLEMENT_PARSERS(VideoChatStarted); +IMPLEMENT_PARSERS(VideoNote); +IMPLEMENT_PARSERS(Voice); +IMPLEMENT_PARSERS(WebAppData); +IMPLEMENT_PARSERS(WebAppInfo); +IMPLEMENT_PARSERS(WebhookInfo); +IMPLEMENT_PARSERS(WriteAccessAllowed); + +} // namespace TgBot + +#endif // TGBOT_TGTYPEPARSER_H diff --git a/include/tgbot/net/TgLongPoll.h b/include/tgbot/net/TgLongPoll.h index 9c50407cd..82b51bdb3 100644 --- a/include/tgbot/net/TgLongPoll.h +++ b/include/tgbot/net/TgLongPoll.h @@ -22,7 +22,6 @@ class EventHandler; class TGBOT_API TgLongPoll { public: - TgLongPoll(const Api* api, const EventHandler* eventHandler, std::int32_t limit, std::int32_t timeout, std::shared_ptr> allowUpdates); TgLongPoll(const Bot& bot, std::int32_t limit = 100, std::int32_t timeout = 10, const std::shared_ptr>& allowUpdates = nullptr); /** diff --git a/include/tgbot/net/TgWebhookServer.h b/include/tgbot/net/TgWebhookServer.h index f7eb94974..14ef67174 100644 --- a/include/tgbot/net/TgWebhookServer.h +++ b/include/tgbot/net/TgWebhookServer.h @@ -1,6 +1,7 @@ #ifndef TGBOT_TGHTTPSERVER_H #define TGBOT_TGHTTPSERVER_H +#include #include "tgbot/Bot.h" #include "tgbot/EventHandler.h" #include "tgbot/TgTypeParser.h" @@ -12,37 +13,52 @@ namespace TgBot { -template +template class TgWebhookServer : public HttpServer { public: - TgWebhookServer(const typename boost::asio::basic_socket_acceptor::endpoint_type& endpoint, const typename HttpServer::ServerHandler& handler) = delete; + TgWebhookServer( + const typename boost::asio::basic_socket_acceptor::endpoint_type + &endpoint, + const typename HttpServer::ServerHandler &handler) = delete; - TgWebhookServer(const typename boost::asio::basic_socket_acceptor::endpoint_type& endpoint, std::string path, const EventHandler& eventHandler) - : HttpServer(endpoint, - [this](const std::string& _1, const std::unordered_map& _2) { return _handle(_1, _2); }), - _path(std::move(path)), _eventHandler(eventHandler), _tgTypeParser() - { - } + TgWebhookServer( + const typename boost::asio::basic_socket_acceptor::endpoint_type + &endpoint, + std::string path, const EventHandler &eventHandler) + : HttpServer( + endpoint, + [this](const std::string &_1, + const std::unordered_map &_2) { + return _handle(_1, _2); + }), + _path(std::move(path)), _eventHandler(eventHandler) {} - TgWebhookServer(const typename boost::asio::basic_socket_acceptor::endpoint_type& endpoint, const Bot& bot) - : TgWebhookServer(endpoint, "/" + bot.getToken(), bot.getEventHandler()) - { - } + TgWebhookServer( + const typename boost::asio::basic_socket_acceptor::endpoint_type + &endpoint, + const Bot &bot) + : TgWebhookServer(endpoint, "/" + bot.getToken(), bot.getEventHandler()) { + } private: - std::string _handle(const std::string& data, const std::unordered_map& headers) { - if (headers.at("_method") == "POST" && headers.at("_path") == _path) { - _eventHandler.handleUpdate(_tgTypeParser.parseJsonAndGetUpdate(_tgTypeParser.parseJson(data))); - } - return HttpServer::_httpParser.generateResponse("", "text/plain", 200, "OK", false); + std::string + _handle(const std::string &data, + const std::unordered_map &headers) { + if (headers.at("_method") == "POST" && headers.at("_path") == _path) { + Json::Value update; + Json::Reader reader; + reader.parse(data, update, false); + _eventHandler.handleUpdate(parse(update)); } + return HttpServer::_httpParser.generateResponse("", "text/plain", + 200, "OK", false); + } - const std::string _path; - const EventHandler& _eventHandler; - const TgTypeParser _tgTypeParser; + const std::string _path; + const EventHandler &_eventHandler; }; -} +} // namespace TgBot -#endif //TGBOT_TGHTTPSERVER_H +#endif // TGBOT_TGHTTPSERVER_H diff --git a/include/tgbot/tgbot.h b/include/tgbot/tgbot.h index 4cd5f2944..97af13945 100644 --- a/include/tgbot/tgbot.h +++ b/include/tgbot/tgbot.h @@ -6,7 +6,6 @@ #include "tgbot/EventBroadcaster.h" #include "tgbot/EventHandler.h" #include "tgbot/TgException.h" -#include "tgbot/TgTypeParser.h" #include "tgbot/net/BoostHttpOnlySslClient.h" #include "tgbot/net/CurlHttpClient.h" #include "tgbot/net/HttpClient.h" @@ -18,7 +17,6 @@ #include "tgbot/net/TgWebhookServer.h" #include "tgbot/net/TgWebhookTcpServer.h" #include "tgbot/net/Url.h" -#include "tgbot/tgbot.h" #include "tgbot/tools/FileTools.h" #include "tgbot/tools/StringTools.h" #include "tgbot/types/Animation.h" diff --git a/include/tgbot/types/BotCommandScope.h b/include/tgbot/types/BotCommandScope.h index 47a3ee9e6..b3536c6e4 100644 --- a/include/tgbot/types/BotCommandScope.h +++ b/include/tgbot/types/BotCommandScope.h @@ -15,11 +15,11 @@ namespace TgBot { */ class BotCommandScope { public: - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; - BotCommandScope() {} + BotCommandScope() = default; - virtual ~BotCommandScope() {} + virtual ~BotCommandScope() = default; /** * @brief Scope type diff --git a/include/tgbot/types/BotCommandScopeAllChatAdministrators.h b/include/tgbot/types/BotCommandScopeAllChatAdministrators.h index bc814bc0b..0b5909026 100644 --- a/include/tgbot/types/BotCommandScopeAllChatAdministrators.h +++ b/include/tgbot/types/BotCommandScopeAllChatAdministrators.h @@ -14,9 +14,9 @@ namespace TgBot { */ class BotCommandScopeAllChatAdministrators : public BotCommandScope { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "all_chat_administrators"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; BotCommandScopeAllChatAdministrators() { this->type = TYPE; diff --git a/include/tgbot/types/BotCommandScopeAllGroupChats.h b/include/tgbot/types/BotCommandScopeAllGroupChats.h index 8b709d66e..041dfa93a 100644 --- a/include/tgbot/types/BotCommandScopeAllGroupChats.h +++ b/include/tgbot/types/BotCommandScopeAllGroupChats.h @@ -14,9 +14,9 @@ namespace TgBot { */ class BotCommandScopeAllGroupChats : public BotCommandScope { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "all_group_chats"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; BotCommandScopeAllGroupChats() { this->type = TYPE; diff --git a/include/tgbot/types/BotCommandScopeAllPrivateChats.h b/include/tgbot/types/BotCommandScopeAllPrivateChats.h index b2e36b865..ef1ef50ba 100644 --- a/include/tgbot/types/BotCommandScopeAllPrivateChats.h +++ b/include/tgbot/types/BotCommandScopeAllPrivateChats.h @@ -14,9 +14,9 @@ namespace TgBot { */ class BotCommandScopeAllPrivateChats : public BotCommandScope { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "all_private_chats"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; BotCommandScopeAllPrivateChats() { this->type = TYPE; diff --git a/include/tgbot/types/BotCommandScopeChat.h b/include/tgbot/types/BotCommandScopeChat.h index fd36125c5..3dab4f8a7 100644 --- a/include/tgbot/types/BotCommandScopeChat.h +++ b/include/tgbot/types/BotCommandScopeChat.h @@ -15,9 +15,9 @@ namespace TgBot { */ class BotCommandScopeChat : public BotCommandScope { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "chat"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; BotCommandScopeChat() { this->type = TYPE; diff --git a/include/tgbot/types/BotCommandScopeChatAdministrators.h b/include/tgbot/types/BotCommandScopeChatAdministrators.h index f046e317b..74e1173ec 100644 --- a/include/tgbot/types/BotCommandScopeChatAdministrators.h +++ b/include/tgbot/types/BotCommandScopeChatAdministrators.h @@ -15,9 +15,9 @@ namespace TgBot { */ class BotCommandScopeChatAdministrators : public BotCommandScope { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "chat_administrators"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; BotCommandScopeChatAdministrators() { this->type = TYPE; @@ -26,7 +26,7 @@ class BotCommandScopeChatAdministrators : public BotCommandScope { /** * @brief Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) */ - std::int64_t chatId; + std::int64_t chatId{}; }; } diff --git a/include/tgbot/types/BotCommandScopeChatMember.h b/include/tgbot/types/BotCommandScopeChatMember.h index 5beaee642..61f714554 100644 --- a/include/tgbot/types/BotCommandScopeChatMember.h +++ b/include/tgbot/types/BotCommandScopeChatMember.h @@ -15,9 +15,9 @@ namespace TgBot { */ class BotCommandScopeChatMember : public BotCommandScope { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "chat_member"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; BotCommandScopeChatMember() { this->type = TYPE; @@ -26,12 +26,12 @@ class BotCommandScopeChatMember : public BotCommandScope { /** * @brief Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) */ - std::int64_t chatId; + std::int64_t chatId{}; /** * @brief Unique identifier of the target user */ - std::int64_t userId; + std::int64_t userId{}; }; } diff --git a/include/tgbot/types/BotCommandScopeDefault.h b/include/tgbot/types/BotCommandScopeDefault.h index 76b81923c..f915905d1 100644 --- a/include/tgbot/types/BotCommandScopeDefault.h +++ b/include/tgbot/types/BotCommandScopeDefault.h @@ -15,9 +15,9 @@ namespace TgBot { */ class BotCommandScopeDefault : public BotCommandScope { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "default"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; BotCommandScopeDefault() { this->type = TYPE; diff --git a/include/tgbot/types/ChatBoostSourceGiftCode.h b/include/tgbot/types/ChatBoostSourceGiftCode.h index 42bb83bdf..b7029fa5b 100644 --- a/include/tgbot/types/ChatBoostSourceGiftCode.h +++ b/include/tgbot/types/ChatBoostSourceGiftCode.h @@ -17,9 +17,9 @@ namespace TgBot { class ChatBoostSourceGiftCode : public ChatBoostSource { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "gift_code"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatBoostSourceGiftCode() { this->source = SOURCE; diff --git a/include/tgbot/types/ChatBoostSourceGiveaway.h b/include/tgbot/types/ChatBoostSourceGiveaway.h index 8f86ab7fb..807d31516 100644 --- a/include/tgbot/types/ChatBoostSourceGiveaway.h +++ b/include/tgbot/types/ChatBoostSourceGiveaway.h @@ -18,9 +18,9 @@ namespace TgBot { class ChatBoostSourceGiveaway : public ChatBoostSource { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "giveaway"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatBoostSourceGiveaway() { this->source = SOURCE; @@ -31,12 +31,12 @@ class ChatBoostSourceGiveaway : public ChatBoostSource { * * May be 0 if the message isn't sent yet. */ - std::int32_t giveawayMessageId; + std::int32_t giveawayMessageId{}; /** * @brief Optional. True, if the giveaway was completed, but there was no user to win the prize */ - bool isUnclaimed; + bool isUnclaimed{}; }; } diff --git a/include/tgbot/types/ChatBoostSourcePremium.h b/include/tgbot/types/ChatBoostSourcePremium.h index 21fda2650..7f7bf9d74 100644 --- a/include/tgbot/types/ChatBoostSourcePremium.h +++ b/include/tgbot/types/ChatBoostSourcePremium.h @@ -4,6 +4,7 @@ #include "tgbot/types/ChatBoostSource.h" #include +#include namespace TgBot { @@ -15,9 +16,9 @@ namespace TgBot { class ChatBoostSourcePremium : public ChatBoostSource { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "premium"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatBoostSourcePremium() { this->source = SOURCE; diff --git a/include/tgbot/types/ChatMemberAdministrator.h b/include/tgbot/types/ChatMemberAdministrator.h index d9f7a45a7..f955aa7ce 100644 --- a/include/tgbot/types/ChatMemberAdministrator.h +++ b/include/tgbot/types/ChatMemberAdministrator.h @@ -16,9 +16,9 @@ namespace TgBot { class ChatMemberAdministrator : public ChatMember { public: - static const std::string STATUS; + static constexpr std::string_view STATUS = "administrator"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatMemberAdministrator() { this->status = STATUS; @@ -27,84 +27,84 @@ class ChatMemberAdministrator : public ChatMember { /** * @brief True, if the bot is allowed to edit administrator privileges of that user */ - bool canBeEdited; + bool canBeEdited{}; /** * @brief True, if the user's presence in the chat is hidden */ - bool isAnonymous; + bool isAnonymous{}; /** * @brief True, if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode. * * Implied by any other administrator privilege. */ - bool canManageChat; + bool canManageChat{}; /** * @brief True, if the administrator can delete messages of other users */ - bool canDeleteMessages; + bool canDeleteMessages{}; /** * @brief True, if the administrator can manage video chats */ - bool canManageVideoChats; + bool canManageVideoChats{}; /** * @brief True, if the administrator can restrict, ban or unban chat members, or access supergroup statistics */ - bool canRestrictMembers; + bool canRestrictMembers{}; /** * @brief True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user) */ - bool canPromoteMembers; + bool canPromoteMembers{}; /** * @brief True, if the user is allowed to change the chat title, photo and other settings */ - bool canChangeInfo; + bool canChangeInfo{}; /** * @brief True, if the user is allowed to invite new users to the chat */ - bool canInviteUsers; + bool canInviteUsers{}; /** * @brief True, if the administrator can post stories to the chat */ - bool canPostStories; + bool canPostStories{}; /** * @brief True, if the administrator can edit stories posted by other users */ - bool canEditStories; + bool canEditStories{}; /** * @brief True, if the administrator can delete stories posted by other users */ - bool canDeleteStories; + bool canDeleteStories{}; /** * @brief Optional. True, if the administrator can post messages in the channel, or access channel statistics; for channels only */ - bool canPostMessages; + bool canPostMessages{}; /** * @brief Optional. True, if the administrator can edit messages of other users and can pin messages; for channels only */ - bool canEditMessages; + bool canEditMessages{}; /** * @brief Optional. True, if the user is allowed to pin messages; for groups and supergroups only */ - bool canPinMessages; + bool canPinMessages{}; /** * @brief Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only */ - bool canManageTopics; + bool canManageTopics{}; /** * @brief Optional. Custom title for this user diff --git a/include/tgbot/types/ChatMemberBanned.h b/include/tgbot/types/ChatMemberBanned.h index 1e0f25103..920a5df70 100644 --- a/include/tgbot/types/ChatMemberBanned.h +++ b/include/tgbot/types/ChatMemberBanned.h @@ -15,9 +15,9 @@ namespace TgBot { */ class ChatMemberBanned : public ChatMember { public: - static const std::string STATUS; + static constexpr std::string_view STATUS = "kicked"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatMemberBanned() { this->status = STATUS; @@ -28,7 +28,7 @@ class ChatMemberBanned : public ChatMember { * * If 0, then the user is banned forever */ - std::uint32_t untilDate; + std::uint32_t untilDate{}; }; } diff --git a/include/tgbot/types/ChatMemberLeft.h b/include/tgbot/types/ChatMemberLeft.h index 3431acac7..95eccd030 100644 --- a/include/tgbot/types/ChatMemberLeft.h +++ b/include/tgbot/types/ChatMemberLeft.h @@ -14,9 +14,9 @@ namespace TgBot { */ class ChatMemberLeft : public ChatMember { public: - static const std::string STATUS; + static constexpr std::string_view STATUS = "left"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatMemberLeft() { this->status = STATUS; diff --git a/include/tgbot/types/ChatMemberMember.h b/include/tgbot/types/ChatMemberMember.h index 6bdccd724..01c12b265 100644 --- a/include/tgbot/types/ChatMemberMember.h +++ b/include/tgbot/types/ChatMemberMember.h @@ -14,9 +14,9 @@ namespace TgBot { */ class ChatMemberMember : public ChatMember { public: - static const std::string STATUS; + static constexpr std::string_view STATUS = "member"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatMemberMember() { this->status = STATUS; diff --git a/include/tgbot/types/ChatMemberOwner.h b/include/tgbot/types/ChatMemberOwner.h index 2881a3388..4d47607dc 100644 --- a/include/tgbot/types/ChatMemberOwner.h +++ b/include/tgbot/types/ChatMemberOwner.h @@ -15,9 +15,9 @@ namespace TgBot { */ class ChatMemberOwner : public ChatMember { public: - static const std::string STATUS; + static constexpr std::string_view STATUS = "creator"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatMemberOwner() { this->status = STATUS; @@ -31,7 +31,7 @@ class ChatMemberOwner : public ChatMember { /** * @brief True, if the user's presence in the chat is hidden */ - bool isAnonymous; + bool isAnonymous{}; }; } diff --git a/include/tgbot/types/ChatMemberRestricted.h b/include/tgbot/types/ChatMemberRestricted.h index b02edb3de..0c50cd713 100644 --- a/include/tgbot/types/ChatMemberRestricted.h +++ b/include/tgbot/types/ChatMemberRestricted.h @@ -18,9 +18,9 @@ namespace TgBot { class ChatMemberRestricted : public ChatMember { public: - static const std::string STATUS; + static constexpr std::string_view STATUS = "restricted"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ChatMemberRestricted() { this->status = STATUS; @@ -29,84 +29,84 @@ class ChatMemberRestricted : public ChatMember { /** * @brief True, if the user is a member of the chat at the moment of the request */ - bool isMember; + bool isMember{}; /** * @brief True, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues */ - bool canSendMessages; + bool canSendMessages{}; /** * @brief True, if the user is allowed to send audios */ - bool canSendAudios; + bool canSendAudios{}; /** * @brief True, if the user is allowed to send documents */ - bool canSendDocuments; + bool canSendDocuments{}; /** * @brief True, if the user is allowed to send photos */ - bool canSendPhotos; + bool canSendPhotos{}; /** * @brief True, if the user is allowed to send videos */ - bool canSendVideos; + bool canSendVideos{}; /** * @brief True, if the user is allowed to send video notes */ - bool canSendVideoNotes; + bool canSendVideoNotes{}; /** * @brief True, if the user is allowed to send voice notes */ - bool canSendVoiceNotes; + bool canSendVoiceNotes{}; /** * @brief True, if the user is allowed to send polls */ - bool canSendPolls; + bool canSendPolls{}; /** * @brief True, if the user is allowed to send animations, games, stickers and use inline bots */ - bool canSendOtherMessages; + bool canSendOtherMessages{}; /** * @brief True, if the user is allowed to add web page previews to their messages */ - bool canAddWebPagePreviews; + bool canAddWebPagePreviews{}; /** * @brief True, if the user is allowed to change the chat title, photo and other settings */ - bool canChangeInfo; + bool canChangeInfo{}; /** * @brief True, if the user is allowed to invite new users to the chat */ - bool canInviteUsers; + bool canInviteUsers{}; /** * @brief True, if the user is allowed to pin messages */ - bool canPinMessages; + bool canPinMessages{}; /** * @brief True, if the user is allowed to create forum topics */ - bool canManageTopics; + bool canManageTopics{}; /** * @brief Date when restrictions will be lifted for this user; Unix time. * * If 0, then the user is restricted forever */ - std::uint32_t untilDate; + std::uint32_t untilDate{}; }; } diff --git a/include/tgbot/types/InlineQueryResultArticle.h b/include/tgbot/types/InlineQueryResultArticle.h index 5f61f17f5..9f5b326d5 100644 --- a/include/tgbot/types/InlineQueryResultArticle.h +++ b/include/tgbot/types/InlineQueryResultArticle.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace TgBot { @@ -17,7 +18,7 @@ namespace TgBot { */ class InlineQueryResultArticle : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "article"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/InlineQueryResultAudio.h b/include/tgbot/types/InlineQueryResultAudio.h index e4324d318..b30eeac34 100644 --- a/include/tgbot/types/InlineQueryResultAudio.h +++ b/include/tgbot/types/InlineQueryResultAudio.h @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace TgBot { @@ -23,9 +24,9 @@ namespace TgBot { class InlineQueryResultAudio : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "audio"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultAudio() { this->type = TYPE; @@ -66,7 +67,7 @@ class InlineQueryResultAudio : public InlineQueryResult { /** * @brief Optional. Audio duration in seconds */ - std::int32_t audioDuration; + std::int32_t audioDuration{}; /** * @brief Optional. Content of the message to be sent instead of the audio diff --git a/include/tgbot/types/InlineQueryResultCachedAudio.h b/include/tgbot/types/InlineQueryResultCachedAudio.h index 303f4a053..9665a7ee8 100644 --- a/include/tgbot/types/InlineQueryResultCachedAudio.h +++ b/include/tgbot/types/InlineQueryResultCachedAudio.h @@ -22,9 +22,9 @@ namespace TgBot { class InlineQueryResultCachedAudio : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "audio"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultCachedAudio() { this->type = TYPE; diff --git a/include/tgbot/types/InlineQueryResultCachedDocument.h b/include/tgbot/types/InlineQueryResultCachedDocument.h index 950369d39..aceca9c5a 100644 --- a/include/tgbot/types/InlineQueryResultCachedDocument.h +++ b/include/tgbot/types/InlineQueryResultCachedDocument.h @@ -22,9 +22,9 @@ namespace TgBot { class InlineQueryResultCachedDocument : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "document"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultCachedDocument() { this->type = TYPE; diff --git a/include/tgbot/types/InlineQueryResultCachedGif.h b/include/tgbot/types/InlineQueryResultCachedGif.h index b75ca397f..02b4de0d4 100644 --- a/include/tgbot/types/InlineQueryResultCachedGif.h +++ b/include/tgbot/types/InlineQueryResultCachedGif.h @@ -20,9 +20,9 @@ namespace TgBot { */ class InlineQueryResultCachedGif : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "gif"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultCachedGif() { this->type = TYPE; diff --git a/include/tgbot/types/InlineQueryResultCachedMpeg4Gif.h b/include/tgbot/types/InlineQueryResultCachedMpeg4Gif.h index 91bc4ae5e..b089db77e 100644 --- a/include/tgbot/types/InlineQueryResultCachedMpeg4Gif.h +++ b/include/tgbot/types/InlineQueryResultCachedMpeg4Gif.h @@ -20,9 +20,9 @@ namespace TgBot { */ class InlineQueryResultCachedMpeg4Gif : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "mpeg4_gif"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultCachedMpeg4Gif() { this->type = TYPE; diff --git a/include/tgbot/types/InlineQueryResultCachedPhoto.h b/include/tgbot/types/InlineQueryResultCachedPhoto.h index 8ab23e81a..3533e38e8 100644 --- a/include/tgbot/types/InlineQueryResultCachedPhoto.h +++ b/include/tgbot/types/InlineQueryResultCachedPhoto.h @@ -20,9 +20,9 @@ namespace TgBot { */ class InlineQueryResultCachedPhoto : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "photo"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultCachedPhoto() { this->type = TYPE; diff --git a/include/tgbot/types/InlineQueryResultCachedSticker.h b/include/tgbot/types/InlineQueryResultCachedSticker.h index d566446ec..3411b8894 100644 --- a/include/tgbot/types/InlineQueryResultCachedSticker.h +++ b/include/tgbot/types/InlineQueryResultCachedSticker.h @@ -20,9 +20,9 @@ namespace TgBot { class InlineQueryResultCachedSticker : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "sticker"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultCachedSticker() { this->type = TYPE; diff --git a/include/tgbot/types/InlineQueryResultCachedVideo.h b/include/tgbot/types/InlineQueryResultCachedVideo.h index b82cf345a..81b8788bd 100644 --- a/include/tgbot/types/InlineQueryResultCachedVideo.h +++ b/include/tgbot/types/InlineQueryResultCachedVideo.h @@ -7,6 +7,7 @@ #include #include +#include #include namespace TgBot { @@ -20,9 +21,9 @@ namespace TgBot { */ class InlineQueryResultCachedVideo : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "video"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultCachedVideo() { this->type = TYPE; diff --git a/include/tgbot/types/InlineQueryResultCachedVoice.h b/include/tgbot/types/InlineQueryResultCachedVoice.h index 1a14df344..98196c2d9 100644 --- a/include/tgbot/types/InlineQueryResultCachedVoice.h +++ b/include/tgbot/types/InlineQueryResultCachedVoice.h @@ -22,7 +22,7 @@ namespace TgBot { class InlineQueryResultCachedVoice : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "voice"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/InlineQueryResultContact.h b/include/tgbot/types/InlineQueryResultContact.h index 1773adecf..6b20f8052 100644 --- a/include/tgbot/types/InlineQueryResultContact.h +++ b/include/tgbot/types/InlineQueryResultContact.h @@ -21,9 +21,9 @@ namespace TgBot { class InlineQueryResultContact : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "contact"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultContact() { this->type = TYPE; @@ -62,12 +62,12 @@ class InlineQueryResultContact : public InlineQueryResult { /** * @brief Optional. Thumbnail width */ - std::int32_t thumbnailWidth; + std::int32_t thumbnailWidth{}; /** * @brief Optional. Thumbnail height */ - std::int32_t thumbnailHeight; + std::int32_t thumbnailHeight{}; }; } diff --git a/include/tgbot/types/InlineQueryResultDocument.h b/include/tgbot/types/InlineQueryResultDocument.h index 32f27c4f6..7ebe4d278 100644 --- a/include/tgbot/types/InlineQueryResultDocument.h +++ b/include/tgbot/types/InlineQueryResultDocument.h @@ -24,9 +24,9 @@ namespace TgBot { class InlineQueryResultDocument : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "document"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultDocument() { this->type = TYPE; @@ -82,12 +82,12 @@ class InlineQueryResultDocument : public InlineQueryResult { /** * @brief Optional. Thumbnail width */ - std::int32_t thumbnailWidth; + std::int32_t thumbnailWidth{}; /** * @brief Optional. Thumbnail height */ - std::int32_t thumbnailHeight; + std::int32_t thumbnailHeight{}; }; } diff --git a/include/tgbot/types/InlineQueryResultGame.h b/include/tgbot/types/InlineQueryResultGame.h index 0a56c2204..55a988ba2 100644 --- a/include/tgbot/types/InlineQueryResultGame.h +++ b/include/tgbot/types/InlineQueryResultGame.h @@ -16,7 +16,7 @@ namespace TgBot { class InlineQueryResultGame : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "game"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/InlineQueryResultGif.h b/include/tgbot/types/InlineQueryResultGif.h index a5115c97d..7cf7dd563 100644 --- a/include/tgbot/types/InlineQueryResultGif.h +++ b/include/tgbot/types/InlineQueryResultGif.h @@ -21,9 +21,9 @@ namespace TgBot { */ class InlineQueryResultGif : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "gif"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultGif() { this->type = TYPE; @@ -38,17 +38,17 @@ class InlineQueryResultGif : public InlineQueryResult { /** * @brief Optional. Width of the GIF */ - std::int32_t gifWidth; + std::int32_t gifWidth{}; /** * @brief Optional. Height of the GIF */ - std::int32_t gifHeight; + std::int32_t gifHeight{}; /** * @brief Optional. Duration of the GIF */ - std::int32_t gifDuration; + std::int32_t gifDuration{}; /** * @brief URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result diff --git a/include/tgbot/types/InlineQueryResultLocation.h b/include/tgbot/types/InlineQueryResultLocation.h index cf2f1e0ea..21438c508 100644 --- a/include/tgbot/types/InlineQueryResultLocation.h +++ b/include/tgbot/types/InlineQueryResultLocation.h @@ -21,7 +21,7 @@ namespace TgBot { class InlineQueryResultLocation : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "location"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/InlineQueryResultMpeg4Gif.h b/include/tgbot/types/InlineQueryResultMpeg4Gif.h index cf6aed424..c5cfd9d7e 100644 --- a/include/tgbot/types/InlineQueryResultMpeg4Gif.h +++ b/include/tgbot/types/InlineQueryResultMpeg4Gif.h @@ -21,9 +21,9 @@ namespace TgBot { */ class InlineQueryResultMpeg4Gif : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "mpeg4_gif"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultMpeg4Gif() { this->type = TYPE; @@ -38,17 +38,17 @@ class InlineQueryResultMpeg4Gif : public InlineQueryResult { /** * @brief Optional. Video width */ - std::int32_t mpeg4Width; + std::int32_t mpeg4Width{}; /** * @brief Optional. Video height */ - std::int32_t mpeg4Height; + std::int32_t mpeg4Height{}; /** * @brief Optional. Video duration */ - std::int32_t mpeg4Duration; + std::int32_t mpeg4Duration{}; /** * @brief URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result diff --git a/include/tgbot/types/InlineQueryResultPhoto.h b/include/tgbot/types/InlineQueryResultPhoto.h index 45e855e57..e3f06e95a 100644 --- a/include/tgbot/types/InlineQueryResultPhoto.h +++ b/include/tgbot/types/InlineQueryResultPhoto.h @@ -21,7 +21,7 @@ namespace TgBot { */ class InlineQueryResultPhoto : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "photo"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/InlineQueryResultVenue.h b/include/tgbot/types/InlineQueryResultVenue.h index 8fc4ef856..c9de59938 100644 --- a/include/tgbot/types/InlineQueryResultVenue.h +++ b/include/tgbot/types/InlineQueryResultVenue.h @@ -21,9 +21,9 @@ namespace TgBot { class InlineQueryResultVenue : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "venue"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultVenue() { this->type = TYPE; @@ -32,12 +32,12 @@ class InlineQueryResultVenue : public InlineQueryResult { /** * @brief Latitude of the venue location in degrees */ - float latitude; + float latitude{}; /** * @brief Longitude of the venue location in degrees */ - float longitude; + float longitude{}; /** * @brief Title of the venue @@ -86,12 +86,12 @@ class InlineQueryResultVenue : public InlineQueryResult { /** * @brief Optional. Thumbnail width */ - std::int32_t thumbnailWidth; + std::int32_t thumbnailWidth{}; /** * @brief Optional. Thumbnail height */ - std::int32_t thumbnailHeight; + std::int32_t thumbnailHeight{}; }; } diff --git a/include/tgbot/types/InlineQueryResultVideo.h b/include/tgbot/types/InlineQueryResultVideo.h index 72350587b..51bae9cd6 100644 --- a/include/tgbot/types/InlineQueryResultVideo.h +++ b/include/tgbot/types/InlineQueryResultVideo.h @@ -23,9 +23,9 @@ namespace TgBot { */ class InlineQueryResultVideo : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "video"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultVideo() { this->type = TYPE; @@ -70,17 +70,17 @@ class InlineQueryResultVideo : public InlineQueryResult { /** * @brief Optional. Video width */ - std::int32_t videoWidth; + std::int32_t videoWidth{}; /** * @brief Optional. Video height */ - std::int32_t videoHeight; + std::int32_t videoHeight{}; /** * @brief Optional. Video duration in seconds */ - std::int32_t videoDuration; + std::int32_t videoDuration{}; /** * @brief Optional. Short description of the result diff --git a/include/tgbot/types/InlineQueryResultVoice.h b/include/tgbot/types/InlineQueryResultVoice.h index e64b7fbef..9850da1e1 100644 --- a/include/tgbot/types/InlineQueryResultVoice.h +++ b/include/tgbot/types/InlineQueryResultVoice.h @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace TgBot { @@ -23,9 +24,9 @@ namespace TgBot { class InlineQueryResultVoice : public InlineQueryResult { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "voice"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InlineQueryResultVoice() { this->type = TYPE; @@ -61,7 +62,7 @@ class InlineQueryResultVoice : public InlineQueryResult { /** * @brief Optional. Recording duration in seconds */ - std::int32_t voiceDuration; + std::int32_t voiceDuration{}; /** * @brief Optional. Content of the message to be sent instead of the voice recording diff --git a/include/tgbot/types/InputContactMessageContent.h b/include/tgbot/types/InputContactMessageContent.h index 44e832445..c700b687e 100644 --- a/include/tgbot/types/InputContactMessageContent.h +++ b/include/tgbot/types/InputContactMessageContent.h @@ -15,9 +15,9 @@ namespace TgBot { */ class InputContactMessageContent : public InputMessageContent { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "contact"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputContactMessageContent() { this->type = TYPE; diff --git a/include/tgbot/types/InputInvoiceMessageContent.h b/include/tgbot/types/InputInvoiceMessageContent.h index 36f905610..2eddac81b 100644 --- a/include/tgbot/types/InputInvoiceMessageContent.h +++ b/include/tgbot/types/InputInvoiceMessageContent.h @@ -18,9 +18,9 @@ namespace TgBot { */ class InputInvoiceMessageContent : public InputMessageContent { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "invoice"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputInvoiceMessageContent() { this->type = TYPE; @@ -63,7 +63,7 @@ class InputInvoiceMessageContent : public InputMessageContent { * See the exp parameter in https://core.telegram.org/bots/payments/currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). * Defaults to 0 */ - std::int32_t maxTipAmount; + std::int32_t maxTipAmount{}; /** * @brief Optional. A JSON-serialized array of suggested amounts of tip in the smallest units of the currency (integer, not float/double). @@ -88,52 +88,52 @@ class InputInvoiceMessageContent : public InputMessageContent { /** * @brief Optional. Photo size */ - std::int32_t photoSize; + std::int32_t photoSize{}; /** * @brief Optional. Photo width */ - std::int32_t photoWidth; + std::int32_t photoWidth{}; /** * @brief Optional. Photo height */ - std::int32_t photoHeight; + std::int32_t photoHeight{}; /** * @brief Optional. Pass True, if you require the user's full name to complete the order */ - bool needName; + bool needName{}; /** * @brief Optional. Pass True, if you require the user's phone number to complete the order */ - bool needPhoneNumber; + bool needPhoneNumber{}; /** * @brief Optional. Pass True, if you require the user's email address to complete the order */ - bool needEmail; + bool needEmail{}; /** * @brief Optional. Pass True, if you require the user's shipping address to complete the order */ - bool needShippingAddress; + bool needShippingAddress{}; /** * @brief Optional. Pass True, if user's phone number should be sent to provider */ - bool sendPhoneNumberToProvider; + bool sendPhoneNumberToProvider{}; /** * @brief Optional. Pass True, if user's email address should be sent to provider */ - bool sendEmailToProvider; + bool sendEmailToProvider{}; /** * @brief Optional. Pass True, if the final price depends on the shipping method */ - bool isFlexible; + bool isFlexible{}; }; } diff --git a/include/tgbot/types/InputLocationMessageContent.h b/include/tgbot/types/InputLocationMessageContent.h index 8b9c22f25..866e366f6 100644 --- a/include/tgbot/types/InputLocationMessageContent.h +++ b/include/tgbot/types/InputLocationMessageContent.h @@ -14,9 +14,9 @@ namespace TgBot { */ class InputLocationMessageContent : public InputMessageContent { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "location"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputLocationMessageContent() { this->type = TYPE; @@ -25,34 +25,34 @@ class InputLocationMessageContent : public InputMessageContent { /** * @brief Latitude of the location in degrees */ - float latitude; + float latitude{}; /** * @brief Longitude of the location in degrees */ - float longitude; + float longitude{}; /** * @brief Optional. The radius of uncertainty for the location, measured in meters; 0-1500 */ - float horizontalAccuracy; + float horizontalAccuracy{}; /** * @brief Optional. Period in seconds for which the location can be updated, should be between 60 and 86400. */ - std::int32_t livePeriod; + std::int32_t livePeriod{}; /** * @brief Optional. For live locations, a direction in which the user is moving, in degrees. * Must be between 1 and 360 if specified. */ - std::int32_t heading; + std::int32_t heading{}; /** * @brief Optional. For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. * Must be between 1 and 100000 if specified. */ - std::int32_t proximityAlertRadius; + std::int32_t proximityAlertRadius{}; }; } diff --git a/include/tgbot/types/InputMediaAnimation.h b/include/tgbot/types/InputMediaAnimation.h index b79f05948..cb73d6b90 100644 --- a/include/tgbot/types/InputMediaAnimation.h +++ b/include/tgbot/types/InputMediaAnimation.h @@ -16,9 +16,9 @@ namespace TgBot { class InputMediaAnimation : public InputMedia { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "animation"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputMediaAnimation() { this->type = TYPE; @@ -38,22 +38,22 @@ class InputMediaAnimation : public InputMedia { /** * @brief Optional. Animation width */ - std::int32_t width; + std::int32_t width{}; /** * @brief Optional. Animation height */ - std::int32_t height; + std::int32_t height{}; /** * @brief Optional. Animation duration in seconds */ - std::int32_t duration; + std::int32_t duration{}; /** * @brief Optional. Pass True if the animation needs to be covered with a spoiler animation */ - bool hasSpoiler; + bool hasSpoiler{}; }; } diff --git a/include/tgbot/types/InputMediaAudio.h b/include/tgbot/types/InputMediaAudio.h index abfc0232b..f178160a5 100644 --- a/include/tgbot/types/InputMediaAudio.h +++ b/include/tgbot/types/InputMediaAudio.h @@ -16,9 +16,9 @@ namespace TgBot { class InputMediaAudio : public InputMedia { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "audio"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputMediaAudio() { this->type = TYPE; @@ -37,7 +37,7 @@ class InputMediaAudio : public InputMedia { /** * @brief Optional. Duration of the audio in seconds */ - std::int32_t duration; + std::int32_t duration{}; /** * @brief Optional. Performer of the audio diff --git a/include/tgbot/types/InputMediaDocument.h b/include/tgbot/types/InputMediaDocument.h index 12a02e917..842e1b403 100644 --- a/include/tgbot/types/InputMediaDocument.h +++ b/include/tgbot/types/InputMediaDocument.h @@ -16,9 +16,9 @@ namespace TgBot { class InputMediaDocument : public InputMedia { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "document"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputMediaDocument() { this->type = TYPE; @@ -38,7 +38,7 @@ class InputMediaDocument : public InputMedia { * @brief Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data. * Always true, if the document is sent as part of an album. */ - bool disableContentTypeDetection; + bool disableContentTypeDetection{}; }; } diff --git a/include/tgbot/types/InputMediaPhoto.h b/include/tgbot/types/InputMediaPhoto.h index 5897beb81..552f4d9bb 100644 --- a/include/tgbot/types/InputMediaPhoto.h +++ b/include/tgbot/types/InputMediaPhoto.h @@ -14,9 +14,9 @@ namespace TgBot { */ class InputMediaPhoto : public InputMedia { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "photo"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputMediaPhoto() { this->type = TYPE; @@ -25,7 +25,7 @@ class InputMediaPhoto : public InputMedia { /** * @brief Optional. Pass True if the photo needs to be covered with a spoiler animation */ - bool hasSpoiler; + bool hasSpoiler{}; }; } diff --git a/include/tgbot/types/InputMediaVideo.h b/include/tgbot/types/InputMediaVideo.h index 734e7bbde..cd59996f0 100644 --- a/include/tgbot/types/InputMediaVideo.h +++ b/include/tgbot/types/InputMediaVideo.h @@ -16,9 +16,9 @@ namespace TgBot { */ class InputMediaVideo : public InputMedia { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "video"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputMediaVideo() { this->type = TYPE; @@ -38,27 +38,27 @@ class InputMediaVideo : public InputMedia { /** * @brief Optional. Video width */ - std::int32_t width; + std::int32_t width{}; /** * @brief Optional. Video height */ - std::int32_t height; + std::int32_t height{}; /** * @brief Optional. Video duration in seconds */ - std::int32_t duration; + std::int32_t duration{}; /** * @brief Optional. Pass True if the uploaded video is suitable for streaming */ - bool supportsStreaming; + bool supportsStreaming{}; /** * @brief Optional. Pass True if the video needs to be covered with a spoiler animation */ - bool hasSpoiler; + bool hasSpoiler{}; }; } diff --git a/include/tgbot/types/InputTextMessageContent.h b/include/tgbot/types/InputTextMessageContent.h index 12b81fd95..53888c101 100644 --- a/include/tgbot/types/InputTextMessageContent.h +++ b/include/tgbot/types/InputTextMessageContent.h @@ -19,9 +19,9 @@ namespace TgBot { class InputTextMessageContent : public InputMessageContent { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "text"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputTextMessageContent() { this->type = TYPE; diff --git a/include/tgbot/types/InputVenueMessageContent.h b/include/tgbot/types/InputVenueMessageContent.h index 41ac5e0ae..aca36132a 100644 --- a/include/tgbot/types/InputVenueMessageContent.h +++ b/include/tgbot/types/InputVenueMessageContent.h @@ -15,9 +15,9 @@ namespace TgBot { */ class InputVenueMessageContent : public InputMessageContent { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "venue"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; InputVenueMessageContent() { this->type = TYPE; @@ -26,12 +26,12 @@ class InputVenueMessageContent : public InputMessageContent { /** * @brief Latitude of the location in degrees */ - float latitude; + float latitude{}; /** * @brief Longitude of the location in degrees */ - float longitude; + float longitude{}; /** * @brief Name of the venue diff --git a/include/tgbot/types/MenuButtonCommands.h b/include/tgbot/types/MenuButtonCommands.h index ae514274e..4e5aa2c2c 100644 --- a/include/tgbot/types/MenuButtonCommands.h +++ b/include/tgbot/types/MenuButtonCommands.h @@ -14,9 +14,9 @@ namespace TgBot { */ class MenuButtonCommands : public MenuButton { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "commands"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; MenuButtonCommands() { this->type = TYPE; diff --git a/include/tgbot/types/MenuButtonDefault.h b/include/tgbot/types/MenuButtonDefault.h index 69cde9276..bb7bcc2e4 100644 --- a/include/tgbot/types/MenuButtonDefault.h +++ b/include/tgbot/types/MenuButtonDefault.h @@ -14,9 +14,9 @@ namespace TgBot { */ class MenuButtonDefault : public MenuButton { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "default"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; MenuButtonDefault() { this->type = TYPE; diff --git a/include/tgbot/types/MenuButtonWebApp.h b/include/tgbot/types/MenuButtonWebApp.h index ba26c5178..fefd91bdb 100644 --- a/include/tgbot/types/MenuButtonWebApp.h +++ b/include/tgbot/types/MenuButtonWebApp.h @@ -16,9 +16,9 @@ namespace TgBot { */ class MenuButtonWebApp : public MenuButton { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "web_app"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; MenuButtonWebApp() { this->type = TYPE; diff --git a/include/tgbot/types/MessageOriginChannel.h b/include/tgbot/types/MessageOriginChannel.h index 2a534abe0..de20fd3ba 100644 --- a/include/tgbot/types/MessageOriginChannel.h +++ b/include/tgbot/types/MessageOriginChannel.h @@ -18,9 +18,9 @@ namespace TgBot { class MessageOriginChannel : public MessageOrigin { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "channel"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; MessageOriginChannel() { this->type = TYPE; @@ -34,7 +34,7 @@ class MessageOriginChannel : public MessageOrigin { /** * @brief Unique message identifier inside the chat */ - std::int32_t messageId; + std::int32_t messageId{}; /** * @brief Optional. Signature of the original post author diff --git a/include/tgbot/types/MessageOriginChat.h b/include/tgbot/types/MessageOriginChat.h index 8a750e7e7..8b14c162e 100644 --- a/include/tgbot/types/MessageOriginChat.h +++ b/include/tgbot/types/MessageOriginChat.h @@ -17,9 +17,9 @@ namespace TgBot { class MessageOriginChat : public MessageOrigin { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "chat"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; MessageOriginChat() { this->type = TYPE; diff --git a/include/tgbot/types/MessageOriginHiddenUser.h b/include/tgbot/types/MessageOriginHiddenUser.h index 616661ab5..77dd0fba5 100644 --- a/include/tgbot/types/MessageOriginHiddenUser.h +++ b/include/tgbot/types/MessageOriginHiddenUser.h @@ -16,9 +16,9 @@ namespace TgBot { class MessageOriginHiddenUser : public MessageOrigin { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "hidden_user"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; MessageOriginHiddenUser() { this->type = TYPE; diff --git a/include/tgbot/types/MessageOriginUser.h b/include/tgbot/types/MessageOriginUser.h index 4f94e72d0..221a91897 100644 --- a/include/tgbot/types/MessageOriginUser.h +++ b/include/tgbot/types/MessageOriginUser.h @@ -16,9 +16,9 @@ namespace TgBot { class MessageOriginUser : public MessageOrigin { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "user"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; MessageOriginUser() { this->type = TYPE; diff --git a/include/tgbot/types/PassportElementErrorDataField.h b/include/tgbot/types/PassportElementErrorDataField.h index 70f3d344a..0822efcac 100644 --- a/include/tgbot/types/PassportElementErrorDataField.h +++ b/include/tgbot/types/PassportElementErrorDataField.h @@ -16,9 +16,9 @@ namespace TgBot { */ class PassportElementErrorDataField : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "data"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; PassportElementErrorDataField() { this->source = SOURCE; diff --git a/include/tgbot/types/PassportElementErrorFile.h b/include/tgbot/types/PassportElementErrorFile.h index 07c51743e..45b565442 100644 --- a/include/tgbot/types/PassportElementErrorFile.h +++ b/include/tgbot/types/PassportElementErrorFile.h @@ -16,7 +16,7 @@ namespace TgBot { */ class PassportElementErrorFile : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "file"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/PassportElementErrorFiles.h b/include/tgbot/types/PassportElementErrorFiles.h index 307c197e4..88ad1f319 100644 --- a/include/tgbot/types/PassportElementErrorFiles.h +++ b/include/tgbot/types/PassportElementErrorFiles.h @@ -17,9 +17,9 @@ namespace TgBot { */ class PassportElementErrorFiles : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "files"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; PassportElementErrorFiles() { this->source = SOURCE; diff --git a/include/tgbot/types/PassportElementErrorFrontSide.h b/include/tgbot/types/PassportElementErrorFrontSide.h index 5bac68353..1132855e8 100644 --- a/include/tgbot/types/PassportElementErrorFrontSide.h +++ b/include/tgbot/types/PassportElementErrorFrontSide.h @@ -16,7 +16,7 @@ namespace TgBot { */ class PassportElementErrorFrontSide : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "front_side"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/PassportElementErrorReverseSide.h b/include/tgbot/types/PassportElementErrorReverseSide.h index a2ca6779e..4a2ab7e1a 100644 --- a/include/tgbot/types/PassportElementErrorReverseSide.h +++ b/include/tgbot/types/PassportElementErrorReverseSide.h @@ -16,9 +16,9 @@ namespace TgBot { */ class PassportElementErrorReverseSide : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "reverse_side"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; PassportElementErrorReverseSide() { this->source = SOURCE; diff --git a/include/tgbot/types/PassportElementErrorSelfie.h b/include/tgbot/types/PassportElementErrorSelfie.h index 95dd77a47..5a19e8055 100644 --- a/include/tgbot/types/PassportElementErrorSelfie.h +++ b/include/tgbot/types/PassportElementErrorSelfie.h @@ -16,9 +16,9 @@ namespace TgBot { */ class PassportElementErrorSelfie : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "selfie"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; PassportElementErrorSelfie() { this->source = SOURCE; diff --git a/include/tgbot/types/PassportElementErrorTranslationFile.h b/include/tgbot/types/PassportElementErrorTranslationFile.h index 616b3e4b3..d8e51bea6 100644 --- a/include/tgbot/types/PassportElementErrorTranslationFile.h +++ b/include/tgbot/types/PassportElementErrorTranslationFile.h @@ -16,9 +16,9 @@ namespace TgBot { */ class PassportElementErrorTranslationFile : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "translation_file"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; PassportElementErrorTranslationFile() { this->source = SOURCE; diff --git a/include/tgbot/types/PassportElementErrorTranslationFiles.h b/include/tgbot/types/PassportElementErrorTranslationFiles.h index b26c6b7ed..e66a217b8 100644 --- a/include/tgbot/types/PassportElementErrorTranslationFiles.h +++ b/include/tgbot/types/PassportElementErrorTranslationFiles.h @@ -17,7 +17,7 @@ namespace TgBot { */ class PassportElementErrorTranslationFiles : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "translation_files"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/PassportElementErrorUnspecified.h b/include/tgbot/types/PassportElementErrorUnspecified.h index 062f216de..d0266e72b 100644 --- a/include/tgbot/types/PassportElementErrorUnspecified.h +++ b/include/tgbot/types/PassportElementErrorUnspecified.h @@ -16,7 +16,7 @@ namespace TgBot { */ class PassportElementErrorUnspecified : public PassportElementError { public: - static const std::string SOURCE; + static constexpr std::string_view SOURCE = "unspecified"; typedef std::shared_ptr Ptr; diff --git a/include/tgbot/types/ReactionTypeCustomEmoji.h b/include/tgbot/types/ReactionTypeCustomEmoji.h index 4185c74a9..1a628f288 100644 --- a/include/tgbot/types/ReactionTypeCustomEmoji.h +++ b/include/tgbot/types/ReactionTypeCustomEmoji.h @@ -16,9 +16,9 @@ namespace TgBot { class ReactionTypeCustomEmoji : public ReactionType { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "custom_emoji"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ReactionTypeCustomEmoji() { this->type = TYPE; diff --git a/include/tgbot/types/ReactionTypeEmoji.h b/include/tgbot/types/ReactionTypeEmoji.h index 770e9613c..d20500501 100644 --- a/include/tgbot/types/ReactionTypeEmoji.h +++ b/include/tgbot/types/ReactionTypeEmoji.h @@ -16,9 +16,9 @@ namespace TgBot { class ReactionTypeEmoji : public ReactionType { public: - static const std::string TYPE; + static constexpr std::string_view TYPE = "emoji"; - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; ReactionTypeEmoji() { this->type = TYPE; diff --git a/samples/common_defs.cmake b/samples/common_defs.cmake new file mode 100644 index 000000000..1dde22fb2 --- /dev/null +++ b/samples/common_defs.cmake @@ -0,0 +1,20 @@ + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +set(Boost_USE_MULTITHREADED ON) + +find_package(Threads REQUIRED) +find_package(OpenSSL REQUIRED) +find_package(Boost COMPONENTS system REQUIRED) +find_package(JsonCpp QUIET) +if (NOT TARGET JsonCpp::JsonCPP) + include(/usr/local/lib/cmake/tgbot-cpp/FindJsonCppCustom.cmake) +endif() +find_package(CURL) +include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) +if (CURL_FOUND) + include_directories(${CURL_INCLUDE_DIRS}) + add_definitions(-DHAVE_CURL) +endif() +set(LINK_LIB_LIST /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES} JsonCpp::JsonCpp) \ No newline at end of file diff --git a/samples/echobot-curl-client/CMakeLists.txt b/samples/echobot-curl-client/CMakeLists.txt index 74b45c5c6..f06ac7cb6 100644 --- a/samples/echobot-curl-client/CMakeLists.txt +++ b/samples/echobot-curl-client/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(echobot-curl-client) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(echobot-curl-client src/main.cpp) - -target_link_libraries(echobot-curl-client /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(${PROJECT_NAME} ${LINK_LIB_LIST}) diff --git a/samples/echobot-curl-client/src/main.cpp b/samples/echobot-curl-client/src/main.cpp index a957011bb..fa3defa7e 100644 --- a/samples/echobot-curl-client/src/main.cpp +++ b/samples/echobot-curl-client/src/main.cpp @@ -13,9 +13,7 @@ int main() { string token(getenv("TOKEN")); printf("Token: %s\n", token.c_str()); - CurlHttpClient curlHttpClient; - - Bot bot(token, curlHttpClient); + Bot bot(token, std::make_unique()); bot.getEvents().onCommand("start", [&bot](Message::Ptr message) { bot.getApi().sendMessage(message->chat->id, "Hi!"); }); diff --git a/samples/echobot-setmycommands/CMakeLists.txt b/samples/echobot-setmycommands/CMakeLists.txt index f8d4ad23a..84b432098 100644 --- a/samples/echobot-setmycommands/CMakeLists.txt +++ b/samples/echobot-setmycommands/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(echobot-setmycommands) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(echobot-setmycommands src/main.cpp) - -target_link_libraries(echobot-setmycommands /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(${PROJECT_NAME} ${LINK_LIB_LIST}) diff --git a/samples/echobot-submodule/CMakeLists.txt b/samples/echobot-submodule/CMakeLists.txt index e7a16f1f9..3b9444d21 100644 --- a/samples/echobot-submodule/CMakeLists.txt +++ b/samples/echobot-submodule/CMakeLists.txt @@ -1,22 +1,7 @@ cmake_minimum_required(VERSION 3.10.2) project(echobot-submodule) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - +include(../common_defs.cmake) add_subdirectory(tgbot-cpp) add_executable(echobot-submodule src/main.cpp) - -target_link_libraries(echobot-submodule TgBot ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +target_link_libraries(echobot-submodule TgBot ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES} JsonCpp::JsonCpp) diff --git a/samples/echobot-webhook-server/CMakeLists.txt b/samples/echobot-webhook-server/CMakeLists.txt index 3f4e8b82e..cae15af2d 100644 --- a/samples/echobot-webhook-server/CMakeLists.txt +++ b/samples/echobot-webhook-server/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(echobot-webhook-server) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(echobot-webhook-server src/main.cpp) - -target_link_libraries(echobot-webhook-server /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(${PROJECT_NAME} ${LINK_LIB_LIST}) diff --git a/samples/echobot/CMakeLists.txt b/samples/echobot/CMakeLists.txt index 20f52970e..801929b4a 100644 --- a/samples/echobot/CMakeLists.txt +++ b/samples/echobot/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(echobot) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(echobot src/main.cpp) - -target_link_libraries(echobot /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(echobot ${LINK_LIB_LIST}) diff --git a/samples/inline-keyboard/CMakeLists.txt b/samples/inline-keyboard/CMakeLists.txt index 01d8718bf..663e5e788 100644 --- a/samples/inline-keyboard/CMakeLists.txt +++ b/samples/inline-keyboard/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(inline-keyboard) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(inline-keyboard src/main.cpp) - -target_link_libraries(inline-keyboard /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(${PROJECT_NAME} ${LINK_LIB_LIST}) diff --git a/samples/photo/CMakeLists.txt b/samples/photo/CMakeLists.txt index a4edadcb5..2fbe261db 100644 --- a/samples/photo/CMakeLists.txt +++ b/samples/photo/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(photo) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(photo src/main.cpp) - -target_link_libraries(photo /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(${PROJECT_NAME} ${LINK_LIB_LIST}) diff --git a/samples/receive-file/CMakeLists.txt b/samples/receive-file/CMakeLists.txt index 6f86a9ced..823bb6f86 100644 --- a/samples/receive-file/CMakeLists.txt +++ b/samples/receive-file/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(receive-file) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(receive-file src/main.cpp) - -target_link_libraries(receive-file /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(${PROJECT_NAME} ${LINK_LIB_LIST}) diff --git a/samples/received-text-processing/CMakeLists.txt b/samples/received-text-processing/CMakeLists.txt index a6bc7dd18..ab25726cd 100644 --- a/samples/received-text-processing/CMakeLists.txt +++ b/samples/received-text-processing/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(received-text-processing) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(received-processing-text src/main.cpp) - -target_link_libraries(received-processing-text /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(${PROJECT_NAME} ${LINK_LIB_LIST}) diff --git a/samples/reply-keyboard/CMakeLists.txt b/samples/reply-keyboard/CMakeLists.txt index 451069217..f138a0a02 100644 --- a/samples/reply-keyboard/CMakeLists.txt +++ b/samples/reply-keyboard/CMakeLists.txt @@ -1,21 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) project(reply-keyboard) -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(Boost_USE_MULTITHREADED ON) - -find_package(Threads REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Boost COMPONENTS system REQUIRED) -find_package(CURL) -include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) -if (CURL_FOUND) - include_directories(${CURL_INCLUDE_DIRS}) - add_definitions(-DHAVE_CURL) -endif() - -add_executable(reply-keyboard src/main.cpp) - -target_link_libraries(reply-keyboard /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES}) +include(../common_defs.cmake) +add_executable(${PROJECT_NAME} src/main.cpp) +target_link_libraries(${PROJECT_NAME} ${LINK_LIB_LIST}) diff --git a/src/Api.cpp b/src/Api.cpp index 2c4b82aae..1a65b009c 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1,2877 +1,2815 @@ -#include "tgbot/Api.h" +#include +#include +#include +#include +#include #include +#include +#include #include +#include -namespace TgBot { - -Api::Api(std::string token, const HttpClient& httpClient, const std::string& url) - : _httpClient(httpClient), _token(std::move(token)), _tgTypeParser(), _url(url) { +namespace { +std::vector +escapeJSONStringVec(const std::vector &vec) { + std::vector newVec = vec; + for (auto i = newVec.begin(); i != newVec.end(); ++i) { + std::stringstream ss; + ss << std::quoted(StringTools::escapeJsonString(*i)); + *i = ss.str(); + } + return newVec; } -std::vector Api::getUpdates(std::int32_t offset, - std::int32_t limit, - std::int32_t timeout, - const StringArrayPtr& allowedUpdates) const { - std::vector args; - args.reserve(4); - - if (offset != 0) { - args.emplace_back("offset", offset); - } - if (limit != 100) { - args.emplace_back("limit", std::max(1, std::min(100, limit))); - } - if (timeout != 0) { - args.emplace_back("timeout", timeout); - } - if (allowedUpdates != nullptr) { - std::string allowedUpdatesJson = _tgTypeParser.parseArray( - [] (const std::string& s)->std::string { - return s; - }, *allowedUpdates); - args.emplace_back("allowed_updates", allowedUpdatesJson); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); -} +} // namespace +namespace TgBot { -bool Api::setWebhook(const std::string& url, - InputFile::Ptr certificate, +ApiImpl::ApiImpl(std::string token, std::unique_ptr httpClient, + std::string url) + : _httpClient(std::move(httpClient)), _token(std::move(token)), _url(std::move(url)) {} + +std::vector +ApiImpl::getUpdates(std::int32_t offset, std::int32_t limit, std::int32_t timeout, + const StringArrayPtr &allowedUpdates) const { + std::vector args; + args.reserve(4); + + if (offset != 0) { + args.emplace_back("offset", offset); + } + if (limit != 100) { + args.emplace_back("limit", std::max(1, std::min(100, limit))); + } + if (timeout != 0) { + args.emplace_back("timeout", timeout); + } + if (allowedUpdates != nullptr) { + std::string allowedUpdatesJson = putJSON(*allowedUpdates); + args.emplace_back("allowed_updates", allowedUpdatesJson); + } + + return parseArray(sendRequest("getUpdates", args)); +} + +bool ApiImpl::setWebhook(const std::string &url, InputFile::Ptr certificate, std::int32_t maxConnections, - const StringArrayPtr& allowedUpdates, - const std::string& ipAddress, - bool dropPendingUpdates, - const std::string& secretToken) const { - std::vector args; - args.reserve(7); - - args.emplace_back("url", url); - if (certificate != nullptr) { - args.emplace_back("certificate", certificate->data, true, certificate->mimeType, certificate->fileName); - } - if (!ipAddress.empty()) { - args.emplace_back("ip_address", ipAddress); - } - if (maxConnections != 40) { - args.emplace_back("max_connections", std::max(1, std::min(100, maxConnections))); - } - if (allowedUpdates != nullptr) { - auto allowedUpdatesJson = _tgTypeParser.parseArray( - [] (const std::string& s)->std::string { - return s; - }, *allowedUpdates); - args.emplace_back("allowed_updates", allowedUpdatesJson); - } - if (dropPendingUpdates) { - args.emplace_back("drop_pending_updates", dropPendingUpdates); - } - if (!secretToken.empty()) { - args.emplace_back("secret_token", secretToken); - } - - return sendRequest("setWebhook", args).get("", false); -} - -bool Api::deleteWebhook(bool dropPendingUpdates) const { - std::vector args; - args.reserve(1); - - if (dropPendingUpdates) { - args.emplace_back("drop_pending_updates", dropPendingUpdates); - } - - return sendRequest("deleteWebhook", args).get("", false); -} - -WebhookInfo::Ptr Api::getWebhookInfo() const { - boost::property_tree::ptree p = sendRequest("getWebhookInfo"); - - if (!p.get_child_optional("url")) { - return nullptr; - } - - if (p.get("url", "") != std::string("")) { - return _tgTypeParser.parseJsonAndGetWebhookInfo(p); - } else { - return nullptr; - } -} - -User::Ptr Api::getMe() const { - return _tgTypeParser.parseJsonAndGetUser(sendRequest("getMe")); -} - -bool Api::logOut() const { - return sendRequest("logOut").get("", false); -} - -bool Api::close() const { - return sendRequest("close").get("", false); -} - -Message::Ptr Api::sendMessage(boost::variant chatId, - const std::string& text, + const StringArrayPtr &allowedUpdates, + const std::string &ipAddress, bool dropPendingUpdates, + const std::string &secretToken) const { + std::vector args; + args.reserve(7); + + args.emplace_back("url", url); + if (certificate != nullptr) { + args.emplace_back("certificate", certificate->data, true, + certificate->mimeType, certificate->fileName); + } + if (!ipAddress.empty()) { + args.emplace_back("ip_address", ipAddress); + } + if (maxConnections != 40) { + args.emplace_back("max_connections", + std::max(1, std::min(100, maxConnections))); + } + if (allowedUpdates != nullptr) { + auto allowedUpdatesJson = putJSON(*allowedUpdates); + args.emplace_back("allowed_updates", allowedUpdatesJson); + } + if (dropPendingUpdates) { + args.emplace_back("drop_pending_updates", dropPendingUpdates); + } + if (!secretToken.empty()) { + args.emplace_back("secret_token", secretToken); + } + + return sendRequest("setWebhook", args).asBool(); +} + +bool ApiImpl::deleteWebhook(bool dropPendingUpdates) const { + std::vector args; + args.reserve(1); + + if (dropPendingUpdates) { + args.emplace_back("drop_pending_updates", dropPendingUpdates); + } + + return sendRequest("deleteWebhook", args).asBool(); +} + +WebhookInfo::Ptr ApiImpl::getWebhookInfo() const { + const auto& p = sendRequest("getWebhookInfo"); + + if (!p.isMember("url")) { + return nullptr; + } + + if (!p["url"].asString().empty()) { + return parse(p["url"]); + } else { + return nullptr; + } +} + +User::Ptr ApiImpl::getMe() const { return parse(sendRequest("getMe")); } + +bool ApiImpl::logOut() const { return sendRequest("logOut").asBool(); } + +bool ApiImpl::close() const { return sendRequest("close").asBool(); } + +Message::Ptr ApiImpl::sendMessage(boost::variant chatId, + const std::string &text, LinkPreviewOptions::Ptr linkPreviewOptions, ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, - const std::string& parseMode, + const std::string &parseMode, bool disableNotification, - const std::vector& entities, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(11); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("text", text); - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!entities.empty()) { - args.emplace_back("entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, entities)); - } - if (linkPreviewOptions != nullptr) { - args.emplace_back("link_preview_options", _tgTypeParser.parseLinkPreviewOptions(linkPreviewOptions)); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); -} + const std::vector &entities, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(11); -Message::Ptr Api::forwardMessage(boost::variant chatId, - boost::variant fromChatId, - std::int32_t messageId, - bool disableNotification, - bool protectContent, - std::int32_t messageThreadId) const { - std::vector args; - args.reserve(6); - - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("from_chat_id", fromChatId); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("text", text); + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!entities.empty()) { + args.emplace_back("entities", putJSON(entities)); + } + if (linkPreviewOptions != nullptr) { + args.emplace_back("link_preview_options", putJSON(linkPreviewOptions)); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendMessage", args)); +} + +Message::Ptr +ApiImpl::forwardMessage(boost::variant chatId, + boost::variant fromChatId, + std::int32_t messageId, bool disableNotification, + bool protectContent, std::int32_t messageThreadId) const { + std::vector args; + args.reserve(6); + + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("from_chat_id", fromChatId); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + args.emplace_back("message_id", messageId); + + return parse(sendRequest("forwardMessage", args)); +} + +std::vector +ApiImpl::forwardMessages(boost::variant chatId, + boost::variant fromChatId, + const std::vector &messageIds, + std::int32_t messageThreadId, bool disableNotification, + bool protectContent) const { + std::vector args; + args.reserve(6); + + args.emplace_back("chat_id", chatId); + args.emplace_back("from_chat_id", fromChatId); + if (!messageIds.empty()) { + args.emplace_back("message_ids", putJSON(messageIds)); + } + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + + return parseArray(sendRequest("forwardMessages", args)); +} + +MessageId::Ptr +ApiImpl::copyMessage(boost::variant chatId, + boost::variant fromChatId, + std::int32_t messageId, const std::string &caption, + const std::string &parseMode, + const std::vector &captionEntities, + bool disableNotification, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, bool protectContent, + std::int32_t messageThreadId) const { + std::vector args; + args.reserve(11); + + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("from_chat_id", fromChatId); + args.emplace_back("message_id", messageId); + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("copyMessage", args)); +} + +std::vector +ApiImpl::copyMessages(boost::variant chatId, + boost::variant fromChatId, + const std::vector &messageIds, + std::int32_t messageThreadId, bool disableNotification, + bool protectContent, bool removeCaption) const { + std::vector args; + args.reserve(7); + + args.emplace_back("chat_id", chatId); + args.emplace_back("from_chat_id", fromChatId); + + if (!messageIds.empty()) { + args.emplace_back("message_ids", putJSON(messageIds)); + } + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (removeCaption) { + args.emplace_back("remove_caption", removeCaption); + } + + return parseArray(sendRequest("copyMessages", args)); +} + +Message::Ptr +ApiImpl::sendPhoto(boost::variant chatId, + boost::variant photo, + const std::string &caption, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, + bool hasSpoiler, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(12); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (photo.which() == 0) { // InputFile::Ptr + auto file = boost::get(photo); + args.emplace_back("photo", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("photo", boost::get(photo)); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (hasSpoiler) { + args.emplace_back("has_spoiler", hasSpoiler); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup != nullptr) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendPhoto", args)); +} + +Message::Ptr +ApiImpl::sendAudio(boost::variant chatId, + boost::variant audio, + const std::string &caption, std::int32_t duration, + const std::string &performer, const std::string &title, + boost::variant thumbnail, + ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(15); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (audio.which() == 0) { // InputFile::Ptr + auto file = boost::get(audio); + args.emplace_back("audio", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("audio", boost::get(audio)); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (duration) { + args.emplace_back("duration", duration); + } + if (!performer.empty()) { + args.emplace_back("performer", performer); + } + if (!title.empty()) { + args.emplace_back("title", title); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendAudio", args)); +} + +Message::Ptr ApiImpl::sendDocument( + boost::variant chatId, + boost::variant document, + boost::variant thumbnail, + const std::string &caption, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + bool disableContentTypeDetection, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(13); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (document.which() == 0) { // InputFile::Ptr + auto file = boost::get(document); + args.emplace_back("document", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("document", boost::get(document)); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (disableContentTypeDetection) { + args.emplace_back("disable_content_type_detection", + disableContentTypeDetection); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendDocument", args)); +} + +Message::Ptr +ApiImpl::sendVideo(boost::variant chatId, + boost::variant video, + bool supportsStreaming, std::int32_t duration, + std::int32_t width, std::int32_t height, + boost::variant thumbnail, + const std::string &caption, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, + bool hasSpoiler, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(17); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (video.which() == 0) { // InputFile::Ptr + auto file = boost::get(video); + args.emplace_back("video", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("video", boost::get(video)); + } + if (duration != 0) { + args.emplace_back("duration", duration); + } + if (width != 0) { + args.emplace_back("width", width); + } + if (height != 0) { + args.emplace_back("height", height); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (hasSpoiler) { + args.emplace_back("has_spoiler", hasSpoiler); + } + if (supportsStreaming) { + args.emplace_back("supports_streaming", supportsStreaming); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup != nullptr) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendVideo", args)); +} + +Message::Ptr ApiImpl::sendAnimation( + boost::variant chatId, + boost::variant animation, + std::int32_t duration, std::int32_t width, std::int32_t height, + boost::variant thumbnail, + const std::string &caption, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, bool hasSpoiler, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(16); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (animation.which() == 0) { // InputFile::Ptr + auto file = boost::get(animation); + args.emplace_back("animation", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("animation", boost::get(animation)); + } + if (duration != 0) { + args.emplace_back("duration", duration); + } + if (width != 0) { + args.emplace_back("width", width); + } + if (height != 0) { + args.emplace_back("height", height); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (hasSpoiler) { + args.emplace_back("has_spoiler", hasSpoiler); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup != nullptr) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendAnimation", args)); +} + +Message::Ptr +ApiImpl::sendVoice(boost::variant chatId, + boost::variant voice, + const std::string &caption, std::int32_t duration, + ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(12); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (voice.which() == 0) { // InputFile::Ptr + auto file = boost::get(voice); + args.emplace_back("voice", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("voice", boost::get(voice)); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (duration) { + args.emplace_back("duration", duration); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendVoice", args)); +} + +Message::Ptr ApiImpl::sendVideoNote( + boost::variant chatId, + boost::variant videoNote, + ReplyParameters::Ptr replyParameters, bool disableNotification, + std::int32_t duration, std::int32_t length, + boost::variant thumbnail, + GenericReply::Ptr replyMarkup, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(11); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (videoNote.which() == 0) { // InputFile::Ptr + auto file = boost::get(videoNote); + args.emplace_back("video_note", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("video_note", boost::get(videoNote)); + } + if (duration) { + args.emplace_back("duration", duration); + } + if (length) { + args.emplace_back("length", length); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendVideoNote", args)); +} + +std::vector ApiImpl::sendMediaGroup( + boost::variant chatId, + const std::vector &media, bool disableNotification, + ReplyParameters::Ptr replyParameters, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(7); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("media", putJSON(media)); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + + return parseArray(sendRequest("sendMediaGroup", args)); +} + +Message::Ptr ApiImpl::sendLocation( + boost::variant chatId, float latitude, + float longitude, std::int32_t livePeriod, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, + bool disableNotification, float horizontalAccuracy, std::int32_t heading, + std::int32_t proximityAlertRadius, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(13); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("latitude", latitude); + args.emplace_back("longitude", longitude); + if (horizontalAccuracy) { + args.emplace_back("horizontal_accuracy", horizontalAccuracy); + } + if (livePeriod) { + args.emplace_back("live_period", std::max(60, std::min(86400, livePeriod))); + } + if (heading) { + args.emplace_back("heading", std::max(1, std::min(360, heading))); + } + if (proximityAlertRadius) { + args.emplace_back("proximity_alert_radius", + std::max(1, std::min(100000, proximityAlertRadius))); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendLocation", args)); +} + +Message::Ptr ApiImpl::editMessageLiveLocation( + float latitude, float longitude, + boost::variant chatId, std::int32_t messageId, + const std::string &inlineMessageId, InlineKeyboardMarkup::Ptr replyMarkup, + float horizontalAccuracy, std::int32_t heading, + std::int32_t proximityAlertRadius) const { + std::vector args; + args.reserve(9); + + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } + } + if (messageId) { args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + args.emplace_back("latitude", latitude); + args.emplace_back("longitude", longitude); + if (horizontalAccuracy) { + args.emplace_back("horizontal_accuracy", horizontalAccuracy); + } + if (heading) { + args.emplace_back("heading", heading); + } + if (proximityAlertRadius) { + args.emplace_back("proximity_alert_radius", proximityAlertRadius); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("editMessageLiveLocation", args)); +} + +Message::Ptr +ApiImpl::stopMessageLiveLocation(boost::variant chatId, + std::int32_t messageId, + const std::string &inlineMessageId, + InlineKeyboardMarkup::Ptr replyMarkup) const { + std::vector args; + args.reserve(4); - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args)); -} - -std::vector Api::forwardMessages(boost::variant chatId, - boost::variant fromChatId, - const std::vector& messageIds, - std::int32_t messageThreadId, - bool disableNotification, - bool protectContent) const { - std::vector args; - args.reserve(6); - - args.emplace_back("chat_id", chatId); - args.emplace_back("from_chat_id", fromChatId); - if (!messageIds.empty()) { - args.emplace_back("message_ids", _tgTypeParser.parseArray( - [] (const std::int32_t& i)->std::int32_t { - return i; - }, messageIds)); - } - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageId, sendRequest("forwardMessages", args)); -} - -MessageId::Ptr Api::copyMessage(boost::variant chatId, - boost::variant fromChatId, - std::int32_t messageId, - const std::string& caption, - const std::string& parseMode, - const std::vector& captionEntities, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool protectContent, - std::int32_t messageThreadId) const { - std::vector args; - args.reserve(11); - - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); } - args.emplace_back("from_chat_id", fromChatId); + } + if (messageId) { args.emplace_back("message_id", messageId); - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessageId(sendRequest("copyMessage", args)); -} - -std::vector Api::copyMessages(boost::variant chatId, - boost::variant fromChatId, - const std::vector& messageIds, - std::int32_t messageThreadId, - bool disableNotification, - bool protectContent, - bool removeCaption) const { - std::vector args; - args.reserve(7); - - args.emplace_back("chat_id", chatId); - args.emplace_back("from_chat_id", fromChatId); - - if (!messageIds.empty()) { - args.emplace_back("message_ids", _tgTypeParser.parseArray( - [] (const std::int32_t& i)->std::int32_t { - return i; - }, messageIds)); - } - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (removeCaption) { - args.emplace_back("remove_caption", removeCaption); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageId, sendRequest("copyMessages", args)); -} - -Message::Ptr Api::sendPhoto(boost::variant chatId, - boost::variant photo, - const std::string& caption, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - bool hasSpoiler, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(12); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (photo.which() == 0) { // InputFile::Ptr - auto file = boost::get(photo); - args.emplace_back("photo", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("photo", boost::get(photo)); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (hasSpoiler) { - args.emplace_back("has_spoiler", hasSpoiler); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup != nullptr) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args)); -} - -Message::Ptr Api::sendAudio(boost::variant chatId, - boost::variant audio, - const std::string& caption, - std::int32_t duration, - const std::string& performer, - const std::string& title, - boost::variant thumbnail, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(15); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (audio.which() == 0) { // InputFile::Ptr - auto file = boost::get(audio); - args.emplace_back("audio", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("audio", boost::get(audio)); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (!performer.empty()) { - args.emplace_back("performer", performer); - } - if (!title.empty()) { - args.emplace_back("title", title); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args)); -} - -Message::Ptr Api::sendDocument(boost::variant chatId, - boost::variant document, - boost::variant thumbnail, - const std::string& caption, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - bool disableContentTypeDetection, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(13); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (document.which() == 0) { // InputFile::Ptr - auto file = boost::get(document); - args.emplace_back("document", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("document", boost::get(document)); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (disableContentTypeDetection) { - args.emplace_back("disable_content_type_detection", disableContentTypeDetection); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDocument", args)); -} - -Message::Ptr Api::sendVideo(boost::variant chatId, - boost::variant video, - bool supportsStreaming, - std::int32_t duration, - std::int32_t width, - std::int32_t height, - boost::variant thumbnail, - const std::string& caption , - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - bool hasSpoiler, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(17); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (video.which() == 0) { // InputFile::Ptr - auto file = boost::get(video); - args.emplace_back("video", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("video", boost::get(video)); - } - if (duration != 0) { - args.emplace_back("duration", duration); - } - if (width != 0) { - args.emplace_back("width", width); - } - if (height != 0) { - args.emplace_back("height", height); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (hasSpoiler) { - args.emplace_back("has_spoiler", hasSpoiler); - } - if (supportsStreaming) { - args.emplace_back("supports_streaming", supportsStreaming); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup != nullptr) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); -} - -Message::Ptr Api::sendAnimation(boost::variant chatId, - boost::variant animation, - std::int32_t duration, - std::int32_t width, - std::int32_t height, - boost::variant thumbnail, - const std::string& caption, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - bool hasSpoiler, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(16); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (animation.which() == 0) { // InputFile::Ptr - auto file = boost::get(animation); - args.emplace_back("animation", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("animation", boost::get(animation)); - } - if (duration != 0) { - args.emplace_back("duration", duration); - } - if (width != 0) { - args.emplace_back("width", width); - } - if (height != 0) { - args.emplace_back("height", height); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (hasSpoiler) { - args.emplace_back("has_spoiler", hasSpoiler); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup != nullptr) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); -} - -Message::Ptr Api::sendVoice(boost::variant chatId, - boost::variant voice, - const std::string& caption, - std::int32_t duration, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(12); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (voice.which() == 0) { // InputFile::Ptr - auto file = boost::get(voice); - args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("voice", boost::get(voice)); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args)); -} - -Message::Ptr Api::sendVideoNote(boost::variant chatId, - boost::variant videoNote, - ReplyParameters::Ptr replyParameters, - bool disableNotification, - std::int32_t duration, - std::int32_t length, - boost::variant thumbnail, - GenericReply::Ptr replyMarkup, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(11); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (videoNote.which() == 0) { // InputFile::Ptr - auto file = boost::get(videoNote); - args.emplace_back("video_note", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("video_note", boost::get(videoNote)); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (length) { - args.emplace_back("length", length); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideoNote", args)); -} - -std::vector Api::sendMediaGroup(boost::variant chatId, - const std::vector& media, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(7); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("media", _tgTypeParser.parseArray(&TgTypeParser::parseInputMedia, media)); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); -} - -Message::Ptr Api::sendLocation(boost::variant chatId, - float latitude, - float longitude, - std::int32_t livePeriod, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool disableNotification, - float horizontalAccuracy, - std::int32_t heading, - std::int32_t proximityAlertRadius, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(13); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("latitude", latitude); - args.emplace_back("longitude", longitude); - if (horizontalAccuracy) { - args.emplace_back("horizontal_accuracy", horizontalAccuracy); - } - if (livePeriod) { - args.emplace_back("live_period", std::max(60, std::min(86400, livePeriod))); - } - if (heading) { - args.emplace_back("heading", std::max(1, std::min(360, heading))); - } - if (proximityAlertRadius) { - args.emplace_back("proximity_alert_radius", std::max(1, std::min(100000, proximityAlertRadius))); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendLocation", args)); -} - -Message::Ptr Api::editMessageLiveLocation(float latitude, - float longitude, - boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - InlineKeyboardMarkup::Ptr replyMarkup, - float horizontalAccuracy, - std::int32_t heading, - std::int32_t proximityAlertRadius) const { - std::vector args; - args.reserve(9); - - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - args.emplace_back("latitude", latitude); - args.emplace_back("longitude", longitude); - if (horizontalAccuracy) { - args.emplace_back("horizontal_accuracy", horizontalAccuracy); - } - if (heading) { - args.emplace_back("heading", heading); - } - if (proximityAlertRadius) { - args.emplace_back("proximity_alert_radius", proximityAlertRadius); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); -} - -Message::Ptr Api::stopMessageLiveLocation(boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - InlineKeyboardMarkup::Ptr replyMarkup) const { - std::vector args; - args.reserve(4); - - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("stopMessageLiveLocation", args)); -} - -Message::Ptr Api::sendVenue(boost::variant chatId, - float latitude, - float longitude, - const std::string& title, - const std::string& address, - const std::string& foursquareId, - const std::string& foursquareType, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& googlePlaceId, - const std::string& googlePlaceType, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(15); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("latitude", latitude); - args.emplace_back("longitude", longitude); - args.emplace_back("title", title); - args.emplace_back("address", address); - if (!foursquareId.empty()) { - args.emplace_back("foursquare_id", foursquareId); - } - if (!foursquareType.empty()) { - args.emplace_back("foursquare_type", foursquareType); - } - if (!googlePlaceId.empty()) { - args.emplace_back("google_place_id", googlePlaceId); - } - if (!googlePlaceType.empty()) { - args.emplace_back("google_place_type", googlePlaceType); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args)); -} - -Message::Ptr Api::sendContact(boost::variant chatId, - const std::string& phoneNumber, - const std::string& firstName, - const std::string& lastName , - const std::string& vcard, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(11); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("phone_number", phoneNumber); - args.emplace_back("first_name", firstName); - if (!lastName.empty()) { - args.emplace_back("last_name", lastName); - } - if (!vcard.empty()) { - args.emplace_back("vcard", vcard); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendContact", args)); -} - -Message::Ptr Api::sendPoll(boost::variant chatId, - const std::string& question, - const std::vector& options, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool isAnonymous, - const std::string& type, - bool allowsMultipleAnswers, - std::int32_t correctOptionId, - const std::string& explanation, - const std::string& explanationParseMode, - const std::vector& explanationEntities, - std::int32_t openPeriod, - std::int32_t closeDate, - bool isClosed, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(19); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("question", question); - args.emplace_back("options", _tgTypeParser.parseArray( - [](const std::string& option)->std::string { - return "\"" + StringTools::escapeJsonString(option) + "\""; - }, options)); - if (!isAnonymous) { - args.emplace_back("is_anonymous", isAnonymous); - } - if (!type.empty()) { - args.emplace_back("type", type); - } - if (allowsMultipleAnswers) { - args.emplace_back("allows_multiple_answers", allowsMultipleAnswers); - } - if (correctOptionId != -1) { - args.emplace_back("correct_option_id", correctOptionId); - } - if (!explanation.empty()) { - args.emplace_back("explanation", explanation); - } - if (!explanationParseMode.empty()) { - args.emplace_back("explanation_parse_mode", explanationParseMode); - } - if (!explanationEntities.empty()) { - args.emplace_back("explanation_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, explanationEntities)); - } - if (openPeriod != 0) { - args.emplace_back("open_period", openPeriod); - } - if (closeDate != 0) { - args.emplace_back("close_date", closeDate); - } - if (isClosed) { - args.emplace_back("is_closed", isClosed); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); -} - -Message::Ptr Api::sendDice(boost::variant chatId, + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("stopMessageLiveLocation", args)); +} + +Message::Ptr ApiImpl::sendVenue( + boost::variant chatId, float latitude, + float longitude, const std::string &title, const std::string &address, + const std::string &foursquareId, const std::string &foursquareType, + bool disableNotification, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &googlePlaceId, + const std::string &googlePlaceType, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(15); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("latitude", latitude); + args.emplace_back("longitude", longitude); + args.emplace_back("title", title); + args.emplace_back("address", address); + if (!foursquareId.empty()) { + args.emplace_back("foursquare_id", foursquareId); + } + if (!foursquareType.empty()) { + args.emplace_back("foursquare_type", foursquareType); + } + if (!googlePlaceId.empty()) { + args.emplace_back("google_place_id", googlePlaceId); + } + if (!googlePlaceType.empty()) { + args.emplace_back("google_place_type", googlePlaceType); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendVenue", args)); +} + +Message::Ptr +ApiImpl::sendContact(boost::variant chatId, + const std::string &phoneNumber, const std::string &firstName, + const std::string &lastName, const std::string &vcard, + bool disableNotification, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, std::int32_t messageThreadId, + bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(11); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("phone_number", phoneNumber); + args.emplace_back("first_name", firstName); + if (!lastName.empty()) { + args.emplace_back("last_name", lastName); + } + if (!vcard.empty()) { + args.emplace_back("vcard", vcard); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendContact", args)); +} + +Message::Ptr ApiImpl::sendPoll( + boost::variant chatId, + const std::string &question, const std::vector &options, + bool disableNotification, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, bool isAnonymous, const std::string &type, + bool allowsMultipleAnswers, std::int32_t correctOptionId, + const std::string &explanation, const std::string &explanationParseMode, + const std::vector &explanationEntities, + std::int32_t openPeriod, std::int32_t closeDate, bool isClosed, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(19); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("question", question); + args.emplace_back("options", putJSON(escapeJSONStringVec(options))); + if (!isAnonymous) { + args.emplace_back("is_anonymous", isAnonymous); + } + if (!type.empty()) { + args.emplace_back("type", type); + } + if (allowsMultipleAnswers) { + args.emplace_back("allows_multiple_answers", allowsMultipleAnswers); + } + if (correctOptionId != -1) { + args.emplace_back("correct_option_id", correctOptionId); + } + if (!explanation.empty()) { + args.emplace_back("explanation", explanation); + } + if (!explanationParseMode.empty()) { + args.emplace_back("explanation_parse_mode", explanationParseMode); + } + if (!explanationEntities.empty()) { + args.emplace_back("explanation_entities", putJSON(explanationEntities)); + } + if (openPeriod != 0) { + args.emplace_back("open_period", openPeriod); + } + if (closeDate != 0) { + args.emplace_back("close_date", closeDate); + } + if (isClosed) { + args.emplace_back("is_closed", isClosed); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendPoll", args)); +} + +Message::Ptr ApiImpl::sendDice(boost::variant chatId, bool disableNotification, ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, - const std::string& emoji, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(8); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (!emoji.empty()) { - args.emplace_back("emoji", emoji); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } + const std::string &emoji, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(8); - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args)); -} - -bool Api::setMessageReaction(boost::variant chatId, + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (!emoji.empty()) { + args.emplace_back("emoji", emoji); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendDice", args)); +} + +bool ApiImpl::setMessageReaction(boost::variant chatId, std::int32_t messageId, - const std::vector& reaction, + const std::vector &reaction, bool isBig) const { - std::vector args; - args.reserve(4); + std::vector args; + args.reserve(4); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); - if (!reaction.empty()) { - args.emplace_back("reaction", _tgTypeParser.parseArray(&TgTypeParser::parseReactionType, reaction)); - } - if (isBig) { - args.emplace_back("is_big", isBig); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (!reaction.empty()) { + args.emplace_back("reaction", putJSON(reaction)); + } + if (isBig) { + args.emplace_back("is_big", isBig); + } - return sendRequest("setMessageReaction", args).get("", false); + return sendRequest("setMessageReaction", args).asBool(); } -bool Api::sendChatAction(std::int64_t chatId, - const std::string& action, +bool ApiImpl::sendChatAction(std::int64_t chatId, const std::string &action, std::int32_t messageThreadId, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(4); + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(4); - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - args.emplace_back("action", action); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + args.emplace_back("action", action); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } - return sendRequest("sendChatAction", args).get("", false); + return sendRequest("sendChatAction", args).asBool(); } -UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, +UserProfilePhotos::Ptr ApiImpl::getUserProfilePhotos(std::int64_t userId, std::int32_t offset, std::int32_t limit) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("user_id", userId); - if (offset) { - args.emplace_back("offset", offset); - } - if (limit != 100) { - args.emplace_back("limit", std::max(1, std::min(100, limit))); - } + args.emplace_back("user_id", userId); + if (offset) { + args.emplace_back("offset", offset); + } + if (limit != 100) { + args.emplace_back("limit", std::max(1, std::min(100, limit))); + } - return _tgTypeParser.parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); + return parse(sendRequest("getUserProfilePhotos", args)); } -File::Ptr Api::getFile(const std::string& fileId) const { - std::vector args; - args.reserve(1); +File::Ptr ApiImpl::getFile(const std::string &fileId) const { + std::vector args; + args.reserve(1); - args.emplace_back("file_id", fileId); + args.emplace_back("file_id", fileId); - return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args)); + return parse(sendRequest("getFile", args)); } -bool Api::banChatMember(boost::variant chatId, - std::int64_t userId, - std::int32_t untilDate, +bool ApiImpl::banChatMember(boost::variant chatId, + std::int64_t userId, std::int32_t untilDate, bool revokeMessages) const { - std::vector args; - args.reserve(4); + std::vector args; + args.reserve(4); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - if (untilDate != 0) { - args.emplace_back("until_date", untilDate); - } - if (revokeMessages) { - args.emplace_back("revoke_messages", revokeMessages); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + if (untilDate != 0) { + args.emplace_back("until_date", untilDate); + } + if (revokeMessages) { + args.emplace_back("revoke_messages", revokeMessages); + } - return sendRequest("banChatMember", args).get("", false); + return sendRequest("banChatMember", args).asBool(); } -bool Api::unbanChatMember(boost::variant chatId, - std::int64_t userId, - bool onlyIfBanned) const { - std::vector args; - args.reserve(3); +bool ApiImpl::unbanChatMember(boost::variant chatId, + std::int64_t userId, bool onlyIfBanned) const { + std::vector args; + args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - if (onlyIfBanned) { - args.emplace_back("only_if_banned", onlyIfBanned); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + if (onlyIfBanned) { + args.emplace_back("only_if_banned", onlyIfBanned); + } - return sendRequest("unbanChatMember", args).get("", false); + return sendRequest("unbanChatMember", args).asBool(); } -bool Api::restrictChatMember(boost::variant chatId, +bool ApiImpl::restrictChatMember(boost::variant chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, std::uint32_t untilDate, bool useIndependentChatPermissions) const { - std::vector args; - args.reserve(5); - - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); - if (useIndependentChatPermissions != false) { - args.emplace_back("use_independent_chat_permissions", useIndependentChatPermissions); - } - if (untilDate != 0) { - args.emplace_back("until_date", untilDate); - } - - return sendRequest("restrictChatMember", args).get("", false); -} - -bool Api::promoteChatMember(boost::variant chatId, - std::int64_t userId, - bool canChangeInfo, - bool canPostMessages, - bool canEditMessages, - bool canDeleteMessages, - bool canInviteUsers, - bool canPinMessages, - bool canPromoteMembers, - bool isAnonymous, - bool canManageChat, - bool canManageVideoChats, - bool canRestrictMembers, - bool canManageTopics, - bool canPostStories, - bool canEditStories, - bool canDeleteStories) const { - std::vector args; - args.reserve(17); - - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - if (isAnonymous != false) { - args.emplace_back("is_anonymous", isAnonymous); - } - if (canManageChat != false) { - args.emplace_back("can_manage_chat", canManageChat); - } - if (canPostMessages != false) { - args.emplace_back("can_post_messages", canPostMessages); - } - if (canEditMessages != false) { - args.emplace_back("can_edit_messages", canEditMessages); - } - if (canDeleteMessages != false) { - args.emplace_back("can_delete_messages", canDeleteMessages); - } - if (canPostStories != false) { - args.emplace_back("can_post_stories", canPostStories); - } - if (canEditStories != false) { - args.emplace_back("can_edit_stories", canEditStories); - } - if (canDeleteStories != false) { - args.emplace_back("can_delete_stories", canDeleteStories); - } - if (canManageVideoChats != false) { - args.emplace_back("can_manage_video_chats", canManageVideoChats); - } - if (canRestrictMembers != false) { - args.emplace_back("can_restrict_members", canRestrictMembers); - } - if (canPromoteMembers != false) { - args.emplace_back("can_promote_members", canPromoteMembers); - } - if (canChangeInfo != false) { - args.emplace_back("can_change_info", canChangeInfo); - } - if (canInviteUsers != false) { - args.emplace_back("can_invite_users", canInviteUsers); - } - if (canPinMessages != false) { - args.emplace_back("can_pin_messages", canPinMessages); - } - if (canManageTopics != false) { - args.emplace_back("can_manage_topics", canManageTopics); - } - - return sendRequest("promoteChatMember", args).get("", false); -} - -bool Api::setChatAdministratorCustomTitle(boost::variant chatId, - std::int64_t userId, - const std::string& customTitle) const { - std::vector args; - args.reserve(3); - - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - args.emplace_back("custom_title", customTitle); - - return sendRequest("setChatAdministratorCustomTitle", args).get("", false); -} - -bool Api::banChatSenderChat(boost::variant chatId, + std::vector args; + args.reserve(5); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + args.emplace_back("permissions", putJSON(permissions)); + if (useIndependentChatPermissions != false) { + args.emplace_back("use_independent_chat_permissions", + useIndependentChatPermissions); + } + if (untilDate != 0) { + args.emplace_back("until_date", untilDate); + } + + return sendRequest("restrictChatMember", args).asBool(); +} + +bool ApiImpl::promoteChatMember(boost::variant chatId, + std::int64_t userId, bool canChangeInfo, + bool canPostMessages, bool canEditMessages, + bool canDeleteMessages, bool canInviteUsers, + bool canPinMessages, bool canPromoteMembers, + bool isAnonymous, bool canManageChat, + bool canManageVideoChats, bool canRestrictMembers, + bool canManageTopics, bool canPostStories, + bool canEditStories, bool canDeleteStories) const { + std::vector args; + args.reserve(17); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + if (isAnonymous != false) { + args.emplace_back("is_anonymous", isAnonymous); + } + if (canManageChat != false) { + args.emplace_back("can_manage_chat", canManageChat); + } + if (canPostMessages != false) { + args.emplace_back("can_post_messages", canPostMessages); + } + if (canEditMessages != false) { + args.emplace_back("can_edit_messages", canEditMessages); + } + if (canDeleteMessages != false) { + args.emplace_back("can_delete_messages", canDeleteMessages); + } + if (canPostStories != false) { + args.emplace_back("can_post_stories", canPostStories); + } + if (canEditStories != false) { + args.emplace_back("can_edit_stories", canEditStories); + } + if (canDeleteStories != false) { + args.emplace_back("can_delete_stories", canDeleteStories); + } + if (canManageVideoChats != false) { + args.emplace_back("can_manage_video_chats", canManageVideoChats); + } + if (canRestrictMembers != false) { + args.emplace_back("can_restrict_members", canRestrictMembers); + } + if (canPromoteMembers != false) { + args.emplace_back("can_promote_members", canPromoteMembers); + } + if (canChangeInfo != false) { + args.emplace_back("can_change_info", canChangeInfo); + } + if (canInviteUsers != false) { + args.emplace_back("can_invite_users", canInviteUsers); + } + if (canPinMessages != false) { + args.emplace_back("can_pin_messages", canPinMessages); + } + if (canManageTopics != false) { + args.emplace_back("can_manage_topics", canManageTopics); + } + + return sendRequest("promoteChatMember", args).asBool(); +} + +bool ApiImpl::setChatAdministratorCustomTitle( + boost::variant chatId, std::int64_t userId, + const std::string &customTitle) const { + std::vector args; + args.reserve(3); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + args.emplace_back("custom_title", customTitle); + + return sendRequest("setChatAdministratorCustomTitle", args) + .asBool(); +} + +bool ApiImpl::banChatSenderChat(boost::variant chatId, std::int64_t senderChatId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("sender_chat_id", senderChatId); + args.emplace_back("chat_id", chatId); + args.emplace_back("sender_chat_id", senderChatId); - return sendRequest("banChatSenderChat", args).get("", false); + return sendRequest("banChatSenderChat", args).asBool(); } -bool Api::unbanChatSenderChat(boost::variant chatId, +bool ApiImpl::unbanChatSenderChat(boost::variant chatId, std::int64_t senderChatId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("sender_chat_id", senderChatId); + args.emplace_back("chat_id", chatId); + args.emplace_back("sender_chat_id", senderChatId); - return sendRequest("unbanChatSenderChat", args).get("", false); + return sendRequest("unbanChatSenderChat", args).asBool(); } -bool Api::setChatPermissions(boost::variant chatId, +bool ApiImpl::setChatPermissions(boost::variant chatId, ChatPermissions::Ptr permissions, bool useIndependentChatPermissions) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); - if (useIndependentChatPermissions) { - args.emplace_back("use_independent_chat_permissions", useIndependentChatPermissions); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("permissions", putJSON(permissions)); + if (useIndependentChatPermissions) { + args.emplace_back("use_independent_chat_permissions", + useIndependentChatPermissions); + } - return sendRequest("setChatPermissions", args).get("", false); + return sendRequest("setChatPermissions", args).asBool(); } -std::string Api::exportChatInviteLink(boost::variant chatId) const { - std::vector args; - args.reserve(1); +std::string ApiImpl::exportChatInviteLink( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("exportChatInviteLink", args).get("", ""); + return sendRequest("exportChatInviteLink", args).asString(); } -ChatInviteLink::Ptr Api::createChatInviteLink(boost::variant chatId, - std::int32_t expireDate, - std::int32_t memberLimit, - const std::string& name, - bool createsJoinRequest) const { - std::vector args; - args.reserve(5); - - args.emplace_back("chat_id", chatId); - if (!name.empty()) { - args.emplace_back("name", name); - } - if (expireDate != 0) { - args.emplace_back("expire_date", expireDate); - } - if (memberLimit != 0) { - args.emplace_back("member_limit", memberLimit); - } - if (createsJoinRequest) { - args.emplace_back("createsJoinRequest", createsJoinRequest); - } - - return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("createChatInviteLink", args)); -} +ChatInviteLink::Ptr +ApiImpl::createChatInviteLink(boost::variant chatId, + std::int32_t expireDate, std::int32_t memberLimit, + const std::string &name, + bool createsJoinRequest) const { + std::vector args; + args.reserve(5); -ChatInviteLink::Ptr Api::editChatInviteLink(boost::variant chatId, - const std::string& inviteLink, - std::int32_t expireDate, - std::int32_t memberLimit, - const std::string& name, - bool createsJoinRequest) const { - std::vector args; - args.reserve(6); - - args.emplace_back("chat_id", chatId); - args.emplace_back("invite_link", inviteLink); - if (!name.empty()) { - args.emplace_back("name", name); - } - if (expireDate != 0) { - args.emplace_back("expire_date", expireDate); - } - if (memberLimit != 0) { - args.emplace_back("member_limit", memberLimit); - } - if (createsJoinRequest) { - args.emplace_back("createsJoinRequest", createsJoinRequest); - } + args.emplace_back("chat_id", chatId); + if (!name.empty()) { + args.emplace_back("name", name); + } + if (expireDate != 0) { + args.emplace_back("expire_date", expireDate); + } + if (memberLimit != 0) { + args.emplace_back("member_limit", memberLimit); + } + if (createsJoinRequest) { + args.emplace_back("createsJoinRequest", createsJoinRequest); + } + + return parse(sendRequest("createChatInviteLink", args)); +} + +ChatInviteLink::Ptr +ApiImpl::editChatInviteLink(boost::variant chatId, + const std::string &inviteLink, std::int32_t expireDate, + std::int32_t memberLimit, const std::string &name, + bool createsJoinRequest) const { + std::vector args; + args.reserve(6); + + args.emplace_back("chat_id", chatId); + args.emplace_back("invite_link", inviteLink); + if (!name.empty()) { + args.emplace_back("name", name); + } + if (expireDate != 0) { + args.emplace_back("expire_date", expireDate); + } + if (memberLimit != 0) { + args.emplace_back("member_limit", memberLimit); + } + if (createsJoinRequest) { + args.emplace_back("createsJoinRequest", createsJoinRequest); + } - return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("editChatInviteLink", args)); + return parse(sendRequest("editChatInviteLink", args)); } -ChatInviteLink::Ptr Api::revokeChatInviteLink(boost::variant chatId, - const std::string& inviteLink) const { - std::vector args; - args.reserve(2); +ChatInviteLink::Ptr +ApiImpl::revokeChatInviteLink(boost::variant chatId, + const std::string &inviteLink) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("invite_link", inviteLink); + args.emplace_back("chat_id", chatId); + args.emplace_back("invite_link", inviteLink); - return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("revokeChatInviteLink", args)); + return parse(sendRequest("revokeChatInviteLink", args)); } -bool Api::approveChatJoinRequest(boost::variant chatId, - std::int64_t userId) const { - std::vector args; - args.reserve(2); +bool ApiImpl::approveChatJoinRequest( + boost::variant chatId, + std::int64_t userId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); - return sendRequest("approveChatJoinRequest", args).get("", false); + return sendRequest("approveChatJoinRequest", args).asBool(); } -bool Api::declineChatJoinRequest(boost::variant chatId, - std::int64_t userId) const { - std::vector args; - args.reserve(2); +bool ApiImpl::declineChatJoinRequest( + boost::variant chatId, + std::int64_t userId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); - return sendRequest("declineChatJoinRequest", args).get("", false); + return sendRequest("declineChatJoinRequest", args).asBool(); } -bool Api::setChatPhoto(boost::variant chatId, +bool ApiImpl::setChatPhoto(boost::variant chatId, const InputFile::Ptr photo) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName); + args.emplace_back("chat_id", chatId); + args.emplace_back("photo", photo->data, true, photo->mimeType, + photo->fileName); - return sendRequest("setChatPhoto", args).get("", false); + return sendRequest("setChatPhoto", args).asBool(); } -bool Api::deleteChatPhoto(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::deleteChatPhoto( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("deleteChatPhoto", args).get("", false); + return sendRequest("deleteChatPhoto", args).asBool(); } -bool Api::setChatTitle(boost::variant chatId, - const std::string& title) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setChatTitle(boost::variant chatId, + const std::string &title) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("title", title); + args.emplace_back("chat_id", chatId); + args.emplace_back("title", title); - return sendRequest("setChatTitle", args).get("", false); + return sendRequest("setChatTitle", args).asBool(); } -bool Api::setChatDescription(boost::variant chatId, - const std::string& description) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setChatDescription(boost::variant chatId, + const std::string &description) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - if (!description.empty()) { - args.emplace_back("description", description); - } + args.emplace_back("chat_id", chatId); + if (!description.empty()) { + args.emplace_back("description", description); + } - return sendRequest("setChatDescription", args).get("", false); + return sendRequest("setChatDescription", args).asBool(); } -bool Api::pinChatMessage(boost::variant chatId, +bool ApiImpl::pinChatMessage(boost::variant chatId, std::int32_t messageId, bool disableNotification) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } - return sendRequest("pinChatMessage", args).get("", false); + return sendRequest("pinChatMessage", args).asBool(); } -bool Api::unpinChatMessage(boost::variant chatId, +bool ApiImpl::unpinChatMessage(boost::variant chatId, std::int32_t messageId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - if (messageId != 0) { - args.emplace_back("message_id", messageId); - } + args.emplace_back("chat_id", chatId); + if (messageId != 0) { + args.emplace_back("message_id", messageId); + } - return sendRequest("unpinChatMessage", args).get("", false); + return sendRequest("unpinChatMessage", args).asBool(); } -bool Api::unpinAllChatMessages(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::unpinAllChatMessages( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("unpinAllChatMessages", args).get("", false); + return sendRequest("unpinAllChatMessages", args).asBool(); } -bool Api::leaveChat(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::leaveChat(boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("leaveChat", args).get("", false); + return sendRequest("leaveChat", args).asBool(); } -Chat::Ptr Api::getChat(boost::variant chatId) const { - std::vector args; - args.reserve(1); +Chat::Ptr ApiImpl::getChat(boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args)); + return parse(sendRequest("getChat", args)); } -std::vector Api::getChatAdministrators(boost::variant chatId) const { - std::vector args; - args.reserve(1); +std::vector ApiImpl::getChatAdministrators( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); + return parseArray(sendRequest("getChatAdministrators", args)); } -int32_t Api::getChatMemberCount(boost::variant chatId) const { - std::vector args; - args.reserve(1); +int32_t ApiImpl::getChatMemberCount( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("getChatMemberCount", args).get("", 0); + return sendRequest("getChatMemberCount", args).asInt(); } -ChatMember::Ptr Api::getChatMember(boost::variant chatId, - std::int64_t userId) const { - std::vector args; - args.reserve(2); +ChatMember::Ptr +ApiImpl::getChatMember(boost::variant chatId, + std::int64_t userId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); - return _tgTypeParser.parseJsonAndGetChatMember(sendRequest("getChatMember", args)); + return parse(sendRequest("getChatMember", args)); } -bool Api::setChatStickerSet(boost::variant chatId, - const std::string& stickerSetName) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setChatStickerSet(boost::variant chatId, + const std::string &stickerSetName) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("sticker_set_name ", stickerSetName); + args.emplace_back("chat_id", chatId); + args.emplace_back("sticker_set_name ", stickerSetName); - return sendRequest("setChatStickerSet", args).get("", false); + return sendRequest("setChatStickerSet", args).asBool(); } -bool Api::deleteChatStickerSet(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::deleteChatStickerSet( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("deleteChatStickerSet", args).get("", false); + return sendRequest("deleteChatStickerSet", args).asBool(); } -std::vector Api::getForumTopicIconStickers() const { - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getForumTopicIconStickers")); +std::vector ApiImpl::getForumTopicIconStickers() const { + return parseArray(sendRequest("getForumTopicIconStickers")); } -ForumTopic::Ptr Api::createForumTopic(boost::variant chatId, - const std::string& name, - std::int32_t iconColor, - const std::string& iconCustomEmojiId) const { - std::vector args; - args.reserve(4); +ForumTopic::Ptr +ApiImpl::createForumTopic(boost::variant chatId, + const std::string &name, std::int32_t iconColor, + const std::string &iconCustomEmojiId) const { + std::vector args; + args.reserve(4); - args.emplace_back("chat_id", chatId); - args.emplace_back("name", name); - if (iconColor != 0) { - args.emplace_back("icon_color", iconColor); - } - if (!iconCustomEmojiId.empty()) { - args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("name", name); + if (iconColor != 0) { + args.emplace_back("icon_color", iconColor); + } + if (!iconCustomEmojiId.empty()) { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); + } - return _tgTypeParser.parseJsonAndGetForumTopic(sendRequest("createForumTopic", args)); + return parse(sendRequest("createForumTopic", args)); } -bool Api::editForumTopic(boost::variant chatId, - std::int32_t messageThreadId, - const std::string& name, - boost::variant iconCustomEmojiId) const { - std::vector args; - args.reserve(4); +bool ApiImpl::editForumTopic( + boost::variant chatId, + std::int32_t messageThreadId, const std::string &name, + boost::variant iconCustomEmojiId) const { + std::vector args; + args.reserve(4); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); - if (!name.empty()) { - args.emplace_back("name", name); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); + if (!name.empty()) { + args.emplace_back("name", name); + } + if (iconCustomEmojiId.which() == 0) { // std::int32_t + if (boost::get(iconCustomEmojiId) != 0) { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); } - if (iconCustomEmojiId.which() == 0) { // std::int32_t - if (boost::get(iconCustomEmojiId) != 0) { - args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); - } - } else { // std::string - if (boost::get(iconCustomEmojiId) != "") { - args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); - } + } else { // std::string + if (boost::get(iconCustomEmojiId) != "") { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); } + } - return sendRequest("editForumTopic", args).get("", false); + return sendRequest("editForumTopic", args).asBool(); } -bool Api::closeForumTopic(boost::variant chatId, +bool ApiImpl::closeForumTopic(boost::variant chatId, std::int32_t messageThreadId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); - return sendRequest("closeForumTopic", args).get("", false); - } + return sendRequest("closeForumTopic", args).asBool(); +} -bool Api::reopenForumTopic(boost::variant chatId, +bool ApiImpl::reopenForumTopic(boost::variant chatId, std::int32_t messageThreadId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); - return sendRequest("reopenForumTopic", args).get("", false); + return sendRequest("reopenForumTopic", args).asBool(); } -bool Api::deleteForumTopic(boost::variant chatId, +bool ApiImpl::deleteForumTopic(boost::variant chatId, std::int32_t messageThreadId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); - return sendRequest("deleteForumTopic", args).get("", false); + return sendRequest("deleteForumTopic", args).asBool(); } -bool Api::unpinAllForumTopicMessages(boost::variant chatId, - std::int32_t messageThreadId) const { - std::vector args; - args.reserve(2); +bool ApiImpl::unpinAllForumTopicMessages( + boost::variant chatId, + std::int32_t messageThreadId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); - return sendRequest("unpinAllForumTopicMessages", args).get("", false); + return sendRequest("unpinAllForumTopicMessages", args).asBool(); } -bool Api::editGeneralForumTopic(boost::variant chatId, - std::string name) const { - std::vector args; - args.reserve(2); +bool ApiImpl::editGeneralForumTopic( + boost::variant chatId, std::string name) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("name", name); + args.emplace_back("chat_id", chatId); + args.emplace_back("name", name); - return sendRequest("editGeneralForumTopic", args).get("", false); + return sendRequest("editGeneralForumTopic", args).asBool(); } -bool Api::closeGeneralForumTopic(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::closeGeneralForumTopic( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("closeGeneralForumTopic", args).get("", false); + return sendRequest("closeGeneralForumTopic", args).asBool(); } -bool Api::reopenGeneralForumTopic(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::reopenGeneralForumTopic( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("reopenGeneralForumTopic", args).get("", false); + return sendRequest("reopenGeneralForumTopic", args).asBool(); } -bool Api::hideGeneralForumTopic(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::hideGeneralForumTopic( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("hideGeneralForumTopic", args).get("", false); + return sendRequest("hideGeneralForumTopic", args).asBool(); } -bool Api::unhideGeneralForumTopic(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::unhideGeneralForumTopic( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("unhideGeneralForumTopic", args).get("", false); + return sendRequest("unhideGeneralForumTopic", args).asBool(); } -bool Api::unpinAllGeneralForumTopicMessages(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool ApiImpl::unpinAllGeneralForumTopicMessages( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("unpinAllGeneralForumTopicMessages", args).get("", false); + return sendRequest("unpinAllGeneralForumTopicMessages", args) + .asBool(); } -bool Api::answerCallbackQuery(const std::string& callbackQueryId, - const std::string& text, - bool showAlert, - const std::string& url, +bool ApiImpl::answerCallbackQuery(const std::string &callbackQueryId, + const std::string &text, bool showAlert, + const std::string &url, std::int32_t cacheTime) const { - std::vector args; - args.reserve(5); + std::vector args; + args.reserve(5); - args.emplace_back("callback_query_id", callbackQueryId); - if (!text.empty()) { - args.emplace_back("text", text); - } - if (showAlert) { - args.emplace_back("show_alert", showAlert); - } - if (!url.empty()) { - args.emplace_back("url", url); - } - if (cacheTime) { - args.emplace_back("cache_time", cacheTime); - } + args.emplace_back("callback_query_id", callbackQueryId); + if (!text.empty()) { + args.emplace_back("text", text); + } + if (showAlert) { + args.emplace_back("show_alert", showAlert); + } + if (!url.empty()) { + args.emplace_back("url", url); + } + if (cacheTime) { + args.emplace_back("cache_time", cacheTime); + } - return sendRequest("answerCallbackQuery", args).get("", false); + return sendRequest("answerCallbackQuery", args).asBool(); } -UserChatBoosts::Ptr Api::getUserChatBoosts(boost::variant chatId, - std::int32_t userId) const { - std::vector args; - args.reserve(2); +UserChatBoosts::Ptr +ApiImpl::getUserChatBoosts(boost::variant chatId, + std::int32_t userId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); - return _tgTypeParser.parseJsonAndGetUserChatBoosts(sendRequest("getUserChatBoosts", args)); + return parse(sendRequest("getUserChatBoosts", args)); } -BusinessConnection::Ptr Api::getBusinessConnection(const std::string& businessConnectionId) const { - std::vector args; - args.reserve(1); +BusinessConnection::Ptr +ApiImpl::getBusinessConnection(const std::string &businessConnectionId) const { + std::vector args; + args.reserve(1); - args.emplace_back("business_connection_id", businessConnectionId); + args.emplace_back("business_connection_id", businessConnectionId); - return _tgTypeParser.parseJsonAndGetBusinessConnection(sendRequest("getBusinessConnection", args)); + return parse(sendRequest("getBusinessConnection", args)); } -bool Api::setMyCommands(const std::vector& commands, +bool ApiImpl::setMyCommands(const std::vector &commands, BotCommandScope::Ptr scope, - const std::string& languageCode) const { - std::vector args; - args.reserve(3); + const std::string &languageCode) const { + std::vector args; + args.reserve(3); - args.emplace_back("commands", _tgTypeParser.parseArray(&TgTypeParser::parseBotCommand, commands)); - if (scope != nullptr) { - args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + args.emplace_back("commands", putJSON(commands)); + if (scope != nullptr) { + args.emplace_back("scope", putJSON(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("setMyCommands", args).get("", false); + return sendRequest("setMyCommands", args).asBool(); } -bool Api::deleteMyCommands(BotCommandScope::Ptr scope, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +bool ApiImpl::deleteMyCommands(BotCommandScope::Ptr scope, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (scope != nullptr) { - args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (scope != nullptr) { + args.emplace_back("scope", putJSON(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("deleteMyCommands", args).get("", false); + return sendRequest("deleteMyCommands", args).asBool(); } -std::vector Api::getMyCommands(BotCommandScope::Ptr scope, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +std::vector +ApiImpl::getMyCommands(BotCommandScope::Ptr scope, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (scope != nullptr) { - args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (scope != nullptr) { + args.emplace_back("scope", putJSON(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands", args)); + return parseArray(sendRequest("getMyCommands", args)); } -bool Api::setMyName(const std::string& name, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setMyName(const std::string &name, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (!name.empty()) { - args.emplace_back("name", name); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!name.empty()) { + args.emplace_back("name", name); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("setMyName", args).get("", false); + return sendRequest("setMyName", args).asBool(); } -BotName::Ptr Api::getMyName(const std::string& languageCode) const { - std::vector args; - args.reserve(1); +BotName::Ptr ApiImpl::getMyName(const std::string &languageCode) const { + std::vector args; + args.reserve(1); - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return _tgTypeParser.parseJsonAndGetBotName(sendRequest("getMyName", args)); + return parse(sendRequest("getMyName", args)); } -bool Api::setMyDescription(const std::string& description, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setMyDescription(const std::string &description, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (!description.empty()) { - args.emplace_back("description", description); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!description.empty()) { + args.emplace_back("description", description); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("setMyDescription", args).get("", false); + return sendRequest("setMyDescription", args).asBool(); } -BotDescription::Ptr Api::getMyDescription(const std::string& languageCode) const { - std::vector args; - args.reserve(1); +BotDescription::Ptr +ApiImpl::getMyDescription(const std::string &languageCode) const { + std::vector args; + args.reserve(1); - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return _tgTypeParser.parseJsonAndGetBotDescription(sendRequest("getMyDescription", args)); + return parse(sendRequest("getMyDescription", args)); } -bool Api::setMyShortDescription(const std::string& shortDescription, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setMyShortDescription(const std::string &shortDescription, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (!shortDescription.empty()) { - args.emplace_back("short_description", shortDescription); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!shortDescription.empty()) { + args.emplace_back("short_description", shortDescription); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("setMyShortDescription", args).get("", false); + return sendRequest("setMyShortDescription", args).asBool(); } -BotShortDescription::Ptr Api::getMyShortDescription(const std::string& languageCode) const { - std::vector args; - args.reserve(1); +BotShortDescription::Ptr +ApiImpl::getMyShortDescription(const std::string &languageCode) const { + std::vector args; + args.reserve(1); - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return _tgTypeParser.parseJsonAndGetBotShortDescription(sendRequest("getMyShortDescription", args)); + return parse(sendRequest("getMyShortDescription", args)); } -bool Api::setChatMenuButton(std::int64_t chatId, +bool ApiImpl::setChatMenuButton(std::int64_t chatId, MenuButton::Ptr menuButton) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - if (chatId != 0) { - args.emplace_back("chat_id", chatId); - } - if (menuButton != nullptr) { - args.emplace_back("menu_button", _tgTypeParser.parseMenuButton(menuButton)); - } + if (chatId != 0) { + args.emplace_back("chat_id", chatId); + } + if (menuButton != nullptr) { + args.emplace_back("menu_button", putJSON(menuButton)); + } - return sendRequest("setChatMenuButton", args).get("", false); + return sendRequest("setChatMenuButton", args).asBool(); } -MenuButton::Ptr Api::getChatMenuButton(std::int64_t chatId) const { - std::vector args; - args.reserve(1); +MenuButton::Ptr ApiImpl::getChatMenuButton(std::int64_t chatId) const { + std::vector args; + args.reserve(1); - if (chatId != 0) { - args.emplace_back("chat_id", chatId); - } + if (chatId != 0) { + args.emplace_back("chat_id", chatId); + } - return _tgTypeParser.parseJsonAndGetMenuButton(sendRequest("getChatMenuButton", args)); + return parse(sendRequest("getChatMenuButton", args)); } -bool Api::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights, +bool ApiImpl::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights, bool forChannels) const { - std::vector args; - args.reserve(2); - - if (rights != nullptr) { - args.emplace_back("rights", _tgTypeParser.parseChatAdministratorRights(rights)); - } - if (forChannels) { - args.emplace_back("for_channels", forChannels); - } - - return sendRequest("setMyDefaultAdministratorRights", args).get("", false); -} + std::vector args; + args.reserve(2); -ChatAdministratorRights::Ptr Api::getMyDefaultAdministratorRights(bool forChannels) const { - std::vector args; - args.reserve(1); - - if (forChannels) { - args.emplace_back("for_channels", forChannels); - } - - return _tgTypeParser.parseJsonAndGetChatAdministratorRights(sendRequest("getMyDefaultAdministratorRights", args)); -} - -Message::Ptr Api::editMessageText(const std::string& text, - boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - const std::string& parseMode, - LinkPreviewOptions::Ptr linkPreviewOptions, - InlineKeyboardMarkup::Ptr replyMarkup, - const std::vector& entities) const { - std::vector args; - args.reserve(8); - - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - args.emplace_back("text", text); - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!entities.empty()) { - args.emplace_back("entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, entities)); - } - if (linkPreviewOptions) { - args.emplace_back("link_preview_options", _tgTypeParser.parseLinkPreviewOptions(linkPreviewOptions)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); - } - - boost::property_tree::ptree p = sendRequest("editMessageText", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } -} - -Message::Ptr Api::editMessageCaption(boost::variant chatId, - std::int32_t messageId, - const std::string& caption, - const std::string& inlineMessageId, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - const std::vector& captionEntities) const { - std::vector args; - args.reserve(7); - - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } + if (rights != nullptr) { + args.emplace_back("rights", putJSON(rights)); + } + if (forChannels) { + args.emplace_back("for_channels", forChannels); + } - boost::property_tree::ptree p = sendRequest("editMessageCaption", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } + return sendRequest("setMyDefaultAdministratorRights", args) + .asBool(); } -Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, - boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - GenericReply::Ptr replyMarkup) const { - - std::vector args; - args.reserve(5); +ChatAdministratorRights::Ptr +ApiImpl::getMyDefaultAdministratorRights(bool forChannels) const { + std::vector args; + args.reserve(1); - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } + if (forChannels) { + args.emplace_back("for_channels", forChannels); + } - boost::property_tree::ptree p = sendRequest("editMessageMedia", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } + return parse( + sendRequest("getMyDefaultAdministratorRights", args)); } -Message::Ptr Api::editMessageReplyMarkup(boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - const GenericReply::Ptr replyMarkup) const { - - std::vector args; - args.reserve(4); +Message::Ptr ApiImpl::editMessageText( + const std::string &text, boost::variant chatId, + std::int32_t messageId, const std::string &inlineMessageId, + const std::string &parseMode, LinkPreviewOptions::Ptr linkPreviewOptions, + InlineKeyboardMarkup::Ptr replyMarkup, + const std::vector &entities) const { + std::vector args; + args.reserve(8); - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); } - - boost::property_tree::ptree p = sendRequest("editMessageReplyMarkup", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } -} - -Poll::Ptr Api::stopPoll(boost::variant chatId, + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + args.emplace_back("text", text); + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!entities.empty()) { + args.emplace_back("entities", putJSON(entities)); + } + if (linkPreviewOptions) { + args.emplace_back("link_preview_options", putJSON(linkPreviewOptions)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + const auto p = sendRequest("editMessageText", args); + if (p.isMember("message_id")) { + return parse(p); + } else { + return nullptr; + } +} + +Message::Ptr ApiImpl::editMessageCaption( + boost::variant chatId, std::int32_t messageId, + const std::string &caption, const std::string &inlineMessageId, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + const std::vector &captionEntities) const { + std::vector args; + args.reserve(7); + + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + const auto p = sendRequest("editMessageCaption", args); + if (p.isMember("message_id")) { + return parse(p); + } else { + return nullptr; + } +} + +Message::Ptr ApiImpl::editMessageMedia( + InputMedia::Ptr media, boost::variant chatId, + std::int32_t messageId, const std::string &inlineMessageId, + GenericReply::Ptr replyMarkup) const { + + std::vector args; + args.reserve(5); + + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } + } + args.emplace_back("media", putJSON(media)); + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + const auto& p = sendRequest("editMessageMedia", args); + if (p.isMember("message_id")) { + return parse(p); + } else { + return nullptr; + } +} + +Message::Ptr +ApiImpl::editMessageReplyMarkup(boost::variant chatId, + std::int32_t messageId, + const std::string &inlineMessageId, + const GenericReply::Ptr replyMarkup) const { + + std::vector args; + args.reserve(4); + + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + const auto& p = sendRequest("editMessageReplyMarkup", args); + if (p.isMember("message_id")) { + return parse(p); + } else { + return nullptr; + } +} + +Poll::Ptr ApiImpl::stopPoll(boost::variant chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } - return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args)); + return parse(sendRequest("stopPoll", args)); } -bool Api::deleteMessage(boost::variant chatId, +bool ApiImpl::deleteMessage(boost::variant chatId, std::int32_t messageId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); - return sendRequest("deleteMessage", args).get("", false); + return sendRequest("deleteMessage", args).asBool(); } -bool Api::deleteMessages(boost::variant chatId, - const std::vector& messageIds) const { - std::vector args; - args.reserve(2); - - args.emplace_back("chat_id", chatId); - if (!messageIds.empty()) { - args.emplace_back("message_ids", _tgTypeParser.parseArray( - [] (const std::int32_t& i)->std::int32_t { - return i; - }, messageIds)); - } +bool ApiImpl::deleteMessages(boost::variant chatId, + const std::vector &messageIds) const { + std::vector args; + args.reserve(2); - return sendRequest("deleteMessages", args).get("", false); -} + args.emplace_back("chat_id", chatId); + if (!messageIds.empty()) { + args.emplace_back("message_ids", putJSON(messageIds)); + } -Message::Ptr Api::sendSticker(boost::variant chatId, - boost::variant sticker, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool disableNotification, - std::int32_t messageThreadId, - bool protectContent, - const std::string& emoji, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(9); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (sticker.which() == 0) { // InputFile::Ptr - auto file = boost::get(sticker); - args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("sticker", boost::get(sticker)); - } - if (!emoji.empty()) { - args.emplace_back("emoji", emoji); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendSticker", args)); + return sendRequest("deleteMessages", args).asBool(); } -StickerSet::Ptr Api::getStickerSet(const std::string& name) const { - std::vector args; - args.reserve(1); +Message::Ptr ApiImpl::sendSticker( + boost::variant chatId, + boost::variant sticker, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, + bool disableNotification, std::int32_t messageThreadId, bool protectContent, + const std::string &emoji, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(9); - args.emplace_back("name", name); + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (sticker.which() == 0) { // InputFile::Ptr + auto file = boost::get(sticker); + args.emplace_back("sticker", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("sticker", boost::get(sticker)); + } + if (!emoji.empty()) { + args.emplace_back("emoji", emoji); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } - return _tgTypeParser.parseJsonAndGetStickerSet(sendRequest("getStickerSet", args)); + return parse(sendRequest("sendSticker", args)); } -std::vector Api::getCustomEmojiStickers(const std::vector& customEmojiIds) const { - std::vector args; - args.reserve(1); +StickerSet::Ptr ApiImpl::getStickerSet(const std::string &name) const { + std::vector args; + args.reserve(1); - args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray( - [] (const std::string& customEmojiId) -> std::string { - return "\"" + StringTools::escapeJsonString(customEmojiId) + "\""; - }, customEmojiIds)); + args.emplace_back("name", name); - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args)); + return parse(sendRequest("getStickerSet", args)); } -File::Ptr Api::uploadStickerFile(std::int64_t userId, - InputFile::Ptr sticker, - const std::string& stickerFormat) const { - std::vector args; - args.reserve(3); +std::vector ApiImpl::getCustomEmojiStickers( + const std::vector &customEmojiIds) const { + std::vector args; + args.reserve(1); - args.emplace_back("user_id", userId); - args.emplace_back("sticker", sticker->data, true, sticker->mimeType, sticker->fileName); - args.emplace_back("sticker_format", stickerFormat); + args.emplace_back("custom_emoji_ids", + putJSON(escapeJSONStringVec(customEmojiIds))); - return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); + return parseArray(sendRequest("getCustomEmojiStickers", args)); } -bool Api::createNewStickerSet(std::int64_t userId, - const std::string& name, - const std::string& title, - const std::vector& stickers, - Sticker::Type stickerType, - bool needsRepainting) const { - std::vector args; - args.reserve(6); +File::Ptr ApiImpl::uploadStickerFile(std::int64_t userId, InputFile::Ptr sticker, + const std::string &stickerFormat) const { + std::vector args; + args.reserve(3); - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("title", title); - args.emplace_back("stickers", _tgTypeParser.parseArray(&TgTypeParser::parseInputSticker, stickers)); - if (stickerType == Sticker::Type::Regular) { - args.emplace_back("sticker_type", "regular"); - } else if (stickerType == Sticker::Type::Mask) { - args.emplace_back("sticker_type", "mask"); - } else if (stickerType == Sticker::Type::CustomEmoji) { - args.emplace_back("sticker_type", "custom_emoji"); - } - if (needsRepainting) { - args.emplace_back("needs_repainting", needsRepainting); - } + args.emplace_back("user_id", userId); + args.emplace_back("sticker", sticker->data, true, sticker->mimeType, + sticker->fileName); + args.emplace_back("sticker_format", stickerFormat); - return sendRequest("createNewStickerSet", args).get("", false); + return parse(sendRequest("uploadStickerFile", args)); } -bool Api::addStickerToSet(std::int64_t userId, - const std::string& name, +bool ApiImpl::createNewStickerSet(std::int64_t userId, const std::string &name, + const std::string &title, + const std::vector &stickers, + Sticker::Type stickerType, + bool needsRepainting) const { + std::vector args; + args.reserve(6); + + args.emplace_back("user_id", userId); + args.emplace_back("name", name); + args.emplace_back("title", title); + args.emplace_back("stickers", putJSON(stickers)); + if (stickerType == Sticker::Type::Regular) { + args.emplace_back("sticker_type", "regular"); + } else if (stickerType == Sticker::Type::Mask) { + args.emplace_back("sticker_type", "mask"); + } else if (stickerType == Sticker::Type::CustomEmoji) { + args.emplace_back("sticker_type", "custom_emoji"); + } + if (needsRepainting) { + args.emplace_back("needs_repainting", needsRepainting); + } + + return sendRequest("createNewStickerSet", args).asBool(); +} + +bool ApiImpl::addStickerToSet(std::int64_t userId, const std::string &name, InputSticker::Ptr sticker) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("sticker", _tgTypeParser.parseInputSticker(sticker)); + args.emplace_back("user_id", userId); + args.emplace_back("name", name); + args.emplace_back("sticker", putJSON(sticker)); - return sendRequest("addStickerToSet", args).get("", false); + return sendRequest("addStickerToSet", args).asBool(); } -bool Api::setStickerPositionInSet(const std::string& sticker, +bool ApiImpl::setStickerPositionInSet(const std::string &sticker, std::int32_t position) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("sticker", sticker); - args.emplace_back("position", position); + args.emplace_back("sticker", sticker); + args.emplace_back("position", position); - return sendRequest("setStickerPositionInSet", args).get("", false); + return sendRequest("setStickerPositionInSet", args).asBool(); } -bool Api::deleteStickerFromSet(const std::string& sticker) const { - std::vector args; - args.reserve(1); +bool ApiImpl::deleteStickerFromSet(const std::string &sticker) const { + std::vector args; + args.reserve(1); - args.emplace_back("sticker", sticker); + args.emplace_back("sticker", sticker); - return sendRequest("deleteStickerFromSet", args).get("", false); + return sendRequest("deleteStickerFromSet", args).asBool(); } -bool Api::replaceStickerInSet(std::int64_t userId, - const std::string& name, - const std::string& oldSticker, - InputSticker::Ptr sticker) const { - std::vector args; - args.reserve(4); +bool ApiImpl::replaceStickerInSet(std::int64_t userId, const std::string &name, + const std::string &oldSticker, + InputSticker::Ptr sticker) const { + std::vector args; + args.reserve(4); - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("old_sticker", oldSticker); - args.emplace_back("sticker", _tgTypeParser.parseInputSticker(sticker)); + args.emplace_back("user_id", userId); + args.emplace_back("name", name); + args.emplace_back("old_sticker", oldSticker); + args.emplace_back("sticker", putJSON(sticker)); - return sendRequest("replaceStickerInSet", args).get("", false); + return sendRequest("replaceStickerInSet", args).asBool(); } -bool Api::setStickerEmojiList(const std::string& sticker, - const std::vector& emojiList) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setStickerEmojiList(const std::string &sticker, + const std::vector &emojiList) const { + std::vector args; + args.reserve(2); - args.emplace_back("sticker", sticker); - args.emplace_back("emoji_list", _tgTypeParser.parseArray( - [](const std::string& emoji)->std::string { - return "\"" + StringTools::escapeJsonString(emoji) + "\""; - }, emojiList)); - - return sendRequest("setStickerEmojiList", args).get("", false); + args.emplace_back("sticker", sticker); + args.emplace_back("emoji_list", putJSON(escapeJSONStringVec(emojiList))); + return sendRequest("setStickerEmojiList", args).asBool(); } -bool Api::setStickerKeywords(const std::string& sticker, - const std::vector& keywords) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setStickerKeywords(const std::string &sticker, + const std::vector &keywords) const { + std::vector args; + args.reserve(2); - args.emplace_back("sticker", sticker); - if (!keywords.empty()) { - args.emplace_back("keywords", _tgTypeParser.parseArray( - [](const std::string& keyword)->std::string { - return "\"" + StringTools::escapeJsonString(keyword) + "\""; - }, keywords)); - } + args.emplace_back("sticker", sticker); + if (!keywords.empty()) { + args.emplace_back("keywords", putJSON(escapeJSONStringVec(keywords))); + } - return sendRequest("setStickerKeywords", args).get("", false); + return sendRequest("setStickerKeywords", args).asBool(); } -bool Api::setStickerMaskPosition(const std::string& sticker, +bool ApiImpl::setStickerMaskPosition(const std::string &sticker, MaskPosition::Ptr maskPosition) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("sticker", sticker); - if (maskPosition != nullptr) { - args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); - } + args.emplace_back("sticker", sticker); + if (maskPosition != nullptr) { + args.emplace_back("mask_position", putJSON(maskPosition)); + } - return sendRequest("setStickerMaskPosition", args).get("", false); + return sendRequest("setStickerMaskPosition", args).asBool(); } -bool Api::setStickerSetTitle(const std::string& name, - const std::string& title) const { - std::vector args; - args.reserve(2); +bool ApiImpl::setStickerSetTitle(const std::string &name, + const std::string &title) const { + std::vector args; + args.reserve(2); - args.emplace_back("name", name); - args.emplace_back("title", title); + args.emplace_back("name", name); + args.emplace_back("title", title); - return sendRequest("setStickerSetTitle", args).get("", false); + return sendRequest("setStickerSetTitle", args).asBool(); } -bool Api::setStickerSetThumbnail(const std::string& name, - std::int64_t userId, - const std::string& format, - boost::variant thumbnail) const { - std::vector args; - args.reserve(4); +bool ApiImpl::setStickerSetThumbnail( + const std::string &name, std::int64_t userId, const std::string &format, + boost::variant thumbnail) const { + std::vector args; + args.reserve(4); - args.emplace_back("name", name); - args.emplace_back("user_id", userId); - args.emplace_back("format", format); - if (thumbnail.which() == 0) { // InputFile::Ptr - if (boost::get(thumbnail) != nullptr) { - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } - } else { // std::string - if (boost::get(thumbnail) != "") { - args.emplace_back("thumbnail", boost::get(thumbnail)); - } + args.emplace_back("name", name); + args.emplace_back("user_id", userId); + args.emplace_back("format", format); + if (thumbnail.which() == 0) { // InputFile::Ptr + if (boost::get(thumbnail) != nullptr) { + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); } - - return sendRequest("setStickerSetThumbnail", args).get("", false); -} - -bool Api::setCustomEmojiStickerSetThumbnail(const std::string& name, - const std::string& customEmojiId) const { - std::vector args; - args.reserve(2); - - args.emplace_back("name", name); - if (!customEmojiId.empty()) { - args.emplace_back("custom_emoji_id", customEmojiId); + } else { // std::string + if (boost::get(thumbnail) != "") { + args.emplace_back("thumbnail", boost::get(thumbnail)); } + } - return sendRequest("setCustomEmojiStickerSetThumbnail", args).get("", false); + return sendRequest("setStickerSetThumbnail", args).asBool(); } -bool Api::deleteStickerSet(const std::string& name) const { - std::vector args; - args.reserve(1); +bool ApiImpl::setCustomEmojiStickerSetThumbnail( + const std::string &name, const std::string &customEmojiId) const { + std::vector args; + args.reserve(2); - args.emplace_back("name", name); + args.emplace_back("name", name); + if (!customEmojiId.empty()) { + args.emplace_back("custom_emoji_id", customEmojiId); + } - return sendRequest("deleteStickerSet", args).get("", false); + return sendRequest("setCustomEmojiStickerSetThumbnail", args) + .asBool(); } -bool Api::answerInlineQuery(const std::string& inlineQueryId, - const std::vector& results, - std::int32_t cacheTime, - bool isPersonal, - const std::string& nextOffset, - InlineQueryResultsButton::Ptr button) const { - std::vector args; - args.reserve(6); - - args.emplace_back("inline_query_id", inlineQueryId); - args.emplace_back("results", _tgTypeParser.parseArray(&TgTypeParser::parseInlineQueryResult, results)); - if (cacheTime != 300) { - args.emplace_back("cache_time", cacheTime); - } - if (isPersonal != false) { - args.emplace_back("is_personal", isPersonal); - } - if (!nextOffset.empty()) { - args.emplace_back("next_offset", nextOffset); - } - if (button != nullptr) { - args.emplace_back("button", _tgTypeParser.parseInlineQueryResultsButton(button)); - } - - return sendRequest("answerInlineQuery", args).get("", false); -} - -SentWebAppMessage::Ptr Api::answerWebAppQuery(const std::string& webAppQueryId, - InlineQueryResult::Ptr result) const { - std::vector args; - args.reserve(2); - - args.emplace_back("web_app_query_id", webAppQueryId); - args.emplace_back("result", _tgTypeParser.parseInlineQueryResult(result)); - - return _tgTypeParser.parseJsonAndGetSentWebAppMessage(sendRequest("answerWebAppQuery", args)); -} - -Message::Ptr Api::sendInvoice(boost::variant chatId, - const std::string& title, - const std::string& description, - const std::string& payload, - const std::string& providerToken, - const std::string& currency, - const std::vector& prices, - const std::string& providerData, - const std::string& photoUrl, - std::int32_t photoSize, - std::int32_t photoWidth, - std::int32_t photoHeight, - bool needName, - bool needPhoneNumber, - bool needEmail, - bool needShippingAddress, - bool sendPhoneNumberToProvider, - bool sendEmailToProvider, - bool isFlexible, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool disableNotification, - std::int32_t messageThreadId, - std::int32_t maxTipAmount, - const std::vector& suggestedTipAmounts, - const std::string& startParameter, - bool protectContent) const { - std::vector args; - args.reserve(27); - - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("title", title); - args.emplace_back("description", description); - args.emplace_back("payload", payload); - args.emplace_back("provider_token", providerToken); - args.emplace_back("currency", currency); - args.emplace_back("prices", _tgTypeParser.parseArray(&TgTypeParser::parseLabeledPrice, prices)); - args.emplace_back("max_tip_amount", maxTipAmount); - if (!suggestedTipAmounts.empty()) { - args.emplace_back("suggested_tip_amounts", _tgTypeParser.parseArray([] (const std::int32_t& option) -> std::int32_t { - return option; - }, suggestedTipAmounts)); - } - if (!startParameter.empty()) { - args.emplace_back("start_parameter", startParameter); - } - if (!providerData.empty()) { - args.emplace_back("provider_data", providerData); - } - if (!photoUrl.empty()) { - args.emplace_back("photo_url", photoUrl); - } - if (photoSize) { - args.emplace_back("photo_size", photoSize); - } - if (photoWidth) { - args.emplace_back("photo_width", photoWidth); - } - if (photoHeight) { - args.emplace_back("photo_height", photoHeight); - } - if (needName) { - args.emplace_back("need_name", needName); - } - if (needPhoneNumber) { - args.emplace_back("need_phone_number", needPhoneNumber); - } - if (needEmail) { - args.emplace_back("need_email", needEmail); - } - if (needShippingAddress) { - args.emplace_back("need_shipping_address", needShippingAddress); - } - if (sendPhoneNumberToProvider) { - args.emplace_back("send_phone_number_to_provider", sendPhoneNumberToProvider); - } - if (sendEmailToProvider) { - args.emplace_back("send_email_to_provider", sendEmailToProvider); - } - if (isFlexible) { - args.emplace_back("is_flexible", isFlexible); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendInvoice", args)); -} - -std::string Api::createInvoiceLink(const std::string& title, - const std::string& description, - const std::string& payload, - const std::string& providerToken, - const std::string& currency, - const std::vector& prices, - std::int32_t maxTipAmount, - const std::vector& suggestedTipAmounts, - const std::string& providerData, - const std::string& photoUrl, - std::int32_t photoSize, - std::int32_t photoWidth, - std::int32_t photoHeight, - bool needName, - bool needPhoneNumber, - bool needEmail, - bool needShippingAddress, - bool sendPhoneNumberToProvider, - bool sendEmailToProvider, - bool isFlexible) const { - std::vector args; - args.reserve(20); +bool ApiImpl::deleteStickerSet(const std::string &name) const { + std::vector args; + args.reserve(1); - args.emplace_back("title", title); - args.emplace_back("description", description); - args.emplace_back("payload", payload); - args.emplace_back("provider_token", providerToken); - args.emplace_back("currency", currency); - args.emplace_back("prices", _tgTypeParser.parseArray(&TgTypeParser::parseLabeledPrice, prices)); - args.emplace_back("max_tip_amount", maxTipAmount); - if (!suggestedTipAmounts.empty()) { - args.emplace_back("suggested_tip_amounts", _tgTypeParser.parseArray([] (const std::int32_t& option) -> std::int32_t { - return option; - }, suggestedTipAmounts)); - } - if (!providerData.empty()) { - args.emplace_back("provider_data", providerData); - } - if (!photoUrl.empty()) { - args.emplace_back("photo_url", photoUrl); - } - if (photoSize) { - args.emplace_back("photo_size", photoSize); - } - if (photoWidth) { - args.emplace_back("photo_width", photoWidth); - } - if (photoHeight) { - args.emplace_back("photo_height", photoHeight); - } - if (needName) { - args.emplace_back("need_name", needName); - } - if (needPhoneNumber) { - args.emplace_back("need_phone_number", needPhoneNumber); - } - if (needEmail) { - args.emplace_back("need_email", needEmail); - } - if (needShippingAddress) { - args.emplace_back("need_shipping_address", needShippingAddress); - } - if (sendPhoneNumberToProvider) { - args.emplace_back("send_phone_number_to_provider", sendPhoneNumberToProvider); - } - if (sendEmailToProvider) { - args.emplace_back("send_email_to_provider", sendEmailToProvider); - } - if (isFlexible) { - args.emplace_back("is_flexible", isFlexible); - } + args.emplace_back("name", name); - return sendRequest("createInvoiceLink", args).get("", ""); + return sendRequest("deleteStickerSet", args).asBool(); } -bool Api::answerShippingQuery(const std::string& shippingQueryId, - bool ok, - const std::vector& shippingOptions, - const std::string& errorMessage) const { - std::vector args; - args.reserve(4); +bool ApiImpl::answerInlineQuery(const std::string &inlineQueryId, + const std::vector &results, + std::int32_t cacheTime, bool isPersonal, + const std::string &nextOffset, + InlineQueryResultsButton::Ptr button) const { + std::vector args; + args.reserve(6); + + args.emplace_back("inline_query_id", inlineQueryId); + args.emplace_back("results", putJSON(results)); + if (cacheTime != 300) { + args.emplace_back("cache_time", cacheTime); + } + if (isPersonal != false) { + args.emplace_back("is_personal", isPersonal); + } + if (!nextOffset.empty()) { + args.emplace_back("next_offset", nextOffset); + } + if (button != nullptr) { + args.emplace_back("button", putJSON(button)); + } + + return sendRequest("answerInlineQuery", args).asBool(); +} + +SentWebAppMessage::Ptr +ApiImpl::answerWebAppQuery(const std::string &webAppQueryId, + InlineQueryResult::Ptr result) const { + std::vector args; + args.reserve(2); + + args.emplace_back("web_app_query_id", webAppQueryId); + args.emplace_back("result", putJSON(result)); + + return parse(sendRequest("answerWebAppQuery", args)); +} + +Message::Ptr +ApiImpl::sendInvoice(boost::variant chatId, + const std::string &title, const std::string &description, + const std::string &payload, const std::string &providerToken, + const std::string ¤cy, + const std::vector &prices, + const std::string &providerData, const std::string &photoUrl, + std::int32_t photoSize, std::int32_t photoWidth, + std::int32_t photoHeight, bool needName, bool needPhoneNumber, + bool needEmail, bool needShippingAddress, + bool sendPhoneNumberToProvider, bool sendEmailToProvider, + bool isFlexible, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, bool disableNotification, + std::int32_t messageThreadId, std::int32_t maxTipAmount, + const std::vector &suggestedTipAmounts, + const std::string &startParameter, bool protectContent) const { + std::vector args; + args.reserve(27); + + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("title", title); + args.emplace_back("description", description); + args.emplace_back("payload", payload); + args.emplace_back("provider_token", providerToken); + args.emplace_back("currency", currency); + args.emplace_back("prices", putJSON(prices)); + args.emplace_back("max_tip_amount", maxTipAmount); + if (!suggestedTipAmounts.empty()) { + args.emplace_back("suggested_tip_amounts", putJSON(suggestedTipAmounts)); + } + if (!startParameter.empty()) { + args.emplace_back("start_parameter", startParameter); + } + if (!providerData.empty()) { + args.emplace_back("provider_data", providerData); + } + if (!photoUrl.empty()) { + args.emplace_back("photo_url", photoUrl); + } + if (photoSize) { + args.emplace_back("photo_size", photoSize); + } + if (photoWidth) { + args.emplace_back("photo_width", photoWidth); + } + if (photoHeight) { + args.emplace_back("photo_height", photoHeight); + } + if (needName) { + args.emplace_back("need_name", needName); + } + if (needPhoneNumber) { + args.emplace_back("need_phone_number", needPhoneNumber); + } + if (needEmail) { + args.emplace_back("need_email", needEmail); + } + if (needShippingAddress) { + args.emplace_back("need_shipping_address", needShippingAddress); + } + if (sendPhoneNumberToProvider) { + args.emplace_back("send_phone_number_to_provider", + sendPhoneNumberToProvider); + } + if (sendEmailToProvider) { + args.emplace_back("send_email_to_provider", sendEmailToProvider); + } + if (isFlexible) { + args.emplace_back("is_flexible", isFlexible); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendInvoice", args)); +} + +std::string ApiImpl::createInvoiceLink( + const std::string &title, const std::string &description, + const std::string &payload, const std::string &providerToken, + const std::string ¤cy, const std::vector &prices, + std::int32_t maxTipAmount, + const std::vector &suggestedTipAmounts, + const std::string &providerData, const std::string &photoUrl, + std::int32_t photoSize, std::int32_t photoWidth, std::int32_t photoHeight, + bool needName, bool needPhoneNumber, bool needEmail, + bool needShippingAddress, bool sendPhoneNumberToProvider, + bool sendEmailToProvider, bool isFlexible) const { + std::vector args; + args.reserve(20); + + args.emplace_back("title", title); + args.emplace_back("description", description); + args.emplace_back("payload", payload); + args.emplace_back("provider_token", providerToken); + args.emplace_back("currency", currency); + args.emplace_back("prices", putJSON(prices)); + args.emplace_back("max_tip_amount", maxTipAmount); + if (!suggestedTipAmounts.empty()) { + args.emplace_back("suggested_tip_amounts", putJSON(suggestedTipAmounts)); + } + if (!providerData.empty()) { + args.emplace_back("provider_data", providerData); + } + if (!photoUrl.empty()) { + args.emplace_back("photo_url", photoUrl); + } + if (photoSize) { + args.emplace_back("photo_size", photoSize); + } + if (photoWidth) { + args.emplace_back("photo_width", photoWidth); + } + if (photoHeight) { + args.emplace_back("photo_height", photoHeight); + } + if (needName) { + args.emplace_back("need_name", needName); + } + if (needPhoneNumber) { + args.emplace_back("need_phone_number", needPhoneNumber); + } + if (needEmail) { + args.emplace_back("need_email", needEmail); + } + if (needShippingAddress) { + args.emplace_back("need_shipping_address", needShippingAddress); + } + if (sendPhoneNumberToProvider) { + args.emplace_back("send_phone_number_to_provider", + sendPhoneNumberToProvider); + } + if (sendEmailToProvider) { + args.emplace_back("send_email_to_provider", sendEmailToProvider); + } + if (isFlexible) { + args.emplace_back("is_flexible", isFlexible); + } + + return sendRequest("createInvoiceLink", args).asString(); +} + +bool ApiImpl::answerShippingQuery( + const std::string &shippingQueryId, bool ok, + const std::vector &shippingOptions, + const std::string &errorMessage) const { + std::vector args; + args.reserve(4); + + args.emplace_back("shipping_query_id", shippingQueryId); + args.emplace_back("ok", ok); + if (!shippingOptions.empty()) { + args.emplace_back("shipping_options", putJSON(shippingOptions)); + } + if (!errorMessage.empty()) { + args.emplace_back("error_message", errorMessage); + } + + return sendRequest("answerShippingQuery", args).asBool(); +} + +bool ApiImpl::answerPreCheckoutQuery(const std::string &preCheckoutQueryId, bool ok, + const std::string &errorMessage) const { + std::vector args; + args.reserve(3); + + args.emplace_back("pre_checkout_query_id", preCheckoutQueryId); + args.emplace_back("ok", ok); + if (!errorMessage.empty()) { + args.emplace_back("error_message", errorMessage); + } + + return sendRequest("answerPreCheckoutQuery", args).asBool(); +} + +bool ApiImpl::setPassportDataErrors( + std::int64_t userId, + const std::vector &errors) const { + std::vector args; + args.reserve(2); + + args.emplace_back("user_id", userId); + args.emplace_back("errors", putJSON(errors)); + + return sendRequest("setPassportDataErrors", args).asBool(); +} + +Message::Ptr ApiImpl::sendGame(std::int64_t chatId, + const std::string &gameShortName, + ReplyParameters::Ptr replyParameters, + InlineKeyboardMarkup::Ptr replyMarkup, + bool disableNotification, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(8); - args.emplace_back("shipping_query_id", shippingQueryId); - args.emplace_back("ok", ok); - if (!shippingOptions.empty()) { - args.emplace_back("shipping_options", _tgTypeParser.parseArray(&TgTypeParser::parseShippingOption, shippingOptions)); - } - if (!errorMessage.empty()) { - args.emplace_back("error_message", errorMessage); - } + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("game_short_name", gameShortName); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendGame", args)); +} + +Message::Ptr ApiImpl::setGameScore(std::int64_t userId, std::int32_t score, + bool force, bool disableEditMessage, + std::int64_t chatId, std::int32_t messageId, + const std::string &inlineMessageId) const { + std::vector args; + args.reserve(7); + + args.emplace_back("user_id", userId); + args.emplace_back("score", score); + if (force) { + args.emplace_back("force", force); + } + if (disableEditMessage) { + args.emplace_back("disable_edit_message", disableEditMessage); + } + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } - return sendRequest("answerShippingQuery", args).get("", false); + return parse(sendRequest("setGameScore", args)); } -bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, - bool ok, - const std::string& errorMessage) const { - std::vector args; - args.reserve(3); +std::vector +ApiImpl::getGameHighScores(std::int64_t userId, std::int64_t chatId, + std::int32_t messageId, + const std::string &inlineMessageId) const { + std::vector args; + args.reserve(4); - args.emplace_back("pre_checkout_query_id", preCheckoutQueryId); - args.emplace_back("ok", ok); - if (!errorMessage.empty()) { - args.emplace_back("error_message", errorMessage); - } + args.emplace_back("user_id", userId); + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } - return sendRequest("answerPreCheckoutQuery", args).get("", false); + return parseArray(sendRequest("getGameHighScores", args)); } -bool Api::setPassportDataErrors(std::int64_t userId, - const std::vector& errors) const { - std::vector args; - args.reserve(2); - - args.emplace_back("user_id", userId); - args.emplace_back("errors", _tgTypeParser.parseArray(&TgTypeParser::parsePassportElementError, errors)); +std::string ApiImpl::downloadFile(const std::string &filePath, + const std::vector &args) const { + std::string url(_url); + url += "/file/bot"; + url += _token; + url += "/"; + url += filePath; - return sendRequest("setPassportDataErrors", args).get("", false); + return _httpClient->makeRequest(url, args); } -Message::Ptr Api::sendGame(std::int64_t chatId, - const std::string& gameShortName, - ReplyParameters::Ptr replyParameters, - InlineKeyboardMarkup::Ptr replyMarkup, - bool disableNotification, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(8); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("game_short_name", gameShortName); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendGame", args)); -} - -Message::Ptr Api::setGameScore(std::int64_t userId, - std::int32_t score, - bool force, - bool disableEditMessage, - std::int64_t chatId, - std::int32_t messageId, - const std::string& inlineMessageId) const { - std::vector args; - args.reserve(7); - - args.emplace_back("user_id", userId); - args.emplace_back("score", score); - if (force) { - args.emplace_back("force", force); - } - if (disableEditMessage) { - args.emplace_back("disable_edit_message", disableEditMessage); - } - if (chatId) { - args.emplace_back("chat_id", chatId); - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } +bool ApiImpl::blockedByUser(std::int64_t chatId) const { + bool isBotBlocked = false; - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("setGameScore", args)); -} + try { + sendChatAction(chatId, "typing"); -std::vector Api::getGameHighScores(std::int64_t userId, - std::int64_t chatId, - std::int32_t messageId, - const std::string& inlineMessageId) const { - std::vector args; - args.reserve(4); + } catch (std::exception &e) { + std::string error = e.what(); - args.emplace_back("user_id", userId); - if (chatId) { - args.emplace_back("chat_id", chatId); + if (error.compare("Forbidden: bot was blocked by the user") == 0) { + isBotBlocked = true; } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args)); -} + } -std::string Api::downloadFile(const std::string& filePath, - const std::vector& args) const { - std::string url(_url); - url += "/file/bot"; - url += _token; - url += "/"; - url += filePath; - - return _httpClient.makeRequest(url, args); + return isBotBlocked; } -bool Api::blockedByUser(std::int64_t chatId) const { - bool isBotBlocked = false; - - try { - sendChatAction(chatId, "typing"); - - } catch (std::exception& e) { - std::string error = e.what(); +constexpr bool kSendRequestDebug = false; - if (error.compare("Forbidden: bot was blocked by the user") == 0) { - isBotBlocked = true; - } - } +Json::Value +TgBot::ApiImpl::sendRequest(const std::string &method, + const std::vector &args) const { + std::string url(_url); + url += "/bot"; + url += _token; + url += "/"; + url += method; - return isBotBlocked; -} - -boost::property_tree::ptree Api::sendRequest(const std::string& method, const std::vector& args) const { - std::string url(_url); - url += "/bot"; - url += _token; - url += "/"; - url += method; - - int requestRetryBackoff = _httpClient.getRequestBackoff(); - int retries = 0; - while (1) - { - try { - std::string serverResponse = _httpClient.makeRequest(url, args); - - if (!serverResponse.compare(0, 6, "")) { - std::string message = "tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token."; - throw TgException(message, TgException::ErrorCode::HtmlResponse); - } - - boost::property_tree::ptree result; - try { - result = _tgTypeParser.parseJson(serverResponse); - } catch (boost::property_tree::ptree_error& e) { - std::string message = "tgbot-cpp library can't parse json response. " + std::string(e.what()); - - throw TgException(message, TgException::ErrorCode::InvalidJson); - } - - if (result.get("ok", false)) { - return result.get_child("result"); - } else { - std::string message = result.get("description", ""); - size_t errorCode = result.get("error_code", 0u); - - throw TgException(message, static_cast(errorCode)); - } - } catch (...) { - int max_retries = _httpClient.getRequestMaxRetries(); - if ((max_retries >= 0) && (retries == max_retries)) { - throw; - } else { - std::this_thread::sleep_for(std::chrono::seconds(requestRetryBackoff)); - retries++; - continue; - } - } + int requestRetryBackoff = _httpClient->getRequestBackoff(); + int retries = 0; + if constexpr (kSendRequestDebug) { + std::cout << "tgbot-cpp: Sending request: " << method << std::endl; + for (const auto &arg : args) { + std::cout << arg.name << " is " << arg.value << std::endl; } -} -} + } + while (1) { + try { + std::string serverResponse = _httpClient->makeRequest(url, args); + + if (!serverResponse.compare(0, 6, "")) { + std::string message = + "tgbot-cpp library have got html page instead of json response. " + "Maybe you entered wrong bot token."; + throw TgException(message, TgException::ErrorCode::HtmlResponse); + } + + Json::Value result; + Json::Reader reader; + if (!reader.parse(serverResponse, result, false)){ + std::string message = "tgbot-cpp library can't parse json response."; + throw TgException(message, TgException::ErrorCode::InvalidJson); + } + + if (result["ok"].asBool()) { + return result["result"]; + } else { + std::string message = result["description"].asString(); + int errorCode = result["error_code"].as(); + + throw TgException(message, + static_cast(errorCode)); + } + } catch (const TgException& ex) { + if constexpr (kSendRequestDebug) { + std::cerr << "tgbot-cpp: Error: " << ex.what() << std::endl; + } + int max_retries = _httpClient->getRequestMaxRetries(); + if ((max_retries >= 0) && (retries == max_retries)) { + throw; + } else { + std::this_thread::sleep_for(std::chrono::seconds(requestRetryBackoff)); + retries++; + continue; + } + } + } +} +} // namespace TgBot diff --git a/src/Bot.cpp b/src/Bot.cpp index 080b9a2a5..1e6d20482 100644 --- a/src/Bot.cpp +++ b/src/Bot.cpp @@ -1,3 +1,4 @@ +#include "tgbot/ApiImpl.h" #include "tgbot/net/BoostHttpOnlySslClient.h" #include "tgbot/Bot.h" @@ -8,16 +9,15 @@ namespace TgBot { -Bot::Bot(std::string token, const HttpClient& httpClient, const std::string& url) +Bot::Bot(std::string token, std::unique_ptr httpClient, const std::string& url) : _token(std::move(token)) - , _api(_token, httpClient, url) + , _api(std::make_unique(_token, std::move(httpClient), url)) , _eventBroadcaster(std::make_unique()) , _eventHandler(getEvents()) { } -HttpClient& Bot::_getDefaultHttpClient() { - static BoostHttpOnlySslClient instance; - return instance; +std::unique_ptr Bot::_getDefaultHttpClient() { + return std::make_unique(); } } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index d3e9bd921..de1f91b3c 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1,153 +1,440 @@ -#include "tgbot/TgTypeParser.h" +#include +#include +#include + +#include +#include namespace TgBot { -Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); - result->updateId = data.get("update_id", 0); - result->message = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "message"); - result->editedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message"); - result->channelPost = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "channel_post"); - result->editedChannelPost = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_channel_post"); - result->businessConnection = tryParseJson(&TgTypeParser::parseJsonAndGetBusinessConnection, data, "business_connection"); - result->businessMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "business_message"); - result->editedBusinessMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_business_message"); - result->deletedBusinessMessages = tryParseJson(&TgTypeParser::parseJsonAndGetBusinessMessagesDeleted, data, "deleted_business_messages"); - result->messageReaction = tryParseJson(&TgTypeParser::parseJsonAndGetMessageReactionUpdated, data, "message_reaction"); - result->messageReactionCount = tryParseJson(&TgTypeParser::parseJsonAndGetMessageReactionCountUpdated, data, "message_reaction_count"); - result->inlineQuery = tryParseJson(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query"); - result->chosenInlineResult = tryParseJson(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result"); - result->callbackQuery = tryParseJson(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query"); - result->shippingQuery = tryParseJson(&TgTypeParser::parseJsonAndGetShippingQuery, data, "shipping_query"); - result->preCheckoutQuery = tryParseJson(&TgTypeParser::parseJsonAndGetPreCheckoutQuery, data, "pre_checkout_query"); - result->poll = tryParseJson(&TgTypeParser::parseJsonAndGetPoll, data, "poll"); - result->pollAnswer = tryParseJson(&TgTypeParser::parseJsonAndGetPollAnswer, data, "poll_answer"); - result->myChatMember = tryParseJson(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "my_chat_member"); - result->chatMember = tryParseJson(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "chat_member"); - result->chatJoinRequest = tryParseJson(&TgTypeParser::parseJsonAndGetChatJoinRequest, data, "chat_join_request"); - result->chatBoost = tryParseJson(&TgTypeParser::parseJsonAndGetChatBoostUpdated, data, "chat_boost"); - result->removedChatBoost = tryParseJson(&TgTypeParser::parseJsonAndGetChatBoostRemoved, data, "removed_chat_boost"); - return result; -} - -std::string TgTypeParser::parseUpdate(const Update::Ptr& object) const { - if (!object) { - return ""; +// T should be instance of std::shared_ptr. +template +std::shared_ptr parse(const Json::Value &data, const std::string &key) { + if (!data.isMember(key)) { + return nullptr; } - std::string result; - result += '{'; - appendToJson(result, "update_id", object->updateId); - appendToJson(result, "message", parseMessage(object->message)); - appendToJson(result, "edited_message", parseMessage(object->editedMessage)); - appendToJson(result, "channel_post", parseMessage(object->channelPost)); - appendToJson(result, "edited_channel_post", parseMessage(object->editedChannelPost)); - appendToJson(result, "business_connection", parseBusinessConnection(object->businessConnection)); - appendToJson(result, "business_message", parseMessage(object->businessMessage)); - appendToJson(result, "edited_business_message", parseMessage(object->editedBusinessMessage)); - appendToJson(result, "deleted_business_messages", parseBusinessMessagesDeleted(object->deletedBusinessMessages)); - appendToJson(result, "message_reaction", parseMessageReactionUpdated(object->messageReaction)); - appendToJson(result, "message_reaction_count", parseMessageReactionCountUpdated(object->messageReactionCount)); - appendToJson(result, "inline_query", parseInlineQuery(object->inlineQuery)); - appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult)); - appendToJson(result, "callback_query", parseCallbackQuery(object->callbackQuery)); - appendToJson(result, "shipping_query", parseShippingQuery(object->shippingQuery)); - appendToJson(result, "pre_checkout_query", parsePreCheckoutQuery(object->preCheckoutQuery)); - appendToJson(result, "poll", parsePoll(object->poll)); - appendToJson(result, "poll_answer", parsePollAnswer(object->pollAnswer)); - appendToJson(result, "my_chat_member", parseChatMemberUpdated(object->myChatMember)); - appendToJson(result, "chat_member", parseChatMemberUpdated(object->chatMember)); - appendToJson(result, "chat_join_request", parseChatJoinRequest(object->chatJoinRequest)); - appendToJson(result, "chat_boost", parseChatBoostUpdated(object->chatBoost)); - appendToJson(result, "removed_chat_boost", parseChatBoostRemoved(object->removedChatBoost)); - removeLastComma(result); - result += '}'; - return result; -} - -WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); - result->url = data.get("url", ""); - result->hasCustomCertificate = data.get("has_custom_certificate", false); - result->pendingUpdateCount = data.get("pending_update_count", 0); - result->ipAddress = data.get("ip_address", ""); - result->lastErrorDate = data.get("last_error_date", 0); - result->lastErrorMessage = data.get("last_error_message", ""); - result->lastSynchronizationErrorDate = data.get("last_synchronization_error_date", 0); - result->maxConnections = data.get("max_connections", 0); - result->allowedUpdates = parseJsonAndGetArray( - [] (const boost::property_tree::ptree& innerData)->std::string { - return innerData.get(""); - }, data, "allowed_updates"); - return result; -} - -std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const { - if (!object) { - return ""; + return parse(data[key]); +} + +template +struct JsonExtractor { + explicit JsonExtractor(const Json::Value &data) : value_(data.as()) {} + JsonExtractor(const Json::Value &data, const T default_value) { + if (data.type() == Json::nullValue) { + value_ = default_value; + } else { + value_ = data.as(); + } } - std::string result; - result += '{'; - appendToJson(result, "url", object->url); - appendToJson(result, "has_custom_certificate", object->hasCustomCertificate); - appendToJson(result, "pending_update_count", object->pendingUpdateCount); - appendToJson(result, "ip_address", object->ipAddress); - appendToJson(result, "last_error_date", object->lastErrorDate); - appendToJson(result, "last_error_message", object->lastErrorMessage); - appendToJson(result, "last_synchronization_error_date", object->lastSynchronizationErrorDate); - appendToJson(result, "max_connections", object->maxConnections); - appendToJson(result, "allowed_updates", parseArray( - [] (const std::string& s)->std::string { - return s; - }, object->allowedUpdates)); - removeLastComma(result); - result += '}'; - return result; -} - -User::Ptr TgTypeParser::parseJsonAndGetUser(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); - result->id = data.get("id", 0); - result->isBot = data.get("is_bot", false); - result->firstName = data.get("first_name", ""); - result->lastName = data.get("last_name", ""); - result->username = data.get("username", ""); - result->languageCode = data.get("language_code", ""); - result->isPremium = data.get("is_premium", false); - result->addedToAttachmentMenu = data.get("added_to_attachment_menu", false); - result->canJoinGroups = data.get("can_join_groups", false); - result->canReadAllGroupMessages = data.get("can_read_all_group_messages", false); - result->supportsInlineQueries = data.get("supports_inline_queries", false); - result->canConnectToBusiness = data.get("can_connect_to_business", false); - return result; -} - -std::string TgTypeParser::parseUser(const User::Ptr& object) const { - if (!object) { - return ""; + + operator T() const { return value_; } + + private: + T value_; +}; + +struct JsonWrapper { + JsonWrapper() = default; + + template + void put(const char (&key)[N], T &&value) { + static_assert(N > 1, "Key must not be empty"); + data_[key] = std::forward(value); + } + // Overload for JSON::Value to avoid null values. + template + void put(const char (&key)[N], Json::Value &&value) { + if (value.type() != Json::nullValue) { + data_[key] = std::forward(value); + } } - std::string result; - result += '{'; - appendToJson(result, "id", object->id); - appendToJson(result, "is_bot", object->isBot); - appendToJson(result, "first_name", object->firstName); - appendToJson(result, "last_name", object->lastName); - appendToJson(result, "username", object->username); - appendToJson(result, "language_code", object->languageCode); - appendToJson(result, "is_premium", object->isPremium); - appendToJson(result, "added_to_attachment_menu", object->addedToAttachmentMenu); - appendToJson(result, "can_join_groups", object->canJoinGroups); - appendToJson(result, "can_read_all_group_messages", object->canReadAllGroupMessages); - appendToJson(result, "supports_inline_queries", object->supportsInlineQueries); - appendToJson(result, "can_connect_to_business", object->canConnectToBusiness); - removeLastComma(result); - result += '}'; - return result; -} - -Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& data) const { + + static void merge(Json::Value &thiz, const Json::Value &other) { + if (!thiz.isObject() || !other.isObject()) { + return; + } + + for (const auto &key : other.getMemberNames()) { + if (thiz[key].isObject()) { + merge(thiz[key], other[key]); + } else { + thiz[key] = other[key]; + } + } + } + + void operator+=(const Json::Value &other) { merge(data_, other); } + + JsonWrapper &operator=(Json::Value &&other) { + data_ = std::forward(other); + return *this; + } + operator Json::Value() const { return data_; } + + private: + Json::Value data_; +}; + +using IntElement = JsonExtractor; +using StringElement = JsonExtractor; +using BoolElement = JsonExtractor; +using UintElement = JsonExtractor; +using LongElement = JsonExtractor; +using FloatElement = JsonExtractor; + +#define AS_JSON_ELEMENT(type, key) (type(data[key])) +#define AS_JSON_ELEMENT_DEFAULT(type, key, def) (type(data[key], def)) +#define AS_BOOL(key) AS_JSON_ELEMENT(BoolElement, key) +#define AS_INT(key) AS_JSON_ELEMENT(IntElement, key) +#define AS_LONG(key) AS_JSON_ELEMENT(LongElement, key) +#define AS_UINT(key) AS_JSON_ELEMENT(UintElement, key) +#define AS_STRING(key) AS_JSON_ELEMENT(StringElement, key) +#define AS_FLOAT(key) AS_JSON_ELEMENT(FloatElement, key) +#define AS_BYTE(key) (std::uint8_t) AS_INT(key) +#define AS_BOOL_DEFAULT(key, def) AS_JSON_ELEMENT_DEFAULT(BoolElement, key, def) +#define AS_FLOAT_DEFAULT(key, def) \ + AS_JSON_ELEMENT_DEFAULT(FloatElement, key, def) + +// Pre-defined parsing functions for known types. +DECLARE_PARSER_FROM_JSON(Message) { + auto result = std::make_shared(); + result->messageId = AS_INT("message_id"); + result->messageThreadId = AS_INT("message_thread_id"); + result->from = parse(data, "from"); + result->senderChat = parse(data, "sender_chat"); + result->senderBoostCount = AS_INT("sender_boost_count"); + result->senderBusinessBot = parse(data, "sender_business_bot"); + result->date = AS_UINT("date"); + result->businessConnectionId = AS_STRING("business_connection_id"); + result->chat = parse(data, "chat"); + result->forwardOrigin = parse(data, "forward_origin"); + result->isTopicMessage = AS_BOOL("is_topic_message"); + result->isAutomaticForward = AS_BOOL("is_automatic_forward"); + result->replyToMessage = parse(data, "reply_to_message"); + result->externalReply = parse(data, "external_reply"); + result->quote = parse(data, "quote"); + result->replyToStory = parse(data, "reply_to_story"); + result->viaBot = parse(data, "via_bot"); + result->editDate = AS_UINT("edit_date"); + result->hasProtectedContent = AS_BOOL("has_protected_content"); + result->isFromOffline = AS_BOOL("is_from_offline"); + result->mediaGroupId = AS_STRING("media_group_id"); + result->authorSignature = AS_STRING("author_signature"); + result->text = AS_STRING("text"); + result->entities = parseArray(data, "entities"); + result->linkPreviewOptions = + parse(data, "link_preview_options"); + result->animation = parse(data, "animation"); + result->audio = parse