diff options
49 files changed, 2614 insertions, 162 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 0a2b7bd..ae8bbdb 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -37,6 +37,9 @@ #include "tgbot/types/Update.h" #include "tgbot/types/InlineQueryResult.h" #include "tgbot/types/Venue.h" +#include "tgbot/types/WebhookInfo.h" +#include "tgbot/types/ChatMember.h" +#include "tgbot/types/File.h" namespace TgBot { @@ -48,6 +51,8 @@ class Bot; */ class Api { +typedef std::shared_ptr<std::vector<std::string>> StringArrayPtr; + friend class Bot; public: @@ -112,6 +117,7 @@ public: * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. * @param audio Audio to send. + * @param caption Audio caption, 0-200 characters * @param duration Duration of sent audio in seconds. * @param performer Performer * @param title Track name @@ -120,7 +126,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration = 0, + Message::Ptr sendAudio(int64_t chatId, const InputFile::Ptr& audio, const std::string &caption = "", int32_t duration = 0, const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; @@ -128,6 +134,7 @@ public: * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. * @param audio Id of the audio that is already on the Telegram servers. + * @param caption Audio caption, 0-200 characters * @param duration Duration of sent audio in seconds. * @param performer Performer * @param title Track name @@ -136,7 +143,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(int64_t chatId, const std::string& audioId, int32_t duration = 0, + Message::Ptr sendAudio(int64_t chatId, const std::string& audioId, const std::string &caption = "", int32_t duration = 0, const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; @@ -144,24 +151,26 @@ public: * Use this method to send general files. * @param chatId Unique identifier for the target chat. * @param document Document to send. + * @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. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(int64_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId = 0, + Message::Ptr sendDocument(int64_t chatId, const InputFile::Ptr& document, const std::string &caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** * 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 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. * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(int64_t chatId, const std::string& documentId, int32_t replyToMessageId = 0, + Message::Ptr sendDocument(int64_t chatId, const std::string& documentId, const std::string &caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** @@ -192,50 +201,60 @@ public: * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. * @param video Video to send. + * @param duration Duration of sent video in seconds + * @param width Video width + * @param height Video height + * @param caption Video caption (may also be used when resending videos 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 disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId = 0, - const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "", + int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. * @param video Id of the video that is already on the Telegram servers. + * @param duration Duration of sent video in seconds + * @param width Video width + * @param height Video height + * @param caption Video caption (may also be used when resending videos 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. 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 sendVideo(int64_t chatId, const std::string& videoId, int32_t replyToMessageId = 0, - const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + Message::Ptr sendVideo(int64_t chatId, const std::string& videoId, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "", + int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. * @param chatId Unique identifier for the target chat. * @param voice Audio file to send. + * @param caption Voice message caption, 0-200 characters * @param duration Duration of send audio in seconds. * @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 sendVoice(int64_t chatId, const InputFile::Ptr& voice, int duration = 0, int32_t replyToMessageId = 0, + Message::Ptr sendVoice(int64_t chatId, const InputFile::Ptr& voice, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. * @param chatId Unique identifier for the target chat. * @param voiceId Id of the voice that is already on the Telegram servers. + * @param caption Voice message caption, 0-200 characters * @param duration Duration of send audio in seconds. * @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 sendVoice(int64_t chatId, const std::string& voiceId, int duration = 0, int32_t replyToMessageId = 0, + Message::Ptr sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; /** @@ -300,15 +319,107 @@ public: UserProfilePhotos::Ptr getUserProfilePhotos(int32_t userId, int32_t offset = 0, int32_t limit = 100) const; /** + * Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. + * @param fileId File identifier to get info about + * @return A File object. + */ + File::Ptr getFile(int32_t fileId) const; + + /** + * Use this method for your bot to leave a group, supergroup or channel. + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * @return True on success + */ + bool leaveChat(int64_t chatId) const; + + /** + * Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success. + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * @return Chat object. + */ + Chat::Ptr getChat(int64_t chatId) const; + + /** + * Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * @return ChatMember object. + */ + std::vector<ChatMember::Ptr> getChatAdministrators(int64_t chatId) const; + + /** + * Use this method to get the number of members in a chat. Returns Int on success. + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * @return Int. + */ + int32_t getChatMembersCount(int64_t chatId) const; + + /** + * Use this method to get information about a member of a chat. Returns a ChatMember object on success. + * @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 ChatMember object. + */ + ChatMember::Ptr getChatMember(int64_t chatId, int32_t userId) const; + + /** + * Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. + * @param callbackQueryId Unique identifier for the query to be answered + * @param text Optional Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters + * @param showAlert Optional If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. + * @param url Optional URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @Botfather, specify the URL that opens your game – note that this will only work if the query comes from a callback_game button + * @param cacheTime Optional The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0. + * @return True on success + */ + bool answerCallbackQuery(const std::string & callbackQueryId, const std::string & text="", bool showAlert=false, const std::string &url="", int32_t cacheTime=0) const; + + /** + * Use this method to edit text and game messages sent by the bot or via the bot (for inline bots) + * @param text New text of the message + * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message + * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message + * @param parseMode Optional Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. + * @param disableWebPagePreview Optional Disables link previews for links in this message + * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. + * @return Message object on success, otherwise nullptr + */ + Message::Ptr editMessageText(const std::string& text, int64_t chatId=0, int32_t messageId=0, const std::string& inlineMessageId="", + const std::string& parseMode = "", bool disableWebPagePreview = false, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + + /** + * Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). + * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message + * @param caption Optional New caption of the message + * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message + * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. + * @return Message object on success, otherwise nullptr + */ + Message::Ptr editMessageCaption(int64_t chatId = 0, int32_t messageId = 0, const std::string& caption = "", + const std::string& inlineMessageId = "", const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + + /** + * Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). + * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message + * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message + * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. + * @return Message object on success, otherwise nullptr + */ + Message::Ptr editMessageReplyMarkup(int64_t chatId = 0, int32_t messageId = 0, const std::string& inlineMessageId = "", + const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + + /** * Use this method to receive incoming updates using long polling. * This method will not work if an outgoing webhook is set up. * In order to avoid getting duplicate updates, recalculate offset after each server response. * @param offset Optional. Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. * @param limit Optional. Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100. * @param timeout Optional. Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. + * @param allowed_updates Optional. List the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used. * @return An Array of Update objects */ - std::vector<Update::Ptr> getUpdates(int32_t offset = 0, int32_t limit = 100, int32_t timeout = 0) const; + std::vector<Update::Ptr> getUpdates(int32_t offset = 0, int32_t limit = 100, int32_t timeout = 0, const StringArrayPtr &allowedUpdates = nullptr) const; /** * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. @@ -318,7 +429,20 @@ public: * Ports currently supported for Webhooks: 443, 80, 88, 8443. * @param url Optional. HTTPS url to send updates to. Use an empty string to remove webhook integration. */ - void setWebhook(const std::string& url = "", const InputFile::Ptr& certificate = nullptr) const; + void setWebhook(const std::string& url = "", const InputFile::Ptr& certificate = nullptr, int32_t maxConnection = 40, const StringArrayPtr &allowedUpdates = nullptr) const; + + /** + * Use this method to remove webhook integration if you decide to switch back to getUpdates. + * Returns True on success. Requires no parameters. + */ + bool deleteWebhook() const; + + /** + * Use this method to get current webhook status. + * Requires no parameters. On success, returns a WebhookInfo object. + * If the bot is using getUpdates, will return an object with the url field empty. + */ + WebhookInfo::Ptr getWebhookInfo() const; /** * Use this method to send answers to an inline query. @@ -328,23 +452,28 @@ public: * @param cacheTime The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300. * @param isPersonal Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query. * @param nextOffset Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes. + * @param switchPmText If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter + * @param switchPmParameter Parameter for the start message sent to the bot when user presses the switch button + * @return True on success */ - void answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results, - int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset="") const; + bool answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results, + int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset="", const std::string& switchPmText="", const std::string& switchPmParameter="") const; /** * Use this method to kick a user from a group or a supergroup. * @param chatId Unique identifier for the target group. * @param userId Unique identifier of the target user. + * @return True on success */ - void kickChatMember(int64_t chatId, int32_t userId) const; + bool kickChatMember(int64_t chatId, int32_t userId) const; /** * Use this method to unban a previously kicked user in a supergroup. * @param chatId Unique identifier for the target group. * @param userId Unique identifier of the target user. + * @return True on success */ - void unbanChatMember(int64_t chatId, int32_t userId) const; + bool unbanChatMember(int64_t chatId, int32_t userId) const; private: boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const; diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 9e5a1d7..89c6dec 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -40,21 +40,46 @@ #include "tgbot/types/Location.h" #include "tgbot/types/Update.h" #include "tgbot/types/UserProfilePhotos.h" +#include "tgbot/types/File.h" #include "tgbot/types/ReplyKeyboardMarkup.h" -#include "tgbot/types/ReplyKeyboardHide.h" +#include "tgbot/types/KeyboardButton.h" +#include "tgbot/types/ReplyKeyboardRemove.h" #include "tgbot/types/ForceReply.h" +#include "tgbot/types/ChatMember.h" +#include "tgbot/types/ResponseParameters.h" #include "tgbot/types/GenericReply.h" #include "tgbot/types/InlineQuery.h" #include "tgbot/types/InlineQueryResult.h" +#include "tgbot/types/InlineQueryResultCachedAudio.h" +#include "tgbot/types/InlineQueryResultCachedDocument.h" +#include "tgbot/types/InlineQueryResultCachedGif.h" +#include "tgbot/types/InlineQueryResultCachedMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultCachedPhoto.h" +#include "tgbot/types/InlineQueryResultCachedSticker.h" +#include "tgbot/types/InlineQueryResultCachedVideo.h" +#include "tgbot/types/InlineQueryResultCachedVoice.h" #include "tgbot/types/InlineQueryResultArticle.h" -#include "tgbot/types/InlineQueryResultPhoto.h" +#include "tgbot/types/InlineQueryResultAudio.h" +#include "tgbot/types/InlineQueryResultContact.h" +#include "tgbot/types/InlineQueryResultGame.h" +#include "tgbot/types/InlineQueryResultDocument.h" #include "tgbot/types/InlineQueryResultGif.h" +#include "tgbot/types/InlineQueryResultLocation.h" #include "tgbot/types/InlineQueryResultMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultPhoto.h" +#include "tgbot/types/InlineQueryResultVenue.h" #include "tgbot/types/InlineQueryResultVideo.h" +#include "tgbot/types/InlineQueryResultVoice.h" #include "tgbot/types/ChosenInlineResult.h" #include "tgbot/types/CallbackQuery.h" #include "tgbot/types/InlineKeyboardMarkup.h" #include "tgbot/types/InlineKeyboardButton.h" +#include "tgbot/types/WebhookInfo.h" +#include "tgbot/types/InputMessageContent.h" +#include "tgbot/types/InputTextMessageContent.h" +#include "tgbot/types/InputLocationMessageContent.h" +#include "tgbot/types/InputVenueMessageContent.h" +#include "tgbot/types/InputContactMessageContent.h" namespace TgBot { @@ -94,20 +119,85 @@ public: std::string parseUpdate(const Update::Ptr& object) const; UserProfilePhotos::Ptr parseJsonAndGetUserProfilePhotos(const boost::property_tree::ptree& data) const; std::string parseUserProfilePhotos(const UserProfilePhotos::Ptr& object) const; + + File::Ptr parseJsonAndGetFile(const boost::property_tree::ptree& data) const; + std::string parseFile(const File::Ptr& object) const; + ReplyKeyboardMarkup::Ptr parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const; std::string parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Ptr& object) const; - ReplyKeyboardHide::Ptr parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const; + + KeyboardButton::Ptr parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const; + std::string parseKeyboardButton(const KeyboardButton::Ptr& object) const; + + ReplyKeyboardRemove::Ptr parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const; + std::string parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const; + ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const; std::string parseForceReply(const ForceReply::Ptr& object) const; + + ChatMember::Ptr parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const; + std::string parseChatMember(const ChatMember::Ptr& object) const; + + ResponseParameters::Ptr parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const; + std::string parseResponseParameters(const ResponseParameters::Ptr& object) const; + GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const; std::string parseGenericReply(const GenericReply::Ptr& object) const; + InlineQuery::Ptr parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const; std::string parseInlineQuery(const InlineQuery::Ptr& object) const; + InlineQueryResult::Ptr parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const; std::string parseInlineQueryResult(const InlineQueryResult::Ptr& object) const; + + InlineQueryResultCachedAudio::Ptr parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const; + + InlineQueryResultCachedDocument::Ptr parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const; + + InlineQueryResultCachedGif::Ptr parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const; + + InlineQueryResultCachedMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const; + + InlineQueryResultCachedPhoto::Ptr parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const; + + InlineQueryResultCachedSticker::Ptr parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const; + + InlineQueryResultCachedVideo::Ptr parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const; + + InlineQueryResultCachedVoice::Ptr parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const; + InlineQueryResultArticle::Ptr parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const; std::string parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const; + + InlineQueryResultAudio::Ptr parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const; + + InlineQueryResultContact::Ptr parseJsonAndGetInlineQueryResultContact(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const; + + InlineQueryResultGame::Ptr parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const; + + InlineQueryResultDocument::Ptr parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const; + + InlineQueryResultLocation::Ptr parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const; + + InlineQueryResultVenue::Ptr parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const; + + InlineQueryResultVoice::Ptr parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const; + InlineQueryResultPhoto::Ptr parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const; std::string parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const; InlineQueryResultGif::Ptr parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const; @@ -118,6 +208,7 @@ public: std::string parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const; ChosenInlineResult::Ptr parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const; std::string parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const; + CallbackQuery::Ptr parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const; std::string parseCallbackQuery(const CallbackQuery::Ptr& object) const; InlineKeyboardMarkup::Ptr parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const; @@ -125,6 +216,24 @@ public: InlineKeyboardButton::Ptr parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const; std::string parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const; + WebhookInfo::Ptr parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const; + std::string parseWebhookInfo(const WebhookInfo::Ptr& object) const; + + InputMessageContent::Ptr parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputMessageContent(const InputMessageContent::Ptr& object) const; + + InputTextMessageContent::Ptr parseJsonAndGetInputTextMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const; + + InputLocationMessageContent::Ptr parseJsonAndGetInputLocationMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const; + + InputVenueMessageContent::Ptr parseJsonAndGetInputVenueMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const; + + InputContactMessageContent::Ptr parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const; + std::string parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const; + inline boost::property_tree::ptree parseJson(const std::string& json) const { boost::property_tree::ptree tree; std::istringstream input(json); @@ -151,6 +260,19 @@ public: } template<typename T> + std::vector<T> parseJsonAndGetArray(std::function<T(const boost::property_tree::ptree&)> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { + std::vector<T> result; + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { + return result; + } + for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { + result.push_back(parseFunc(innerTreeItem.second)); + } + return result; + } + + template<typename T> std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { std::vector<std::shared_ptr<T>> result; auto treeItem = data.find(keyName); @@ -182,6 +304,8 @@ public: template<typename T> std::string parseArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::shared_ptr<T>>& objects) const { + if (objects.empty()) + return ""; std::string result; result += '['; for (const std::shared_ptr<T>& item : objects) { @@ -194,7 +318,24 @@ public: } template<typename T> + std::string parseArray(std::function<T(const T&)> parseFunc, const std::vector<T>& objects) const { + if (objects.empty()) + return ""; + std::string result; + result += '['; + for (const T& item : objects) { + result += parseFunc(item); + result += ','; + } + result.erase(result.length() - 1); + result += ']'; + return result; + } + + template<typename T> std::string parse2DArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::vector<std::shared_ptr<T>>>& objects) const { + if (objects.empty()) + return ""; std::string result; result += '['; for (const std::vector<std::shared_ptr<T>>& item : objects) { diff --git a/include/tgbot/tgbot.h b/include/tgbot/tgbot.h index 34dc0a9..36b7dab 100644 --- a/include/tgbot/tgbot.h +++ b/include/tgbot/tgbot.h @@ -38,7 +38,7 @@ #include "tgbot/types/Location.h" #include "tgbot/types/Message.h" #include "tgbot/types/PhotoSize.h" -#include "tgbot/types/ReplyKeyboardHide.h" +#include "tgbot/types/ReplyKeyboardRemove.h" #include "tgbot/types/ReplyKeyboardMarkup.h" #include "tgbot/types/Sticker.h" #include "tgbot/types/Update.h" diff --git a/include/tgbot/types/Audio.h b/include/tgbot/types/Audio.h index e39eb00..14cf17f 100644 --- a/include/tgbot/types/Audio.h +++ b/include/tgbot/types/Audio.h @@ -48,6 +48,18 @@ public: int32_t duration; /** + * Optional. Performer of the audio as defined by sender + * or by audio tags + */ + std::string performer; + + /** + * Optional. Title of the audio as defined by sender or + * by audio tags + */ + std::string title; + + /** * Optional. MIME type of the file as defined by sender. */ std::string mimeType; diff --git a/include/tgbot/types/CallbackQuery.h b/include/tgbot/types/CallbackQuery.h index 5f6871d..8d684c0 100644 --- a/include/tgbot/types/CallbackQuery.h +++ b/include/tgbot/types/CallbackQuery.h @@ -42,10 +42,19 @@ public: std::string inlineMessageId; /** + * Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games. + */ + std::string chatInstance; + + /** * Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field. */ std::string data; + /* + * Optional. Short name of a Game to be returned, serves as the unique identifier for the game + */ + std::string gameShortName; }; } diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h index 9a109e7..1491fd3 100644 --- a/include/tgbot/types/Chat.h +++ b/include/tgbot/types/Chat.h @@ -76,6 +76,12 @@ public: * other party in private chat */ std::string lastName; + + /** + * Optional. True if a group + * has All Members Are Admins enabled. + */ + bool allMembersAreAdministrators; }; } diff --git a/include/tgbot/types/ChatMember.h b/include/tgbot/types/ChatMember.h new file mode 100644 index 0000000..7f4b139 --- /dev/null +++ b/include/tgbot/types/ChatMember.h @@ -0,0 +1,35 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_CHATMEMBER_H +#define TGBOT_CHATMEMBER_H + +#include <memory> +#include <string> + +#include "tgbot/types/User.h" + +namespace TgBot { + +/** + * This object contains information about one member of the chat. + * @ingroup types + */ +class ChatMember { +public: + typedef std::shared_ptr<ChatMember> Ptr; + + /** + * Information about the user + */ + User::Ptr user; + + /** + * The member's status in the chat. Can be creator, administrator, member, left or kicked + */ + std::string status; +}; +} + +#endif //TGBOT_CHATMEMBER_H diff --git a/include/tgbot/types/ChosenInlineResult.h b/include/tgbot/types/ChosenInlineResult.h index c6d730e..4492e52 100644 --- a/include/tgbot/types/ChosenInlineResult.h +++ b/include/tgbot/types/ChosenInlineResult.h @@ -9,6 +9,7 @@ #include <memory> #include "tgbot/types/User.h" +#include "tgbot/types/Location.h" namespace TgBot { @@ -31,6 +32,18 @@ public: User::Ptr from; /** + * Optional. Sender location, only for bots that require user location + */ + Location::Ptr location; + + /** + * Optional. Identifier of the sent inline message. + * Available only if there is an inline keyboard attached to the message. + * Will be also received in callback queries and can be used to edit the message. + */ + std::string inlineMessageId; + + /** * The query that was used to obtain the result. */ std::string query; diff --git a/include/tgbot/types/File.h b/include/tgbot/types/File.h new file mode 100644 index 0000000..a370dd6 --- /dev/null +++ b/include/tgbot/types/File.h @@ -0,0 +1,45 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_CPP_FILE_H +#define TGBOT_CPP_FILE_H + +#include <string> +#include <memory> + +namespace TgBot { + +/** + * This object represents a file ready to be downloaded. + * The file can be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>. + * It is guaranteed that the link will be valid for at least 1 hour. + * When the link expires, a new one can be requested by calling getFile. + * Maximum file size to download is 20 MB + * @ingroup types + */ +class File { + +public: + typedef std::shared_ptr<File> Ptr; + + /** + * Unique identifier for this file + */ + std::string fileId; + + /** + * Optional. File size, if known + */ + int32_t fileSize; + + /** + * Optional. File path. + * Use https://api.telegram.org/file/bot<token>/<file_path> to get the file. + */ + std::string filePath; +}; + +} + +#endif //TGBOT_CPP_FILE_H diff --git a/include/tgbot/types/InlineKeyboardButton.h b/include/tgbot/types/InlineKeyboardButton.h index 1a71341..a8fb3db 100644 --- a/include/tgbot/types/InlineKeyboardButton.h +++ b/include/tgbot/types/InlineKeyboardButton.h @@ -37,6 +37,11 @@ public: * Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. */ std::string switchInlineQuery; + + /** + * Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. + */ + std::string switchInlineQueryCurrentChat; }; } diff --git a/include/tgbot/types/InlineQuery.h b/include/tgbot/types/InlineQuery.h index a469ea7..f2c22c3 100644 --- a/include/tgbot/types/InlineQuery.h +++ b/include/tgbot/types/InlineQuery.h @@ -9,6 +9,7 @@ #include <string> #include "tgbot/types/User.h" +#include "tgbot/types/Location.h" namespace TgBot { @@ -30,6 +31,11 @@ public: */ User::Ptr from; + /** + * Optional. Sender location, only for bots that request user location + */ + Location::Ptr location; + /** * Text of the query. */ diff --git a/include/tgbot/types/InlineQueryResult.h b/include/tgbot/types/InlineQueryResult.h index d3eb968..d06bffd 100644 --- a/include/tgbot/types/InlineQueryResult.h +++ b/include/tgbot/types/InlineQueryResult.h @@ -8,6 +8,9 @@ #include <memory> #include <string> +#include "tgbot/types/InlineKeyboardMarkup.h" +#include "tgbot/types/InputMessageContent.h" + namespace TgBot { /** @@ -19,7 +22,7 @@ public: typedef std::shared_ptr<InlineQueryResult> Ptr; InlineQueryResult() { - this->disableWebPagePreview = false; + } virtual ~InlineQueryResult() { } @@ -35,31 +38,24 @@ public: std::string id; /** - * Optional. Title of the result. + * Requred, optional or missing. See description of derived classes. Title of the result. */ std::string title; /** - * Text of the message t be sent. (1-4096 characters) - */ - std::string messageText; - - /** - * Optional. Send Markdown or HTML, if you want Telegram apps to - * show bold, italic, fixed-width text or inline URLs in your bot's message. - */ - std::string parseMode; - - /** - * Optional. Disables link previews for links in the send message. - */ - bool disableWebPagePreview; - - /** - * Optional. Url of the thumbnail for the result. - */ - std::string thumbUrl; - + * Optional or missing. See description of derived classes. Caption of the file to be sent, 0-200 characters + */ + std::string caption; + + /** + * Optional. Inline keyboard attached to the message + */ + InlineKeyboardMarkup::Ptr replyMarkup; + + /** + * Requred, optional or missing. See description of derived classes. Content of the message to be sent + */ + InputMessageContent::Ptr inputMessageContent; }; } diff --git a/include/tgbot/types/InlineQueryResultArticle.h b/include/tgbot/types/InlineQueryResultArticle.h index c903255..924963c 100644 --- a/include/tgbot/types/InlineQueryResultArticle.h +++ b/include/tgbot/types/InlineQueryResultArticle.h @@ -44,6 +44,11 @@ public: */ std::string description; + /** + * Optional. Url of the thumbnail for the result + */ + std::string thumbUrl; + /** * Optional. Thumbnail width. */ diff --git a/include/tgbot/types/InlineQueryResultAudio.h b/include/tgbot/types/InlineQueryResultAudio.h new file mode 100644 index 0000000..7c02e4e --- /dev/null +++ b/include/tgbot/types/InlineQueryResultAudio.h @@ -0,0 +1,47 @@ +// +// Created by Konstantin Kukin on 27/12/16 +// + +#ifndef TGBOT_INLINEQUERYRESULTAUDIO_H +#define TGBOT_INLINEQUERYRESULTAUDIO_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to an mp3 audio file. + * @ingroup types + */ +class InlineQueryResultAudio : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultAudio> Ptr; + + InlineQueryResultAudio() { + this->type = TYPE; + this->audioDuration = 0; + } + + /** + * A valid URL for the audio file + */ + std::string audioUrl; + + /** + * Optional. Performer + */ + std::string performer; + + /** + * Optional. Audio duration in seconds + */ + int32_t audioDuration; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTAUDIO_H diff --git a/include/tgbot/types/InlineQueryResultCachedAudio.h b/include/tgbot/types/InlineQueryResultCachedAudio.h new file mode 100644 index 0000000..db1db2f --- /dev/null +++ b/include/tgbot/types/InlineQueryResultCachedAudio.h @@ -0,0 +1,37 @@ +// +// Created by Konstantin Kukin on 27/12/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTCACHEDAUDIO_H +#define TGBOT_INLINEQUERYRESULTCACHEDAUDIO_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to an mp3 audio file stored on the Telegram servers. + * @ingroup types + */ +class InlineQueryResultCachedAudio : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultCachedAudio> Ptr; + + InlineQueryResultCachedAudio() { + this->type = TYPE; + } + + /** + * A valid file identifier for the audio file + */ + std::string audioFileId; + +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCACHEDAUDIO_H diff --git a/include/tgbot/types/InlineQueryResultCachedDocument.h b/include/tgbot/types/InlineQueryResultCachedDocument.h new file mode 100644 index 0000000..60ad19d --- /dev/null +++ b/include/tgbot/types/InlineQueryResultCachedDocument.h @@ -0,0 +1,41 @@ +// +// Created by Konstantin Kukin on 27/12/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTCACHEDDOCUMENT_H +#define TGBOT_INLINEQUERYRESULTCACHEDDOCUMENT_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to a file stored on the Telegram servers. + * @ingroup types + */ +class InlineQueryResultCachedDocument : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultCachedDocument> Ptr; + + InlineQueryResultCachedDocument() { + this->type = TYPE; + } + + /** + * A valid file identifier for the file + */ + std::string documentFileId; + + /** + * Optional. Short description of the result + */ + std::string description; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCACHEDDOCUMENT_H diff --git a/include/tgbot/types/InlineQueryResultCachedGif.h b/include/tgbot/types/InlineQueryResultCachedGif.h new file mode 100644 index 0000000..e360d4d --- /dev/null +++ b/include/tgbot/types/InlineQueryResultCachedGif.h @@ -0,0 +1,37 @@ +// +// Created by Konstantin Kukin on 27/12/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTCACHEDGIF_H +#define TGBOT_INLINEQUERYRESULTCACHEDGIF_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to an animated GIF file stored on the Telegram servers. + * @ingroup types + */ +class InlineQueryResultCachedGif : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultCachedGif> Ptr; + + InlineQueryResultCachedGif() { + this->type = TYPE; + } + + /** + * A valid file identifier for the GIF file + */ + std::string gifFileId; + +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCACHEDGIF_H diff --git a/include/tgbot/types/InlineQueryResultCachedMpeg4Gif.h b/include/tgbot/types/InlineQueryResultCachedMpeg4Gif.h new file mode 100644 index 0000000..55c7f92 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultCachedMpeg4Gif.h @@ -0,0 +1,37 @@ +// +// Created by Konstantin Kukin on 27/12/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTCACHEDMPEG4GIF_H +#define TGBOT_INLINEQUERYRESULTCACHEDMPEG4GIF_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. + * @ingroup types + */ +class InlineQueryResultCachedMpeg4Gif : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultCachedMpeg4Gif> Ptr; + + InlineQueryResultCachedMpeg4Gif() { + this->type = TYPE; + } + + /** + * A valid file identifier for the MP4 file + */ + std::string mpeg4FileId; + +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCACHEDMPEG4GIF_H diff --git a/include/tgbot/types/InlineQueryResultCachedPhoto.h b/include/tgbot/types/InlineQueryResultCachedPhoto.h new file mode 100644 index 0000000..ac21224 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultCachedPhoto.h @@ -0,0 +1,41 @@ +// +// Created by Konstantin Kukin on 27/12/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTCACHEDPHOTO_H +#define TGBOT_INLINEQUERYRESULTCACHEDPHOTO_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to a photo stored on the Telegram servers. + * @ingroup types + */ +class InlineQueryResultCachedPhoto : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultCachedPhoto> Ptr; + + InlineQueryResultCachedPhoto() { + this->type = TYPE; + } + + /** + * A valid file identifier of the photo + */ + std::string photoFileId; + + /** + * Optional. Short description of the result + */ + std::string description; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCACHEDPHOTO_H diff --git a/include/tgbot/types/InlineQueryResultCachedSticker.h b/include/tgbot/types/InlineQueryResultCachedSticker.h new file mode 100644 index 0000000..597479c --- /dev/null +++ b/include/tgbot/types/InlineQueryResultCachedSticker.h @@ -0,0 +1,36 @@ +// +// Created by Konstantin Kukin on 27/12/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTCACHEDSTICKER_H +#define TGBOT_INLINEQUERYRESULTCACHEDSTICKER_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to a sticker stored on the Telegram servers. + * @ingroup types + */ +class InlineQueryResultCachedSticker : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultCachedSticker> Ptr; + + InlineQueryResultCachedSticker() { + this->type = TYPE; + } + + /** + * A valid file identifier of the sticker + */ + std::string stickerFileId; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCACHEDSTICKER_H diff --git a/include/tgbot/types/InlineQueryResultCachedVideo.h b/include/tgbot/types/InlineQueryResultCachedVideo.h new file mode 100644 index 0000000..48010bf --- /dev/null +++ b/include/tgbot/types/InlineQueryResultCachedVideo.h @@ -0,0 +1,41 @@ +// +// Created by Konstantin Kukin on 27/12/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTCACHEDVIDEO_H +#define TGBOT_INLINEQUERYRESULTCACHEDVIDEO_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to a video file stored on the Telegram servers. + * @ingroup types + */ +class InlineQueryResultCachedVideo : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultCachedVideo> Ptr; + + InlineQueryResultCachedVideo() { + this->type = TYPE; + } + + /** + * A valid file identifier of the video + */ + std::string videoFileId; + + /** + * Optional. Short description of the result + */ + std::string description; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCACHEDVIDEO_H diff --git a/include/tgbot/types/InlineQueryResultCachedVoice.h b/include/tgbot/types/InlineQueryResultCachedVoice.h new file mode 100644 index 0000000..1e70ff5 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultCachedVoice.h @@ -0,0 +1,36 @@ +// +// Created by Konstantin Kukin on 27/12/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTCACHEDVOICE_H +#define TGBOT_INLINEQUERYRESULTCACHEDVOICE_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to a voice message stored on the Telegram servers. + * @ingroup types + */ +class InlineQueryResultCachedVoice : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultCachedVoice> Ptr; + + InlineQueryResultCachedVoice() { + this->type = TYPE; + } + + /** + * A valid file identifier of the voice message + */ + std::string voiceFileId; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCACHEDVOICE_H diff --git a/include/tgbot/types/InlineQueryResultContact.h b/include/tgbot/types/InlineQueryResultContact.h new file mode 100644 index 0000000..80d04d5 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultContact.h @@ -0,0 +1,63 @@ +// +// Created by Konstantin Kukin on 27/12/16 +// + +#ifndef TGBOT_INLINEQUERYRESULTCONTACT_H +#define TGBOT_INLINEQUERYRESULTCONTACT_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a contact with a phone number + * @ingroup types + */ +class InlineQueryResultContact : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultContact> Ptr; + + InlineQueryResultContact() { + this->type = TYPE; + this->thumbHeight = 0; + this->thumbWidth = 0; + } + + /** + * Contact's phone number + */ + std::string phoneNumber; + + /** + * Contact's first name + */ + std::string firstName; + + /** + * Optional. Contact's last name + */ + std::string lastName; + + /** + * Optional. Url of the thumbnail for the result + */ + std::string thumbUrl; + + /** + * Optional. Thumbnail width. + */ + int32_t thumbWidth; + + /** + * Optinal. Thumbnail height + */ + int32_t thumbHeight; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTCONTACT_H diff --git a/include/tgbot/types/InlineQueryResultDocument.h b/include/tgbot/types/InlineQueryResultDocument.h new file mode 100644 index 0000000..70e0d33 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultDocument.h @@ -0,0 +1,63 @@ +// +// Created by Konstantin Kukin on 27/12/16 +// + +#ifndef TGBOT_INLINEQUERYRESULTDOCUMENT_H +#define TGBOT_INLINEQUERYRESULTDOCUMENT_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to a file. + * @ingroup types + */ +class InlineQueryResultDocument : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultDocument> Ptr; + + InlineQueryResultDocument() { + this->type = TYPE; + this->thumbHeight = 0; + this->thumbWidth = 0; + } + + /** + * A valid URL for the file + */ + std::string documentUrl; + + /** + * Mime type of the content of the file, either application/pdf or application/zip + */ + std::string mimeType; + + /** + * Optional. Short description of the result + */ + std::string description; + + /** + * Optional. Url of the thumbnail for the result + */ + std::string thumbUrl; + + /** + * Optional. Thumbnail width. + */ + int32_t thumbWidth; + + /** + * Optinal. Thumbnail height + */ + int32_t thumbHeight; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTDOCUMENT_H diff --git a/include/tgbot/types/InlineQueryResultGame.h b/include/tgbot/types/InlineQueryResultGame.h new file mode 100644 index 0000000..d06d1bd --- /dev/null +++ b/include/tgbot/types/InlineQueryResultGame.h @@ -0,0 +1,36 @@ +// +// Created by Konstantin Kukin on 27/12/16 +// + +#ifndef TGBOT_INLINEQUERYRESULTGAME_H +#define TGBOT_INLINEQUERYRESULTGAME_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a Game. + * @ingroup types + */ +class InlineQueryResultGame : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultGame> Ptr; + + InlineQueryResultGame() { + this->type = TYPE; + } + + /** + * Short name of the game + */ + std::string gameShortName; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTGAME_H diff --git a/include/tgbot/types/InlineQueryResultGif.h b/include/tgbot/types/InlineQueryResultGif.h index 8892f56..0dc67e8 100644 --- a/include/tgbot/types/InlineQueryResultGif.h +++ b/include/tgbot/types/InlineQueryResultGif.h @@ -44,9 +44,9 @@ public: int32_t gifHeight; /** - * Optional. Caption for the GIF file to be sent. + * URL of the static thumbnail for the result (jpeg or gif) */ - std::string caption; + std::string thumbUrl; }; } diff --git a/include/tgbot/types/InlineQueryResultLocation.h b/include/tgbot/types/InlineQueryResultLocation.h new file mode 100644 index 0000000..e5cf6ab --- /dev/null +++ b/include/tgbot/types/InlineQueryResultLocation.h @@ -0,0 +1,58 @@ +// +// Created by Konstantin Kukin on 27/12/16 +// + +#ifndef TGBOT_INLINEQUERYRESULTLOCATION_H +#define TGBOT_INLINEQUERYRESULTLOCATION_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a location on a map. + * @ingroup types + */ +class InlineQueryResultLocation : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultLocation> Ptr; + + InlineQueryResultLocation() { + this->type = TYPE; + this->thumbHeight = 0; + this->thumbWidth = 0; + } + + /** + * Location latitude in degrees + */ + float latitude; + + /** + * Location longitude in degrees + */ + float longitude; + + /** + * Optional. Url of the thumbnail for the result + */ + std::string thumbUrl; + + /** + * Optional. Thumbnail width. + */ + int32_t thumbWidth; + + /** + * Optinal. Thumbnail height + */ + int32_t thumbHeight; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTLOCATION_H diff --git a/include/tgbot/types/InlineQueryResultMpeg4Gif.h b/include/tgbot/types/InlineQueryResultMpeg4Gif.h index 0ba80aa..c1dbb9e 100644 --- a/include/tgbot/types/InlineQueryResultMpeg4Gif.h +++ b/include/tgbot/types/InlineQueryResultMpeg4Gif.h @@ -39,10 +39,9 @@ public: int32_t mpeg4Height; /** - * Optional. Caption of the MPEG-4 file to be sent. - */ - std::string caption; - + * URL of the static thumbnail (jpeg or gif) for the result + */ + std::string thumbUrl; }; } diff --git a/include/tgbot/types/InlineQueryResultPhoto.h b/include/tgbot/types/InlineQueryResultPhoto.h index 1c333f6..b689d35 100644 --- a/include/tgbot/types/InlineQueryResultPhoto.h +++ b/include/tgbot/types/InlineQueryResultPhoto.h @@ -33,6 +33,11 @@ public: */ std::string photoUrl; + /** + * URL of the thumbnail for the photo + */ + std::string thumbUrl; + /** * Optional. Width of the photo. */ @@ -47,11 +52,6 @@ public: * Optional. Short description of the result. */ std::string description; - - /** - * Optional. Caption of the photo to be sent. - */ - std::string caption; }; } diff --git a/include/tgbot/types/InlineQueryResultVenue.h b/include/tgbot/types/InlineQueryResultVenue.h new file mode 100644 index 0000000..c2e47c5 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultVenue.h @@ -0,0 +1,68 @@ +// +// Created by Konstantin Kukin on 27/12/16 +// + +#ifndef TGBOT_INLINEQUERYRESULTVENUE_H +#define TGBOT_INLINEQUERYRESULTVENUE_H + +#include <string> +#include <memory> + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a venue. + * @ingroup types + */ +class InlineQueryResultVenue : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultVenue> Ptr; + + InlineQueryResultVenue() { + this->type = TYPE; + this->thumbHeight = 0; + this->thumbWidth = 0; + } + + /** + * Latitude of the venue location in degrees + */ + float latitude; + + /** + * Longitude of the venue location in degrees + */ + float longitude; + + /** + * Address of the venue + */ + std::string address; + + /** + * Optional. Foursquare identifier of the venue if known + */ + std::string foursquareId; + + /** + * Optional. Url of the thumbnail for the result + */ + std::string thumbUrl; + + /** + * Optional. Thumbnail width. + */ + int32_t thumbWidth; + + /** + * Optinal. Thumbnail height + */ + int32_t thumbHeight; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTVENUE_H diff --git a/include/tgbot/types/InlineQueryResultVideo.h b/include/tgbot/types/InlineQueryResultVideo.h index 6449c6d..1515486 100644 --- a/include/tgbot/types/InlineQueryResultVideo.h +++ b/include/tgbot/types/InlineQueryResultVideo.h @@ -35,6 +35,11 @@ public: std::string mimeType; /** + * URL of the thumbnail (jpeg only) for the video + */ + std::string thumbUrl; + + /** * Optional. Video width. */ int32_t videoWidth; diff --git a/include/tgbot/types/InlineQueryResultVoice.h b/include/tgbot/types/InlineQueryResultVoice.h new file mode 100644 index 0000000..2bc4aac --- /dev/null +++ b/include/tgbot/types/InlineQueryResultVoice.h @@ -0,0 +1,37 @@ +// +// Created by Konstantin Kukin on 27/12/16 +// + +#ifndef TGBOT_INLINEQUERYRESULTVOICE_H +#define TGBOT_INLINEQUERYRESULTVOICE_H + +namespace TgBot { + +/** + * Represents link to a page containing an embedded video player or a video file. + * @ingroup types + */ +class InlineQueryResultVoice : public InlineQueryResult { +public: + static const std::string TYPE; + + typedef std::shared_ptr<InlineQueryResultVoice> Ptr; + + InlineQueryResultVoice() { + this->type = TYPE; + this->voiceDuration = 0; + }; + + /** + * A valid URL for the voice recording + */ + std::string voiceUrl; + + /** + * Optional. Recording duration in seconds + */ + int32_t voiceDuration; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTVOICE_H diff --git a/include/tgbot/types/InputContactMessageContent.h b/include/tgbot/types/InputContactMessageContent.h new file mode 100644 index 0000000..421093c --- /dev/null +++ b/include/tgbot/types/InputContactMessageContent.h @@ -0,0 +1,44 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_INPUTCONTACTMESSAGECONTENT_H +#define TGBOT_INPUTCONTACTMESSAGECONTENT_H + +#include <memory> +#include <string> + +namespace TgBot { + +/** +* Represents the content of a contact message to be sent as the result of an inline query. +* @ingroup types +*/ +class InputContactMessageContent : public InputMessageContent { +public: + typedef std::shared_ptr<InputContactMessageContent> Ptr; + + InputContactMessageContent() : + InputMessageContent("InputContactMessageContent") + {} + + /** + * Contact's phone number + */ + std::string phoneNumber; + + /** + * Contact's first name + */ + std::string firstName; + + /** + * Optional. Contact's last name + */ + std::string lastName; + + virtual ~InputContactMessageContent() { } +}; +} + +#endif //TGBOT_INPUTCONTACTMESSAGECONTENT_H diff --git a/include/tgbot/types/InputLocationMessageContent.h b/include/tgbot/types/InputLocationMessageContent.h new file mode 100644 index 0000000..3405353 --- /dev/null +++ b/include/tgbot/types/InputLocationMessageContent.h @@ -0,0 +1,38 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_INPUTLOCATIONMESSAGECONTENT_H +#define TGBOT_INPUTLOCATIONMESSAGECONTENT_H + +#include <memory> + +namespace TgBot { + +/** +* Represents the content of a location message to be sent as the result of an inline query. +* @ingroup types +*/ +class InputLocationMessageContent : public InputMessageContent { +public: + typedef std::shared_ptr<InputLocationMessageContent> Ptr; + + InputLocationMessageContent() : + InputMessageContent("InputLocationMessageContent") + {} + + /** + * Latitude of the location in degrees + */ + float latitude; + + /** + * Longitude of the location in degrees + */ + float longitude; + + virtual ~InputLocationMessageContent() { } +}; +} + +#endif //TGBOT_INPUTLOCATIONMESSAGECONTENT_H diff --git a/include/tgbot/types/InputMessageContent.h b/include/tgbot/types/InputMessageContent.h new file mode 100644 index 0000000..587dcf8 --- /dev/null +++ b/include/tgbot/types/InputMessageContent.h @@ -0,0 +1,37 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_INPUTMESSAGECONTENT_H +#define TGBOT_INPUTMESSAGECONTENT_H + +#include <memory> + +namespace TgBot { + +/** +* This object represents the content of a message to be sent as a result of an inline query. +* @ingroup types +*/ +class InputMessageContent { +public: + typedef std::shared_ptr<InputMessageContent> Ptr; + + InputMessageContent(const std::string &tType): + type(tType) + {} + + /** + * May be + * InputTextMessageContent + * InputLocationMessageContent + * InputVenueMessageContent + * InputContactMessageContent + */ + std::string type; + + virtual ~InputMessageContent() { } +}; +} + +#endif //TGBOT_INPUTMESSAGECONTENT_H diff --git a/include/tgbot/types/InputTextMessageContent.h b/include/tgbot/types/InputTextMessageContent.h new file mode 100644 index 0000000..4c33069 --- /dev/null +++ b/include/tgbot/types/InputTextMessageContent.h @@ -0,0 +1,44 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_INPUTTEXTMESSAGECONTENT_H +#define TGBOT_INPUTTEXTMESSAGECONTENT_H + +#include <memory> +#include <string> + +namespace TgBot { + +/** +* Represents the content of a text message to be sent as the result of an inline query. +* @ingroup types +*/ +class InputTextMessageContent : public InputMessageContent { +public: + typedef std::shared_ptr<InputTextMessageContent> Ptr; + + InputTextMessageContent(): + InputMessageContent("InputTextMessageContent") + {} + + /** + * Text of the message to be sent, 1-4096 characters + */ + std::string messageText; + + /** + * Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. + */ + std::string parseMode; + + /** + * Optional. Disables link previews for links in the sent message + */ + bool disableWebPagePreview; + + virtual ~InputTextMessageContent() { } +}; +} + +#endif //TGBOT_INPUTTEXTMESSAGECONTENT_H diff --git a/include/tgbot/types/InputVenueMessageContent.h b/include/tgbot/types/InputVenueMessageContent.h new file mode 100644 index 0000000..3ffc998 --- /dev/null +++ b/include/tgbot/types/InputVenueMessageContent.h @@ -0,0 +1,55 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + + +#ifndef TGBOT_INPUTVENUEMESSAGECONTENT_H +#define TGBOT_INPUTVENUEMESSAGECONTENT_H + +#include <memory> +#include <string> + +namespace TgBot { + +/** +* Represents the content of a venue message to be sent as the result of an inline query. +* @ingroup types +*/ +class InputVenueMessageContent : public InputMessageContent { +public: + typedef std::shared_ptr<InputVenueMessageContent> Ptr; + + InputVenueMessageContent() : + InputMessageContent("InputVenueMessageContent") + {} + + /** + * Latitude of the location in degrees + */ + float latitude; + + /** + * Longitude of the location in degrees + */ + float longitude; + + /** + * Name of the venue + */ + std::string title; + + /** + * Address of the venue + */ + std::string address; + + /** + * Optional. Foursquare identifier of the venue, if known + */ + std::string foursquareId; + + virtual ~InputVenueMessageContent() { } +}; +} + +#endif //TGBOT_INPUTVENUEMESSAGECONTENT_H diff --git a/include/tgbot/types/KeyboardButton.h b/include/tgbot/types/KeyboardButton.h new file mode 100644 index 0000000..637aced --- /dev/null +++ b/include/tgbot/types/KeyboardButton.h @@ -0,0 +1,44 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_CPP_KEYBOARDBUTTON_H +#define TGBOT_CPP_KEYBOARDBUTTON_H + +#include <string> +#include <memory> + +namespace TgBot { + +/** + * This object represents one button of the reply keyboard. + * For simple text buttons String can be used instead of this + * object to specify text of the button. Optional fields are mutually exclusive. + * @ingroup types + */ +class KeyboardButton { + +public: + typedef std::shared_ptr<KeyboardButton> Ptr; + + /** + * Text of the button. If none of the optional fields are used, + * it will be sent to the bot as a message when the button is pressed + */ + std::string text; + + /** + * Optional. If True, the user's phone number will be sent as a contact + * when the button is pressed. Available in private chats only + */ + bool requestContact; + + /** + * Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only. + */ + bool requestLocation; +}; + +} + +#endif //TGBOT_CPP_KEYBOARDBUTTON_H diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index be1d313..415f616 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -86,6 +86,16 @@ public: User::Ptr forwardFrom; /** + * Optional. For messages forwarded from a channel, information about the original channel + */ + Chat::Ptr forwardFromChat; + + /** + * Optional. For forwarded channel posts, identifier of the original message in the channel + */ + int32_t forwardFromMessageId; + + /** * Optional. For forwarded messages, date the original message was sent in Unix time. */ int32_t forwardDate; @@ -96,6 +106,11 @@ public: Message::Ptr replyToMessage; /** + * Optional. Date the message was last edited in Unix time + */ + int32_t editDate; + + /** * Optional. For text messages, the actual UTF-8 text of the message. */ std::string text; diff --git a/include/tgbot/types/MessageEntity.h b/include/tgbot/types/MessageEntity.h index 37301e6..ad445cf 100644 --- a/include/tgbot/types/MessageEntity.h +++ b/include/tgbot/types/MessageEntity.h @@ -7,6 +7,7 @@ #include <memory> #include <string> +#include "tgbot/types/User.h" namespace TgBot { @@ -37,6 +38,11 @@ public: * Optional. For “text_link” only, url that will be opened after user taps on the text */ std::string url; + + /** + * Optional. For “text_mention” only, the mentioned user + */ + User::Ptr user; }; } diff --git a/include/tgbot/types/ReplyKeyboardHide.h b/include/tgbot/types/ReplyKeyboardHide.h deleted file mode 100644 index acb0e5c..0000000 --- a/include/tgbot/types/ReplyKeyboardHide.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2015 Oleg Morozenkov - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef TGBOT_CPP_REPLYKEYBOARDHIDE_H -#define TGBOT_CPP_REPLYKEYBOARDHIDE_H - -#include <memory> - -#include "tgbot/types/GenericReply.h" - -namespace TgBot { - -/** - * Upon receiving a message with this object, Telegram clients will hide the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup). - * @ingroup types - */ -class ReplyKeyboardHide : public GenericReply { - -public: - typedef std::shared_ptr<ReplyKeyboardHide> Ptr; - - /** - * Requests clients to hide the custom keyboard. - */ - const bool hideKeyboard = true; - - /** - * Optional. Use this parameter if you want to hide keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. - * Example: A user votes in a poll, bot returns confirmation message in reply to the vote and hides keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. - */ - bool selective = false; -}; - -} - -#endif //TGBOT_CPP_REPLYKEYBOARDHIDE_H diff --git a/include/tgbot/types/ReplyKeyboardRemove.h b/include/tgbot/types/ReplyKeyboardRemove.h new file mode 100644 index 0000000..c47fb7d --- /dev/null +++ b/include/tgbot/types/ReplyKeyboardRemove.h @@ -0,0 +1,40 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_CPP_REPLYKEYBOARDREMOVE_H +#define TGBOT_CPP_REPLYKEYBOARDREMOVE_H + +#include <memory> + +#include "tgbot/types/GenericReply.h" + +namespace TgBot { + +/** + * Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. + * By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden + * immediately after the user presses a button (see ReplyKeyboardMarkup). + * @ingroup types + */ +class ReplyKeyboardRemove : public GenericReply { + +public: + typedef std::shared_ptr<ReplyKeyboardRemove> Ptr; + + /** + * Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; + * if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup) + */ + const bool removeKeyboard = true; + + /** + * Optional. Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + * Example: A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. + */ + bool selective = false; +}; + +} + +#endif //TGBOT_CPP_REPLYKEYBOARDREMOVE_H diff --git a/include/tgbot/types/ResponseParameters.h b/include/tgbot/types/ResponseParameters.h new file mode 100644 index 0000000..0c8bba9 --- /dev/null +++ b/include/tgbot/types/ResponseParameters.h @@ -0,0 +1,35 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_RESPONSEPARAMETERS_H +#define TGBOT_RESPONSEPARAMETERS_H + +#include <memory> + +namespace TgBot { + +/** + * Contains information about why a request was unsuccessfull. + * @ingroup types + */ +class ResponseParameters { +public: + typedef std::shared_ptr<ResponseParameters> Ptr; + + /** + * 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. + */ + int32_t migrateToChatId; + + /** + * Optional. In case of exceeding flood control, the number of seconds left to wait before the request can be repeated + */ + int32_t retryAfter; +}; +} + +#endif //TGBOT_RESPONSEPARAMETERS_H diff --git a/include/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h index 252fb41..94140c1 100644 --- a/include/tgbot/types/Sticker.h +++ b/include/tgbot/types/Sticker.h @@ -60,6 +60,11 @@ public: PhotoSize::Ptr thumb; /** + * Optional. Emoji associated with the sticker + */ + std::string emoji; + + /** * Optional. File size. */ int32_t fileSize; diff --git a/include/tgbot/types/Update.h b/include/tgbot/types/Update.h index 7a3c106..53fe697 100644 --- a/include/tgbot/types/Update.h +++ b/include/tgbot/types/Update.h @@ -52,6 +52,21 @@ public: Message::Ptr message; /** + * Optional. New version of a message that is known to the bot and was edited + */ + Message::Ptr editedMessage; + + /** + * Optional. New incoming channel post of any kind — text, photo, sticker, etc. + */ + Message::Ptr channelPost; + + /** + * Optional. New version of a channel post that is known to the bot and was edited + */ + Message::Ptr editedChannelPost; + + /** * Optional. New incoming inline query */ InlineQuery::Ptr inlineQuery; diff --git a/include/tgbot/types/WebhookInfo.h b/include/tgbot/types/WebhookInfo.h new file mode 100644 index 0000000..f08e4ac --- /dev/null +++ b/include/tgbot/types/WebhookInfo.h @@ -0,0 +1,59 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_WEBHOOKINFO_H +#define TGBOT_WEBHOOKINFO_H + +#include <string> +#include <vector> +#include <memory> + +namespace TgBot { + +/** + * Contains information about the current status of a webhook. + * @ingroup types + */ +class WebhookInfo { +public: + typedef std::shared_ptr<WebhookInfo> Ptr; + + /** + * Webhook URL, may be empty if webhook is not set up. + */ + std::string url; + + /** + * True, if a custom certificate was provided for webhook certificate checks + */ + bool hasCustomCertificate; + + /** + * Number of updates awaiting delivery + */ + int32_t pendingUpdateCount; + + /** + * Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook + */ + int32_t lastErrorDate; + + /** + * Optional. Error message in human - readable format for the most recent error that happened when trying to deliver an update via webhook + */ + std::string lastErrorMessage; + + /** + * Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery + */ + int32_t maxConnections; + + /** + * Optional. A list of update types the bot is subscribed to. Defaults to all update types + */ + std::vector<std::string> allowedUpdates; +}; +} + +#endif //TGBOT_WEBHOOKINFO_H diff --git a/src/Api.cpp b/src/Api.cpp index 54cb692..361b4d6 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -109,10 +109,13 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, const std::string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (duration) { args.push_back(HttpReqArg("duration", duration)); } @@ -134,10 +137,13 @@ Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const std::string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audioId)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (duration) { args.push_back(HttpReqArg("duration", duration)); } @@ -159,10 +165,13 @@ Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t durat return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("document", document->data, true, document->mimeType, document->fileName)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -175,10 +184,13 @@ Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, i return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args)); } -Message::Ptr Api::sendDocument(int64_t chatId, const string& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("document", document)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -223,10 +235,22 @@ Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t r return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args)); } -Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t duration, int32_t width, int32_t height, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video", video->data, true, video->mimeType, video->fileName)); + if (duration) { + args.push_back(HttpReqArg("duration", duration)); + } + if (width) { + args.push_back(HttpReqArg("width", width)); + } + if (height) { + args.push_back(HttpReqArg("height", height)); + } + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -239,10 +263,22 @@ Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t duration, int32_t width, int32_t height, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video", videoId)); + if (duration) { + args.push_back(HttpReqArg("duration", duration)); + } + if (width) { + args.push_back(HttpReqArg("width", width)); + } + if (height) { + args.push_back(HttpReqArg("height", height)); + } + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -255,10 +291,13 @@ Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t reply return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr& voice, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr& voice, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("voice", voice->data, true, voice->mimeType, voice->fileName)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (duration){ args.push_back(HttpReqArg("duration", duration)); } @@ -274,10 +313,13 @@ Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr& voice, int dur return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendVoice(int64_t chatId, const std::string& voiceId, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("voice", voiceId)); + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } if (duration){ args.push_back(HttpReqArg("duration", duration)); } @@ -368,7 +410,152 @@ UserProfilePhotos::Ptr Api::getUserProfilePhotos(int32_t userId, int32_t offset, return TgTypeParser::getInstance().parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); } -vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeout) const { +File::Ptr Api::getFile(int32_t fileId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("file_id", fileId)); + return TgTypeParser::getInstance().parseJsonAndGetFile(sendRequest("getFile", args)); +} + +bool Api::leaveChat(int64_t chatId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + return sendRequest("leaveChat", args).get<bool>("", false); +} + +Chat::Ptr Api::getChat(int64_t chatId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + return TgTypeParser::getInstance().parseJsonAndGetChat(sendRequest("getChat", args)); +} + +std::vector<ChatMember::Ptr> Api::getChatAdministrators(int64_t chatId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + return TgTypeParser::getInstance().parseJsonAndGetArray<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); +} + +int32_t Api::getChatMembersCount(int64_t chatId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + return sendRequest("getChatMembersCount", args).get<int32_t>("", 0); +} + +bool Api::answerCallbackQuery(const std::string & callbackQueryId, const std::string & text, bool showAlert, const std::string &url, int32_t cacheTime) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("callback_query_id", callbackQueryId)); + if (!text.empty()) { + args.push_back(HttpReqArg("text", text)); + } + if (showAlert) { + args.push_back(HttpReqArg("show_alert", showAlert)); + } + if (!url.empty()) { + args.push_back(HttpReqArg("url", url)); + } + if (cacheTime) { + args.push_back(HttpReqArg("cache_time", cacheTime)); + } + return sendRequest("answerCallbackQuery", args).get<bool>("", false); +} + +Message::Ptr Api::editMessageText(const std::string& text, int64_t chatId, int32_t messageId, const std::string& inlineMessageId, + const std::string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr& replyMarkup) const { + + vector<HttpReqArg> args; + args.push_back(HttpReqArg("text", text)); + if (chatId) { + args.push_back(HttpReqArg("chat_id", chatId)); + } + if (messageId) { + args.push_back(HttpReqArg("message_id", messageId)); + } + if (!inlineMessageId.empty()) { + args.push_back(HttpReqArg("inline_message_id", inlineMessageId)); + } + if (!parseMode.empty()) { + args.push_back(HttpReqArg("parse_mode", parseMode)); + } + if (disableWebPagePreview) { + args.push_back(HttpReqArg("disable_web_page_preview", disableWebPagePreview)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + ptree p = sendRequest("editMessageText", args); + if (p.get_child_optional("message_id")) { + return TgTypeParser::getInstance().parseJsonAndGetMessage(p); + } else { + return nullptr; + } +} + +Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const std::string& caption, + const std::string& inlineMessageId, const GenericReply::Ptr& replyMarkup) const { + + vector<HttpReqArg> args; + if (chatId) { + args.push_back(HttpReqArg("chat_id", chatId)); + } + if (messageId) { + args.push_back(HttpReqArg("message_id", messageId)); + } + if (!caption.empty()) { + args.push_back(HttpReqArg("caption", caption)); + } + if (!inlineMessageId.empty()) { + args.push_back(HttpReqArg("inline_message_id", inlineMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + ptree p = sendRequest("editMessageCaption", args); + if (p.get_child_optional("message_id")) { + return TgTypeParser::getInstance().parseJsonAndGetMessage(p); + } else { + return nullptr; + } + +} + +Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, const std::string& inlineMessageId, + const GenericReply::Ptr& replyMarkup) const { + + vector<HttpReqArg> args; + if (chatId) { + args.push_back(HttpReqArg("chat_id", chatId)); + } + if (messageId) { + args.push_back(HttpReqArg("message_id", messageId)); + } + if (!inlineMessageId.empty()) { + args.push_back(HttpReqArg("inline_message_id", inlineMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + ptree p = sendRequest("editMessageReplyMarkup", args); + if (p.get_child_optional("message_id")) { + return TgTypeParser::getInstance().parseJsonAndGetMessage(p); + } else { + return nullptr; + } +} + +ChatMember::Ptr Api::getChatMember(int64_t chatId, int32_t userId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + return TgTypeParser::getInstance().parseJsonAndGetChatMember(sendRequest("getChatMember", args)); +} + +vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeout, const StringArrayPtr &allowedUpdates) const { vector<HttpReqArg> args; if (offset) { args.push_back(HttpReqArg("offset", offset)); @@ -378,43 +565,96 @@ vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo if (timeout) { args.push_back(HttpReqArg("timeout", timeout)); } + if (allowedUpdates!=nullptr) { + string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<std::string>( + [](const std::string &s)->std::string { + return s; + }, *allowedUpdates); + args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson)); + } return TgTypeParser::getInstance().parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); } -void Api::setWebhook(const string& url, const InputFile::Ptr& certificate) const { +void Api::setWebhook(const string& url, const InputFile::Ptr& certificate, int32_t maxConnection, const StringArrayPtr &allowedUpdates) const { vector<HttpReqArg> args; if (!url.empty()) args.push_back(HttpReqArg("url", url)); if (certificate != nullptr) args.push_back(HttpReqArg("certificate", certificate->data, true, certificate->mimeType, certificate->fileName)); + if (maxConnection!=40) + args.push_back(HttpReqArg("max_connections", maxConnection)); + + if (allowedUpdates!=nullptr) + { + string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<std::string>( + [](const std::string &s)->std::string { + return s; + }, *allowedUpdates); + args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson)); + } sendRequest("setWebhook", args); } -void Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results, - int32_t cacheTime, bool isPersonal, const std::string& nextOffset) const { +bool Api::deleteWebhook() const +{ + ptree p = sendRequest("deleteWebhook"); + return p.get<bool>("", false); +} + +WebhookInfo::Ptr Api::getWebhookInfo() const +{ + ptree p = sendRequest("getWebhookInfo"); + + if (!p.get_child_optional("url")) + return nullptr; + + if (p.get<string>("url","")!=string("")) + { + return TgTypeParser::getInstance().parseJsonAndGetWebhookInfo(p); + } + else + { + return nullptr; + } +} + +bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results, + int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("inline_query_id", inlineQueryId)); string resultsJson = TgTypeParser::getInstance().parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results); args.push_back(HttpReqArg("results", resultsJson)); - args.push_back(HttpReqArg("cache_time", cacheTime)); - args.push_back(HttpReqArg("is_personal", isPersonal)); - args.push_back(HttpReqArg("next_offset", nextOffset)); - sendRequest("answerInlineQuery", args); + if (cacheTime) { + args.push_back(HttpReqArg("cache_time", cacheTime)); + } + if (isPersonal) { + args.push_back(HttpReqArg("is_personal", isPersonal)); + } + if (!nextOffset.empty()) { + args.push_back(HttpReqArg("next_offset", nextOffset)); + } + if (!switchPmText.empty()) { + args.push_back(HttpReqArg("switch_pm_text", switchPmText)); + } + if (!switchPmParameter.empty()) { + args.push_back(HttpReqArg("switch_pm_parameter", switchPmParameter)); + } + return sendRequest("answerInlineQuery", args).get<bool>("", false); } -void Api::kickChatMember(int64_t chatId, int32_t userId) const { +bool Api::kickChatMember(int64_t chatId, int32_t userId) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("user_id", userId)); - sendRequest("kickChatMember", args); + return sendRequest("kickChatMember", args).get<bool>("", false); } -void Api::unbanChatMember(int64_t chatId, int32_t userId) const { +bool Api::unbanChatMember(int64_t chatId, int32_t userId) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("user_id", userId)); - sendRequest("unbanChatMember", args); + return sendRequest("unbanChatMember", args).get<bool>("", false); } ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) const { diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 174afe9..45124e2 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -49,6 +49,7 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { result->username = data.get("username", ""); result->firstName = data.get<string>("first_name", ""); result->lastName = data.get("last_name", ""); + result->allMembersAreAdministrators = data.get<bool>("all_members_are_administrators", false); return result; } @@ -108,6 +109,7 @@ MessageEntity::Ptr TgTypeParser::parseJsonAndGetEntity(const ptree& data) const{ result->offset=data.get<int32_t>("offset"); result->length=data.get<int32_t>("length"); result->url=data.get<string>("url", ""); + result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); return result; } @@ -118,8 +120,11 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->date = data.get<int32_t>("date"); result->chat = parseJsonAndGetChat(data.find("chat")->second); result->forwardFrom = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "forward_from"); + result->forwardFromChat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "forward_from_chat"); + result->forwardFromMessageId = data.get<int32_t>("forward_from_message_id", 0); result->forwardDate = data.get("forward_date", 0); result->replyToMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message"); + result->editDate = data.get<int32_t>("edit_date", 0); result->text = data.get("text", ""); result->entities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetEntity, data, "entities"); result->audio = tryParseJson<Audio>(&TgTypeParser::parseJsonAndGetAudio, data, "audio"); @@ -154,8 +159,11 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "date", object->date); appendToJson(result, "chat", parseChat(object->chat)); appendToJson(result, "forward_from", parseUser(object->forwardFrom)); + appendToJson(result, "forward_from_chat", parseChat(object->forwardFromChat)); + appendToJson(result, "forward_from_message_id", object->forwardFromMessageId); appendToJson(result, "forward_date", object->forwardDate); appendToJson(result, "reply_to_message", parseMessage(object->replyToMessage)); + appendToJson(result, "edit_date", object->editDate); appendToJson(result, "text", object->text); appendToJson(result, "audio", parseAudio(object->audio)); appendToJson(result, "document", parseDocument(object->document)); @@ -208,6 +216,8 @@ Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const ptree& data) const { Audio::Ptr result(new Audio); result->fileId = data.get<string>("file_id"); result->duration = data.get<int32_t>("duration"); + result->performer = data.get<string>("performer", ""); + result->title = data.get<string>("title", ""); result->mimeType = data.get("mime_type", ""); result->fileSize = data.get("file_size", 0); return result; @@ -260,6 +270,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const { result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->emoji = data.get<string>("emoji"); result->fileSize = data.get("file_size", 0); return result; } @@ -274,6 +285,7 @@ string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "emoji", object->emoji); appendToJson(result, "file_size", object->fileSize); result.erase(result.length() - 1); result += '}'; @@ -336,8 +348,8 @@ string TgTypeParser::parseContact(const Contact::Ptr& object) const { Location::Ptr TgTypeParser::parseJsonAndGetLocation(const ptree& data) const { Location::Ptr result(new Location); - result->longitude = data.get<float>("longitude"); - result->latitude = data.get<float>("latitude"); + result->longitude = data.get<float>("longitude", 0); + result->latitude = data.get<float>("latitude", 0); return result; } @@ -358,6 +370,9 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const ptree& data) const { Update::Ptr result(new Update); result->updateId = data.get<int32_t>("update_id"); result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message"); + result->editedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message"); + result->channelPost = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "channel_post"); + result->editedChannelPost = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_channel_post"); result->inlineQuery = tryParseJson<InlineQuery>(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query"); result->chosenInlineResult = tryParseJson<ChosenInlineResult>(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result"); result->callbackQuery = tryParseJson<CallbackQuery>(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query"); @@ -372,6 +387,9 @@ string TgTypeParser::parseUpdate(const Update::Ptr& object) const { result += '{'; appendToJson(result, "update_id", object->updateId); appendToJson(result, "message", parseMessage(object->message)); + appendToJson(result, "edited_message", parseMessage(object->editedMessage)); + appendToJson(result, "channel_post", parseMessage(object->channelPost)); + appendToJson(result, "edited_channel_post", parseMessage(object->editedChannelPost)); appendToJson(result, "inline_query", parseInlineQuery(object->inlineQuery)); appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult)); appendToJson(result, "callback_query", parseCallbackQuery(object->callbackQuery)); @@ -400,6 +418,28 @@ string TgTypeParser::parseUserProfilePhotos(const UserProfilePhotos::Ptr& object return result; } +File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& data) const { + File::Ptr result(new File); + result->fileId = data.get<string>("file_id"); + result->filePath = data.get<int32_t>("file_size", 0); + result->filePath = data.get<string>("file_path", ""); + return result; +} + +string TgTypeParser::parseFile(const File::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_size", object->fileSize); + appendToJson(result, "file_path", object->filePath); + result.erase(result.length() - 1); + result += '}'; + return result; +} + ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const { ReplyKeyboardMarkup::Ptr result(new ReplyKeyboardMarkup); for (const pair<const string, ptree>& item : data.find("keyboard")->second) { @@ -442,19 +482,41 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt return result; } -ReplyKeyboardHide::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const { - ReplyKeyboardHide::Ptr result(new ReplyKeyboardHide); - result->selective = data.get<bool>("selective"); +KeyboardButton::Ptr TgTypeParser::parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const { + KeyboardButton::Ptr result(new KeyboardButton); + result->text = data.get<string>("text"); + result->requestContact = data.get<bool>("request_contact", false); + result->requestLocation = data.get<bool>("request_location", false); return result; } -std::string TgTypeParser::parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const { +std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) const { if (!object) { return ""; } string result; result += '{'; - appendToJson(result, "hide_keyboard", object->hideKeyboard); + appendToJson(result, "text", object->text); + appendToJson(result, "request_contact", object->requestContact); + appendToJson(result, "request_location", object->requestLocation); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +ReplyKeyboardRemove::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const { + ReplyKeyboardRemove::Ptr result(new ReplyKeyboardRemove); + result->selective = data.get<bool>("selective", false); + return result; +} + +std::string TgTypeParser::parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "remove_keyboard", object->removeKeyboard); appendToJson(result, "selective", object->selective); result.erase(result.length() - 1); result += '}'; @@ -480,11 +542,51 @@ std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const { return result; } +ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const { + ChatMember::Ptr result(new ChatMember); + result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); + result->status = data.get<string>("status"); + return result; +} + +std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "user", parseUser(object->user)); + appendToJson(result, "status", object->status); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const { + ResponseParameters::Ptr result(new ResponseParameters); + result->migrateToChatId = data.get<int32_t>("migrate_to_chat_id", 0); + result->retryAfter = data.get<int32_t>("retry_after", 0); + return result; +} + +std::string TgTypeParser::parseResponseParameters(const ResponseParameters::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "migrate_to_chat_id", object->migrateToChatId); + appendToJson(result, "retry_after", object->retryAfter); + result.erase(result.length() - 1); + result += '}'; + return result; +} + GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const { if (data.find("force_reply") != data.not_found()) { return static_pointer_cast<GenericReply>(parseJsonAndGetForceReply(data)); - } else if (data.find("hide_keyboard") != data.not_found()) { - return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardHide(data)); + } else if (data.find("remove_keyboard") != data.not_found()) { + return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardRemove(data)); } else if (data.find("keyboard") != data.not_found()) { return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardMarkup(data)); } else if (data.find("inline_keyboard") != data.not_found()) { @@ -498,8 +600,8 @@ std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) con } if (dynamic_pointer_cast<ForceReply>(object) != nullptr) { return parseForceReply(static_pointer_cast<ForceReply>(object)); - } else if (dynamic_pointer_cast<ReplyKeyboardHide>(object) != nullptr) { - return parseReplyKeyboardHide(static_pointer_cast<ReplyKeyboardHide>(object)); + } else if (dynamic_pointer_cast<ReplyKeyboardRemove>(object) != nullptr) { + return parseReplyKeyboardRemove(static_pointer_cast<ReplyKeyboardRemove>(object)); } else if (dynamic_pointer_cast<ReplyKeyboardMarkup>(object) != nullptr){ return parseReplyKeyboardMarkup(static_pointer_cast<ReplyKeyboardMarkup>(object)); } else if (dynamic_pointer_cast<InlineKeyboardMarkup>(object) != nullptr){ @@ -511,6 +613,7 @@ InlineQuery::Ptr TgTypeParser::parseJsonAndGetInlineQuery(const boost::property_ InlineQuery::Ptr result(new InlineQuery); result->id = data.get<string>("id"); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); result->query = data.get<string>("query"); result->offset = data.get<string>("offset"); @@ -525,6 +628,7 @@ std::string TgTypeParser::parseInlineQuery(const InlineQuery::Ptr& object) const result += '{'; appendToJson(result, "id", object->id); appendToJson(result, "from", parseUser(object->from)); + appendToJson(result, "location", parseLocation(object->location)); appendToJson(result, "query", object->query); appendToJson(result, "offset", object->offset); result.erase(result.length() - 1); @@ -536,8 +640,38 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos string type = data.get<string>("type"); InlineQueryResult::Ptr result; - if (type == InlineQueryResultArticle::TYPE) { + if (type == InlineQueryResultCachedAudio::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultCachedAudio(data)); + } else if (type == InlineQueryResultCachedDocument::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultCachedDocument(data)); + } else if (type == InlineQueryResultCachedGif::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultCachedGif(data)); + } else if (type == InlineQueryResultCachedMpeg4Gif::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultCachedMpeg4Gif(data)); + } else if (type == InlineQueryResultCachedPhoto::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultCachedPhoto(data)); + } else if (type == InlineQueryResultCachedSticker::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultCachedSticker(data)); + } else if (type == InlineQueryResultCachedVideo::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultCachedVideo(data)); + } else if (type == InlineQueryResultCachedVoice::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultCachedVoice(data)); + } else if (type == InlineQueryResultArticle::TYPE) { result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultArticle(data)); + } else if (type == InlineQueryResultAudio::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultAudio(data)); + } else if (type == InlineQueryResultContact::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultContact(data)); + } else if (type == InlineQueryResultGame::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultGame(data)); + } else if (type == InlineQueryResultDocument::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultDocument(data)); + } else if (type == InlineQueryResultLocation::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultLocation(data)); + } else if (type == InlineQueryResultVenue::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultVenue(data)); + } else if (type == InlineQueryResultVoice::TYPE) { + result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultVoice(data)); } else if (type == InlineQueryResultPhoto::TYPE) { result = static_pointer_cast<InlineQueryResult>(parseJsonAndGetInlineQueryResultPhoto(data)); } else if (type == InlineQueryResultGif::TYPE) { @@ -552,10 +686,9 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos result->id = data.get<string>("id"); result->title = data.get<string>("title", ""); - result->messageText = data.get<string>("message_text", ""); - result->parseMode = data.get<string>("parse_mode", ""); - result->disableWebPagePreview = data.get("disable_web_page_preview", false); - result->thumbUrl = data.get<string>("thumb_url", ""); + result->caption = data.get<string>("caption", ""); + result->replyMarkup = tryParseJson<InlineKeyboardMarkup>(&TgTypeParser::parseJsonAndGetInlineKeyboardMarkup, data, "reply_markup"); + result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content"); return result; } @@ -570,34 +703,246 @@ std::string TgTypeParser::parseInlineQueryResult(const InlineQueryResult::Ptr& o appendToJson(result, "id", object->id); appendToJson(result, "type", object->type); appendToJson(result, "title", object->title); - appendToJson(result, "message_text", object->messageText); - appendToJson(result, "parse_mode", object->parseMode); - appendToJson(result, "disable_web_page_preview", object->disableWebPagePreview); - appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "caption", object->caption); + appendToJson(result, "reply_markup", parseInlineKeyboardMarkup(object->replyMarkup)); + appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent)); - if (object->type == InlineQueryResultArticle::TYPE){ + if (object->type == InlineQueryResultCachedAudio::TYPE) { + result += parseInlineQueryResultCachedAudio(static_pointer_cast<InlineQueryResultCachedAudio>(object)); + } + else if (object->type == InlineQueryResultCachedDocument::TYPE) { + result += parseInlineQueryResultCachedDocument(static_pointer_cast<InlineQueryResultCachedDocument>(object)); + } + else if (object->type == InlineQueryResultCachedGif::TYPE) { + result += parseInlineQueryResultCachedGif(static_pointer_cast<InlineQueryResultCachedGif>(object)); + } + else if (object->type == InlineQueryResultCachedMpeg4Gif::TYPE) { + result += parseInlineQueryResultCachedMpeg4Gif(static_pointer_cast<InlineQueryResultCachedMpeg4Gif>(object)); + } + else if (object->type == InlineQueryResultCachedPhoto::TYPE) { + result += parseInlineQueryResultCachedPhoto(static_pointer_cast<InlineQueryResultCachedPhoto>(object)); + } + else if (object->type == InlineQueryResultCachedSticker::TYPE) { + result += parseInlineQueryResultCachedSticker(static_pointer_cast<InlineQueryResultCachedSticker>(object)); + } + else if (object->type == InlineQueryResultCachedVideo::TYPE) { + result += parseInlineQueryResultCachedVideo(static_pointer_cast<InlineQueryResultCachedVideo>(object)); + } + else if (object->type == InlineQueryResultCachedVoice::TYPE) { + result += parseInlineQueryResultCachedVoice(static_pointer_cast<InlineQueryResultCachedVoice>(object)); + } + else if (object->type == InlineQueryResultArticle::TYPE) { result += parseInlineQueryResultArticle(static_pointer_cast<InlineQueryResultArticle>(object)); - } else if (object->type == InlineQueryResultPhoto::TYPE){ + } + else if (object->type == InlineQueryResultAudio::TYPE) { + result += parseInlineQueryResultAudio(static_pointer_cast<InlineQueryResultAudio>(object)); + } + else if (object->type == InlineQueryResultContact::TYPE) { + result += parseInlineQueryResultContact(static_pointer_cast<InlineQueryResultContact>(object)); + } + else if (object->type == InlineQueryResultGame::TYPE) { + result += parseInlineQueryResultGame(static_pointer_cast<InlineQueryResultGame>(object)); + } + else if (object->type == InlineQueryResultDocument::TYPE) { + result += parseInlineQueryResultDocument(static_pointer_cast<InlineQueryResultDocument>(object)); + } + else if (object->type == InlineQueryResultLocation::TYPE) { + result += parseInlineQueryResultLocation(static_pointer_cast<InlineQueryResultLocation>(object)); + } + else if (object->type == InlineQueryResultVenue::TYPE) { + result += parseInlineQueryResultVenue(static_pointer_cast<InlineQueryResultVenue>(object)); + } + else if (object->type == InlineQueryResultVoice::TYPE) { + result += parseInlineQueryResultVoice(static_pointer_cast<InlineQueryResultVoice>(object)); + } + else if (object->type == InlineQueryResultPhoto::TYPE) { result += parseInlineQueryResultPhoto(static_pointer_cast<InlineQueryResultPhoto>(object)); - } else if (object->type == InlineQueryResultGif::TYPE){ + } + else if (object->type == InlineQueryResultGif::TYPE) { result += parseInlineQueryResultGif(static_pointer_cast<InlineQueryResultGif>(object)); - } else if (object->type == InlineQueryResultMpeg4Gif::TYPE){ + } + else if (object->type == InlineQueryResultMpeg4Gif::TYPE) { result += parseInlineQueryResultMpeg4Gif(static_pointer_cast<InlineQueryResultMpeg4Gif>(object)); - } else if (object->type == InlineQueryResultVideo::TYPE){ + } + else if (object->type == InlineQueryResultVideo::TYPE) { result += parseInlineQueryResultVideo(static_pointer_cast<InlineQueryResultVideo>(object)); } - + result.erase(result.length() - 1); result += '}'; return result; } +InlineQueryResultCachedAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedAudio::Ptr result(new InlineQueryResultCachedAudio); + result->audioFileId = data.get<string>("audio_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "audio_file_id", object->audioFileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultCachedDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedDocument::Ptr result(new InlineQueryResultCachedDocument); + result->documentFileId = data.get<string>("document_file_id"); + result->description = data.get<string>("description", ""); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "document_file_id", object->documentFileId); + appendToJson(result, "description", object->description); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedGif::Ptr result(new InlineQueryResultCachedGif); + result->gifFileId = data.get<string>("gif_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "gif_file_id", object->gifFileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedMpeg4Gif::Ptr result(new InlineQueryResultCachedMpeg4Gif); + result->mpeg4FileId = data.get<string>("mpeg4_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "mpeg4_file_id", object->mpeg4FileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedPhoto::Ptr result(new InlineQueryResultCachedPhoto); + result->photoFileId = data.get<string>("photo_file_id"); + result->description = data.get<string>("description", ""); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "photo_file_id", object->photoFileId); + appendToJson(result, "description", object->description); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedSticker::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedSticker::Ptr result(new InlineQueryResultCachedSticker); + result->stickerFileId = data.get<string>("sticker_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "sticker_file_id", object->stickerFileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultCachedVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedVideo::Ptr result(new InlineQueryResultCachedVideo); + result->videoFileId = data.get<string>("video_file_id"); + result->description = data.get<string>("description", ""); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "video_file_id", object->videoFileId); + appendToJson(result, "description", object->description); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedVoice::Ptr result(new InlineQueryResultCachedVoice); + result->voiceFileId = data.get<string>("voice_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "voice_file_id", object->voiceFileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + InlineQueryResultArticle::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). InlineQueryResultArticle::Ptr result(new InlineQueryResultArticle); result->url = data.get<string>("url", ""); result->hideUrl = data.get("hide_url", false); result->description = data.get<string>("description", ""); + result->thumbUrl = data.get<string>("thumb_url", ""); result->thumbWidth = data.get("thumb_width", 0); result->thumbHeight = data.get("thumb_height", 0); return result; @@ -613,20 +958,203 @@ std::string TgTypeParser::parseInlineQueryResultArticle(const InlineQueryResultA appendToJson(result, "url", object->url); appendToJson(result, "hide_url", object->hideUrl); appendToJson(result, "description", object->description); + appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumb_width", object->thumbWidth); + appendToJson(result, "thumb_height", object->thumbHeight); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultAudio::Ptr result(new InlineQueryResultAudio); + result->audioUrl = data.get<string>("audio_url"); + result->performer = data.get<string>("performer", ""); + result->audioDuration = data.get<int32_t>("audio_duration", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "audio_url", object->audioUrl); + appendToJson(result, "performer", object->performer); + appendToJson(result, "audio_duration", object->audioDuration); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultContact::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultContact(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultContact::Ptr result(new InlineQueryResultContact); + result->phoneNumber = data.get<string>("phone_number"); + result->firstName = data.get<string>("first_name"); + result->lastName = data.get<string>("last_name", ""); + result->thumbUrl = data.get<string>("thumb_url", ""); + result->thumbWidth = data.get<int32_t>("thumb_width", 0); + result->thumbHeight = data.get<int32_t>("thumb_height", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "phone_number", object->phoneNumber); + appendToJson(result, "first_name", object->firstName); + appendToJson(result, "last_name", object->lastName); + appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumb_width", object->thumbWidth); + appendToJson(result, "thumb_height", object->thumbHeight); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultGame::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultGame::Ptr result(new InlineQueryResultGame); + result->gameShortName = data.get<string>("game_short_name"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "game_short_name", object->gameShortName); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultDocument::Ptr result(new InlineQueryResultDocument); + result->documentUrl = data.get<string>("document_url"); + result->mimeType = data.get<string>("mime_type"); + result->description = data.get<string>("description", ""); + result->thumbUrl = data.get<string>("thumb_url", ""); + result->thumbWidth = data.get<int32_t>("thumb_width", 0); + result->thumbHeight = data.get<int32_t>("thumb_height", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "document_url", object->documentUrl); + appendToJson(result, "mime_type", object->mimeType); + appendToJson(result, "description", object->description); + appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumb_width", object->thumbWidth); + appendToJson(result, "thumb_height", object->thumbHeight); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultLocation::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultLocation::Ptr result(new InlineQueryResultLocation); + result->latitude = data.get<float>("latitude"); + result->longitude = data.get<float>("longitude"); + result->thumbUrl = data.get<string>("thumb_url", ""); + result->thumbWidth = data.get<int32_t>("thumb_width", 0); + result->thumbHeight = data.get<int32_t>("thumb_height", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); + appendToJson(result, "thumb_url", object->thumbUrl); appendToJson(result, "thumb_width", object->thumbWidth); appendToJson(result, "thumb_height", object->thumbHeight); // The last comma will be erased by parseInlineQueryResult(). return result; } + +InlineQueryResultVenue::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultVenue::Ptr result(new InlineQueryResultVenue); + result->latitude = data.get<float>("latitude"); + result->longitude = data.get<float>("longitude"); + result->address = data.get<string>("address"); + result->foursquareId = data.get<string>("foursquare_id", ""); + result->thumbUrl = data.get<string>("thumb_url", ""); + result->thumbWidth = data.get<int32_t>("thumb_width", 0); + result->thumbHeight = data.get<int32_t>("thumb_height", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); + appendToJson(result, "address", object->address); + appendToJson(result, "foursquare_id", object->foursquareId); + appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumb_width", object->thumbWidth); + appendToJson(result, "thumb_height", object->thumbHeight); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultVoice::Ptr result(new InlineQueryResultVoice); + result->voiceUrl = data.get<string>("voice_url"); + result->voiceDuration = data.get<int32_t>("voice_duration", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "voice_url", object->voiceUrl); + appendToJson(result, "voice_duration", object->voiceDuration); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + InlineQueryResultPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). InlineQueryResultPhoto::Ptr result(new InlineQueryResultPhoto); result->photoUrl = data.get<string>("photo_url", ""); + result->thumbUrl = data.get<string>("thumb_url"); result->photoWidth = data.get("photo_width", 0); result->photoHeight = data.get("photo_height", 0); result->description = data.get<string>("description", ""); - result->caption = data.get<string>("caption", ""); return result; } @@ -638,10 +1166,10 @@ std::string TgTypeParser::parseInlineQueryResultPhoto(const InlineQueryResultPho // curly brackets to the result string. string result; appendToJson(result, "photo_url", object->photoUrl); + appendToJson(result, "thumb_url", object->thumbUrl); appendToJson(result, "photo_width", object->photoWidth); appendToJson(result, "photo_height", object->photoHeight); appendToJson(result, "description", object->description); - appendToJson(result, "caption", object->caption); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -652,7 +1180,7 @@ InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(cons result->gifUrl = data.get<string>("gif_url", ""); result->gifWidth = data.get("gif_width", 0); result->gifHeight = data.get("gif_height", 0); - result->caption = data.get<string>("caption", ""); + result->thumbUrl = data.get<string>("thumb_url"); return result; } std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const { @@ -665,7 +1193,7 @@ std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif:: appendToJson(result, "gif_url", object->gifUrl); appendToJson(result, "gif_width", object->gifWidth); appendToJson(result, "gif_height", object->gifHeight); - appendToJson(result, "caption", object->caption); + appendToJson(result, "thumb_url", object->thumbUrl); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -676,7 +1204,7 @@ InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpe result->mpeg4Url = data.get<string>("mpeg4_url"); result->mpeg4Width = data.get("mpeg4_width", 0); result->mpeg4Height = data.get("mpeg4_height", 0); - result->caption = data.get("caption", ""); + result->thumbUrl = data.get<string>("thumb_url"); return result; } @@ -690,7 +1218,7 @@ std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResult appendToJson(result, "mpeg4_url", object->mpeg4Url); appendToJson(result, "mpeg4_width", object->mpeg4Width); appendToJson(result, "mpeg4_height", object->mpeg4Height); - appendToJson(result, "caption", object->caption); + appendToJson(result, "thumb_url", object->thumbUrl); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -700,7 +1228,8 @@ InlineQueryResultVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVideo( InlineQueryResultVideo::Ptr result(new InlineQueryResultVideo); result->videoUrl = data.get<string>("video_url"); result->mimeType = data.get<string>("mime_type"); - result->videoWidth = data.get("video_height", 0); + result->thumbUrl = data.get<string>("thumb_url"); + result->videoWidth = data.get("video_width", 0); result->videoHeight = data.get("video_height", 0); result->videoDuration = data.get("video_duration", 0); result->description = data.get<string>("description", ""); @@ -716,6 +1245,7 @@ std::string TgTypeParser::parseInlineQueryResultVideo(const InlineQueryResultVid string result; appendToJson(result, "video_url", object->videoUrl); appendToJson(result, "mime_type", object->mimeType); + appendToJson(result, "thumb_url", object->thumbUrl); appendToJson(result, "video_width", object->videoWidth); appendToJson(result, "video_height", object->videoHeight); appendToJson(result, "video_duration", object->videoDuration); @@ -728,6 +1258,8 @@ ChosenInlineResult::Ptr TgTypeParser::parseJsonAndGetChosenInlineResult(const bo ChosenInlineResult::Ptr result(new ChosenInlineResult); result->resultId = data.get<string>("result_id"); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); + result->inlineMessageId = data.get<string>("inline_message_id", ""); result->query = data.get<string>("query"); return result; } @@ -753,6 +1285,8 @@ CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::prope result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message"); result->inlineMessageId = data.get<string>("inline_message_id", ""); + result->chatInstance = data.get<string>("chat_instance"); + result->gameShortName = data.get<string>("game_short_name", ""); result->data = data.get<string>("data", ""); return result; } @@ -768,6 +1302,8 @@ std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) c appendToJson(result, "from", parseUser(object->from)); appendToJson(result, "message", parseMessage(object->message)); appendToJson(result, "inline_message_id", object->inlineMessageId); + appendToJson(result, "chat_instance", object->chatInstance); + appendToJson(result, "game_short_name", object->gameShortName); appendToJson(result, "data", object->data); result.erase(result.length() - 1); result += '}'; @@ -809,6 +1345,7 @@ InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(cons result->url = data.get<string>("url", ""); result->callbackData = data.get<string>("callback_data", ""); result->switchInlineQuery = data.get<string>("switch_inline_query", ""); + result->switchInlineQueryCurrentChat = data.get<string>("switch_inline_query_current_chat", ""); return result; } std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const { @@ -821,11 +1358,188 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton:: appendToJson(result, "url", object->url); appendToJson(result, "callback_data", object->callbackData); appendToJson(result, "switch_inline_query", object->switchInlineQuery); + appendToJson(result, "switch_inline_query_current_chat", object->switchInlineQueryCurrentChat); result.erase(result.length() - 1); result += '}'; return result; } +WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const { + WebhookInfo::Ptr result(new WebhookInfo); + result->url = data.get<string>("url"); + result->hasCustomCertificate = data.get<bool>("has_custom_certificate"); + result->pendingUpdateCount = data.get<int32_t>("pending_update_count"); + result->lastErrorDate = data.get<int32_t>("last_error_date", 0); + result->lastErrorMessage = data.get<string>("last_error_message", ""); + result->maxConnections = data.get<int32_t>("max_connections", 0); + result->allowedUpdates = parseJsonAndGetArray<std::string>( + [](const boost::property_tree::ptree& innerData)->std::string { + return innerData.get<std::string>(""); + } + , data, "allowed_updates"); + return result; +} + +std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "url", object->url); + appendToJson(result, "has_custom_certificate", object->hasCustomCertificate); + appendToJson(result, "pending_update_count", object->pendingUpdateCount); + appendToJson(result, "last_error_date", object->lastErrorDate); + appendToJson(result, "last_error_message", object->lastErrorMessage); + appendToJson(result, "max_connections", object->maxConnections); + appendToJson(result, "allowed_updates", + parseArray<std::string>([](const std::string &s)->std::string { + return s; + } + , object->allowedUpdates)); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +InputMessageContent::Ptr TgTypeParser::parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const { + InputMessageContent::Ptr result; + // define InputMessageContent type + + string tMessageText = data.get<string>("message_text", ""); + float tLatitude = data.get<float>("latitude", 1000); // latitude belong (-90,90) + string tTitle = data.get<string>("title", ""); + string tPnoneNumber = data.get<string>("phone_number", ""); + + if (!tMessageText.empty()) { + result = static_pointer_cast<InputMessageContent>(parseJsonAndGetInputTextMessageContent(data)); + } else if (!tTitle.empty()) { + result = static_pointer_cast<InputMessageContent>(parseJsonAndGetInputVenueMessageContent(data)); + } else if (tLatitude != 1000) { + result = static_pointer_cast<InputMessageContent>(parseJsonAndGetInputLocationMessageContent(data)); + } else if (!tPnoneNumber.empty()) { + result = static_pointer_cast<InputMessageContent>(parseJsonAndGetInputContactMessageContent(data)); + } + + return result; +} + +std::string TgTypeParser::parseInputMessageContent(const InputMessageContent::Ptr& object) const { + if (!object){ + return ""; + } + + string result; + result += '{'; + + if (object->type == std::string("InputTextMessageContent")) { + result += parseInputTextMessageContent(static_pointer_cast<InputTextMessageContent>(object)); + } + else if (object->type == std::string("InputLocationMessageContent")) { + result += parseInputLocationMessageContent(static_pointer_cast<InputLocationMessageContent>(object)); + } + else if (object->type == std::string("InputVenueMessageContent")) { + result += parseInputVenueMessageContent(static_pointer_cast<InputVenueMessageContent>(object)); + } + else if (object->type == std::string("InputContactMessageContent")) { + result += parseInputContactMessageContent(static_pointer_cast<InputContactMessageContent>(object)); + } + + result.erase(result.length() - 1); + result += '}'; + return result; +} + +InputTextMessageContent::Ptr TgTypeParser::parseJsonAndGetInputTextMessageContent(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). + InputTextMessageContent::Ptr result(new InputTextMessageContent); + result->messageText = data.get<string>("message_text"); + result->parseMode = data.get<string>("parse_mode", ""); + result->disableWebPagePreview = data.get<bool>("disable_web_page_preview", false); + return result; +} + +std::string TgTypeParser::parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInputMessageContent() + string result; + appendToJson(result, "message_text", object->messageText); + appendToJson(result, "parse_mode", object->parseMode); + appendToJson(result, "disable_web_page_preview", object->disableWebPagePreview); + // The last comma will be erased by parseInputMessageContent(). + return result; +} + +InputLocationMessageContent::Ptr TgTypeParser::parseJsonAndGetInputLocationMessageContent(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). + InputLocationMessageContent::Ptr result(new InputLocationMessageContent); + result->latitude = data.get<float>("latitude"); + result->longitude = data.get<float>("longitude"); + return result; +} + +std::string TgTypeParser::parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInputMessageContent() + string result; + appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); + // The last comma will be erased by parseInputMessageContent(). + return result; +} + +InputVenueMessageContent::Ptr TgTypeParser::parseJsonAndGetInputVenueMessageContent(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). + InputVenueMessageContent::Ptr result(new InputVenueMessageContent); + result->latitude = data.get<float>("latitude"); + result->longitude = data.get<float>("longitude"); + result->title = data.get<string>("title"); + result->address = data.get<string>("address"); + result->foursquareId = data.get<string>("foursquare_id", ""); + return result; +} + +std::string TgTypeParser::parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInputMessageContent() + string result; + appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); + appendToJson(result, "title", object->title); + appendToJson(result, "address", object->address); + appendToJson(result, "foursquare_id", object->foursquareId); + // The last comma will be erased by parseInputMessageContent(). + return result; +} + +InputContactMessageContent::Ptr TgTypeParser::parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). + InputContactMessageContent::Ptr result(new InputContactMessageContent); + result->phoneNumber = data.get<string>("phone_number"); + result->firstName = data.get<string>("first_name"); + result->lastName = data.get<string>("last_name", ""); + return result; +} + +std::string TgTypeParser::parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInputMessageContent() + string result; + appendToJson(result, "phone_number", object->phoneNumber); + appendToJson(result, "first_name", object->firstName); + appendToJson(result, "last_name", object->lastName); + // The last comma will be erased by parseInputMessageContent(). + return result; +} + void TgTypeParser::appendToJson(string& json, const string& varName, const string& value) const { if (value.empty()) { return; diff --git a/src/types/InlineQueryResult.cpp b/src/types/InlineQueryResult.cpp index be1f14a..9f90e19 100644 --- a/src/types/InlineQueryResult.cpp +++ b/src/types/InlineQueryResult.cpp @@ -1,6 +1,22 @@ // // Created by Andrea Giove on 27/03/16. // + +#include "tgbot/types/InlineQueryResultCachedAudio.h" +#include "tgbot/types/InlineQueryResultCachedDocument.h" +#include "tgbot/types/InlineQueryResultCachedGif.h" +#include "tgbot/types/InlineQueryResultCachedMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultCachedPhoto.h" +#include "tgbot/types/InlineQueryResultCachedSticker.h" +#include "tgbot/types/InlineQueryResultCachedVideo.h" +#include "tgbot/types/InlineQueryResultCachedVoice.h" +#include "tgbot/types/InlineQueryResultAudio.h" +#include "tgbot/types/InlineQueryResultContact.h" +#include "tgbot/types/InlineQueryResultGame.h" +#include "tgbot/types/InlineQueryResultDocument.h" +#include "tgbot/types/InlineQueryResultLocation.h" +#include "tgbot/types/InlineQueryResultVenue.h" +#include "tgbot/types/InlineQueryResultVoice.h" #include "tgbot/types/InlineQueryResultArticle.h" #include "tgbot/types/InlineQueryResultGif.h" #include "tgbot/types/InlineQueryResultMpeg4Gif.h" @@ -9,8 +25,24 @@ using namespace TgBot; +const std::string InlineQueryResultCachedAudio::TYPE = "cached_audio"; +const std::string InlineQueryResultCachedDocument::TYPE = "cached_document"; +const std::string InlineQueryResultCachedGif::TYPE = "cached_gif"; +const std::string InlineQueryResultCachedMpeg4Gif::TYPE = "cached_mpeg4gif"; +const std::string InlineQueryResultCachedPhoto::TYPE = "cached_photo"; +const std::string InlineQueryResultCachedSticker::TYPE = "cached_sticker"; +const std::string InlineQueryResultCachedVideo::TYPE = "cached_video"; +const std::string InlineQueryResultCachedVoice::TYPE = "cached_voice"; + const std::string InlineQueryResultArticle::TYPE = "article"; +const std::string InlineQueryResultAudio::TYPE = "audio"; +const std::string InlineQueryResultContact::TYPE = "contact"; +const std::string InlineQueryResultGame::TYPE = "game"; +const std::string InlineQueryResultDocument::TYPE = "document"; const std::string InlineQueryResultGif::TYPE = "gif"; +const std::string InlineQueryResultLocation::TYPE = "location"; const std::string InlineQueryResultMpeg4Gif::TYPE = "mpeg4_gif"; const std::string InlineQueryResultPhoto::TYPE = "photo"; +const std::string InlineQueryResultVenue::TYPE = "venue"; const std::string InlineQueryResultVideo::TYPE = "video"; +const std::string InlineQueryResultVoice::TYPE = "voice"; |