From 89fba68b63057b412140db544a075304ea8b79d7 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sat, 5 Nov 2022 21:53:54 +0100 Subject: Update to Bot API 6.3 --- README.md | 2 +- include/tgbot/Api.h | 291 +++++++++++++++++++------- include/tgbot/TgTypeParser.h | 16 ++ include/tgbot/types/Chat.h | 42 +++- include/tgbot/types/ChatAdministratorRights.h | 6 + include/tgbot/types/ChatMemberAdministrator.h | 8 +- include/tgbot/types/ChatMemberRestricted.h | 12 +- include/tgbot/types/ChatPermissions.h | 100 +++++---- include/tgbot/types/ForumTopic.h | 41 ++++ include/tgbot/types/ForumTopicClosed.h | 21 ++ include/tgbot/types/ForumTopicCreated.h | 36 ++++ include/tgbot/types/ForumTopicReopened.h | 21 ++ include/tgbot/types/Message.h | 61 +++++- src/Api.cpp | 258 ++++++++++++++++++----- src/TgTypeParser.cpp | 125 ++++++++++- 15 files changed, 842 insertions(+), 198 deletions(-) create mode 100644 include/tgbot/types/ForumTopic.h create mode 100644 include/tgbot/types/ForumTopicClosed.h create mode 100644 include/tgbot/types/ForumTopicCreated.h create mode 100644 include/tgbot/types/ForumTopicReopened.h diff --git a/README.md b/README.md index ea92550..30c4019 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp). ## State -- [x] Bot API 3.0 ~ 6.2 +- [x] Bot API 3.0 ~ 6.3 ## Sample diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 9dd2f5e..7dceb75 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -25,6 +25,7 @@ #include "tgbot/types/LabeledPrice.h" #include "tgbot/types/ShippingOption.h" #include "tgbot/types/BotCommand.h" +#include "tgbot/types/ForumTopic.h" #include #include @@ -170,6 +171,7 @@ public: * @param entities Optional. A JSON-serialized list of special entities that appear in message text, which can be specified instead of parseMode * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -183,7 +185,8 @@ public: bool disableNotification = false, const std::vector& entities = std::vector(), bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to forward messages of any kind. @@ -195,6 +198,7 @@ public: * @param messageId Message identifier in the chat specified in fromChatId * @param disableNotification Optional. Sends the message silently. 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. */ @@ -202,7 +206,8 @@ public: boost::variant fromChatId, std::int32_t messageId, bool disableNotification = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to copy messages of any kind. @@ -222,6 +227,7 @@ public: * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, 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. */ @@ -235,7 +241,8 @@ public: std::int32_t replyToMessageId = 0, bool allowSendingWithoutReply = false, GenericReply::Ptr replyMarkup = std::make_shared(), - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send photos. @@ -250,6 +257,7 @@ public: * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -262,7 +270,8 @@ public: bool disableNotification = false, const std::vector& captionEntities = std::vector(), bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send audio files, if you want Telegram clients to display them in the music player. @@ -286,6 +295,7 @@ public: * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -302,7 +312,8 @@ public: bool disableNotification = false, const std::vector& captionEntities = std::vector(), bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send general files. @@ -321,6 +332,7 @@ public: * @param disableContentTypeDetection Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -335,7 +347,8 @@ public: const std::vector& captionEntities = std::vector(), bool disableContentTypeDetection = false, bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). @@ -357,6 +370,7 @@ public: * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -374,7 +388,8 @@ public: bool disableNotification = false, const std::vector& captionEntities = std::vector(), bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). @@ -395,6 +410,7 @@ public: * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -411,7 +427,8 @@ public: bool disableNotification = false, const std::vector& captionEntities = std::vector(), bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. @@ -430,6 +447,7 @@ public: * @param captionEntities Optional. A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parseMode * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -443,7 +461,8 @@ public: bool disableNotification = false, const std::vector& captionEntities = std::vector(), bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send video messages. @@ -460,6 +479,7 @@ public: * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -472,7 +492,8 @@ public: boost::variant thumb = "", GenericReply::Ptr replyMarkup = std::make_shared(), bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send a group of photos, videos, documents or audios as an album. @@ -485,6 +506,7 @@ public: * @param replyToMessageId Optional. If the messages are a reply, ID of the original message * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @param protectContent Optional. Protects the contents of the sent messages 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, an array of Messages that were sent is returned. */ @@ -493,7 +515,8 @@ public: bool disableNotification = false, std::int32_t replyToMessageId = 0, bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send point on the map. @@ -510,6 +533,7 @@ public: * @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 allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -524,7 +548,8 @@ public: std::int32_t heading = 0, std::int32_t proximityAlertRadius = 0, bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to edit live location messages. @@ -585,6 +610,7 @@ public: * @param googlePlaceType Optional. Google Places type of the venue. (See https://developers.google.com/places/web-service/supported_types) * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -601,7 +627,8 @@ public: const std::string& googlePlaceId = "", const std::string& googlePlaceType = "", bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send phone contacts. @@ -616,6 +643,7 @@ public: * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove keyboard or to force a reply from the user. * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -628,7 +656,8 @@ public: std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send a native poll. @@ -651,6 +680,7 @@ public: * @param isClosed Optional. Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -671,7 +701,8 @@ public: std::int32_t closeDate = 0, bool isClosed = false, bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to send an animated emoji that will display a random value. @@ -683,6 +714,7 @@ public: * @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 allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @param protectContent Optional. Protects the contents of the sent message from forwarding + * @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. */ @@ -692,7 +724,8 @@ public: GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& emoji = "", bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method when you need to tell the user that something is happening on the bot's side. @@ -805,17 +838,18 @@ public: * * @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 create channel posts, channels only - * @param canEditMessages Optional. Pass True, if the administrator can edit messages of other users and can pin messages, 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, 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 he has 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, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups 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 + * @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 create channel posts, channels only + * @param canEditMessages Optional. Pass True if the administrator can edit messages of other users and can pin messages, 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, 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 he has 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, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups 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 + * @param canManageTopics Optional. Pass True if the user is allowed to create, rename, close, and reopen forum topics, supergroups only * * @return Returns True on success. */ @@ -831,7 +865,8 @@ public: bool isAnonymous = false, bool canManageChat = false, bool canManageVideoChats = false, - bool canRestrictMembers = false) const; + bool canRestrictMembers = false, + bool canManageTopics = false) const; /** * @brief Use this method to set a custom title for an administrator in a supergroup promoted by the bot. @@ -1094,60 +1129,153 @@ public: Chat::Ptr getChat(boost::variant chatId) const; /** - * @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. - */ + * @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; /** - * @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. - */ + * @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; /** - * @brief Use this method to get information about a member of a 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. - */ + * @brief Use this method to get information about a member of a 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; /** - * @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. - */ + * @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; /** - * @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. - */ + * @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; + /** + * @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; + + /** + * @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 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 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; + + /** + * @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 New topic name, 1-128 characters + * @param iconCustomEmojiId New unique identifier of the custom emoji shown as the topic icon. Use Api::getForumTopicIconStickers to get all allowed custom emoji identifiers + * + * @return Returns True on success. + */ + bool editForumTopic(boost::variant chatId, + std::int32_t messageThreadId, + const std::string& name, + const std::string& iconCustomEmojiId) const; + + /** + * @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; + + /** + * @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; + + /** + * @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; + + /** + * @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; + /** * @brief Use this method to send answers to callback queries sent from inline keyboards. * @@ -1317,15 +1445,15 @@ public: GenericReply::Ptr replyMarkup = std::make_shared()) const; /** - * @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. - */ + * @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 = "", @@ -1348,6 +1476,7 @@ public: * @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. @@ -1373,6 +1502,7 @@ public: * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -1382,7 +1512,8 @@ public: GenericReply::Ptr replyMarkup = std::make_shared(), bool disableNotification = false, bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to get a sticker set. @@ -1567,6 +1698,7 @@ public: * @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 + * @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. */ @@ -1596,7 +1728,8 @@ public: std::int32_t maxTipAmount = 0, const std::vector& suggestedTipAmounts = std::vector(), const std::string& startParameter = "", - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to create a link for an invoice. @@ -1704,6 +1837,7 @@ public: * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. * @param allowSendingWithoutReply Optional. Pass True if the message should be sent even if the specified replied-to message is not found * @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 On success, the sent Message is returned. */ @@ -1713,7 +1847,8 @@ public: InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared(), bool disableNotification = false, bool allowSendingWithoutReply = false, - bool protectContent = false) const; + bool protectContent = false, + std::int32_t messageThreadId = 0) const; /** * @brief Use this method to set the score of the specified user in a game message. diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index e7f4cd5..b303c47 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -26,6 +26,9 @@ #include "tgbot/types/WebAppData.h" #include "tgbot/types/ProximityAlertTriggered.h" #include "tgbot/types/MessageAutoDeleteTimerChanged.h" +#include "tgbot/types/ForumTopicCreated.h" +#include "tgbot/types/ForumTopicClosed.h" +#include "tgbot/types/ForumTopicReopened.h" #include "tgbot/types/VideoChatScheduled.h" #include "tgbot/types/VideoChatStarted.h" #include "tgbot/types/VideoChatEnded.h" @@ -56,6 +59,7 @@ #include "tgbot/types/ChatJoinRequest.h" #include "tgbot/types/ChatPermissions.h" #include "tgbot/types/ChatLocation.h" +#include "tgbot/types/ForumTopic.h" #include "tgbot/types/BotCommand.h" #include "tgbot/types/BotCommandScope.h" #include "tgbot/types/BotCommandScopeDefault.h" @@ -226,6 +230,15 @@ public: MessageAutoDeleteTimerChanged::Ptr parseJsonAndGetMessageAutoDeleteTimerChanged(const boost::property_tree::ptree& data) const; std::string parseMessageAutoDeleteTimerChanged(const MessageAutoDeleteTimerChanged::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; + + ForumTopicReopened::Ptr parseJsonAndGetForumTopicReopened(const boost::property_tree::ptree& data) const; + std::string parseForumTopicReopened(const ForumTopicReopened::Ptr& object) const; + VideoChatScheduled::Ptr parseJsonAndGetVideoChatScheduled(const boost::property_tree::ptree& data) const; std::string parseVideoChatScheduled(const VideoChatScheduled::Ptr& object) const; @@ -316,6 +329,9 @@ public: ChatLocation::Ptr parseJsonAndGetChatLocation(const boost::property_tree::ptree& data) const; std::string parseChatLocation(const ChatLocation::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; diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h index 4a3f761..2d31289 100644 --- a/include/tgbot/types/Chat.h +++ b/include/tgbot/types/Chat.h @@ -8,6 +8,7 @@ #include #include #include +#include namespace TgBot { @@ -33,8 +34,8 @@ public: /** * @brief Unique identifier for this chat. * - * This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. - * But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. */ std::int64_t id; @@ -63,107 +64,142 @@ public: */ std::string lastName; + /** + * @brief Optional. True, if the supergroup chat is a forum (has topics enabled) + */ + bool isForum; + /** * @brief Optional. Chat photo. + * * Returned only in Api::getChat. */ ChatPhoto::Ptr photo; + /** + * @brief Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels. + * + * Returned only in Api::getChat. + */ + std::vector activeUsernames; + + /** + * @brief Optional. Custom emoji identifier of emoji status of the other party in a private chat. + * + * Returned only in Api::getChat. + */ + std::string emojiStatusCustomEmojiId; + /** * @brief Optional. Bio of the other party in a private chat. + * * Returned only in Api::getChat. */ std::string bio; /** * @brief Optional. True, if privacy settings of the other party in the private chat allows to use tg://user?id= links only in chats with the user. + * * Returned only in Api::getChat. */ bool hasPrivateForwards; /** * @brief Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. + * * Returned only in Api::getChat. */ bool hasRestrictedVoiceAndVideoMessages; /** * @brief Optional. True, if users need to join the supergroup before they can send messages. + * * Returned only in Api::getChat. */ bool joinToSendMessages; /** * @brief Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. + * * Returned only in Api::getChat. */ bool joinByRequest; /** * @brief Optional. Description, for groups, supergroups and channel chats. + * * Returned only in Api::getChat. */ std::string description; /** * @brief Optional. Primary invite link, for groups, supergroups and channel chats. + * * Returned only in Api::getChat. */ std::string inviteLink; /** * @brief Optional. The most recent pinned message (by sending date). + * * Returned only in Api::getChat. */ std::shared_ptr pinnedMessage; /** * @brief Optional. Default chat member permissions, for groups and supergroups. + * * Returned only in Api::getChat. */ ChatPermissions::Ptr permissions; /** * @brief Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user; in seconds. + * * Returned only in Api::getChat. */ std::int32_t slowModeDelay; /** * @brief Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. + * * Returned only in Api::getChat. */ std::int32_t messageAutoDeleteTime; /** * @brief Optional. True, if messages from the chat can't be forwarded to other chats. + * * Returned only in Api::getChat. */ bool hasProtectedContent; /** * @brief Optional. For supergroups, name of group sticker set. + * * Returned only in Api::getChat. */ std::string stickerSetName; /** * @brief Optional. True, if the bot can change the group sticker set. + * * Returned only in Api::getChat. */ bool canSetStickerSet; /** * @brief Optional. Unique identifier for the linked chat, i.e. the discussion group identifier for a channel and vice versa; for supergroups and channel chats. - * Returned only in Api::getChat. * * This identifier may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. * But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + * Returned only in Api::getChat. */ std::int64_t linkedChatId; /** * @brief Optional. For supergroups, the location to which the supergroup is connected. + * * Returned only in Api::getChat. */ ChatLocation::Ptr location; diff --git a/include/tgbot/types/ChatAdministratorRights.h b/include/tgbot/types/ChatAdministratorRights.h index 52c70ca..8e20b18 100644 --- a/include/tgbot/types/ChatAdministratorRights.h +++ b/include/tgbot/types/ChatAdministratorRights.h @@ -21,6 +21,7 @@ public: /** * @brief True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. + * * Implied by any other administrator privilege */ bool canManageChat; @@ -69,6 +70,11 @@ public: * @brief Optional. True, if the user is allowed to pin messages; groups and supergroups only */ bool canPinMessages; + + /** + * @brief Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only + */ + bool canManageTopics; }; } diff --git a/include/tgbot/types/ChatMemberAdministrator.h b/include/tgbot/types/ChatMemberAdministrator.h index 02fc6bd..714ed1d 100644 --- a/include/tgbot/types/ChatMemberAdministrator.h +++ b/include/tgbot/types/ChatMemberAdministrator.h @@ -35,6 +35,7 @@ public: /** * @brief True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. + * * Implied by any other administrator privilege */ bool canManageChat; @@ -45,7 +46,7 @@ public: bool canDeleteMessages; /** - * @brief rue, if the administrator can manage video chats + * @brief True, if the administrator can manage video chats */ bool canManageVideoChats; @@ -84,6 +85,11 @@ public: */ bool canPinMessages; + /** + * @brief Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only + */ + bool canManageTopics; + /** * @brief Optional. Custom title for this user */ diff --git a/include/tgbot/types/ChatMemberRestricted.h b/include/tgbot/types/ChatMemberRestricted.h index d64c849..ab19b03 100644 --- a/include/tgbot/types/ChatMemberRestricted.h +++ b/include/tgbot/types/ChatMemberRestricted.h @@ -10,6 +10,7 @@ namespace TgBot { /** * @brief Represents a chat member that is under certain restrictions in the chat. + * * Supergroups only. * * @ingroup types @@ -40,10 +41,15 @@ public: bool canInviteUsers; /** - * @brief True, if the user is allowed to pin messages; groups and supergroups only + * @brief True, if the user is allowed to pin messages */ bool canPinMessages; + /** + * @brief True, if the user is allowed to create forum topics + */ + bool canManageTopics; + /** * @brief True, if the user is allowed to send text messages, contacts, locations and venues */ @@ -70,7 +76,9 @@ public: bool canAddWebPagePreviews; /** - * @brief Date when restrictions will be lifted for this user; unix time + * @brief Date when restrictions will be lifted for this user; unix time. + * + * If 0, then the user is restricted forever */ std::uint32_t untilDate; }; diff --git a/include/tgbot/types/ChatPermissions.h b/include/tgbot/types/ChatPermissions.h index e6500db..0d8e056 100644 --- a/include/tgbot/types/ChatPermissions.h +++ b/include/tgbot/types/ChatPermissions.h @@ -1,63 +1,71 @@ -#ifndef TGBOT_CPP_CHATPERMISSIONS_H -#define TGBOT_CPP_CHATPERMISSIONS_H +#ifndef TGBOT_CHATPERMISSIONS_H +#define TGBOT_CHATPERMISSIONS_H #include -#include namespace TgBot { - /** - * @brief This object describes actions that a non-administrator user is allowed to take in a chat. - * @ingroup types - */ - - class ChatPermissions { - public: - typedef std::shared_ptr Ptr; +/** + * @brief Describes actions that a non-administrator user is allowed to take in a chat. + * + * @ingroup types + */ - /** - * @brief Optional. True, if the user is allowed to send text messages, contacts, locations and venues. - */ - bool canSendMessages = false; +class ChatPermissions { +public: + typedef std::shared_ptr Ptr; - /** - * @brief Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages. - */ - bool canSendMediaMessages = false; - - /** - * @brief Optional. True, if the user is allowed to send polls, implies can_send_messages. - */ - bool canSendPolls = false; + /** + * @brief Optional. True, if the user is allowed to send text messages, contacts, locations and venues + */ + bool canSendMessages; - /** - * @brief Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages. - */ - bool canSendOtherMessages = false; + /** + * @brief Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies canSendMessages + */ + bool canSendMediaMessages; - /** - * @brief Optional. True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages. - */ - bool canAddWebPagePreviews = false; + /** + * @brief Optional. True, if the user is allowed to send polls, implies canSendMessages + */ + bool canSendPolls; - /** - * @brief Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups. - */ - bool canChangeInfo = false; + /** + * @brief Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, implies canSendMediaMessages + */ + bool canSendOtherMessages; - /** - * @brief Optional. True, if the user is allowed to invite new users to the chat. - */ - bool canInviteUsers = false; + /** + * @brief Optional. True, if the user is allowed to add web page previews to their messages, implies canSendMediaMessages + */ + bool canAddWebPagePreviews; - /** - * @brief Optional. True, if the user is allowed to pin messages. Ignored in public supergroups. - */ - bool canPinMessages = false; + /** + * @brief Optional. True, if the user is allowed to change the chat title, photo and other settings. + * + * Ignored in public supergroups + */ + bool canChangeInfo; + /** + * @brief Optional. True, if the user is allowed to invite new users to the chat + */ + bool canInviteUsers; + /** + * @brief Optional. True, if the user is allowed to pin messages. + * + * Ignored in public supergroups + */ + bool canPinMessages; - }; + /** + * @brief Optional. True, if the user is allowed to create forum topics. + * + * If omitted defaults to the value of canPinMessages + */ + bool canManageTopics; +}; } -#endif //TGBOT_CPP_CHATPERMISSIONS_H +#endif //TGBOT_CHATPERMISSIONS_H diff --git a/include/tgbot/types/ForumTopic.h b/include/tgbot/types/ForumTopic.h new file mode 100644 index 0000000..9821cd1 --- /dev/null +++ b/include/tgbot/types/ForumTopic.h @@ -0,0 +1,41 @@ +#ifndef TGBOT_FORUMTOPIC_H +#define TGBOT_FORUMTOPIC_H + +#include +#include +#include + +namespace TgBot { + +/** + * @brief This object represents a forum topic. + * + * @ingroup types + */ +class ForumTopic { +public: + typedef std::shared_ptr Ptr; + + /** + * @brief Unique identifier of the forum topic + */ + std::int32_t messageThreadId; + + /** + * @brief Name of the topic + */ + std::string name; + + /** + * @brief Color of the topic icon in RGB format + */ + std::int32_t iconColor; + + /** + * @brief Optional. Unique identifier of the custom emoji shown as the topic icon + */ + std::string iconCustomEmojiId; +}; +} + +#endif //TGBOT_FORUMTOPIC_H diff --git a/include/tgbot/types/ForumTopicClosed.h b/include/tgbot/types/ForumTopicClosed.h new file mode 100644 index 0000000..7e71a09 --- /dev/null +++ b/include/tgbot/types/ForumTopicClosed.h @@ -0,0 +1,21 @@ +#ifndef TGBOT_FORUMTOPICCLOSED_H +#define TGBOT_FORUMTOPICCLOSED_H + +#include + +namespace TgBot { + +/** + * @brief This object represents a service message about a forum topic closed in the chat. + * + * Currently holds no information. + * + * @ingroup types + */ +class ForumTopicClosed { +public: + typedef std::shared_ptr Ptr; +}; +} + +#endif //TGBOT_FORUMTOPICCLOSED_H diff --git a/include/tgbot/types/ForumTopicCreated.h b/include/tgbot/types/ForumTopicCreated.h new file mode 100644 index 0000000..58bbf20 --- /dev/null +++ b/include/tgbot/types/ForumTopicCreated.h @@ -0,0 +1,36 @@ +#ifndef TGBOT_FORUMTOPICCREATED_H +#define TGBOT_FORUMTOPICCREATED_H + +#include +#include +#include + +namespace TgBot { + +/** + * @brief This object represents a service message about a new forum topic created in the chat. + * + * @ingroup types + */ +class ForumTopicCreated { +public: + typedef std::shared_ptr Ptr; + + /** + * @brief Name of the topic + */ + std::string name; + + /** + * @brief Color of the topic icon in RGB format + */ + std::int32_t iconColor; + + /** + * @brief Optional. Unique identifier of the custom emoji shown as the topic icon + */ + std::string iconCustomEmojiId; +}; +} + +#endif //TGBOT_FORUMTOPICCREATED_H diff --git a/include/tgbot/types/ForumTopicReopened.h b/include/tgbot/types/ForumTopicReopened.h new file mode 100644 index 0000000..64f5d39 --- /dev/null +++ b/include/tgbot/types/ForumTopicReopened.h @@ -0,0 +1,21 @@ +#ifndef TGBOT_FORUMTOPICREOPENED_H +#define TGBOT_FORUMTOPICREOPENED_H + +#include + +namespace TgBot { + +/** + * @brief This object represents a service message about a forum topic reopened in the chat. + * + * Currently holds no information. + * + * @ingroup types + */ +class ForumTopicReopened { +public: + typedef std::shared_ptr Ptr; +}; +} + +#endif //TGBOT_FORUMTOPICREOPENED_H diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index 2c7915a..4d1ea7b 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -24,6 +24,9 @@ #include "tgbot/types/SuccessfulPayment.h" #include "tgbot/types/PassportData.h" #include "tgbot/types/ProximityAlertTriggered.h" +#include "tgbot/types/ForumTopicCreated.h" +#include "tgbot/types/ForumTopicClosed.h" +#include "tgbot/types/ForumTopicReopened.h" #include "tgbot/types/VideoChatScheduled.h" #include "tgbot/types/VideoChatStarted.h" #include "tgbot/types/VideoChatEnded.h" @@ -52,14 +55,21 @@ public: */ std::int32_t messageId; + /** + * @brief Optional. Unique identifier of a message thread to which the message belongs; for supergroups only + */ + std::int32_t messageThreadId; + /** * @brief Optional. Sender of the message; empty for messages sent to channels. + * * For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. */ User::Ptr from; /** * @brief Optional. Sender of the message, sent on behalf of a chat. + * * For example, the channel itself for channel posts, the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. * For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. */ @@ -91,7 +101,7 @@ public: std::int32_t forwardFromMessageId; /** - * @brief Optional. For messages forwarded from channels, signature of the post author if present + * @brief Optional. For forwarded messages that were originally sent in channels or by an anonymous chat administrator, signature of the message sender if present */ std::string forwardSignature; @@ -105,6 +115,11 @@ public: */ std::int32_t forwardDate; + /** + * @brief Optional. True, if the message is sent to a forum topic + */ + bool isTopicMessage; + /** * @brief Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group */ @@ -112,6 +127,7 @@ public: /** * @brief Optional. For replies, the original message. + * * Note that the Message object in this field will not contain further replyToMessage fields even if it itself is a reply. */ Message::Ptr replyToMessage; @@ -142,7 +158,7 @@ public: std::string authorSignature; /** - * @brief Optional. For text messages, the actual UTF-8 text of the message, 0-4096 characters + * @brief Optional. For text messages, the actual UTF-8 text of the message */ std::string text; @@ -153,6 +169,7 @@ public: /** * @brief Optional. Message is an animation, information about the animation. + * * For backward compatibility, when this field is set, the document field will also be set */ Animation::Ptr animation; @@ -193,7 +210,7 @@ public: Voice::Ptr voice; /** - * @brief Optional. Caption for the animation, audio, document, photo, video or voice, 0-1024 characters + * @brief Optional. Caption for the animation, audio, document, photo, video or voice */ std::string caption; @@ -213,7 +230,7 @@ public: Dice::Ptr dice; /** - * @brief Optional. Message is a game, information about the game + * @brief Optional. Message is a game, information about the game. https://core.telegram.org/bots/api#games */ Game::Ptr game; @@ -224,6 +241,7 @@ public: /** * @brief Optional. Message is a venue, information about the venue. + * * For backward compatibility, when this field is set, the location field will also be set */ Venue::Ptr venue; @@ -234,7 +252,7 @@ public: Location::Ptr location; /** - * @brief Optional. Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members) + * @brief Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members) */ std::vector newChatMembers; @@ -265,6 +283,7 @@ public: /** * @brief Optional. Service message: the supergroup has been created. + * * This field can't be received in a message coming through updates, because bot can't be a member of a supergroup when it is created. * It can only be found in replyToMessage if someone replies to a very first message in a directly created supergroup. */ @@ -272,6 +291,7 @@ public: /** * @brief Optional. Service message: the channel has been created. + * * This field can't be received in a message coming through updates, because bot can't be a member of a channel when it is created. * It can only be found in replyToMessage if someone replies to a very first message in a channel. */ @@ -285,39 +305,43 @@ public: /** * @brief Optional. The group has been migrated to a supergroup with the specified identifier. * - * This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. - * But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. */ std::int64_t migrateToChatId; /** * @brief Optional. The supergroup has been migrated from a group with the specified identifier. * - * This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. - * But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + * This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. + * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. */ std::int64_t migrateFromChatId; /** * @brief Optional. Specified message was pinned. + * * Note that the Message object in this field will not contain further replyToMessage fields even if it is itself a reply. */ Message::Ptr pinnedMessage; /** * @brief Optional. Message is an invoice for a payment, information about the invoice. + * * https://core.telegram.org/bots/api#payments */ Invoice::Ptr invoice; /** - * @brief Optional. Message is a service message about a successful payment, information about the payment + * @brief Optional. Message is a service message about a successful payment, information about the payment. + * * https://core.telegram.org/bots/api#payments */ SuccessfulPayment::Ptr successfulPayment; /** * @brief Optional. The domain name of the website on which the user has logged in. + * * https://core.telegram.org/widgets/login */ std::string connectedWebsite; @@ -329,10 +353,26 @@ public: /** * @brief Optional. Service message. + * * A user in the chat triggered another user's proximity alert while sharing Live Location. */ ProximityAlertTriggered::Ptr proximityAlertTriggered; + /** + * @brief Optional. Service message: forum topic created + */ + ForumTopicCreated::Ptr forumTopicCreated; + + /** + * @brief Optional. Service message: forum topic closed + */ + ForumTopicClosed::Ptr forumTopicClosed; + + /** + * @brief Optional. Service message: forum topic reopened + */ + ForumTopicReopened::Ptr forumTopicReopened; + /** * @brief Optional. Service message: video chat scheduled */ @@ -360,6 +400,7 @@ public: /** * @brief Optional. Inline keyboard attached to the message. + * * loginUrl buttons are represented as ordinary url buttons. */ InlineKeyboardMarkup::Ptr replyMarkup; diff --git a/src/Api.cpp b/src/Api.cpp index 9eefc09..a80feb1 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -116,11 +116,15 @@ Message::Ptr Api::sendMessage(boost::variant chatId, bool disableNotification, const std::vector& entities, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(10); + args.reserve(11); 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); @@ -154,11 +158,15 @@ Message::Ptr Api::forwardMessage(boost::variant chatI boost::variant fromChatId, std::int32_t messageId, bool disableNotification, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(5); + 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); @@ -181,11 +189,15 @@ MessageId::Ptr Api::copyMessage(boost::variant chatId std::int32_t replyToMessageId, bool allowSendingWithoutReply, GenericReply::Ptr replyMarkup, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(11); + args.reserve(12); 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()) { @@ -225,11 +237,15 @@ Message::Ptr Api::sendPhoto(boost::variant chatId, bool disableNotification, const std::vector& captionEntities, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(10); + args.reserve(11); 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); @@ -277,11 +293,15 @@ Message::Ptr Api::sendAudio(boost::variant chatId, bool disableNotification, const std::vector& captionEntities, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(14); + args.reserve(15); 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); @@ -345,11 +365,15 @@ Message::Ptr Api::sendDocument(boost::variant chatId, const std::vector& captionEntities, bool disableContentTypeDetection, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(12); + args.reserve(13); 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); @@ -410,11 +434,15 @@ Message::Ptr Api::sendVideo(boost::variant chatId, bool disableNotification, const std::vector& captionEntities, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(15); + args.reserve(16); 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); @@ -483,11 +511,15 @@ Message::Ptr Api::sendAnimation(boost::variant chatId bool disableNotification, const std::vector& captionEntities, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(14); + args.reserve(15); 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); @@ -550,11 +582,15 @@ Message::Ptr Api::sendVoice(boost::variant chatId, bool disableNotification, const std::vector& captionEntities, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(11); + args.reserve(12); 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); @@ -601,11 +637,15 @@ Message::Ptr Api::sendVideoNote(boost::variant chatId boost::variant thumb, GenericReply::Ptr replyMarkup, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(10); + args.reserve(11); 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); @@ -651,11 +691,15 @@ std::vector Api::sendMediaGroup(boost::variant args; - args.reserve(6); + args.reserve(7); 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); @@ -684,11 +728,15 @@ Message::Ptr Api::sendLocation(boost::variant chatId, std::int32_t heading, std::int32_t proximityAlertRadius, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(12); + args.reserve(13); 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) { @@ -797,11 +845,15 @@ Message::Ptr Api::sendVenue(boost::variant chatId, const std::string& googlePlaceId, const std::string& googlePlaceType, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(14); + args.reserve(15); 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); @@ -838,19 +890,23 @@ Message::Ptr Api::sendVenue(boost::variant chatId, } 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, - std::int32_t replyToMessageId, - GenericReply::Ptr replyMarkup, - bool allowSendingWithoutReply, - bool protectContent) const { + const std::string& phoneNumber, + const std::string& firstName, + const std::string& lastName , + const std::string& vcard, + bool disableNotification, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + bool allowSendingWithoutReply, + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(10); + args.reserve(11); 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()) { @@ -895,11 +951,15 @@ Message::Ptr Api::sendPoll(boost::variant chatId, std::int32_t closeDate, bool isClosed, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(18); + args.reserve(19); 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 { @@ -960,11 +1020,15 @@ Message::Ptr Api::sendDice(boost::variant chatId, GenericReply::Ptr replyMarkup, const std::string& emoji, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(7); + args.reserve(8); args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } if (!emoji.empty()) { args.emplace_back("emoji", emoji); } @@ -1087,9 +1151,10 @@ bool Api::promoteChatMember(boost::variant chatId, bool isAnonymous, bool canManageChat, bool canManageVideoChats, - bool canRestrictMembers) const { + bool canRestrictMembers, + bool canManageTopics) const { std::vector args; - args.reserve(13); + args.reserve(14); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); @@ -1126,6 +1191,9 @@ bool Api::promoteChatMember(boost::variant chatId, if (canPinMessages) { args.emplace_back("can_pin_messages", canPinMessages); } + if (canManageTopics) { + args.emplace_back("can_manage_topics", canManageTopics); + } return sendRequest("promoteChatMember", args).get("", false); } @@ -1418,6 +1486,88 @@ bool Api::deleteChatStickerSet(boost::variant chatId) return sendRequest("deleteChatStickerSet", args).get("", false); } +std::vector Api::getForumTopicIconStickers() const { + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, 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); + + 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)); +} + +bool Api::editForumTopic(boost::variant chatId, + std::int32_t messageThreadId, + const std::string& name, + const std::string& iconCustomEmojiId) const { + std::vector args; + args.reserve(4); + + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("name", name); + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); + + return sendRequest("editForumTopic", args).get("", false); +} + +bool Api::closeForumTopic(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); + + return sendRequest("closeForumTopic", args).get("", false); + } + +bool Api::reopenForumTopic(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); + + return sendRequest("reopenForumTopic", args).get("", false); +} + +bool Api::deleteForumTopic(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); + + return sendRequest("deleteForumTopic", args).get("", false); +} + +bool Api::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); + + return sendRequest("unpinAllForumTopicMessages", args).get("", false); +} + bool Api::answerCallbackQuery(const std::string& callbackQueryId, const std::string& text, bool showAlert, @@ -1716,11 +1866,15 @@ Message::Ptr Api::sendSticker(boost::variant chatId, GenericReply::Ptr replyMarkup, bool disableNotification, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(7); + args.reserve(8); 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); @@ -1954,11 +2108,15 @@ Message::Ptr Api::sendInvoice(boost::variant chatId, std::int32_t maxTipAmount, const std::vector& suggestedTipAmounts, const std::string& startParameter, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(27); + args.reserve(28); 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); @@ -2155,11 +2313,15 @@ Message::Ptr Api::sendGame(std::int64_t chatId, InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification, bool allowSendingWithoutReply, - bool protectContent) const { + bool protectContent, + std::int32_t messageThreadId) const { std::vector args; - args.reserve(7); + args.reserve(8); 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); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 1f49489..3745e1c 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -145,7 +145,13 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& d result->username = data.get("username", ""); result->firstName = data.get("first_name", ""); result->lastName = data.get("last_name", ""); + result->isForum = data.get("is_forum", false); result->photo = tryParseJson(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo"); + result->activeUsernames = parseJsonAndGetArray( + [] (const boost::property_tree::ptree& innerData)->std::string { + return innerData.get(""); + }, data, "active_usernames"); + result->emojiStatusCustomEmojiId = data.get("emoji_status_custom_emoji_id", ""); result->bio = data.get("bio", ""); result->hasPrivateForwards = data.get("has_private_forwards", false); result->hasRestrictedVoiceAndVideoMessages = data.get("has_restricted_voice_and_video_messages", false); @@ -185,7 +191,13 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const { appendToJson(result, "username", object->username); appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); + appendToJson(result, "is_forum", object->isForum); appendToJson(result, "photo", parseChatPhoto(object->photo)); + appendToJson(result, "active_usernames", + parseArray([] (const std::string& s)->std::string { + return s; + }, object->activeUsernames)); + appendToJson(result, "emoji_status_custom_emoji_id", object->emojiStatusCustomEmojiId); appendToJson(result, "bio", object->bio); appendToJson(result, "has_private_forwards", object->hasPrivateForwards); appendToJson(result, "has_restricted_voice_and_video_messages", object->hasRestrictedVoiceAndVideoMessages); @@ -210,6 +222,7 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const { Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->messageId = data.get("message_id", 0); + result->messageThreadId = data.get("message_thread_id", 0); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->senderChat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "sender_chat"); result->date = data.get("date", 0); @@ -220,6 +233,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt result->forwardSignature = data.get("forward_signature", ""); result->forwardSenderName = data.get("forward_sender_name", ""); result->forwardDate = data.get("forward_date", 0); + result->isTopicMessage = data.get("is_topic_message", false); result->isAutomaticForward = data.get("is_automatic_forward", false); result->replyToMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message"); result->viaBot = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "via_bot"); @@ -261,8 +275,10 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt result->successfulPayment = tryParseJson(&TgTypeParser::parseJsonAndGetSuccessfulPayment, data, "successful_payment"); result->connectedWebsite = data.get("connected_website", ""); result->passportData = tryParseJson(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data"); - result->passportData = tryParseJson(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data"); result->proximityAlertTriggered = tryParseJson(&TgTypeParser::parseJsonAndGetProximityAlertTriggered, data, "proximity_alert_triggered"); + result->forumTopicCreated = tryParseJson(&TgTypeParser::parseJsonAndGetForumTopicCreated, data, "forum_topic_created"); + result->forumTopicClosed = tryParseJson(&TgTypeParser::parseJsonAndGetForumTopicClosed, data, "forum_topic_closed"); + result->forumTopicReopened = tryParseJson(&TgTypeParser::parseJsonAndGetForumTopicReopened, data, "forum_topic_reopened"); result->videoChatScheduled = tryParseJson(&TgTypeParser::parseJsonAndGetVideoChatScheduled, data, "video_chat_scheduled"); result->videoChatStarted = tryParseJson(&TgTypeParser::parseJsonAndGetVideoChatStarted, data, "video_chat_started"); result->videoChatEnded = tryParseJson(&TgTypeParser::parseJsonAndGetVideoChatEnded, data, "video_chat_ended"); @@ -279,6 +295,7 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const { std::string result; result += '{'; appendToJson(result, "message_id", object->messageId); + appendToJson(result, "message_thread_id", object->messageThreadId); appendToJson(result, "from", parseUser(object->from)); appendToJson(result, "sender_chat", parseChat(object->senderChat)); appendToJson(result, "date", object->date); @@ -289,6 +306,7 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "forward_signature", object->forwardSignature); appendToJson(result, "forward_sender_name", object->forwardSenderName); appendToJson(result, "forward_date", object->forwardDate); + appendToJson(result, "is_topic_message", object->isTopicMessage); appendToJson(result, "is_automatic_forward", object->isAutomaticForward); appendToJson(result, "reply_to_message", parseMessage(object->replyToMessage)); appendToJson(result, "via_bot", parseUser(object->viaBot)); @@ -331,6 +349,9 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "connected_website", object->connectedWebsite); appendToJson(result, "passport_data", parsePassportData(object->passportData)); appendToJson(result, "proximity_alert_triggered", parseProximityAlertTriggered(object->proximityAlertTriggered)); + appendToJson(result, "forum_topic_created", parseForumTopicCreated(object->forumTopicCreated)); + appendToJson(result, "forum_topic_closed", parseForumTopicClosed(object->forumTopicClosed)); + appendToJson(result, "forum_topic_reopened", parseForumTopicReopened(object->forumTopicReopened)); appendToJson(result, "video_chat_scheduled", parseVideoChatScheduled(object->videoChatScheduled)); appendToJson(result, "video_chat_started", parseVideoChatStarted(object->videoChatStarted)); appendToJson(result, "video_chat_ended", parseVideoChatEnded(object->videoChatEnded)); @@ -922,6 +943,60 @@ std::string TgTypeParser::parseMessageAutoDeleteTimerChanged(const MessageAutoDe return result; } +ForumTopicCreated::Ptr TgTypeParser::parseJsonAndGetForumTopicCreated(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->name = data.get("name", ""); + result->iconColor = data.get("icon_color", 0); + result->iconCustomEmojiId = data.get("icon_custom_emoji_id", ""); + return result; +} + +std::string TgTypeParser::parseForumTopicCreated(const ForumTopicCreated::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "name", object->name); + appendToJson(result, "icon_color", object->iconColor); + appendToJson(result, "icon_custom_emoji_id", object->iconCustomEmojiId); + removeLastComma(result); + result += '}'; + return result; +} + +ForumTopicClosed::Ptr TgTypeParser::parseJsonAndGetForumTopicClosed(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + return result; +} + +std::string TgTypeParser::parseForumTopicClosed(const ForumTopicClosed::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + //removeLastComma(result); + result += '}'; + return result; +} + +ForumTopicReopened::Ptr TgTypeParser::parseJsonAndGetForumTopicReopened(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + return result; +} + +std::string TgTypeParser::parseForumTopicReopened(const ForumTopicReopened::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + //removeLastComma(result); + result += '}'; + return result; +} + VideoChatScheduled::Ptr TgTypeParser::parseJsonAndGetVideoChatScheduled(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->startDate = data.get("start_date", 0); @@ -1363,6 +1438,7 @@ ChatAdministratorRights::Ptr TgTypeParser::parseJsonAndGetChatAdministratorRight result->canPostMessages = data.get("can_post_messages", false); result->canEditMessages = data.get("can_edit_messages", false); result->canPinMessages = data.get("can_pin_messages", false); + result->canManageTopics = data.get("can_manage_topics", false); return result; } @@ -1383,6 +1459,7 @@ std::string TgTypeParser::parseChatAdministratorRights(const ChatAdministratorRi appendToJson(result, "can_post_messages", object->canPostMessages); appendToJson(result, "can_edit_messages", object->canEditMessages); appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "can_manage_topics", object->canManageTopics); removeLastComma(result); result += '}'; return result; @@ -1478,6 +1555,7 @@ ChatMemberAdministrator::Ptr TgTypeParser::parseJsonAndGetChatMemberAdministrato result->canPostMessages = data.get("can_post_messages", false); result->canEditMessages = data.get("can_edit_messages", false); result->canPinMessages = data.get("can_pin_messages", false); + result->canManageTopics = data.get("can_manage_topics", false); result->customTitle = data.get("custom_title", ""); return result; } @@ -1501,6 +1579,7 @@ std::string TgTypeParser::parseChatMemberAdministrator(const ChatMemberAdministr appendToJson(result, "can_post_messages", object->canPostMessages); appendToJson(result, "can_edit_messages", object->canEditMessages); appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "can_manage_topics", object->canManageTopics); appendToJson(result, "custom_title", object->customTitle); // The last comma will be erased by parseChatMember(). return result; @@ -1530,6 +1609,7 @@ ChatMemberRestricted::Ptr TgTypeParser::parseJsonAndGetChatMemberRestricted(cons result->canChangeInfo = data.get("can_change_info", false); result->canInviteUsers = data.get("can_invite_users", false); result->canPinMessages = data.get("can_pin_messages", false); + result->canManageTopics = data.get("can_manage_topics", false); result->canSendMessages = data.get("can_send_messages", false); result->canSendMediaMessages = data.get("can_send_media_messages", false); result->canSendPolls = data.get("can_send_polls", false); @@ -1550,6 +1630,7 @@ std::string TgTypeParser::parseChatMemberRestricted(const ChatMemberRestricted:: appendToJson(result, "can_change_info", object->canChangeInfo); appendToJson(result, "can_invite_users", object->canInviteUsers); appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "can_manage_topics", object->canManageTopics); appendToJson(result, "can_send_messages", object->canSendMessages); appendToJson(result, "can_send_media_messages", object->canSendMediaMessages); appendToJson(result, "can_send_polls", object->canSendPolls); @@ -1652,14 +1733,15 @@ std::string TgTypeParser::parseChatJoinRequest(const ChatJoinRequest::Ptr& objec ChatPermissions::Ptr TgTypeParser::parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); - result->canSendMessages = data.get("can_send_messages"); - result->canSendMediaMessages = data.get("can_send_media_messages"); - result->canSendPolls = data.get("can_send_polls"); - result->canSendOtherMessages = data.get("can_send_other_messages"); - result->canAddWebPagePreviews = data.get("can_add_web_page_previews"); - result->canChangeInfo = data.get("can_change_info"); - result->canInviteUsers = data.get("can_invite_users"); - result->canPinMessages = data.get("can_pin_messages"); + result->canSendMessages = data.get("can_send_messages", false); + result->canSendMediaMessages = data.get("can_send_media_messages", false); + result->canSendPolls = data.get("can_send_polls", false); + result->canSendOtherMessages = data.get("can_send_other_messages", false); + result->canAddWebPagePreviews = data.get("can_add_web_page_previews", false); + result->canChangeInfo = data.get("can_change_info", false); + result->canInviteUsers = data.get("can_invite_users", false); + result->canPinMessages = data.get("can_pin_messages", false); + result->canManageTopics = data.get("can_manage_topics", false); return result; } @@ -1677,6 +1759,7 @@ std::string TgTypeParser::parseChatPermissions(const ChatPermissions::Ptr& objec appendToJson(result, "can_change_info", object->canChangeInfo); appendToJson(result, "can_invite_users", object->canInviteUsers); appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "can_manage_topics", object->canManageTopics); removeLastComma(result); result += '}'; return result; @@ -1702,6 +1785,30 @@ std::string TgTypeParser::parseChatLocation(const ChatLocation::Ptr& object) con return result; } +ForumTopic::Ptr TgTypeParser::parseJsonAndGetForumTopic(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->messageThreadId = data.get("message_thread_id", 0); + result->name = data.get("name", ""); + result->iconColor = data.get("icon_color", 0); + result->iconCustomEmojiId = data.get("icon_custom_emoji_id", ""); + return result; +} + +std::string TgTypeParser::parseForumTopic(const ForumTopic::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "message_thread_id", object->messageThreadId); + appendToJson(result, "name", object->name); + appendToJson(result, "icon_color", object->iconColor); + appendToJson(result, "icon_custom_emoji_id", object->iconCustomEmojiId); + removeLastComma(result); + result += '}'; + return result; +} + BotCommand::Ptr TgTypeParser::parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->command = data.get("command", ""); -- cgit v1.2.3