From 6c2dc4d2eb84e7ba98f73332ccf95ffa5a7adf3f Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 27 Jul 2018 16:03:48 +0900 Subject: Bot API 4.0 - Part 1 --- include/tgbot/Api.h | 34 ++++++++++--- include/tgbot/types/Audio.h | 7 +++ include/tgbot/types/Contact.h | 5 ++ include/tgbot/types/InlineQueryResultContact.h | 5 ++ include/tgbot/types/InlineQueryResultVenue.h | 5 ++ include/tgbot/types/InputContactMessageContent.h | 5 ++ include/tgbot/types/InputVenueMessageContent.h | 4 ++ include/tgbot/types/Message.h | 8 +++ include/tgbot/types/MessageEntity.h | 4 +- include/tgbot/types/Venue.h | 7 ++- src/Api.cpp | 56 +++++++++++++++++--- src/TgTypeParser.cpp | 65 ++++++++++++++---------- 12 files changed, 165 insertions(+), 40 deletions(-) diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 0a781e6..2af7be2 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -27,6 +27,7 @@ #include #include +#include #include "tgbot/TgTypeParser.h" #include "tgbot/net/HttpClient.h" @@ -177,7 +178,7 @@ public: /** * @brief Use this method to send general files. * @param chatId Unique identifier for the target chat. - * @param document Id of the document that is already on the Telegram servers. + * @param documentId of the document that is already on the Telegram servers. * @param caption Document caption (may also be used when resending documents by file_id), 0-200 characters * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. @@ -393,6 +394,25 @@ public: Message::Ptr sendVideo(int64_t chatId, const std::string& videoId, bool supportsStreaming = false, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; + /** + * @brief Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). + * + * Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. + * + * @param chatId Unique identifier for the target chat. + * @param animation Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. + * @param duration Optional. Duration of sent animation in seconds. + * @param width Optional. Animation width. + * @param height Optional. Animation height. + * @param caption Optional. Animation caption (may also be used when resending animation by file_id), 0-200 characters + * @param replyToMessageId Optional. If the message is a reply, ID of the original message. + * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. + * @param parseMode Optional. Set it to "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. + * @param disableNotification Optional. Sends the message silenty. + * @return On success, the sent Message is returned. + */ + Message::Ptr sendAnimation(int64_t chatId, boost::variant animation, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "", + int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; /** * @brief Use this method to send video messages. On success, the sent Message is returned. * @param chatId Unique identifier for the target chat. @@ -405,7 +425,7 @@ public: * @return On success, the sent Message is returned. */ Message::Ptr sendVideoNote(int64_t chatId, InputFile::Ptr videoNote, int64_t replyToMessageId = 0, bool disableNotification = false, - int32_t duration = 0, int32_t length = 0, GenericReply::Ptr replyMarkup = GenericReply::Ptr()); + int32_t duration = 0, int32_t length = 0, GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; /** * @brief Use this method to send video messages. On success, the sent Message is returned. @@ -419,7 +439,7 @@ public: * @return On success, the sent Message is returned. */ Message::Ptr sendVideoNote(int64_t chatId, const std::string& videoNote, int64_t replyToMessageId = 0, bool disableNotification = false, - int32_t duration = 0, int32_t length = 0, GenericReply::Ptr replyMarkup = GenericReply::Ptr()); + int32_t duration = 0, int32_t length = 0, GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; /** * @brief Use this method to send a group of photos or videos as an album. @@ -520,13 +540,14 @@ public: * @param longitude Longitude of location. * @param title Name of the venue. * @param address Address of the venue. - * @param foursquare_id Foursquare identifier of the venue. + * @param foursquareId Foursquare identifier of the venue. + * @param foursquareType Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVenue(int64_t chatId, float latitude, float longitude, const std::string& title, const std::string& address, const std::string& foursquareId = "", + Message::Ptr sendVenue(int64_t chatId, float latitude, float longitude, const std::string& title, const std::string& address, const std::string& foursquareId = "", const std::string& foursquareType = "", bool disableNotification = false, int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared()) const; /** @@ -535,12 +556,13 @@ public: * @param phoneNumber Contact's phone number. * @param firstName Contact's first name. * @param lastName Contact's last name. + * @param vcard Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes. * @param disableNotification Optional. Sends the message silenty. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendContact(int64_t chatId, const std::string& phoneNumber, const std::string& firstName, const std::string& lastName = "", bool disableNotification = false, + Message::Ptr sendContact(int64_t chatId, const std::string& phoneNumber, const std::string& firstName, const std::string& lastName = "", const std::string& vcard = "", bool disableNotification = false, int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared()) const; /** diff --git a/include/tgbot/types/Audio.h b/include/tgbot/types/Audio.h index 3b8b3e3..b77a106 100644 --- a/include/tgbot/types/Audio.h +++ b/include/tgbot/types/Audio.h @@ -26,6 +26,8 @@ #include #include +#include "tgbot/types/PhotoSize.h" + namespace TgBot { /** @@ -69,6 +71,11 @@ public: * @brief Optional. File size. */ int32_t fileSize; + + /** + * @brief Optional. Thumbnail of the album cover to which the music file belongs + */ + PhotoSize::Ptr thumb; }; } diff --git a/include/tgbot/types/Contact.h b/include/tgbot/types/Contact.h index eb17e5a..9cfc477 100644 --- a/include/tgbot/types/Contact.h +++ b/include/tgbot/types/Contact.h @@ -57,6 +57,11 @@ public: * @brief Optional. Contact's user identifier in Telegram. */ std::string userId; + + /** + * @brief Optional. Additional data about the contact in the form of a vCard. + */ + std::string vcard; }; } diff --git a/include/tgbot/types/InlineQueryResultContact.h b/include/tgbot/types/InlineQueryResultContact.h index 39bd570..3f18a2a 100644 --- a/include/tgbot/types/InlineQueryResultContact.h +++ b/include/tgbot/types/InlineQueryResultContact.h @@ -44,6 +44,11 @@ public: */ std::string lastName; + /** + * @brief Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes + */ + std::string vcard; + /** * @brief Optional. Url of the thumbnail for the result */ diff --git a/include/tgbot/types/InlineQueryResultVenue.h b/include/tgbot/types/InlineQueryResultVenue.h index d012463..3f58e19 100644 --- a/include/tgbot/types/InlineQueryResultVenue.h +++ b/include/tgbot/types/InlineQueryResultVenue.h @@ -49,6 +49,11 @@ public: */ std::string foursquareId; + /** + * @brief Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) + */ + std::string foursquareType; + /** * @brief Optional. Url of the thumbnail for the result */ diff --git a/include/tgbot/types/InputContactMessageContent.h b/include/tgbot/types/InputContactMessageContent.h index 865dbba..799fa64 100644 --- a/include/tgbot/types/InputContactMessageContent.h +++ b/include/tgbot/types/InputContactMessageContent.h @@ -38,6 +38,11 @@ public: */ std::string lastName; + /** + * @brief Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes + */ + std::string vcard; + virtual ~InputContactMessageContent() { } }; } diff --git a/include/tgbot/types/InputVenueMessageContent.h b/include/tgbot/types/InputVenueMessageContent.h index 115e7d0..254a0a0 100644 --- a/include/tgbot/types/InputVenueMessageContent.h +++ b/include/tgbot/types/InputVenueMessageContent.h @@ -49,6 +49,10 @@ public: */ std::string foursquareId; + /** + * @brief Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) + */ + virtual ~InputVenueMessageContent() { } }; } diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index 1f5c75a..f92eeaf 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -32,6 +32,7 @@ #include "tgbot/types/Message.h" #include "tgbot/types/Audio.h" #include "tgbot/types/Document.h" +#include "tgbot/types/Animation.h" #include "tgbot/types/Sticker.h" #include "tgbot/types/Video.h" #include "tgbot/types/Contact.h" @@ -140,6 +141,13 @@ public: */ Document::Ptr document; + /** + * @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; + /** * @brief Optional. Message is a game, information about the game. */ diff --git a/include/tgbot/types/MessageEntity.h b/include/tgbot/types/MessageEntity.h index ca495ee..530011b 100644 --- a/include/tgbot/types/MessageEntity.h +++ b/include/tgbot/types/MessageEntity.h @@ -21,7 +21,9 @@ public: typedef std::shared_ptr Ptr; /** - * @brief Type of the entity. One of mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs). + * @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) */ std::string type; diff --git a/include/tgbot/types/Venue.h b/include/tgbot/types/Venue.h index 657d951..cc52314 100644 --- a/include/tgbot/types/Venue.h +++ b/include/tgbot/types/Venue.h @@ -39,7 +39,12 @@ public: /** * @brief Optional. Foursquare identifier of the venue. */ - std::string foursquare_id; + std::string foursquareId; + + /** + * @brief Optional. Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) + */ + std::string foursquareType; }; } diff --git a/src/Api.cpp b/src/Api.cpp index 08f5fac..85ba050 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -517,7 +517,43 @@ Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, bool supports return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) { +Message::Ptr Api::sendAnimation(int64_t chatId, boost::variant animation, int32_t duration, int32_t width, int32_t height, const string& caption, int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { + vector args; + args.reserve(10); + args.emplace_back("chat_id", chatId); + if (animation.which() == 0 /* InputFile::Ptr */) { + args.emplace_back("animation", boost::get(animation)); + } else /* std::string */ { + args.emplace_back("animation", boost::get(animation)); + } + if (duration) { + args.emplace_back("duration", duration); + } + if (width) { + args.emplace_back("width", width); + } + if (height) { + args.emplace_back("height", height); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (replyToMessageId) { + args.emplace_back("reply_to_message_id", replyToMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (disableNotification){ + args.emplace_back("disable_notification", disableNotification); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); +} + +Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) const { vector args; args.reserve(7); args.emplace_back("chat_id", chatId); @@ -540,7 +576,7 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); } -Message::Ptr Api::sendVideoNote(int64_t chatId, const string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) { +Message::Ptr Api::sendVideoNote(int64_t chatId, const string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) const { vector args; args.reserve(7); args.emplace_back("chat_id", chatId); @@ -719,7 +755,7 @@ bool Api::deleteChatStickerSet(int64_t chatId) const { Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector args; - args.reserve(9); + args.reserve(10); args.emplace_back("chat_id", chatId); args.emplace_back("latitude", latitude); args.emplace_back("longitude", longitude); @@ -728,6 +764,9 @@ Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, con if (!foursquareId.empty()) { args.emplace_back("foursquare_id", foursquareId); } + if (!foursquareType.empty()) { + args.emplace_back("foursquare_type", foursquareType); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -740,13 +779,18 @@ Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, con return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args)); } -Message::Ptr Api::sendContact(int64_t chatId, const string& phoneNumber, const string& firstName, const string& lastName, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendContact(int64_t chatId, const string& phoneNumber, const string& firstName, const string& lastName, const string& vcard, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector args; - args.reserve(7); + args.reserve(8); args.emplace_back("chat_id", chatId); args.emplace_back("phone_number", phoneNumber); args.emplace_back("first_name", firstName); - args.emplace_back("last_name", lastName); + if (!lastName.empty()) { + args.emplace_back("last_name", lastName); + } + if (!vcard.empty()) { + args.emplace_back("vcard", vcard); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index dbfb266..5a01aa6 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -153,6 +153,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->captionEntities = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities"); result->audio = tryParseJson