From 76d3a4c33a8808552b55b1bf36934b455528a150 Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Mon, 26 Dec 2016 16:45:35 +0300 Subject: upgrade existing type and create new --- include/tgbot/types/Audio.h | 12 ++++++ include/tgbot/types/CallbackQuery.h | 9 +++++ include/tgbot/types/Chat.h | 6 +++ include/tgbot/types/ChatMember.h | 35 ++++++++++++++++++ include/tgbot/types/File.h | 45 +++++++++++++++++++++++ include/tgbot/types/InlineKeyboardButton.h | 5 +++ include/tgbot/types/InlineQuery.h | 6 +++ include/tgbot/types/KeyboardButton.h | 44 ++++++++++++++++++++++ include/tgbot/types/MessageEntity.h | 6 +++ include/tgbot/types/ReplyKeyboardRemove.h | 40 ++++++++++++++++++++ include/tgbot/types/ResponseParameters.h | 35 ++++++++++++++++++ include/tgbot/types/Sticker.h | 5 +++ include/tgbot/types/WebhookInfo.h | 59 ++++++++++++++++++++++++++++++ 13 files changed, 307 insertions(+) create mode 100644 include/tgbot/types/ChatMember.h create mode 100644 include/tgbot/types/File.h create mode 100644 include/tgbot/types/KeyboardButton.h create mode 100644 include/tgbot/types/ReplyKeyboardRemove.h create mode 100644 include/tgbot/types/ResponseParameters.h create mode 100644 include/tgbot/types/WebhookInfo.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 @@ -47,6 +47,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. */ 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 @@ -41,11 +41,20 @@ 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 +#include + +#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 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/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 +#include + +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/. + * 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 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/ 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 #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/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 +#include + +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 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/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 #include +#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/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 + +#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 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 + +namespace TgBot { + +/** + * Contains information about why a request was unsuccessfull. + * @ingroup types + */ +class ResponseParameters { +public: + typedef std::shared_ptr 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 @@ -59,6 +59,11 @@ public: */ PhotoSize::Ptr thumb; + /** + * Optional. Emoji associated with the sticker + */ + std::string emoji; + /** * Optional. File size. */ 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 +#include +#include + +namespace TgBot { + +/** + * Contains information about the current status of a webhook. + * @ingroup types + */ +class WebhookInfo { +public: + typedef std::shared_ptr 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 allowedUpdates; +}; +} + +#endif //TGBOT_WEBHOOKINFO_H -- cgit v1.2.3 From c912fac6016ec582ac3bfeec642a9b758562c994 Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Tue, 27 Dec 2016 15:17:11 +0300 Subject: upgrade existing inline type and create new --- include/tgbot/types/ChosenInlineResult.h | 13 +++++ include/tgbot/types/InlineQueryResult.h | 38 ++++++------ include/tgbot/types/InlineQueryResultArticle.h | 5 ++ include/tgbot/types/InlineQueryResultAudio.h | 47 +++++++++++++++ include/tgbot/types/InlineQueryResultCachedAudio.h | 37 ++++++++++++ .../tgbot/types/InlineQueryResultCachedDocument.h | 41 +++++++++++++ include/tgbot/types/InlineQueryResultCachedGif.h | 37 ++++++++++++ .../tgbot/types/InlineQueryResultCachedMpeg4Gif.h | 37 ++++++++++++ include/tgbot/types/InlineQueryResultCachedPhoto.h | 41 +++++++++++++ .../tgbot/types/InlineQueryResultCachedSticker.h | 36 ++++++++++++ include/tgbot/types/InlineQueryResultCachedVideo.h | 41 +++++++++++++ include/tgbot/types/InlineQueryResultCachedVoice.h | 36 ++++++++++++ include/tgbot/types/InlineQueryResultContact.h | 63 ++++++++++++++++++++ include/tgbot/types/InlineQueryResultDocument.h | 63 ++++++++++++++++++++ include/tgbot/types/InlineQueryResultGame.h | 36 ++++++++++++ include/tgbot/types/InlineQueryResultGif.h | 4 +- include/tgbot/types/InlineQueryResultLocation.h | 58 ++++++++++++++++++ include/tgbot/types/InlineQueryResultMpeg4Gif.h | 7 +-- include/tgbot/types/InlineQueryResultPhoto.h | 10 ++-- include/tgbot/types/InlineQueryResultVenue.h | 68 ++++++++++++++++++++++ include/tgbot/types/InlineQueryResultVideo.h | 5 ++ include/tgbot/types/InlineQueryResultVoice.h | 37 ++++++++++++ include/tgbot/types/InputContactMessageContent.h | 40 +++++++++++++ include/tgbot/types/InputLocationMessageContent.h | 34 +++++++++++ include/tgbot/types/InputMessageContent.h | 24 ++++++++ include/tgbot/types/InputTextMessageContent.h | 40 +++++++++++++ include/tgbot/types/InputVenueMessageContent.h | 51 ++++++++++++++++ src/TgTypeParser.cpp | 16 ++--- 28 files changed, 925 insertions(+), 40 deletions(-) create mode 100644 include/tgbot/types/InlineQueryResultAudio.h create mode 100644 include/tgbot/types/InlineQueryResultCachedAudio.h create mode 100644 include/tgbot/types/InlineQueryResultCachedDocument.h create mode 100644 include/tgbot/types/InlineQueryResultCachedGif.h create mode 100644 include/tgbot/types/InlineQueryResultCachedMpeg4Gif.h create mode 100644 include/tgbot/types/InlineQueryResultCachedPhoto.h create mode 100644 include/tgbot/types/InlineQueryResultCachedSticker.h create mode 100644 include/tgbot/types/InlineQueryResultCachedVideo.h create mode 100644 include/tgbot/types/InlineQueryResultCachedVoice.h create mode 100644 include/tgbot/types/InlineQueryResultContact.h create mode 100644 include/tgbot/types/InlineQueryResultDocument.h create mode 100644 include/tgbot/types/InlineQueryResultGame.h create mode 100644 include/tgbot/types/InlineQueryResultLocation.h create mode 100644 include/tgbot/types/InlineQueryResultVenue.h create mode 100644 include/tgbot/types/InlineQueryResultVoice.h create mode 100644 include/tgbot/types/InputContactMessageContent.h create mode 100644 include/tgbot/types/InputLocationMessageContent.h create mode 100644 include/tgbot/types/InputMessageContent.h create mode 100644 include/tgbot/types/InputTextMessageContent.h create mode 100644 include/tgbot/types/InputVenueMessageContent.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 #include "tgbot/types/User.h" +#include "tgbot/types/Location.h" namespace TgBot { @@ -30,6 +31,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. */ diff --git a/include/tgbot/types/InlineQueryResult.h b/include/tgbot/types/InlineQueryResult.h index d3eb968..6dad81b 100644 --- a/include/tgbot/types/InlineQueryResult.h +++ b/include/tgbot/types/InlineQueryResult.h @@ -8,6 +8,9 @@ #include #include +#include "tgbot/types/InlineKeyboardMarkup.h" +#include "tgbot/types/InputMessageContent.h" + namespace TgBot { /** @@ -19,7 +22,7 @@ public: typedef std::shared_ptr Ptr; InlineQueryResult() { - this->disableWebPagePreview = false; + //this->disableWebPagePreview = false; } virtual ~InlineQueryResult() { } @@ -40,26 +43,19 @@ public: 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. Caption of the file to be sent, 0-200 characters + */ + std::string caption; + + /** + * Optional. Inline keyboard attached to the message + */ + InlineKeyboardMarkup::Ptr replyMarkup; + + /** + * 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 +#include + +#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 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 @@ -34,6 +34,11 @@ public: */ std::string mimeType; + /** + * URL of the thumbnail (jpeg only) for the video + */ + std::string thumbUrl; + /** * Optional. Video width. */ 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 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..84ba907 --- /dev/null +++ b/include/tgbot/types/InputContactMessageContent.h @@ -0,0 +1,40 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_INPUTCONTACTMESSAGECONTENT_H +#define TGBOT_INPUTCONTACTMESSAGECONTENT_H + +#include +#include + +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 Ptr; + + /** + * 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..737ca9f --- /dev/null +++ b/include/tgbot/types/InputLocationMessageContent.h @@ -0,0 +1,34 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_INPUTLOCATIONMESSAGECONTENT_H +#define TGBOT_INPUTLOCATIONMESSAGECONTENT_H + +#include + +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 Ptr; + + /** + * 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..2063c08 --- /dev/null +++ b/include/tgbot/types/InputMessageContent.h @@ -0,0 +1,24 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_INPUTMESSAGECONTENT_H +#define TGBOT_INPUTMESSAGECONTENT_H + +#include + +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 Ptr; + + 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..4960164 --- /dev/null +++ b/include/tgbot/types/InputTextMessageContent.h @@ -0,0 +1,40 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + +#ifndef TGBOT_INPUTTEXTMESSAGECONTENT_H +#define TGBOT_INPUTTEXTMESSAGECONTENT_H + +#include +#include + +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 Ptr; + + /** + * 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..0b5eab7 --- /dev/null +++ b/include/tgbot/types/InputVenueMessageContent.h @@ -0,0 +1,51 @@ +// +// Created by Konstantin Kukin on 26/12/16. +// + + +#ifndef TGBOT_INPUTVENUEMESSAGECONTENT_H +#define TGBOT_INPUTVENUEMESSAGECONTENT_H + +#include +#include + +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 Ptr; + + /** + * 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 foursquare_id; + + virtual ~InputVenueMessageContent() { } +}; +} + +#endif //TGBOT_INPUTVENUEMESSAGECONTENT_H diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 174afe9..6bd77a7 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -552,10 +552,10 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos result->id = data.get("id"); result->title = data.get("title", ""); - result->messageText = data.get("message_text", ""); - result->parseMode = data.get("parse_mode", ""); - result->disableWebPagePreview = data.get("disable_web_page_preview", false); - result->thumbUrl = data.get("thumb_url", ""); + //result->messageText = data.get("message_text", ""); + //result->parseMode = data.get("parse_mode", ""); + //result->disableWebPagePreview = data.get("disable_web_page_preview", false); + //result->thumbUrl = data.get("thumb_url", ""); return result; } @@ -570,10 +570,10 @@ 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, "message_text", object->messageText); + //appendToJson(result, "parse_mode", object->parseMode); + //appendToJson(result, "disable_web_page_preview", object->disableWebPagePreview); + //appendToJson(result, "thumb_url", object->thumbUrl); if (object->type == InlineQueryResultArticle::TYPE){ result += parseInlineQueryResultArticle(static_pointer_cast(object)); -- cgit v1.2.3 From 9c60e1f40132b2cf2190de55e057c442a2934440 Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Tue, 27 Dec 2016 19:52:26 +0300 Subject: add parse types to JSON part1 --- include/tgbot/TgTypeParser.h | 101 ++++++++++++++++++- include/tgbot/types/InlineQueryResult.h | 2 +- src/TgTypeParser.cpp | 168 ++++++++++++++++++++++++++++++++ 3 files changed, 269 insertions(+), 2 deletions(-) diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 9e5a1d7..214480a 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -40,21 +40,42 @@ #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/KeyboardButton.h" +#include "tgbot/types/ReplyKeyboardRemove.h" #include "tgbot/types/ReplyKeyboardHide.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" namespace TgBot { @@ -94,20 +115,72 @@ 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; + + 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; + ReplyKeyboardHide::Ptr parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const; std::string parseReplyKeyboardHide(const ReplyKeyboardHide::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; + 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 +191,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 +199,9 @@ 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; + inline boost::property_tree::ptree parseJson(const std::string& json) const { boost::property_tree::ptree tree; std::istringstream input(json); @@ -150,6 +227,15 @@ public: return result; } + template + std::vector parseJsonAndGetArray(std::function parseFunc, const boost::property_tree::ptree& data) const { + std::vector result; + for (const std::pair& innerTreeItem : data) { + result.push_back(parseFunc(innerTreeItem.second)); + } + return result; + } + template std::vector> parseJsonAndGetArray(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { std::vector> result; @@ -193,6 +279,19 @@ public: return result; } + template + std::string parseArray(std::function parseFunc, const std::vector& objects) const { + std::string result; + result += '['; + for (const T& item : objects) { + result += parseFunc(item); + result += ','; + } + result.erase(result.length() - 1); + result += ']'; + return result; + } + template std::string parse2DArray(TgTypeToJsonFunc parseFunc, const std::vector>>& objects) const { std::string result; diff --git a/include/tgbot/types/InlineQueryResult.h b/include/tgbot/types/InlineQueryResult.h index 6dad81b..29e6f7a 100644 --- a/include/tgbot/types/InlineQueryResult.h +++ b/include/tgbot/types/InlineQueryResult.h @@ -22,7 +22,7 @@ public: typedef std::shared_ptr Ptr; InlineQueryResult() { - //this->disableWebPagePreview = false; + } virtual ~InlineQueryResult() { } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 6bd77a7..ea176b0 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("first_name", ""); result->lastName = data.get("last_name", ""); + result->allMembersAreAdministrators = data.get("all_members_are_administrators", false); return result; } @@ -108,6 +109,7 @@ MessageEntity::Ptr TgTypeParser::parseJsonAndGetEntity(const ptree& data) const{ result->offset=data.get("offset"); result->length=data.get("length"); result->url=data.get("url", ""); + result->user = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); return result; } @@ -208,6 +210,8 @@ Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const ptree& data) const { Audio::Ptr result(new Audio); result->fileId = data.get("file_id"); result->duration = data.get("duration"); + result->performer = data.get("performer", ""); + result->title = data.get("title", ""); result->mimeType = data.get("mime_type", ""); result->fileSize = data.get("file_size", 0); return result; @@ -260,6 +264,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const { result->width = data.get("width"); result->height = data.get("height"); result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->emoji = data.get("emoji"); result->fileSize = data.get("file_size", 0); return result; } @@ -274,6 +279,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 += '}'; @@ -400,6 +406,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("file_id"); + result->filePath = data.get("file_size", 0); + result->filePath = data.get("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& item : data.find("keyboard")->second) { @@ -442,6 +470,47 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt return result; } +KeyboardButton::Ptr TgTypeParser::parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const { + KeyboardButton::Ptr result(new KeyboardButton); + result->text = data.get("text"); + result->requestContact = data.get("request_contact", false); + result->requestLocation = data.get("request_location", false); + return result; +} + +std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + 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("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 += '}'; + return result; +} + ReplyKeyboardHide::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const { ReplyKeyboardHide::Ptr result(new ReplyKeyboardHide); result->selective = data.get("selective"); @@ -480,6 +549,46 @@ 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(&TgTypeParser::parseJsonAndGetUser, data, "user"); + result->status = data.get("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("migrate_to_chat_id", 0); + result->retryAfter = data.get("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(parseJsonAndGetForceReply(data)); @@ -511,6 +620,7 @@ InlineQuery::Ptr TgTypeParser::parseJsonAndGetInlineQuery(const boost::property_ InlineQuery::Ptr result(new InlineQuery); result->id = data.get("id"); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->location = tryParseJson(&TgTypeParser::parseJsonAndGetLocation, data, "location"); result->query = data.get("query"); result->offset = data.get("offset"); @@ -525,6 +635,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,6 +647,19 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos string type = data.get("type"); InlineQueryResult::Ptr result; + /*if (type == InlineQueryResultCachedAudio::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultArticle(data)); + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + }*/ if (type == InlineQueryResultArticle::TYPE) { result = static_pointer_cast(parseJsonAndGetInlineQueryResultArticle(data)); } else if (type == InlineQueryResultPhoto::TYPE) { @@ -753,6 +877,8 @@ CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::prope result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->message = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "message"); result->inlineMessageId = data.get("inline_message_id", ""); + result->chatInstance = data.get("chat_instance"); + result->gameShortName = data.get("game_short_name", ""); result->data = data.get("data", ""); return result; } @@ -768,6 +894,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 +937,7 @@ InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(cons result->url = data.get("url", ""); result->callbackData = data.get("callback_data", ""); result->switchInlineQuery = data.get("switch_inline_query", ""); + result->switchInlineQueryCurrentChat = data.get("switch_inline_query_current_chat", ""); return result; } std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const { @@ -821,6 +950,45 @@ 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("url"); + result->hasCustomCertificate = data.get("has_custom_certificate"); + result->pendingUpdateCount = data.get("pending_update_count"); + result->lastErrorDate = data.get("last_error_date", 0); + result->lastErrorMessage = data.get("last_error_message", ""); + result->maxConnections = data.get("max_connections", 0); + result->allowedUpdates = parseJsonAndGetArray( + [](const boost::property_tree::ptree& innerData)->std::string { + return innerData.get(""); + } + , data); + 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([](const std::string &s)->std::string { + return s; + } + , object->allowedUpdates)); result.erase(result.length() - 1); result += '}'; return result; -- cgit v1.2.3 From 187311fc635c843f10c275c7e230543b5f67e703 Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Wed, 28 Dec 2016 19:05:44 +0300 Subject: add parse types to JSON part2 --- include/tgbot/TgTypeParser.h | 35 ++ include/tgbot/types/InputContactMessageContent.h | 4 + include/tgbot/types/InputLocationMessageContent.h | 4 + include/tgbot/types/InputMessageContent.h | 13 + include/tgbot/types/InputTextMessageContent.h | 4 + include/tgbot/types/InputVenueMessageContent.h | 6 +- include/tgbot/types/Update.h | 15 + src/TgTypeParser.cpp | 631 ++++++++++++++++++++-- src/types/InlineQueryResult.cpp | 32 ++ 9 files changed, 707 insertions(+), 37 deletions(-) diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 214480a..66e2c41 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -76,6 +76,11 @@ #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 { @@ -181,6 +186,21 @@ public: 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; @@ -202,6 +222,21 @@ public: 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); diff --git a/include/tgbot/types/InputContactMessageContent.h b/include/tgbot/types/InputContactMessageContent.h index 84ba907..421093c 100644 --- a/include/tgbot/types/InputContactMessageContent.h +++ b/include/tgbot/types/InputContactMessageContent.h @@ -18,6 +18,10 @@ class InputContactMessageContent : public InputMessageContent { public: typedef std::shared_ptr Ptr; + InputContactMessageContent() : + InputMessageContent("InputContactMessageContent") + {} + /** * Contact's phone number */ diff --git a/include/tgbot/types/InputLocationMessageContent.h b/include/tgbot/types/InputLocationMessageContent.h index 737ca9f..3405353 100644 --- a/include/tgbot/types/InputLocationMessageContent.h +++ b/include/tgbot/types/InputLocationMessageContent.h @@ -17,6 +17,10 @@ class InputLocationMessageContent : public InputMessageContent { public: typedef std::shared_ptr Ptr; + InputLocationMessageContent() : + InputMessageContent("InputLocationMessageContent") + {} + /** * Latitude of the location in degrees */ diff --git a/include/tgbot/types/InputMessageContent.h b/include/tgbot/types/InputMessageContent.h index 2063c08..587dcf8 100644 --- a/include/tgbot/types/InputMessageContent.h +++ b/include/tgbot/types/InputMessageContent.h @@ -17,6 +17,19 @@ class InputMessageContent { public: typedef std::shared_ptr Ptr; + InputMessageContent(const std::string &tType): + type(tType) + {} + + /** + * May be + * InputTextMessageContent + * InputLocationMessageContent + * InputVenueMessageContent + * InputContactMessageContent + */ + std::string type; + virtual ~InputMessageContent() { } }; } diff --git a/include/tgbot/types/InputTextMessageContent.h b/include/tgbot/types/InputTextMessageContent.h index 4960164..4c33069 100644 --- a/include/tgbot/types/InputTextMessageContent.h +++ b/include/tgbot/types/InputTextMessageContent.h @@ -18,6 +18,10 @@ class InputTextMessageContent : public InputMessageContent { public: typedef std::shared_ptr Ptr; + InputTextMessageContent(): + InputMessageContent("InputTextMessageContent") + {} + /** * Text of the message to be sent, 1-4096 characters */ diff --git a/include/tgbot/types/InputVenueMessageContent.h b/include/tgbot/types/InputVenueMessageContent.h index 0b5eab7..3ffc998 100644 --- a/include/tgbot/types/InputVenueMessageContent.h +++ b/include/tgbot/types/InputVenueMessageContent.h @@ -19,6 +19,10 @@ class InputVenueMessageContent : public InputMessageContent { public: typedef std::shared_ptr Ptr; + InputVenueMessageContent() : + InputMessageContent("InputVenueMessageContent") + {} + /** * Latitude of the location in degrees */ @@ -42,7 +46,7 @@ public: /** * Optional. Foursquare identifier of the venue, if known */ - std::string foursquare_id; + std::string foursquareId; virtual ~InputVenueMessageContent() { } }; 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 @@ -51,6 +51,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 */ diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index ea176b0..939d339 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -342,8 +342,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("longitude"); - result->latitude = data.get("latitude"); + result->longitude = data.get("longitude", 0); + result->latitude = data.get("latitude", 0); return result; } @@ -364,6 +364,9 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const ptree& data) const { Update::Ptr result(new Update); result->updateId = data.get("update_id"); result->message = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "message"); + result->editedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message"); + result->channelPost = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "channel_post"); + result->editedChannelPost = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_channel_post"); result->inlineQuery = tryParseJson(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query"); result->chosenInlineResult = tryParseJson(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result"); result->callbackQuery = tryParseJson(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query"); @@ -378,6 +381,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)); @@ -647,21 +653,38 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos string type = data.get("type"); InlineQueryResult::Ptr result; - /*if (type == InlineQueryResultCachedAudio::TYPE) { - result = static_pointer_cast(parseJsonAndGetInlineQueryResultArticle(data)); - } else if (type == InlineQueryResultCachedDocument::TYPE) { - - } else if (type == InlineQueryResultCachedDocument::TYPE) { - - } else if (type == InlineQueryResultCachedDocument::TYPE) { - + if (type == InlineQueryResultCachedAudio::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedAudio(data)); } else if (type == InlineQueryResultCachedDocument::TYPE) { - - } else if (type == InlineQueryResultCachedDocument::TYPE) { - - }*/ - if (type == InlineQueryResultArticle::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedDocument(data)); + } else if (type == InlineQueryResultCachedGif::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedGif(data)); + } else if (type == InlineQueryResultCachedMpeg4Gif::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedMpeg4Gif(data)); + } else if (type == InlineQueryResultCachedPhoto::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedPhoto(data)); + } else if (type == InlineQueryResultCachedSticker::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedSticker(data)); + } else if (type == InlineQueryResultCachedVideo::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedVideo(data)); + } else if (type == InlineQueryResultCachedVoice::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedVoice(data)); + } else if (type == InlineQueryResultArticle::TYPE) { result = static_pointer_cast(parseJsonAndGetInlineQueryResultArticle(data)); + } else if (type == InlineQueryResultAudio::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultAudio(data)); + } else if (type == InlineQueryResultContact::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultContact(data)); + } else if (type == InlineQueryResultGame::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultGame(data)); + } else if (type == InlineQueryResultDocument::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultDocument(data)); + } else if (type == InlineQueryResultLocation::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultLocation(data)); + } else if (type == InlineQueryResultVenue::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultVenue(data)); + } else if (type == InlineQueryResultVoice::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultVoice(data)); } else if (type == InlineQueryResultPhoto::TYPE) { result = static_pointer_cast(parseJsonAndGetInlineQueryResultPhoto(data)); } else if (type == InlineQueryResultGif::TYPE) { @@ -676,10 +699,9 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos result->id = data.get("id"); result->title = data.get("title", ""); - //result->messageText = data.get("message_text", ""); - //result->parseMode = data.get("parse_mode", ""); - //result->disableWebPagePreview = data.get("disable_web_page_preview", false); - //result->thumbUrl = data.get("thumb_url", ""); + result->caption = data.get("caption", ""); + result->replyMarkup = tryParseJson(&TgTypeParser::parseJsonAndGetInlineKeyboardMarkup, data, "reply_markup"); + result->inputMessageContent = tryParseJson(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content"); return result; } @@ -694,34 +716,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(object)); + } + else if (object->type == InlineQueryResultCachedDocument::TYPE) { + result += parseInlineQueryResultCachedDocument(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedGif::TYPE) { + result += parseInlineQueryResultCachedGif(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedMpeg4Gif::TYPE) { + result += parseInlineQueryResultCachedMpeg4Gif(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedPhoto::TYPE) { + result += parseInlineQueryResultCachedPhoto(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedSticker::TYPE) { + result += parseInlineQueryResultCachedSticker(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedVideo::TYPE) { + result += parseInlineQueryResultCachedVideo(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedVoice::TYPE) { + result += parseInlineQueryResultCachedVoice(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultArticle::TYPE) { result += parseInlineQueryResultArticle(static_pointer_cast(object)); - } else if (object->type == InlineQueryResultPhoto::TYPE){ + } + else if (object->type == InlineQueryResultAudio::TYPE) { + result += parseInlineQueryResultAudio(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultContact::TYPE) { + result += parseInlineQueryResultContact(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultGame::TYPE) { + result += parseInlineQueryResultGame(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultDocument::TYPE) { + result += parseInlineQueryResultDocument(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultLocation::TYPE) { + result += parseInlineQueryResultLocation(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultVenue::TYPE) { + result += parseInlineQueryResultVenue(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultVoice::TYPE) { + result += parseInlineQueryResultVoice(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultPhoto::TYPE) { result += parseInlineQueryResultPhoto(static_pointer_cast(object)); - } else if (object->type == InlineQueryResultGif::TYPE){ + } + else if (object->type == InlineQueryResultGif::TYPE) { result += parseInlineQueryResultGif(static_pointer_cast(object)); - } else if (object->type == InlineQueryResultMpeg4Gif::TYPE){ + } + else if (object->type == InlineQueryResultMpeg4Gif::TYPE) { result += parseInlineQueryResultMpeg4Gif(static_pointer_cast(object)); - } else if (object->type == InlineQueryResultVideo::TYPE){ + } + else if (object->type == InlineQueryResultVideo::TYPE) { result += parseInlineQueryResultVideo(static_pointer_cast(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("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("document_file_id"); + result->description = data.get("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("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("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("photo_file_id"); + result->description = data.get("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("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("video_file_id"); + result->description = data.get("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("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("url", ""); result->hideUrl = data.get("hide_url", false); result->description = data.get("description", ""); + result->thumbUrl = data.get("thumb_url", ""); result->thumbWidth = data.get("thumb_width", 0); result->thumbHeight = data.get("thumb_height", 0); return result; @@ -737,20 +971,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("audio_url"); + result->performer = data.get("performer", ""); + result->audioDuration = data.get("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("phone_number"); + result->firstName = data.get("first_name"); + result->lastName = data.get("last_name", ""); + result->thumbUrl = data.get("thumb_url", ""); + result->thumbWidth = data.get("thumb_width", 0); + result->thumbHeight = data.get("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("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("document_url"); + result->mimeType = data.get("mime_type"); + result->description = data.get("description", ""); + result->thumbUrl = data.get("thumb_url", ""); + result->thumbWidth = data.get("thumb_width", 0); + result->thumbHeight = data.get("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("latitude"); + result->longitude = data.get("longitude"); + result->thumbUrl = data.get("thumb_url", ""); + result->thumbWidth = data.get("thumb_width", 0); + result->thumbHeight = data.get("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("latitude"); + result->longitude = data.get("longitude"); + result->address = data.get("address"); + result->foursquareId = data.get("foursquare_id", ""); + result->thumbUrl = data.get("thumb_url", ""); + result->thumbWidth = data.get("thumb_width", 0); + result->thumbHeight = data.get("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("voice_url"); + result->voiceDuration = data.get("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("photo_url", ""); + result->thumbUrl = data.get("thumb_url"); result->photoWidth = data.get("photo_width", 0); result->photoHeight = data.get("photo_height", 0); result->description = data.get("description", ""); - result->caption = data.get("caption", ""); return result; } @@ -762,10 +1179,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; } @@ -776,7 +1193,7 @@ InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(cons result->gifUrl = data.get("gif_url", ""); result->gifWidth = data.get("gif_width", 0); result->gifHeight = data.get("gif_height", 0); - result->caption = data.get("caption", ""); + result->thumbUrl = data.get("thumb_url"); return result; } std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const { @@ -789,7 +1206,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; } @@ -800,7 +1217,7 @@ InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpe result->mpeg4Url = data.get("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("thumb_url"); return result; } @@ -814,7 +1231,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; } @@ -824,7 +1241,8 @@ InlineQueryResultVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVideo( InlineQueryResultVideo::Ptr result(new InlineQueryResultVideo); result->videoUrl = data.get("video_url"); result->mimeType = data.get("mime_type"); - result->videoWidth = data.get("video_height", 0); + result->thumbUrl = data.get("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("description", ""); @@ -840,6 +1258,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); @@ -852,6 +1271,8 @@ ChosenInlineResult::Ptr TgTypeParser::parseJsonAndGetChosenInlineResult(const bo ChosenInlineResult::Ptr result(new ChosenInlineResult); result->resultId = data.get("result_id"); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->location = tryParseJson(&TgTypeParser::parseJsonAndGetLocation, data, "location"); + result->inlineMessageId = data.get("inline_message_id", ""); result->query = data.get("query"); return result; } @@ -994,6 +1415,144 @@ std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const return result; } +InputMessageContent::Ptr TgTypeParser::parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const { + InputMessageContent::Ptr result; + // define InputMessageContent type + + string tMessageText = data.get("message_text", ""); + float tLatitude = data.get("latitude", 1000); // latitude belong (-90,90) + string tTitle = data.get("title", ""); + string tPnoneNumber = data.get("phone_number", ""); + + if (tMessageText != std::string("")) { + result = static_pointer_cast(parseJsonAndGetInputTextMessageContent(data)); + } else if (tTitle !=std::string("")) { + result = static_pointer_cast(parseJsonAndGetInputVenueMessageContent(data)); + } else if (tLatitude != 1000) { + result = static_pointer_cast(parseJsonAndGetInputLocationMessageContent(data)); + } else if (tPnoneNumber!= std::string("")) { + result = static_pointer_cast(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(object)); + } + else if (object->type == std::string("InputLocationMessageContent")) { + result += parseInputLocationMessageContent(static_pointer_cast(object)); + } + else if (object->type == std::string("InputVenueMessageContent")) { + result += parseInputVenueMessageContent(static_pointer_cast(object)); + } + else if (object->type == std::string("InputContactMessageContent")) { + result += parseInputContactMessageContent(static_pointer_cast(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("message_text"); + result->parseMode = data.get("parse_mode", ""); + result->disableWebPagePreview = data.get("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("latitude"); + result->longitude = data.get("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("latitude"); + result->longitude = data.get("longitude"); + result->title = data.get("title"); + result->address = data.get("address"); + result->foursquareId = data.get("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("phone_number"); + result->firstName = data.get("first_name"); + result->lastName = data.get("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"; -- cgit v1.2.3 From 33e4184338cc7b9ecd8af36ee0ecaff74020356c Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Thu, 29 Dec 2016 17:50:00 +0300 Subject: Rename ReplyKeyboardHide to ReplyKeyboardRemove --- include/tgbot/TgTypeParser.h | 3 -- include/tgbot/tgbot.h | 2 +- include/tgbot/types/InlineQueryResult.h | 6 ++-- include/tgbot/types/ReplyKeyboardHide.h | 55 --------------------------------- src/TgTypeParser.cpp | 27 +++------------- 5 files changed, 8 insertions(+), 85 deletions(-) delete mode 100644 include/tgbot/types/ReplyKeyboardHide.h diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 66e2c41..48f7338 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -44,7 +44,6 @@ #include "tgbot/types/ReplyKeyboardMarkup.h" #include "tgbot/types/KeyboardButton.h" #include "tgbot/types/ReplyKeyboardRemove.h" -#include "tgbot/types/ReplyKeyboardHide.h" #include "tgbot/types/ForceReply.h" #include "tgbot/types/ChatMember.h" #include "tgbot/types/ResponseParameters.h" @@ -133,8 +132,6 @@ public: ReplyKeyboardRemove::Ptr parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const; std::string parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const; - ReplyKeyboardHide::Ptr parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const; ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const; std::string parseForceReply(const ForceReply::Ptr& object) const; 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/InlineQueryResult.h b/include/tgbot/types/InlineQueryResult.h index 29e6f7a..d06bffd 100644 --- a/include/tgbot/types/InlineQueryResult.h +++ b/include/tgbot/types/InlineQueryResult.h @@ -38,12 +38,12 @@ 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; /** - * Optional. Caption of the file to be sent, 0-200 characters + * Optional or missing. See description of derived classes. Caption of the file to be sent, 0-200 characters */ std::string caption; @@ -53,7 +53,7 @@ public: InlineKeyboardMarkup::Ptr replyMarkup; /** - * Content of the message to be sent + * 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/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 - -#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 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/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 939d339..6b0914b 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -517,25 +517,6 @@ std::string TgTypeParser::parseReplyKeyboardRemove(const ReplyKeyboardRemove::Pt return result; } -ReplyKeyboardHide::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const { - ReplyKeyboardHide::Ptr result(new ReplyKeyboardHide); - result->selective = data.get("selective"); - return result; -} - -std::string TgTypeParser::parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const { - if (!object) { - return ""; - } - string result; - result += '{'; - appendToJson(result, "hide_keyboard", object->hideKeyboard); - appendToJson(result, "selective", object->selective); - result.erase(result.length() - 1); - result += '}'; - return result; -} - ForceReply::Ptr TgTypeParser::parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const { ForceReply::Ptr result(new ForceReply); result->selective = data.get("selective"); @@ -598,8 +579,8 @@ std::string TgTypeParser::parseResponseParameters(const ResponseParameters::Ptr& GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const { if (data.find("force_reply") != data.not_found()) { return static_pointer_cast(parseJsonAndGetForceReply(data)); - } else if (data.find("hide_keyboard") != data.not_found()) { - return static_pointer_cast(parseJsonAndGetReplyKeyboardHide(data)); + } else if (data.find("remove_keyboard") != data.not_found()) { + return static_pointer_cast(parseJsonAndGetReplyKeyboardRemove(data)); } else if (data.find("keyboard") != data.not_found()) { return static_pointer_cast(parseJsonAndGetReplyKeyboardMarkup(data)); } else if (data.find("inline_keyboard") != data.not_found()) { @@ -613,8 +594,8 @@ std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) con } if (dynamic_pointer_cast(object) != nullptr) { return parseForceReply(static_pointer_cast(object)); - } else if (dynamic_pointer_cast(object) != nullptr) { - return parseReplyKeyboardHide(static_pointer_cast(object)); + } else if (dynamic_pointer_cast(object) != nullptr) { + return parseReplyKeyboardRemove(static_pointer_cast(object)); } else if (dynamic_pointer_cast(object) != nullptr){ return parseReplyKeyboardMarkup(static_pointer_cast(object)); } else if (dynamic_pointer_cast(object) != nullptr){ -- cgit v1.2.3 From 2d7d1a269383ec1db99b6759f9c58ba08d1d29fe Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Fri, 30 Dec 2016 11:38:22 +0300 Subject: add Webhook functions --- include/tgbot/Api.h | 18 +++++++++++++++++- include/tgbot/TgTypeParser.h | 14 ++++++++++++-- src/Api.cpp | 36 +++++++++++++++++++++++++++++++++++- src/TgTypeParser.cpp | 2 +- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 0a2b7bd..928a017 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -37,6 +37,7 @@ #include "tgbot/types/Update.h" #include "tgbot/types/InlineQueryResult.h" #include "tgbot/types/Venue.h" +#include "tgbot/types/WebhookInfo.h" namespace TgBot { @@ -48,6 +49,8 @@ class Bot; */ class Api { +typedef std::shared_ptr> StringArrayPtr; + friend class Bot; public: @@ -318,7 +321,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. diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 48f7338..89c6dec 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -260,9 +260,13 @@ public: } template - std::vector parseJsonAndGetArray(std::function parseFunc, const boost::property_tree::ptree& data) const { + std::vector parseJsonAndGetArray(std::function parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { std::vector result; - for (const std::pair& innerTreeItem : data) { + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { + return result; + } + for (const std::pair& innerTreeItem : treeItem->second) { result.push_back(parseFunc(innerTreeItem.second)); } return result; @@ -300,6 +304,8 @@ public: template std::string parseArray(TgTypeToJsonFunc parseFunc, const std::vector>& objects) const { + if (objects.empty()) + return ""; std::string result; result += '['; for (const std::shared_ptr& item : objects) { @@ -313,6 +319,8 @@ public: template std::string parseArray(std::function parseFunc, const std::vector& objects) const { + if (objects.empty()) + return ""; std::string result; result += '['; for (const T& item : objects) { @@ -326,6 +334,8 @@ public: template std::string parse2DArray(TgTypeToJsonFunc parseFunc, const std::vector>>& objects) const { + if (objects.empty()) + return ""; std::string result; result += '['; for (const std::vector>& item : objects) { diff --git a/src/Api.cpp b/src/Api.cpp index 54cb692..c4baa2b 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -381,16 +381,50 @@ vector Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo return TgTypeParser::getInstance().parseJsonAndGetArray(&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 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( + [](const std::string &s)->std::string { + return s; + }, *allowedUpdates); + args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson)); + } sendRequest("setWebhook", args); } +bool Api::deleteWebhook() const +{ + ptree p = sendRequest("deleteWebhook"); + return p.get("", false); +} + +WebhookInfo::Ptr Api::getWebhookInfo() const +{ + ptree p = sendRequest("getWebhookInfo"); + + if (!p.get_child_optional("url")) + return nullptr; + + if (p.get("url","")!=string("")) + { + return TgTypeParser::getInstance().parseJsonAndGetWebhookInfo(p); + } + else + { + return nullptr; + } +} + void Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, int32_t cacheTime, bool isPersonal, const std::string& nextOffset) const { vector args; diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 6b0914b..71da2ac 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1370,7 +1370,7 @@ WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_ [](const boost::property_tree::ptree& innerData)->std::string { return innerData.get(""); } - , data); + , data, "allowed_updates"); return result; } -- cgit v1.2.3 From a071ebee5b2f6c418e7f3916bd6f50b152aaf300 Mon Sep 17 00:00:00 2001 From: kukin-konstantin Date: Fri, 30 Dec 2016 14:07:32 +0300 Subject: edit Message type --- include/tgbot/types/Message.h | 15 +++++++++++++++ src/TgTypeParser.cpp | 6 ++++++ 2 files changed, 21 insertions(+) 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 @@ -85,6 +85,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. */ @@ -95,6 +105,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. */ diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 71da2ac..20b8ea2 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -120,8 +120,11 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->date = data.get("date"); result->chat = parseJsonAndGetChat(data.find("chat")->second); result->forwardFrom = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "forward_from"); + result->forwardFromChat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "forward_from_chat"); + result->forwardFromMessageId = data.get("forward_from_message_id", 0); result->forwardDate = data.get("forward_date", 0); result->replyToMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message"); + result->editDate = data.get("edit_date", 0); result->text = data.get("text", ""); result->entities = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetEntity, data, "entities"); result->audio = tryParseJson