diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | include/tgbot/Api.h | 21 | ||||
-rw-r--r-- | include/tgbot/types/Animation.h | 36 | ||||
-rw-r--r-- | include/tgbot/types/Audio.h | 24 | ||||
-rw-r--r-- | include/tgbot/types/Chat.h | 48 | ||||
-rw-r--r-- | include/tgbot/types/ChatMember.h | 7 | ||||
-rw-r--r-- | include/tgbot/types/ChatPhoto.h | 24 | ||||
-rw-r--r-- | include/tgbot/types/Document.h | 20 | ||||
-rw-r--r-- | include/tgbot/types/File.h | 10 | ||||
-rw-r--r-- | include/tgbot/types/MessageEntity.h | 4 | ||||
-rw-r--r-- | include/tgbot/types/PhotoSize.h | 16 | ||||
-rw-r--r-- | include/tgbot/types/Sticker.h | 28 | ||||
-rw-r--r-- | include/tgbot/types/Update.h | 10 | ||||
-rw-r--r-- | include/tgbot/types/Video.h | 20 | ||||
-rw-r--r-- | include/tgbot/types/VideoNote.h | 18 | ||||
-rw-r--r-- | include/tgbot/types/Voice.h | 15 | ||||
-rw-r--r-- | src/Api.cpp | 13 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 84 |
19 files changed, 305 insertions, 99 deletions
@@ -16,5 +16,9 @@ TgBot_test docs/ cmake-build-* +# Visual Studio +/.vs/ +/out/ + # MacOS dependecies .DS_Store @@ -12,7 +12,7 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp). ## State - [x] Bot API 3.0 ~ 3.6 -- [x] Bot API 4.0 ~ 4.4 (Implemented all APIs except 'Telegram Passport') +- [x] Bot API 4.0 ~ 4.5 (Implemented all APIs except 'Telegram Passport') ## Sample diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index cc18807..f5b325e 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -67,7 +67,7 @@ public: */ Message::Ptr sendMessage(std::int64_t chatId, const std::string& text, bool disableWebPagePreview = false, std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; - + Message::Ptr sendMessage(const std::string& chatId, const std::string& text, bool disableWebPagePreview = false, std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; @@ -682,11 +682,20 @@ public: bool canEditMessages = false, bool canDeleteMessages = false, bool canInviteUsers = false, bool canPinMessages = false, bool canPromoteMembers = false) const; /** - * @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 can_restrict_members admin rights. Returns True on success. - * @param chatId Unique identifier for the target chat of the target supergroup. - * @param permissions New default chat permissions. - * @return True on success - */ + * @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 True on success + */ + bool setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const; + + /** + * @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 can_restrict_members admin rights. Returns True on success. + * @param chatId Unique identifier for the target chat of the target supergroup. + * @param permissions New default chat permissions. + * @return True on success + */ bool setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const; /** diff --git a/include/tgbot/types/Animation.h b/include/tgbot/types/Animation.h index ac54b2c..f1f62af 100644 --- a/include/tgbot/types/Animation.h +++ b/include/tgbot/types/Animation.h @@ -10,9 +10,7 @@ namespace TgBot { /** - * @brief You can provide an animation for your game so that it looks stylish in chats (check out Lumberjack for an example). - * - * This object represents an animation file to be displayed in the message containing a game. + * @brief This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). * * @ingroup types */ @@ -21,27 +19,49 @@ public: typedef std::shared_ptr<Animation> Ptr; /** - * @brief Unique file identifier. + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** - * @brief Optional. Animation thumbnail as defined by sender. + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** + * @brief Video width as defined by sender + */ + std::int32_t width; + + /** + * @brief Video height as defined by sender + */ + std::int32_t height; + + /** + * @brief Duration of the video in seconds as defined by sender + */ + std::int32_t duration; + + /** + * @brief Optional. Animation thumbnail as defined by sender */ PhotoSize::Ptr thumb; /** - * @brief Optional. Original animation filename as defined by sender. + * @brief Optional. Original animation filename as defined by sender */ std::string fileName; /** - * @brief Optional. MIME type of the file as defined by sender. + * @brief Optional. MIME type of the file as defined by sender */ std::string mimeType; /** - * @brief Optional. File size. + * @brief Optional. File size */ std::int32_t fileSize; }; diff --git a/include/tgbot/types/Audio.h b/include/tgbot/types/Audio.h index dae8729..0db0a36 100644 --- a/include/tgbot/types/Audio.h +++ b/include/tgbot/types/Audio.h @@ -10,7 +10,7 @@ namespace TgBot { /** - * @brief This object represents an audio file (voice note). + * @brief This object represents an audio file to be treated as music by the Telegram clients. * * @ingroup types */ @@ -20,34 +20,39 @@ public: typedef std::shared_ptr<Audio> Ptr; /** - * @brief Unique identifier for this file. + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** - * @brief Duration of the audio in seconds as defined by sender. + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** + * @brief Duration of the audio in seconds as defined by sender */ std::int32_t duration; /** - * @brief Optional. Performer of the audio as defined by sender - * or by audio tags + * @brief Optional. Performer of the audio as defined by sender or by audio tags */ std::string performer; /** - * @brief Optional. Title of the audio as defined by sender or - * by audio tags + * @brief Optional. Title of the audio as defined by sender or by audio tags */ std::string title; /** - * @brief Optional. MIME type of the file as defined by sender. + * @brief Optional. MIME type of the file as defined by sender */ std::string mimeType; /** - * @brief Optional. File size. + * @brief Optional. File size */ std::int32_t fileSize; @@ -56,7 +61,6 @@ public: */ PhotoSize::Ptr thumb; }; - } #endif //TGBOT_CPP_AUDIO_H diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h index 5731abd..4074643 100644 --- a/include/tgbot/types/Chat.h +++ b/include/tgbot/types/Chat.h @@ -12,7 +12,8 @@ namespace TgBot { class Message; /** - * @brief This object represents a Telegram Chat + * @brief This object represents a chat. + * * @ingroup types */ class Chat { @@ -28,87 +29,102 @@ public: }; /** - * @brief Unique identifier for this chat, not exceeding 1e13 by absolute value + * @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. */ std::int64_t id; /** - * @brief Type of chat: can be either "private", "group", "supergroup, or "channel". + * @brief Type of chat, can be either “private”, “group”, “supergroup” or “channel” */ Type type; /** - * @brief Optional. Title for channels and group chat + * @brief Optional. Title, for supergroups, channels and group chats */ std::string title; /** - * @brief Optional. Username for - * private chats and channels + * @brief Optional. Username, for private chats, supergroups and channels if available */ std::string username; /** - * @brief Optional. First name of the - * other party in private chat + * @brief Optional. First name of the other party in a private chat */ std::string firstName; /** - * @brief Optional. Last name of the - * other party in private chat + * @brief Optional. Last name of the other party in a private chat */ std::string lastName; /** - * @brief Optional. True if a group - * has ‘All Members Are Admins’ enabled. + * @brief Deprecated since API 4.4. New bots should use the permissions field instead. + * + * Optional. True if a group has ‘All Members Are Admins’ enabled. */ bool allMembersAreAdministrators; /** * @brief Optional. Chat photo. + * * Returned only in getChat. */ ChatPhoto::Ptr photo; /** - * @brief Optional. Description, for supergroups and channel chats. + * @brief Optional. Description, for groups, supergroups and channel chats. + * * Returned only in getChat. */ std::string description; /** - * @brief Optional. Chat invite link, for supergroups and channel chats. + * @brief Optional. Chat invite link, for groups, supergroups and channel chats. + * + * Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink. * Returned only in getChat. */ std::string inviteLink; /** - * @brief Optional. Pinned message, for supergroups and channel chats. + * @brief Optional. Pinned message, for groups, supergroups and channels. + * * Returned only in getChat. */ std::shared_ptr<Message> pinnedMessage; /** * @brief Optional. Default chat member permissions, for groups and supergroups. + * * Returned only in getChat. */ ChatPermissions::Ptr permissions; /** + * @brief Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user. + * + * Returned only in getChat. + */ + std::int32_t slowModeDelay; + + /** * @brief Optional. For supergroups, name of group sticker set. + * * Returned only in getChat. */ std::string stickerSetName; /** * @brief Optional. True, if the bot can change the group sticker set. + * * Returned only in getChat. */ bool canSetStickerSet; }; - } #endif //TGBOT_CPP_CHAT_H diff --git a/include/tgbot/types/ChatMember.h b/include/tgbot/types/ChatMember.h index 47e79a4..99be20a 100644 --- a/include/tgbot/types/ChatMember.h +++ b/include/tgbot/types/ChatMember.h @@ -11,9 +11,11 @@ namespace TgBot { /** * @brief This object contains information about one member of the chat. + * * @ingroup types */ class ChatMember { + public: typedef std::shared_ptr<ChatMember> Ptr; @@ -28,6 +30,11 @@ public: std::string status; /** + * @brief Optional. Owner and administrators only. Custom title for this user + */ + std::string customTitle; + + /** * @brief Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time. */ std::uint64_t untilDate; diff --git a/include/tgbot/types/ChatPhoto.h b/include/tgbot/types/ChatPhoto.h index f41d9b8..92275b2 100644 --- a/include/tgbot/types/ChatPhoto.h +++ b/include/tgbot/types/ChatPhoto.h @@ -8,21 +8,41 @@ namespace TgBot { /** * @brief This object represents a chat photo. + * * @ingroup types */ class ChatPhoto { + public: typedef std::shared_ptr<ChatPhoto> Ptr; /** - * @brief Unique file identifier of small (160x160) chat photo. This file_id can be used only for photo download. + * @brief File identifier of small (160x160) chat photo. + * + * This file_id can be used only for photo download and only for as long as the photo is not changed. */ std::string smallFileId; /** - * @brief Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download. + * @brief Unique file identifier of small (160x160) chat photo, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string smallFileUniqueId; + + /** + * @brief File identifier of big (640x640) chat photo. + * + * This file_id can be used only for photo download and only for as long as the photo is not changed. */ std::string bigFileId; + + /** + * @brief Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string bigFileUniqueId; }; } diff --git a/include/tgbot/types/Document.h b/include/tgbot/types/Document.h index b82895f..128b757 100644 --- a/include/tgbot/types/Document.h +++ b/include/tgbot/types/Document.h @@ -10,7 +10,7 @@ namespace TgBot { /** - * @brief This object represents a general file (as opposed to photos and audio files). + * @brief This object represents a general file (as opposed to photos, voice messages and audio files). * * @ingroup types */ @@ -20,31 +20,37 @@ public: typedef std::shared_ptr<Document> Ptr; /** - * @brief Unique file identifier. + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** - * @brief Optional. Document thumbnail as defined by sender. + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** + * @brief Optional. Document thumbnail as defined by sender */ PhotoSize::Ptr thumb; /** - * @brief Optional. Original filename as defined by sender. + * @brief Optional. Original filename as defined by sender */ std::string fileName; /** - * @brief Optional. MIME type of the file as defined by sender. + * @brief Optional. MIME type of the file as defined by sender */ std::string mimeType; /** - * @brief Optional. File size. + * @brief Optional. File size */ std::int32_t fileSize; }; - } #endif //TGBOT_CPP_DOCUMENT_H diff --git a/include/tgbot/types/File.h b/include/tgbot/types/File.h index 3dee2bc..58aa6af 100644 --- a/include/tgbot/types/File.h +++ b/include/tgbot/types/File.h @@ -23,11 +23,18 @@ public: typedef std::shared_ptr<File> Ptr; /** - * @brief Unique identifier for this file + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** * @brief Optional. File size, if known */ std::int32_t fileSize; @@ -39,7 +46,6 @@ public: */ std::string filePath; }; - } #endif //TGBOT_CPP_FILE_H diff --git a/include/tgbot/types/MessageEntity.h b/include/tgbot/types/MessageEntity.h index f12d2a7..9aa283d 100644 --- a/include/tgbot/types/MessageEntity.h +++ b/include/tgbot/types/MessageEntity.h @@ -21,12 +21,12 @@ public: /** * @brief Type of the entity. * - * Can be mention (@username), hashtag, cashtag, bot_command, url, email, phone_number, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames) + * Can be “mention” (@username), “hashtag” (#hashtag), “cashtag” ($USD), “bot_command” (/start@jobs_bot), “url” (https://telegram.org), “email” (do-not-reply@telegram.org), “phone_number” (+1-212-555-0123), “bold” (bold text), “italic” (italic text), “underline” (underlined text), “strikethrough” (strikethrough text), “code” (monowidth string), “pre” (monowidth block), “text_link” (for clickable text URLs), “text_mention” (for users without usernames) */ std::string type; /** - * @brief Offset in UTF-16 code units to the start of the entity. + * @brief Offset in UTF-16 code units to the start of the entity */ std::int32_t offset; diff --git a/include/tgbot/types/PhotoSize.h b/include/tgbot/types/PhotoSize.h index 5d59e8a..a0cb5c5 100644 --- a/include/tgbot/types/PhotoSize.h +++ b/include/tgbot/types/PhotoSize.h @@ -18,26 +18,32 @@ public: typedef std::shared_ptr<PhotoSize> Ptr; /** - * @brief Unique identifier for this file. + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** - * @brief Photo width. + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** + * @brief Photo width */ std::int32_t width; /** - * @brief Photo height. + * @brief Photo height */ std::int32_t height; /** - * @brief Optional. File size. + * @brief Optional. File size */ std::int32_t fileSize; }; - } #endif //TGBOT_CPP_PHOTOSIZE_H diff --git a/include/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h index b1d5945..4986597 100644 --- a/include/tgbot/types/Sticker.h +++ b/include/tgbot/types/Sticker.h @@ -11,7 +11,7 @@ namespace TgBot { /** - * @brief This object represents a general file (as opposed to photos and audio files). + * @brief This object represents a sticker. * * @ingroup types */ @@ -21,27 +21,34 @@ public: typedef std::shared_ptr<Sticker> Ptr; /** - * @brief Unique file identifier. + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** - * @brief Optional. Sticker width. + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** + * @brief Sticker width */ std::int32_t width; /** - * @brief Optional. Sticker height. + * @brief Sticker height */ std::int32_t height; /** - * @brief True, if the sticker is animated. - */ + * @brief True, if the sticker is animated + */ bool isAnimated = false; /** - * @brief Optional. Optional. Sticker thumbnail in .webp or .jpg format. + * @brief Optional. Sticker thumbnail in the .webp or .jpg format */ PhotoSize::Ptr thumb; @@ -51,21 +58,20 @@ public: std::string emoji; /** - * @brief Optional. Name of the sticker set to which the sticker belongs. + * @brief Optional. Name of the sticker set to which the sticker belongs */ std::string setName; /** - * @brief Optional. For mask stickers, the position where the mask should be placed. + * @brief Optional. For mask stickers, the position where the mask should be placed */ MaskPosition::Ptr maskPosition; /** - * @brief Optional. File size. + * @brief Optional. File size */ std::int32_t fileSize; }; - } #endif //TGBOT_CPP_STICKER_H diff --git a/include/tgbot/types/Update.h b/include/tgbot/types/Update.h index fa5f8f3..328ba2a 100644 --- a/include/tgbot/types/Update.h +++ b/include/tgbot/types/Update.h @@ -7,6 +7,7 @@ #include "tgbot/types/CallbackQuery.h" #include "tgbot/types/ShippingQuery.h" #include "tgbot/types/PreCheckoutQuery.h" +#include "tgbot/types/Poll.h" #include <cstdint> #include <memory> @@ -14,7 +15,7 @@ namespace TgBot { /** - * @brief This object represents an incoming update. + * @brief This object represents an incoming update. At most one of the optional parameters can be present in any given update. * * @ingroup types */ @@ -76,6 +77,13 @@ public: * Contains full information about checkout */ PreCheckoutQuery::Ptr preCheckoutQuery; + + /** + * @brief Optional. New poll state. + * + * Bots receive only updates about stopped polls and polls, which are sent by the bot + */ + Poll::Ptr poll; }; } diff --git a/include/tgbot/types/Video.h b/include/tgbot/types/Video.h index 1702c5b..f305891 100644 --- a/include/tgbot/types/Video.h +++ b/include/tgbot/types/Video.h @@ -20,27 +20,34 @@ public: typedef std::shared_ptr<Video> Ptr; /** - * @brief Unique identifier for this file. + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** - * @brief Video width as defined by sender. + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** + * @brief Video width as defined by sender */ std::int32_t width; /** - * @brief Video height as defined by sender. + * @brief Video height as defined by sender */ std::int32_t height; /** - * @brief Duration of the video in seconds as defined by sender. + * @brief Duration of the video in seconds as defined by sender */ std::int32_t duration; /** - * @brief Optional. Video thumbnail. + * @brief Optional. Video thumbnail */ PhotoSize::Ptr thumb; @@ -50,11 +57,10 @@ public: std::string mimeType; /** - * @brief Optional. File size. + * @brief Optional. File size */ std::int32_t fileSize; }; - } #endif //TGBOT_CPP_VIDEO_H diff --git a/include/tgbot/types/VideoNote.h b/include/tgbot/types/VideoNote.h index ebdf0cb..64684a3 100644 --- a/include/tgbot/types/VideoNote.h +++ b/include/tgbot/types/VideoNote.h @@ -20,31 +20,37 @@ public: typedef std::shared_ptr<VideoNote> Ptr; /** - * @brief Unique identifier for this file. + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** - * @brief Video width and height as defined by sender. + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** + * @brief Video width and height (diameter of the video message) as defined by sender */ std::int32_t length; /** - * @brief Duration of the video in seconds as defined by sender. + * @brief Duration of the video in seconds as defined by sender */ std::int32_t duration; /** - * @brief Optional. Video thumbnail. + * @brief Optional. Video thumbnail */ PhotoSize::Ptr thumb; /** - * @brief Optional. File size. + * @brief Optional. File size */ std::int32_t fileSize; }; - } #endif //TGBOT_CPP_VIDEONOTE_H diff --git a/include/tgbot/types/Voice.h b/include/tgbot/types/Voice.h index 78b7282..34ab016 100644 --- a/include/tgbot/types/Voice.h +++ b/include/tgbot/types/Voice.h @@ -17,22 +17,29 @@ public: typedef std::shared_ptr<Voice> Ptr; /** - * @brief Unique identifier for this file. + * @brief Identifier for this file, which can be used to download or reuse the file */ std::string fileId; /** - * @brief Duration of the audio in seconds as defined by sender. + * @brief Unique identifier for this file, which is supposed to be the same over time and for different bots. + * + * Can't be used to download or reuse the file. + */ + std::string fileUniqueId; + + /** + * @brief Duration of the audio in seconds as defined by sender */ std::int32_t duration; /** - * @brief Optional. MIME type of the file as defined by sender; + * @brief Optional. MIME type of the file as defined by sender */ std::string mimeType; /** - * @brief Optional. File size. + * @brief Optional. File size */ std::int32_t fileSize; }; diff --git a/src/Api.cpp b/src/Api.cpp index ff39805..b1a2f69 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -45,7 +45,7 @@ Message::Ptr Api::sendMessage(std::int64_t chatId, const string& text, bool disa } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); } - + Message::Ptr Api::sendMessage(const std::string &chatId, const string& text, bool disableWebPagePreview, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; args.reserve(7); @@ -67,7 +67,7 @@ Message::Ptr Api::sendMessage(const std::string &chatId, const string& text, boo args.emplace_back("parse_mode", parseMode); } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); -} +} Message::Ptr Api::forwardMessage(std::int64_t chatId, std::int64_t fromChatId, std::int32_t messageId, bool disableNotification) const { vector<HttpReqArg> args; @@ -1032,6 +1032,15 @@ bool Api::promoteChatMember(std::int64_t chatId, std::int64_t userId, bool canCh return sendRequest("promoteChatMember", args).get<bool>("", false); } +bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const { + vector<HttpReqArg> 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<bool>("", false); +} + bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const{ vector<HttpReqArg> args; args.reserve(2); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 13ae5d4..db2e750 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -30,6 +30,8 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { result->description = data.get("description", ""); result->inviteLink = data.get("invite_link", ""); result->pinnedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); + result->permissions = tryParseJson<ChatPermissions>(&TgTypeParser::parseJsonAndGetChatPermissions, data, "permissions"); + result->slowModeDelay = data.get<int32_t>("slow_mode_delay"); result->stickerSetName = data.get("sticker_set_name", ""); result->canSetStickerSet = data.get<bool>("can_set_sticker_set", false); @@ -56,6 +58,15 @@ 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, "all_members_are_administrators", object->allMembersAreAdministrators); + appendToJson(result, "photo", parseChatPhoto(object->photo)); + appendToJson(result, "description", object->description); + appendToJson(result, "invite_link", object->inviteLink); + appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage)); + appendToJson(result, "permissions", parseChatPermissions(object->permissions)); + appendToJson(result, "slow_mode_delay", object->slowModeDelay); + appendToJson(result, "sticker_set_name", object->stickerSetName); + appendToJson(result, "can_set_sticker_set", object->canSetStickerSet); removeLastComma(result); result += '}'; return result; @@ -220,6 +231,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const { PhotoSize::Ptr TgTypeParser::parseJsonAndGetPhotoSize(const ptree& data) const { auto result(make_shared<PhotoSize>()); result->fileId = data.get<string>("file_id"); + result->fileUniqueId = data.get<string>("file_unique_id"); result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); result->fileSize = data.get("file_size", 0); @@ -233,6 +245,7 @@ string TgTypeParser::parsePhotoSize(const PhotoSize::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "file_size", object->fileSize); @@ -244,6 +257,7 @@ string TgTypeParser::parsePhotoSize(const PhotoSize::Ptr& object) const { Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const ptree& data) const { auto result(make_shared<Audio>()); result->fileId = data.get<string>("file_id"); + result->fileUniqueId = data.get<string>("file_unique_id"); result->duration = data.get<int32_t>("duration"); result->performer = data.get<string>("performer", ""); result->title = data.get<string>("title", ""); @@ -260,7 +274,10 @@ string TgTypeParser::parseAudio(const Audio::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "duration", object->duration); + appendToJson(result, "performer", object->performer); + appendToJson(result, "title", object->title); appendToJson(result, "mime_type", object->mimeType); appendToJson(result, "file_size", object->fileSize); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); @@ -272,6 +289,7 @@ string TgTypeParser::parseAudio(const Audio::Ptr& object) const { Document::Ptr TgTypeParser::parseJsonAndGetDocument(const ptree& data) const { auto result(make_shared<Document>()); result->fileId = data.get<string>("file_id"); + result->fileUniqueId = data.get<string>("file_unique_id"); result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->fileName = data.get("file_name", ""); result->mimeType = data.get("mime_type", ""); @@ -286,6 +304,7 @@ string TgTypeParser::parseDocument(const Document::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); appendToJson(result, "file_name", object->fileName); appendToJson(result, "mime_type", object->mimeType); @@ -298,6 +317,7 @@ string TgTypeParser::parseDocument(const Document::Ptr& object) const { Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const { auto result(make_shared<Sticker>()); result->fileId = data.get<string>("file_id"); + result->fileUniqueId = data.get<string>("file_unique_id"); result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); result->isAnimated = data.get<bool>("is_animated", false); @@ -316,11 +336,14 @@ string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "is_animated", object->isAnimated); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); appendToJson(result, "emoji", object->emoji); + appendToJson(result, "set_name", object->setName); + appendToJson(result, "mask_position", parseMaskPosition(object->maskPosition)); appendToJson(result, "file_size", object->fileSize); removeLastComma(result); result += '}'; @@ -456,6 +479,7 @@ string TgTypeParser::parseChatPermissions(const ChatPermissions::Ptr& object) co Video::Ptr TgTypeParser::parseJsonAndGetVideo(const ptree& data) const { auto result(make_shared<Video>()); result->fileId = data.get<string>("file_id"); + result->fileUniqueId = data.get<string>("file_unique_id"); result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); result->duration = data.get<int32_t>("duration"); @@ -472,6 +496,7 @@ string TgTypeParser::parseVideo(const Video::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "duration", object->duration); @@ -486,6 +511,7 @@ string TgTypeParser::parseVideo(const Video::Ptr& object) const { Voice::Ptr TgTypeParser::parseJsonAndGetVoice(const ptree& data) const { auto result(make_shared<Voice>()); result->fileId = data.get<string>("file_id"); + result->fileUniqueId = data.get<string>("file_unique_id"); result->duration = data.get<int32_t>("duration"); result->mimeType = data.get("mime_type", ""); result->fileSize = data.get("file_size", 0); @@ -499,6 +525,7 @@ string TgTypeParser::parseVoice(const Voice::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "duration", object->duration); appendToJson(result, "mime_type", object->mimeType); appendToJson(result, "file_size", object->fileSize); @@ -510,6 +537,7 @@ string TgTypeParser::parseVoice(const Voice::Ptr& object) const { VideoNote::Ptr TgTypeParser::parseJsonAndGetVideoNote(const ptree& data) const { auto result(make_shared<VideoNote>()); result->fileId = data.get<string>("file_id"); + result->fileUniqueId = data.get<string>("file_unique_id"); result->length = data.get<int32_t>("length"); result->duration = data.get<int32_t>("duration"); result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); @@ -524,6 +552,7 @@ string TgTypeParser::parseVideoNote(const VideoNote::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "length", object->length); appendToJson(result, "duration", object->duration); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); @@ -586,6 +615,10 @@ string TgTypeParser::parseGameHighScore(const GameHighScore::Ptr& object) const Animation::Ptr TgTypeParser::parseJsonAndGetAnimation(const ptree& data) const { auto result(make_shared<Animation>()); result->fileId = data.get("file_id", ""); + result->fileUniqueId = data.get("file_unique_id", ""); + result->width = data.get<int32_t>("width", 0); + result->height = data.get<int32_t>("height", 0); + result->duration = data.get<int32_t>("duration", 0); result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->fileName = data.get("file_name", ""); result->mimeType = data.get("mime_type", ""); @@ -600,6 +633,10 @@ string TgTypeParser::parseAnimation(const Animation::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); + appendToJson(result, "width", object->width); + appendToJson(result, "height", object->height); + appendToJson(result, "duration", object->duration); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); appendToJson(result, "file_name", object->fileName); appendToJson(result, "mime_type", object->mimeType); @@ -667,6 +704,7 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const ptree& data) const { result->callbackQuery = tryParseJson<CallbackQuery>(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query"); result->shippingQuery = tryParseJson<ShippingQuery>(&TgTypeParser::parseJsonAndGetShippingQuery, data, "shipping_query"); result->preCheckoutQuery = tryParseJson<PreCheckoutQuery>(&TgTypeParser::parseJsonAndGetPreCheckoutQuery, data, "pre_checkout_query"); + result->poll = tryParseJson<Poll>(&TgTypeParser::parseJsonAndGetPoll, data, "poll"); return result; } @@ -686,6 +724,7 @@ string TgTypeParser::parseUpdate(const Update::Ptr& object) const { 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)); removeLastComma(result); result += '}'; return result; @@ -720,8 +759,8 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const result->parseMode = data.get("parse_mode", ""); result->thumb = data.get("thumb", ""); return result; - } - else if (type == "video") { + + } else if (type == "video") { auto result(make_shared<InputMediaVideo>()); result->media = data.get("media", ""); result->caption = data.get("caption", ""); @@ -732,8 +771,8 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const result->duration = data.get<int32_t>("duration", 0); result->supportsStreaming = data.get<bool>("supports_streaming", false); return result; - } - else if (type == "animation") { + + } else if (type == "animation") { auto result(make_shared<InputMediaAnimation>()); result->media = data.get("media", ""); result->caption = data.get("caption", ""); @@ -743,6 +782,7 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const result->height = data.get<int32_t>("height", 0); result->duration = data.get<int32_t>("duration", 0); return result; + } else if (type == "document") { auto result(make_shared<InputMediaDocument>()); result->media = data.get("media", ""); @@ -750,6 +790,7 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const result->parseMode = data.get("parse_mode", ""); result->thumb = data.get("thumb", ""); return result; + } else if (type == "audio") { auto result(make_shared<InputMediaAudio>()); result->media = data.get("media", ""); @@ -760,8 +801,8 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const result->title = data.get<int32_t>("title", 0); result->performer = data.get<int32_t>("performer", 0); return result; - } - else { + + } else { return nullptr; } } @@ -815,6 +856,7 @@ string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const { File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& data) const { auto result(make_shared<File>()); result->fileId = data.get<string>("file_id"); + result->fileUniqueId = data.get<string>("file_unique_id"); result->fileSize = data.get<int32_t>("file_size", 0); result->filePath = data.get<string>("file_path", ""); return result; @@ -827,6 +869,7 @@ string TgTypeParser::parseFile(const File::Ptr& object) const { string result; result += '{'; appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "file_size", object->fileSize); appendToJson(result, "file_path", object->filePath); removeLastComma(result); @@ -936,19 +979,21 @@ ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tr auto result(make_shared<ChatMember>()); result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); result->status = data.get("status", ""); + result->customTitle = data.get("custom_title", ""); result->untilDate = data.get<uint64_t>("until_date", 0); result->canBeEdited = data.get<bool>("can_be_edited", false); - result->canChangeInfo = data.get<bool>("can_change_info", false); result->canPostMessages = data.get<bool>("can_post_messages", false); result->canEditMessages = data.get<bool>("can_edit_messages", false); result->canDeleteMessages = data.get<bool>("can_delete_messages", false); - result->canInviteUsers = data.get<bool>("can_invite_users", false); result->canRestrictMembers = data.get<bool>("can_restrict_members", false); + result->canPromoteMembers = data.get<bool>("can_promote_members", false); + result->canChangeInfo = data.get<bool>("can_change_info", false); + result->canInviteUsers = data.get<bool>("can_invite_users", false); result->canPinMessages = data.get<bool>("can_pin_messages", false); result->isMember = data.get<bool>("is_member", false); - result->canPromoteMembers = data.get<bool>("can_promote_messages", false); result->canSendMessages = data.get<bool>("can_send_messages", false); result->canSendMediaMessages = data.get<bool>("can_send_media_messages", false); + result->canSendPolls = data.get<bool>("can_send_polls", false); result->canSendOtherMessages = data.get<bool>("can_send_other_messages", false); result->canAddWebPagePreviews = data.get<bool>("can_add_web_page_previews", false); return result; @@ -962,6 +1007,23 @@ std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const { result += '{'; appendToJson(result, "user", parseUser(object->user)); appendToJson(result, "status", object->status); + appendToJson(result, "custom_title", object->customTitle); + appendToJson(result, "until_date", object->untilDate); + appendToJson(result, "can_be_edited", object->canBeEdited); + appendToJson(result, "can_post_messages", object->canPostMessages); + appendToJson(result, "can_edit_messages", object->canEditMessages); + appendToJson(result, "can_delete_messages", object->canDeleteMessages); + appendToJson(result, "can_restrict_members", object->canRestrictMembers); + appendToJson(result, "can_promote_members", object->canPromoteMembers); + appendToJson(result, "can_change_info", object->canChangeInfo); + appendToJson(result, "can_invite_users", object->canInviteUsers); + appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "is_member", object->isMember); + appendToJson(result, "can_send_messages", object->canSendMessages); + appendToJson(result, "can_send_media_messages", object->canSendMediaMessages); + appendToJson(result, "can_send_polls", object->canSendPolls); + appendToJson(result, "can_send_other_messages", object->canSendOtherMessages); + appendToJson(result, "can_add_web_page_previews", object->canAddWebPagePreviews); removeLastComma(result); result += '}'; return result; @@ -970,7 +1032,9 @@ std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const { ChatPhoto::Ptr TgTypeParser::parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const { auto result(make_shared<ChatPhoto>()); result->smallFileId = data.get("small_file_id", ""); + result->smallFileUniqueId = data.get("small_file_unique_id", ""); result->bigFileId = data.get("big_file_id", ""); + result->bigFileUniqueId = data.get("big_file_unique_id", ""); return result; } @@ -981,7 +1045,9 @@ std::string TgTypeParser::parseChatPhoto(const ChatPhoto::Ptr& object) const { string result; result += '{'; appendToJson(result, "small_file_id", object->smallFileId); + appendToJson(result, "small_file_unique_id", object->smallFileUniqueId); appendToJson(result, "big_file_id", object->bigFileId); + appendToJson(result, "big_file_unique_id", object->bigFileUniqueId); removeLastComma(result); result += '}'; return result; |