From 4aa6af3180aef70f9a4320a2f6d818f68f5bb669 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Tue, 30 Aug 2022 19:34:12 +0200 Subject: Sort api methods --- include/tgbot/Api.h | 905 ++++++++++++++++----------------- src/Api.cpp | 1399 +++++++++++++++++++++++++-------------------------- 2 files changed, 1152 insertions(+), 1152 deletions(-) diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index e5a17f5..755998b 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -48,6 +48,51 @@ friend class Bot; public: Api(std::string token, const HttpClient& httpClient, const std::string& url); + /** + * @brief Use this method to receive incoming updates using long polling. + * + * This method will not work if an outgoing webhook is set up. + * In order to avoid getting duplicate updates, recalculate offset after each server response. + * + * @param offset Optional. Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. + * @param limit Optional. Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100. + * @param timeout Optional. Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. + * @param allowed_updates Optional. List the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used. + * @return An Array of Update objects + */ + std::vector getUpdates(std::int32_t offset = 0, std::int32_t limit = 100, std::int32_t timeout = 0, const StringArrayPtr& allowedUpdates = nullptr) const; + + /** + * @brief Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. www.example.com/. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. + * You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up. + * We currently do not support self-signed certificates. + * 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 = "", InputFile::Ptr certificate = nullptr, std::int32_t maxConnection = 40, const StringArrayPtr& allowedUpdates = nullptr) const; + + /** + * @brief Use this method to remove webhook integration if you decide to switch back to getUpdates. + * + * Requires no parameters. + * + * @return Returns True on success. + */ + bool deleteWebhook() const; + + /** + * @brief Use this method to get current webhook status. + * + * Requires no parameters. + * If the bot is using getUpdates, will return an object with the url field empty. + * + * @return On success, returns a WebhookInfo object. + */ + WebhookInfo::Ptr getWebhookInfo() const; + /** * @brief A simple method for testing your bot's auth token. * @return Basic information about the bot in form of a User object. @@ -56,7 +101,7 @@ public: /** * @brief Use this method to send text messages. - * + * * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param text Text of the message to be sent * @param parseMode Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. @@ -64,7 +109,7 @@ public: * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. * @param replyToMessageId Optional. If the message is a reply, ID of the original message * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. - * + * * @return On success, the sent @ref Message is returned. */ Message::Ptr sendMessage(boost::variant chatId, const std::string& text, const std::string& parseMode = "", @@ -125,7 +170,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(std::int64_t chatId, boost::variant audio, const std::string &caption = "", std::int32_t duration = 0, + Message::Ptr sendAudio(std::int64_t chatId, boost::variant audio, const std::string& caption = "", std::int32_t duration = 0, const std::string& performer = "", const std::string& title = "", boost::variant thumb = "", std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; @@ -141,170 +186,9 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(std::int64_t chatId, boost::variant document, boost::variant thumb = "", const std::string &caption = "", std::int32_t replyToMessageId = 0, + Message::Ptr sendDocument(std::int64_t chatId, boost::variant document, boost::variant thumb = "", const std::string& caption = "", std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; - /** - * @brief Use this method to send invoices. - * @param chatId Unique identifier for the target private chat. - * @param title Product name, 1-32 characters. - * @param description Product description, 1-255 characters. - * @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. - * @param providerToken Payments provider token, obtained via Botfather. - * @param startParameter Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter. - * @param currency Three-letter ISO 4217 currency code. - * @param prices Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) - * @param providerData Optional. JSON-encoded data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. - * @param photoUrl Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for. - * @param photoSize Optional. Photo size - * @param photoWidth Optional. Photo width - * @param photoHeight Optional. Photo height - * @param needName Optional. Pass True, if you require the user's full name to complete the order. - * @param needPhoneNumber Optional. Pass True, if you require the user's phone number to complete the order. - * @param needEmail Optional. Pass True, if you require the user's email address to complete the order. - * @param needShippingAddress Optional. Pass True, if you require the user's shipping address to complete the order. - * @param sendPhoneNumberToProvider Optional. Pass True, if user's phone number should be sent to provider. - * @param sendEmailToProvider Optional. Pass True, if user's email address should be sent to provider - * @param isFlexible Optional. Pass True, if the final price depends on the shipping method. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button. - * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. - * @return On success, the sent Message is returned. - */ - Message::Ptr sendInvoice(std::int64_t chatId, const std::string& title, const std::string& description, const std::string& payload, - const std::string& providerToken, const std::string& startParameter, const std::string& currency, const std::vector& prices, - const std::string& providerData = "", const std::string& photoUrl = "", std::int32_t photoSize = 0, - std::int32_t photoWidth = 0, std::int32_t photoHeight = 0, bool needName = false, - bool needPhoneNumber = false, bool needEmail = false, bool needShippingAddress = false, - bool sendPhoneNumberToProvider = false, bool sendEmailToProvider = false, bool isFlexible = false, - std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), bool disableNotification = false) const; - - /** - * @brief Use this method to reply to shipping queries. - * - * If you sent an invoice requesting a shipping address and the parameter isFlexible was specified, the Bot API will send an Update with a shipping_query field to the bot. - * - * @param shippingQueryId Unique identifier for the query to be answered. - * @param ok Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible) - * @param shippingOptions Optional. Required if ok is True. A JSON-serialized array of available shipping options. - * @param errorMessage Optional. Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user. - * @return On success, True is returned. - */ - bool answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector& shippingOptions = std::vector(), const std::string& errorMessage = "") const; - - /** - * @brief Use this method to respond to such pre-checkout queries. - * - * Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field preCheckoutQuery. - * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. - * - * @param preCheckoutQueryId Unique identifier for the query to be answered - * @param ok Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems. - * @param errorMessage Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user. - * @return On success, True is returned. - */ - bool answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage = "") const; - - /** - * @brief Use this method to send .webp stickers. - * @param chatId Unique identifier for the target chat. - * @param sticker Sticker to send. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - * @param disableNotification Optional. Sends the message silenty. - * @return On success, the sent message is returned. - */ - Message::Ptr sendSticker(std::int64_t chatId, boost::variant sticker, std::int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared(), bool disableNotification = false) const; - - /** - * @brief Use this method to get a sticker set. - * @param chatId Name of the sticker set. - * @return On success, a StickerSet object is returned. - */ - StickerSet::Ptr getStickerSet(const std::string& name) const; - - /** - * @brief Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). - * @param userId User identifier of sticker file owner. - * @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. - * @return Returns the uploaded File on success. - */ - File::Ptr uploadStickerFile(std::int64_t userId, InputFile::Ptr pngSticker) const; - - /** - * @brief Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields pngSticker or tgsSticker. - * - * @param userId User identifier of created sticker set owner - * @param name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_”. is case insensitive. 1-64 characters. - * @param title Sticker set title, 1-64 characters - * @param emojis One or more emoji corresponding to the sticker - * @param pngSticker Optional. PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. - * @param tgsSticker Optional. TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements - * @param containsMasks Optional. Pass True, if a set of mask stickers should be created - * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces - * - * @return Returns True on success. - */ - bool createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, - const std::string& emojis, boost::variant pngSticker = "", boost::variant tgsSticker = "", - bool containsMasks = false, MaskPosition::Ptr maskPosition = nullptr) const; - - /** - * @brief Deprecated. Use @ref Api::createNewStickerSet - * @deprecated since Bot API 4.7. This remains unchanged for backward compatibility. - */ - bool createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, - boost::variant pngSticker, const std::string& emojis, bool containsMasks = false, MaskPosition::Ptr maskPosition = nullptr) const; - - /** - * @brief Use this method to add a new sticker to a set created by the bot. You must use exactly one of the fields png_sticker or tgs_sticker. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. - * - * @param userId User identifier of sticker set owner - * @param name Sticker set name - * @param emojis One or more emoji corresponding to the sticker - * @param pngSticker Optional. PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. - * @param tgsSticker Optional. TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements - * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces - * - * @return Returns True on success. - */ - bool addStickerToSet(std::int64_t userId, const std::string& name, const std::string& emojis, - boost::variant pngSticker = "", boost::variant tgsSticker = "", MaskPosition::Ptr maskPosition = nullptr) const; - - /** - * @brief Deprecated. Use @ref Api::addStickerToSet - * @deprecated since Bot API 4.7. This remains unchanged for backward compatibility. - */ - bool addStickerToSet(std::int64_t userId, const std::string& name, boost::variant pngSticker, - const std::string& emojis, MaskPosition::Ptr maskPosition = nullptr) const; - - /** - * @brief Use this method to move a sticker in a set created by the bot to a specific position. - * @param stickers File identifier of the sticker. - * @param position New sticker position in the set, zero-based. - * @return Returns True on success. - */ - bool setStickerPositionInSet(const std::string& sticker, std::uint32_t position) const; - - /** - * @brief Use this method to delete a sticker from a set created by the bot. - * @param stickers File identifier of the sticker. - * @return Returns True on success. - */ - bool deleteStickerFromSet(const std::string& sticker) const; - - /** - * @brief Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. - * - * @param name Sticker set name - * @param userId User identifier of the sticker set owner - * @param thumb Optional. A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/animated_stickers#technical-requirements for animated sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. Animated sticker set thumbnail can't be uploaded via HTTP URL. - * - * @return Returns True on success. - */ - bool setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant thumb = "") const; - /** * @brief Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). * @param chatId Unique identifier for the target chat. @@ -321,7 +205,6 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVideo(std::int64_t chatId, boost::variant video, bool supportsStreaming = false, std::int32_t duration = 0, std::int32_t width = 0, std::int32_t height = 0, boost::variant thumb = "", const std::string& caption = "", std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; @@ -343,8 +226,24 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent Message is returned. */ - Message::Ptr sendAnimation(std::int64_t chatId, boost::variant animation, std::int32_t duration = 0, std::int32_t width = 0, std::int32_t height = 0, boost::variant thumb = "", const std::string &caption = "", - std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; + Message::Ptr sendAnimation(std::int64_t chatId, boost::variant animation, std::int32_t duration = 0, std::int32_t width = 0, std::int32_t height = 0, boost::variant thumb = "", const std::string& caption = "", + std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; + + /** + * @brief Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. + * @param chatId Unique identifier for the target chat. + * @param voice Audio file to send. + * @param caption Voice message caption, 0-200 characters + * @param duration Duration of send audio in seconds. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message. + * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. + * @param parseMode Optional. Set it to "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. + * @param disableNotification Optional. Sends the message silenty. + * @return On success, the sent message is returned. + */ + Message::Ptr sendVoice(std::int64_t chatId, boost::variant voice, const std::string& caption = "", int duration = 0, std::int32_t replyToMessageId = 0, + GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; + /** * @brief Use this method to send video messages. On success, the sent Message is returned. * @param chatId Unique identifier for the target chat. @@ -371,33 +270,6 @@ public: std::vector sendMediaGroup(std::int64_t chatId, const std::vector& media, bool disableNotification = false, std::int32_t replyToMessageId = 0) const; - /** - * @brief Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. - * @param chatId Unique identifier for the target chat. - * @param voice Audio file to send. - * @param caption Voice message caption, 0-200 characters - * @param duration Duration of send audio in seconds. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - * @param parseMode Optional. Set it to "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. - * @param disableNotification Optional. Sends the message silenty. - * @return On success, the sent message is returned. - */ - Message::Ptr sendVoice(std::int64_t chatId, boost::variant voice, const std::string& caption = "", int duration = 0, std::int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared(), const std::string& parseMode = "", bool disableNotification = false) const; - - /** - * @brief Use this method to send a game. - * @param chatId Unique identifier for the target chat. - * @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game. - * @param disableNotification Optional. Sends the message silenty. - * @return On success, the sent message is returned. - */ - Message::Ptr sendGame(std::int64_t chatId, const std::string& gameShortName, std::int32_t replyToMessageId = 0, - InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared(), bool disableNotification = false) const; - /** * @brief Use this method to send point on the map. * @param chatId Unique identifier for the target chat. @@ -436,7 +308,6 @@ public: Message::Ptr stopMessageLiveLocation(std::int64_t chatId = 0, std::int32_t messageId = 0, std::int32_t inlineMessageId = 0, InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared()) const; - /** * @brief Use this method to send information about a venue. On success, the sent Message is returned. * @param chatId Unique identifier for the target chat. @@ -467,219 +338,84 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendContact(std::int64_t chatId, const std::string& phoneNumber, const std::string& firstName, const std::string& lastName = "", const std::string& vcard = "", bool disableNotification = false, - std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared()) const; + std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared()) const; /** - * @brief Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). - * - * Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot. - * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. + * @brief Use this method to send a native poll. * - * @param chatId Unique identifier for the target chat. - * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data. - */ - void sendChatAction(std::int64_t chatId, const std::string& action) const; - - /** - * @brief Use this method to get a list of profile pictures for a user. - * @param userId Unique identifier of the target user. - * @param offset Optional. Sequential number of the first photo to be returned. By default, all photos are returned. - * @param limit Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. - * @return A UserProfilePhotos object. - */ - UserProfilePhotos::Ptr getUserProfilePhotos(std::int64_t userId, std::int32_t offset = 0, std::int32_t limit = 100) const; - - /** - * @brief Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. - * @param fileId File identifier to get info about - * @return A File object. - */ - File::Ptr getFile(const std::string &fileId) const; - - /** - * @brief Use this method for your bot to leave a group, supergroup or channel. - * @param chatId Unique identifier for the target chat of the target supergroup or channel. - * @return True on success - */ - bool leaveChat(std::int64_t chatId) const; - - /** - * @brief Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success. - * @param chatId Unique identifier for the target chat of the target supergroup or channel. - * @return Chat object. - */ - Chat::Ptr getChat(std::int64_t chatId) const; - - /** - * @brief Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. - * @param chatId Unique identifier for the target chat of the target supergroup or channel. - * @return ChatMember object. - */ - std::vector getChatAdministrators(std::int64_t chatId) const; - - /** - * @brief Use this method to get the number of members in a chat. Returns Int on success. - * @param chatId Unique identifier for the target chat of the target supergroup or channel. - * @return Int. - */ - std::int32_t getChatMembersCount(std::int64_t chatId) const; - - /** - * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success. - * @param chatId Unique identifier for the target chat of the target supergroup or channel. - * @param userId Unique identifier of the target user - * @return ChatMember object. - */ - ChatMember::Ptr getChatMember(std::int64_t chatId, std::int64_t userId) const; - - /** - * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success. - * @param chatId Unique identifier for the target chat of the target supergroup or channel. - * @param stickerSetName Name of the sticker set to be set as the group sticker set. - * @return Returns True on success. - */ - bool setChatStickerSet(std::int64_t chatId, const std::string& stickerSetName) const; - - /** - * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success. - * @param chatId Unique identifier for the target chat of the target supergroup or channel. - * @return Returns True on success. - */ - bool deleteChatStickerSet(std::int64_t chatId) const; - - - /** - * @brief Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. - * @param callbackQueryId Unique identifier for the query to be answered - * @param text Optional Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters - * @param showAlert Optional If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. - * @param url Optional URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @Botfather, specify the URL that opens your game – note that this will only work if the query comes from a callback_game button - * @param cacheTime Optional The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0. - * @return True on success - */ - bool answerCallbackQuery(const std::string & callbackQueryId, const std::string & text="", bool showAlert=false, const std::string &url="", std::int32_t cacheTime=0) const; - - /** - * @brief Use this method to edit text and game messages sent by the bot or via the bot (for inline bots) - * @param text New text of the message - * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel. - * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message - * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message - * @param parseMode Optional Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. - * @param disableWebPagePreview Optional Disables link previews for links in this message - * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. - * @return Message object on success, otherwise nullptr - */ - Message::Ptr editMessageText(const std::string& text, std::int64_t chatId=0, std::int32_t messageId=0, const std::string& inlineMessageId="", - const std::string& parseMode = "", bool disableWebPagePreview = false, GenericReply::Ptr replyMarkup = std::make_shared()) const; - - /** - * @brief Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). - * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel. - * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message - * @param caption Optional New caption of the message - * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message - * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. - * @return Message object on success, otherwise nullptr - */ - Message::Ptr editMessageCaption(std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& caption = "", - const std::string& inlineMessageId = "", GenericReply::Ptr replyMarkup = std::make_shared()) const; - - /** - * @brief Use this method to edit audio, document, photo, or video messages. - * - * - * If a message is a part of a message album, then it can be edited only to a photo or a video. - * Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. - * Use previously uploaded file via its file_id or specify a URL. + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param question Poll question, 1-255 characters + * @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each + * @param isAnonymous Optional. True, if the poll needs to be anonymous, defaults to True + * @param type Optional. Poll type, “quiz” or “regular”, defaults to “regular” + * @param allowsMultipleAnswers Optional. True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False + * @param correctOptionId Optional. 0-based identifier of the correct answer option, required for polls in quiz mode + * @param isClosed Optional. Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. * - * @param media A JSON-serialized object for a new media content of the message. - * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel. - * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message - * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message - * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. - * @return On success, if the edited message was sent by the bot, the edited Message is returned, otherwise nullptr is returned. + * @return On success, the sent @ref Message is returned. */ - Message::Ptr editMessageMedia(InputMedia::Ptr media, std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", - GenericReply::Ptr replyMarkup = std::make_shared()) const; - - /** - * @brief Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). - * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel. - * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message - * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message - * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. - * @return Message object on success, otherwise nullptr - */ - Message::Ptr editMessageReplyMarkup(std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", - GenericReply::Ptr replyMarkup = std::make_shared()) const; + Message::Ptr sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, + bool isAnonymous = true, const std::string& type = "", bool allowsMultipleAnswers = false, + std::int32_t correctOptionId = 0, bool isClosed = false, bool disableNotification = false, + std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared()) const; /** - * @brief Use this method to delete messages sent by bot (or by other users if bot is admin). - * @param chatId Unique identifier for the target chat or username of the target channel. - * @param messageId Unique identifier for the target message. + * @brief Deprecated. Use @ref Api::sendPoll + * @deprecated since Bot API 4.6. This remains unchanged for backward compatibility. */ - void deleteMessage(std::int64_t chatId, std::int32_t messageId) const; + Message::Ptr sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, + bool disableNotification = false, std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared()) const; /** - * @brief Use this method to receive incoming updates using long polling. + * @brief Use this method to send a dice, which will have a random value from 1 to 6. * - * This method will not work if an outgoing webhook is set up. - * In order to avoid getting duplicate updates, recalculate offset after each server response. + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message + * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. * - * @param offset Optional. Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. - * @param limit Optional. Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100. - * @param timeout Optional. Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. - * @param allowed_updates Optional. List the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used. - * @return An Array of Update objects + * @return On success, the sent @ref Message is returned. */ - std::vector getUpdates(std::int32_t offset = 0, std::int32_t limit = 100, std::int32_t timeout = 0, const StringArrayPtr &allowedUpdates = nullptr) const; + Message::Ptr sendDice(std::int64_t chatId, bool disableNotification = false, std::int32_t replyToMessageId = 0, + GenericReply::Ptr replyMarkup = std::make_shared()) const; /** - * @brief Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. + * @brief Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). * - * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. www.example.com/. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. - * You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up. - * We currently do not support self-signed certificates. - * Ports currently supported for Webhooks: 443, 80, 88, 8443. + * Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot. + * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. * - * @param url Optional. HTTPS url to send updates to. Use an empty string to remove webhook integration. + * @param chatId Unique identifier for the target chat. + * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data. */ - void setWebhook(const std::string& url = "", InputFile::Ptr certificate = nullptr, std::int32_t maxConnection = 40, const StringArrayPtr &allowedUpdates = nullptr) const; + void sendChatAction(std::int64_t chatId, const std::string& action) const; /** - * @brief Use this method to remove webhook integration if you decide to switch back to getUpdates. - * - * Requires no parameters. - * - * @return Returns True on success. + * @brief Use this method to get a list of profile pictures for a user. + * @param userId Unique identifier of the target user. + * @param offset Optional. Sequential number of the first photo to be returned. By default, all photos are returned. + * @param limit Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. + * @return A UserProfilePhotos object. */ - bool deleteWebhook() const; + UserProfilePhotos::Ptr getUserProfilePhotos(std::int64_t userId, std::int32_t offset = 0, std::int32_t limit = 100) const; /** - * @brief Use this method to get current webhook status. - * - * Requires no parameters. - * If the bot is using getUpdates, will return an object with the url field empty. - * - * @return On success, returns a WebhookInfo object. + * @brief Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. + * @param fileId File identifier to get info about + * @return A File object. */ - WebhookInfo::Ptr getWebhookInfo() const; + File::Ptr getFile(const std::string& fileId) const; /** - * @brief Use this method to send answers to an inline query. - * No mode that 50 results per query are allowed. - * @param inlineQueryId Unique identifier for the answered query. - * @param results Array of results for the inline query. - * @param cacheTime The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300. - * @param isPersonal Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query. - * @param nextOffset Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes. - * @param switchPmText If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter - * @param switchPmParameter Parameter for the start message sent to the bot when user presses the switch button - * @return True on success + * @brief Downloads file from Telegram and saves it in memory. + * @param filePath Telegram file path. + * @param args Additional api parameters. + * @return File contents in a string. */ - bool answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, - std::int32_t cacheTime = 300, bool isPersonal = false, const std::string& nextOffset = "", const std::string& switchPmText = "", const std::string& switchPmParameter = "") const; + std::string downloadFile(const std::string& filePath, const std::vector& args = std::vector()) const; /** * @brief Use this method to kick a user from a group or a supergroup. @@ -730,11 +466,11 @@ public: /** * @brief Use this method to set a custom title for an administrator in a supergroup promoted by the bot. - * + * * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) * @param userId Unique identifier of the target user * @param customTitle New custom title for the administrator; 0-16 characters, emoji are not allowed - * + * * @return True on success */ bool setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const; @@ -811,85 +547,134 @@ public: bool unpinChatMessage(std::int64_t chatId) const; /** - * @brief Use this method to set the score of the specified user in a game. - * - * Returns an error, if the new score is not greater than the user's current score in the chat and force is False. - * - * @param userId User identifier. - * @param score New score, must be non-negative. - * @param force Optional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters. - * @param disableEditMessage Optional. Pass True, if the game message should not be automatically edited to include the current scoreboard. - * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat - * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message - * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message - * @return On success, if the message was sent by the bot, returns the edited Message, otherwise returns nullptr. + * @brief Use this method for your bot to leave a group, supergroup or channel. + * @param chatId Unique identifier for the target chat of the target supergroup or channel. + * @return True on success */ - Message::Ptr setGameScore(std::int64_t userId, std::int32_t score, bool force = false, bool disableEditMessage = false, - std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "") const; + bool leaveChat(std::int64_t chatId) const; /** - * @brief Use this method to get data for high score tables. - * - * Will return the score of the specified user and several of his neighbors in a game. - * - * @param userId User identifier. - * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat - * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message - * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message - * @return On success, returns an Array of GameHighScore objects. + * @brief Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success. + * @param chatId Unique identifier for the target chat of the target supergroup or channel. + * @return Chat object. */ - std::vector getGameHighScores(std::int64_t userId, std::int32_t score, bool force = false, - bool disableEditMessage = false, std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "") const; + Chat::Ptr getChat(std::int64_t chatId) const; /** - * @brief Downloads file from Telegram and saves it in memory. - * @param filePath Telegram file path. - * @param args Additional api parameters. - * @return File contents in a string. + * @brief Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. + * @param chatId Unique identifier for the target chat of the target supergroup or channel. + * @return ChatMember object. + */ + std::vector getChatAdministrators(std::int64_t chatId) const; + + /** + * @brief Use this method to get the number of members in a chat. Returns Int on success. + * @param chatId Unique identifier for the target chat of the target supergroup or channel. + * @return Int. + */ + std::int32_t getChatMembersCount(std::int64_t chatId) const; + + /** + * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success. + * @param chatId Unique identifier for the target chat of the target supergroup or channel. + * @param userId Unique identifier of the target user + * @return ChatMember object. + */ + ChatMember::Ptr getChatMember(std::int64_t chatId, std::int64_t userId) const; + + /** + * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success. + * @param chatId Unique identifier for the target chat of the target supergroup or channel. + * @param stickerSetName Name of the sticker set to be set as the group sticker set. + * @return Returns True on success. + */ + bool setChatStickerSet(std::int64_t chatId, const std::string& stickerSetName) const; + + /** + * @brief Use this method to get information about a member of a chat. Returns a ChatMember object on success. + * @param chatId Unique identifier for the target chat of the target supergroup or channel. + * @return Returns True on success. + */ + bool deleteChatStickerSet(std::int64_t chatId) const; + + /** + * @brief Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. + * @param callbackQueryId Unique identifier for the query to be answered + * @param text Optional Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters + * @param showAlert Optional If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. + * @param url Optional URL that will be opened by the user's client. If you have created a Game and accepted the conditions via @Botfather, specify the URL that opens your game – note that this will only work if the query comes from a callback_game button + * @param cacheTime Optional The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0. + * @return True on success */ - std::string downloadFile(const std::string& filePath, const std::vector& args = std::vector()) const; + bool answerCallbackQuery(const std::string& callbackQueryId, const std::string& text = "", bool showAlert = false, const std::string& url = "", std::int32_t cacheTime = 0) const; /** - * @brief Use this method to send a native poll. - * - * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) - * @param question Poll question, 1-255 characters - * @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each - * @param isAnonymous Optional. True, if the poll needs to be anonymous, defaults to True - * @param type Optional. Poll type, “quiz” or “regular”, defaults to “regular” - * @param allowsMultipleAnswers Optional. True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False - * @param correctOptionId Optional. 0-based identifier of the correct answer option, required for polls in quiz mode - * @param isClosed Optional. Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. - * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message - * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. - * - * @return On success, the sent @ref Message is returned. + * @brief Use this method to change the list of the bot's commands. + * @param commands A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified. + * @return True on success. */ - Message::Ptr sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, - bool isAnonymous = true, const std::string& type = "", bool allowsMultipleAnswers = false, - std::int32_t correctOptionId = 0, bool isClosed = false, bool disableNotification = false, - std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared()) const; + bool setMyCommands(const std::vector& commands) const; /** - * @brief Deprecated. Use @ref Api::sendPoll - * @deprecated since Bot API 4.6. This remains unchanged for backward compatibility. + * @brief Use this method to get the current list of the bot's commands. + * @return Array of @ref BotCommand on success. */ - Message::Ptr sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, - bool disableNotification = false, std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared()) const; + std::vector getMyCommands() const; /** - * @brief Use this method to send a dice, which will have a random value from 1 to 6. - * - * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) - * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message - * @param replyMarkup Optional. Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. - * - * @return On success, the sent @ref Message is returned. + * @brief Use this method to edit text and game messages sent by the bot or via the bot (for inline bots) + * @param text New text of the message + * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel. + * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message + * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message + * @param parseMode Optional Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. + * @param disableWebPagePreview Optional Disables link previews for links in this message + * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. + * @return Message object on success, otherwise nullptr */ - Message::Ptr sendDice(std::int64_t chatId, bool disableNotification = false, std::int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared()) const; + Message::Ptr editMessageText(const std::string& text, std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", + const std::string& parseMode = "", bool disableWebPagePreview = false, GenericReply::Ptr replyMarkup = std::make_shared()) const; + + /** + * @brief Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). + * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel. + * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message + * @param caption Optional New caption of the message + * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message + * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. + * @return Message object on success, otherwise nullptr + */ + Message::Ptr editMessageCaption(std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& caption = "", + const std::string& inlineMessageId = "", GenericReply::Ptr replyMarkup = std::make_shared()) const; + + /** + * @brief Use this method to edit audio, document, photo, or video messages. + * + * + * If a message is a part of a message album, then it can be edited only to a photo or a video. + * Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. + * Use previously uploaded file via its file_id or specify a URL. + * + * @param media A JSON-serialized object for a new media content of the message. + * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel. + * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message + * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message + * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. + * @return On success, if the edited message was sent by the bot, the edited Message is returned, otherwise nullptr is returned. + */ + Message::Ptr editMessageMedia(InputMedia::Ptr media, std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", + GenericReply::Ptr replyMarkup = std::make_shared()) const; + + /** + * @brief Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). + * @param chatId Optional Required if inline_message_id is not specified. Unique identifier for the target chat of the target channel. + * @param messageId Optional Required if inline_message_id is not specified. Identifier of the sent message + * @param inlineMessageId Optional Required if chat_id and message_id are not specified. Identifier of the inline message + * @param replyMarkup Optional A JSON-serialized object for an inline keyboard. + * @return Message object on success, otherwise nullptr + */ + Message::Ptr editMessageReplyMarkup(std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", + GenericReply::Ptr replyMarkup = std::make_shared()) const; /** * @brief Use this method to stop a poll which was sent by the bot. @@ -902,11 +687,232 @@ public: Poll::Ptr stopPoll(std::int64_t chatId, std::int64_t messageId, InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared()) const; + /** + * @brief Use this method to delete messages sent by bot (or by other users if bot is admin). + * @param chatId Unique identifier for the target chat or username of the target channel. + * @param messageId Unique identifier for the target message. + */ + void deleteMessage(std::int64_t chatId, std::int32_t messageId) const; + + /** + * @brief Use this method to send .webp stickers. + * @param chatId Unique identifier for the target chat. + * @param sticker Sticker to send. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message. + * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. + * @param disableNotification Optional. Sends the message silenty. + * @return On success, the sent message is returned. + */ + Message::Ptr sendSticker(std::int64_t chatId, boost::variant sticker, std::int32_t replyToMessageId = 0, + GenericReply::Ptr replyMarkup = std::make_shared(), bool disableNotification = false) const; - bool setMyCommands(const std::vector& commands) const; + /** + * @brief Use this method to get a sticker set. + * @param chatId Name of the sticker set. + * @return On success, a StickerSet object is returned. + */ + StickerSet::Ptr getStickerSet(const std::string& name) const; - std::vector getMyCommands() const; + /** + * @brief Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). + * @param userId User identifier of sticker file owner. + * @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. + * @return Returns the uploaded File on success. + */ + File::Ptr uploadStickerFile(std::int64_t userId, InputFile::Ptr pngSticker) const; + /** + * @brief Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields pngSticker or tgsSticker. + * + * @param userId User identifier of created sticker set owner + * @param name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_”. is case insensitive. 1-64 characters. + * @param title Sticker set title, 1-64 characters + * @param emojis One or more emoji corresponding to the sticker + * @param pngSticker Optional. PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. + * @param tgsSticker Optional. TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements + * @param containsMasks Optional. Pass True, if a set of mask stickers should be created + * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces + * + * @return Returns True on success. + */ + bool createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, + const std::string& emojis, boost::variant pngSticker = "", boost::variant tgsSticker = "", + bool containsMasks = false, MaskPosition::Ptr maskPosition = nullptr) const; + + /** + * @brief Deprecated. Use @ref Api::createNewStickerSet + * @deprecated since Bot API 4.7. This remains unchanged for backward compatibility. + */ + bool createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, + boost::variant pngSticker, const std::string& emojis, bool containsMasks = false, MaskPosition::Ptr maskPosition = nullptr) const; + + /** + * @brief Use this method to add a new sticker to a set created by the bot. You must use exactly one of the fields png_sticker or tgs_sticker. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. + * + * @param userId User identifier of sticker set owner + * @param name Sticker set name + * @param emojis One or more emoji corresponding to the sticker + * @param pngSticker Optional. PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. + * @param tgsSticker Optional. TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements + * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces + * + * @return Returns True on success. + */ + bool addStickerToSet(std::int64_t userId, const std::string& name, const std::string& emojis, + boost::variant pngSticker = "", boost::variant tgsSticker = "", MaskPosition::Ptr maskPosition = nullptr) const; + + /** + * @brief Deprecated. Use @ref Api::addStickerToSet + * @deprecated since Bot API 4.7. This remains unchanged for backward compatibility. + */ + bool addStickerToSet(std::int64_t userId, const std::string& name, boost::variant pngSticker, + const std::string& emojis, MaskPosition::Ptr maskPosition = nullptr) const; + + /** + * @brief Use this method to move a sticker in a set created by the bot to a specific position. + * @param stickers File identifier of the sticker. + * @param position New sticker position in the set, zero-based. + * @return Returns True on success. + */ + bool setStickerPositionInSet(const std::string& sticker, std::uint32_t position) const; + + /** + * @brief Use this method to delete a sticker from a set created by the bot. + * @param stickers File identifier of the sticker. + * @return Returns True on success. + */ + bool deleteStickerFromSet(const std::string& sticker) const; + + /** + * @brief Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. + * + * @param name Sticker set name + * @param userId User identifier of the sticker set owner + * @param thumb Optional. A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/animated_stickers#technical-requirements for animated sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. Animated sticker set thumbnail can't be uploaded via HTTP URL. + * + * @return Returns True on success. + */ + bool setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant thumb = "") const; + + /** + * @brief Use this method to send answers to an inline query. + * No mode that 50 results per query are allowed. + * @param inlineQueryId Unique identifier for the answered query. + * @param results Array of results for the inline query. + * @param cacheTime The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300. + * @param isPersonal Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query. + * @param nextOffset Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes. + * @param switchPmText If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter + * @param switchPmParameter Parameter for the start message sent to the bot when user presses the switch button + * @return True on success + */ + bool answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, + std::int32_t cacheTime = 300, bool isPersonal = false, const std::string& nextOffset = "", const std::string& switchPmText = "", const std::string& switchPmParameter = "") const; + + /** + * @brief Use this method to send invoices. + * @param chatId Unique identifier for the target private chat. + * @param title Product name, 1-32 characters. + * @param description Product description, 1-255 characters. + * @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. + * @param providerToken Payments provider token, obtained via Botfather. + * @param startParameter Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter. + * @param currency Three-letter ISO 4217 currency code. + * @param prices Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + * @param providerData Optional. JSON-encoded data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. + * @param photoUrl Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for. + * @param photoSize Optional. Photo size + * @param photoWidth Optional. Photo width + * @param photoHeight Optional. Photo height + * @param needName Optional. Pass True, if you require the user's full name to complete the order. + * @param needPhoneNumber Optional. Pass True, if you require the user's phone number to complete the order. + * @param needEmail Optional. Pass True, if you require the user's email address to complete the order. + * @param needShippingAddress Optional. Pass True, if you require the user's shipping address to complete the order. + * @param sendPhoneNumberToProvider Optional. Pass True, if user's phone number should be sent to provider. + * @param sendEmailToProvider Optional. Pass True, if user's email address should be sent to provider + * @param isFlexible Optional. Pass True, if the final price depends on the shipping method. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message. + * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @return On success, the sent Message is returned. + */ + Message::Ptr sendInvoice(std::int64_t chatId, const std::string& title, const std::string& description, const std::string& payload, + const std::string& providerToken, const std::string& startParameter, const std::string& currency, const std::vector& prices, + const std::string& providerData = "", const std::string& photoUrl = "", std::int32_t photoSize = 0, + std::int32_t photoWidth = 0, std::int32_t photoHeight = 0, bool needName = false, + bool needPhoneNumber = false, bool needEmail = false, bool needShippingAddress = false, + bool sendPhoneNumberToProvider = false, bool sendEmailToProvider = false, bool isFlexible = false, + std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared(), bool disableNotification = false) const; + + /** + * @brief Use this method to reply to shipping queries. + * + * If you sent an invoice requesting a shipping address and the parameter isFlexible was specified, the Bot API will send an Update with a shipping_query field to the bot. + * + * @param shippingQueryId Unique identifier for the query to be answered. + * @param ok Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible) + * @param shippingOptions Optional. Required if ok is True. A JSON-serialized array of available shipping options. + * @param errorMessage Optional. Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user. + * @return On success, True is returned. + */ + bool answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector& shippingOptions = std::vector(), const std::string& errorMessage = "") const; + + /** + * @brief Use this method to respond to such pre-checkout queries. + * + * Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field preCheckoutQuery. + * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. + * + * @param preCheckoutQueryId Unique identifier for the query to be answered + * @param ok Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems. + * @param errorMessage Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user. + * @return On success, True is returned. + */ + bool answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage = "") const; + + /** + * @brief Use this method to send a game. + * @param chatId Unique identifier for the target chat. + * @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message. + * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game. + * @param disableNotification Optional. Sends the message silenty. + * @return On success, the sent message is returned. + */ + Message::Ptr sendGame(std::int64_t chatId, const std::string& gameShortName, std::int32_t replyToMessageId = 0, + InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared(), bool disableNotification = false) const; + + /** + * @brief Use this method to set the score of the specified user in a game. + * + * Returns an error, if the new score is not greater than the user's current score in the chat and force is False. + * + * @param userId User identifier. + * @param score New score, must be non-negative. + * @param force Optional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters. + * @param disableEditMessage Optional. Pass True, if the game message should not be automatically edited to include the current scoreboard. + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * @return On success, if the message was sent by the bot, returns the edited Message, otherwise returns nullptr. + */ + Message::Ptr setGameScore(std::int64_t userId, std::int32_t score, bool force = false, bool disableEditMessage = false, + std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "") const; + + /** + * @brief Use this method to get data for high score tables. + * + * Will return the score of the specified user and several of his neighbors in a game. + * + * @param userId User identifier. + * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat + * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message + * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message + * @return On success, returns an Array of GameHighScore objects. + */ + std::vector getGameHighScores(std::int64_t userId, std::int32_t score, bool force = false, + bool disableEditMessage = false, std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "") const; + private: boost::property_tree::ptree sendRequest(const std::string& method, const std::vector& args = std::vector()) const; @@ -915,7 +921,6 @@ private: const TgTypeParser _tgTypeParser; const std::string _url; }; - } #endif //TGBOT_CPP_API_H diff --git a/src/Api.cpp b/src/Api.cpp index 38ad8e3..def9243 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -19,6 +19,67 @@ Api::Api(string token, const HttpClient& httpClient, const std::string& url) : _token(std::move(token)), _httpClient(httpClient), _tgTypeParser(), _url(url) { } +vector Api::getUpdates(std::int32_t offset, std::int32_t limit, std::int32_t timeout, const StringArrayPtr& allowedUpdates) const { + vector args; + args.reserve(4); + if (offset) { + args.emplace_back("offset", offset); + } + limit = max(1, min(100, limit)); + args.emplace_back("limit", limit); + if (timeout) { + args.emplace_back("timeout", timeout); + } + if (allowedUpdates != nullptr) { + string allowedUpdatesJson = _tgTypeParser.parseArray( + [] (const string& s)->string { + return s; + }, *allowedUpdates); + args.emplace_back("allowed_updates", allowedUpdatesJson); + } + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); +} + +void Api::setWebhook(const string& url, const InputFile::Ptr certificate, std::int32_t maxConnection, const StringArrayPtr& allowedUpdates) const { + vector args; + args.reserve(4); + if (!url.empty()) { + args.emplace_back("url", url); + } + if (certificate != nullptr) { + args.emplace_back("certificate", certificate->data, true, certificate->mimeType, certificate->fileName); + } + if (maxConnection != 40) { + args.emplace_back("max_connections", maxConnection); + } + if (allowedUpdates != nullptr) { + auto allowedUpdatesJson = _tgTypeParser.parseArray( + [] (const string& s)->string { + return s; + }, *allowedUpdates); + args.emplace_back("allowed_updates", allowedUpdatesJson); + } + + sendRequest("setWebhook", args); +} + +bool Api::deleteWebhook() const { + return sendRequest("deleteWebhook").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.parseJsonAndGetWebhookInfo(p); + } else { + return nullptr; + } +} + User::Ptr Api::getMe() const { return _tgTypeParser.parseJsonAndGetUser(sendRequest("getMe")); } @@ -37,7 +98,7 @@ Message::Ptr Api::sendMessage(boost::variant c if (disableWebPagePreview) { args.emplace_back("disable_web_page_preview", disableWebPagePreview); } - if (disableNotification){ + if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } if (replyToMessageId) { @@ -51,8 +112,8 @@ Message::Ptr Api::sendMessage(boost::variant c } Message::Ptr Api::sendMessage(const std::string& chatId, const std::string& text, bool disableWebPagePreview, - std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& parseMode, - bool disableNotification) const { + std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& parseMode, + bool disableNotification) const { return sendMessage(chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup); } @@ -70,7 +131,7 @@ Message::Ptr Api::forwardMessage(std::int64_t chatId, std::int64_t fromChatId, s args.emplace_back("chat_id", chatId); args.emplace_back("from_chat_id", fromChatId); args.emplace_back("message_id", messageId); - if (disableNotification){ + if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args)); @@ -98,13 +159,13 @@ Message::Ptr Api::sendPhoto(std::int64_t chatId, boost::variant audio, const string &caption, std::int32_t duration, const string& performer, const string& title, boost::variant thumb, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendAudio(std::int64_t chatId, boost::variant audio, const string& caption, std::int32_t duration, const string& performer, const string& title, boost::variant thumb, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; args.reserve(11); args.emplace_back("chat_id", chatId); @@ -120,10 +181,10 @@ Message::Ptr Api::sendAudio(std::int64_t chatId, boost::variant document, boost::variant thumb, const string &caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendDocument(std::int64_t chatId, boost::variant document, boost::variant thumb, const string& caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; args.reserve(8); args.emplace_back("chat_id", chatId); @@ -181,64 +242,45 @@ Message::Ptr Api::sendDocument(std::int64_t chatId, boost::variant& prices, - const std::string& providerData, const std::string& photoUrl, std::int32_t photoSize, - std::int32_t photoWidth, std::int32_t photoHeight, bool needName, - bool needPhoneNumber, bool needEmail, bool needShippingAddress, - bool sendPhoneNumberToProvider, bool sendEmailToProvider, bool isFlexible, - std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVideo(std::int64_t chatId, boost::variant video, bool supportsStreaming, std::int32_t duration, std::int32_t width, std::int32_t height, boost::variant thumb, const string& caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; - args.reserve(23); + args.reserve(12); args.emplace_back("chat_id", chatId); - args.emplace_back("title", title); - args.emplace_back("description", description); - args.emplace_back("payload", payload); - args.emplace_back("provider_token", providerToken); - args.emplace_back("start_parameter", startParameter); - args.emplace_back("currency", currency); - args.emplace_back("prices", _tgTypeParser.parseArray(&TgTypeParser::parseLabeledPrice, prices)); - if (!providerData.empty()) { - args.emplace_back("provider_data", providerData); - } - if (!photoUrl.empty()) { - args.emplace_back("photo_url", photoUrl); - } - if (photoSize) { - args.emplace_back("photo_size", photoSize); - } - if (photoWidth) { - args.emplace_back("photo_width", photoWidth); - } - if (photoHeight) { - args.emplace_back("photo_height", photoHeight); - } - if (needName) { - args.emplace_back("need_name", needName); + if (video.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(video); + args.emplace_back("video", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("video", boost::get(video)); } - if (needPhoneNumber) { - args.emplace_back("need_phone_number", needPhoneNumber); + if (supportsStreaming) { + args.emplace_back("supports_streaming", supportsStreaming); } - if (needEmail) { - args.emplace_back("need_email", needEmail); + if (duration) { + args.emplace_back("duration", duration); } - if (needShippingAddress) { - args.emplace_back("need_shipping_address", needShippingAddress); + if (width) { + args.emplace_back("width", width); } - if (sendPhoneNumberToProvider) { - args.emplace_back("send_phone_number_to_provider", sendPhoneNumberToProvider); + if (height) { + args.emplace_back("height", height); } - if (sendEmailToProvider) { - args.emplace_back("send_email_to_provider", sendEmailToProvider); + if (thumb.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(thumb); + args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + auto thumbStr = boost::get(thumb); + if (!thumbStr.empty()) { + args.emplace_back("thumb", thumbStr); + } } - if (isFlexible) { - args.emplace_back("is_flexible", isFlexible); + if (!caption.empty()) { + args.emplace_back("caption", caption); } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); @@ -246,47 +288,45 @@ Message::Ptr Api::sendInvoice(std::int64_t chatId, const std::string& title, con if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification){ + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendInvoice", args)); + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector& shippingOptions, const std::string& errorMessage) const { +Message::Ptr Api::sendAnimation(std::int64_t chatId, boost::variant animation, std::int32_t duration, std::int32_t width, std::int32_t height, boost::variant thumb, const string& caption, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; - args.reserve(4); - args.emplace_back("shipping_query_id", shippingQueryId); - args.emplace_back("ok", ok); - if (!shippingOptions.empty()) { - args.emplace_back("shipping_options", _tgTypeParser.parseArray(&TgTypeParser::parseShippingOption, shippingOptions)); + args.reserve(11); + args.emplace_back("chat_id", chatId); + if (animation.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(animation); + args.emplace_back("animation", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("animation", boost::get(animation)); } - if (!errorMessage.empty()) { - args.emplace_back("error_message", errorMessage); + if (duration) { + args.emplace_back("duration", duration); } - return sendRequest("answerShippingQuery", args).get("", false); -} - -bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage) const { - vector args; - args.reserve(3); - args.emplace_back("pre_checkout_query_id", preCheckoutQueryId); - args.emplace_back("ok", ok); - if (!errorMessage.empty()) { - args.emplace_back("error_message", errorMessage); + if (width) { + args.emplace_back("width", width); } - return sendRequest("answerPreCheckoutQuery", args).get("", false); -} - - -Message::Ptr Api::sendSticker(std::int64_t chatId, boost::variant sticker, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { - vector args; - args.reserve(5); - args.emplace_back("chat_id", chatId); - if (sticker.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(sticker); - args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName); + if (height) { + args.emplace_back("height", height); + } + if (thumb.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(thumb); + args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); } else /* std::string */ { - args.emplace_back("sticker", boost::get(sticker)); + auto thumbStr = boost::get(thumb); + if (!thumbStr.empty()) { + args.emplace_back("thumb", thumbStr); + } + } + if (!caption.empty()) { + args.emplace_back("caption", caption); } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); @@ -294,223 +334,44 @@ Message::Ptr Api::sendSticker(std::int64_t chatId, boost::variant args; - args.reserve(1); - args.emplace_back("name", name); - return _tgTypeParser.parseJsonAndGetStickerSet(sendRequest("getStickerSet", args)); -} - -File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSticker) const { - vector args; - args.reserve(2); - args.emplace_back("user_id", userId); - args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName); - return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); } -bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, - const std::string& emojis, boost::variant pngSticker, boost::variant tgsSticker, - bool containsMasks, MaskPosition::Ptr maskPosition) const { +Message::Ptr Api::sendVoice(std::int64_t chatId, boost::variant voice, const string& caption, int duration, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; args.reserve(8); - - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("title", title); - args.emplace_back("emojis", emojis); - if (pngSticker.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(pngSticker); - args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); + args.emplace_back("chat_id", chatId); + if (voice.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(voice); + args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); } else /* std::string */ { - args.emplace_back("png_sticker", boost::get(pngSticker)); + args.emplace_back("voice", boost::get(voice)); } - if (tgsSticker.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(tgsSticker); - args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("tgs_sticker", boost::get(tgsSticker)); + if (!caption.empty()) { + args.emplace_back("caption", caption); } - if (containsMasks) { - args.emplace_back("contains_mask", containsMasks); + if (duration) { + args.emplace_back("duration", duration); } - if (maskPosition != nullptr) { - args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); + if (replyToMessageId) { + args.emplace_back("reply_to_message_id", replyToMessageId); } - - return sendRequest("createNewStickerSet", args).get("", false); -} - -bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, - boost::variant pngSticker, const std::string& emojis, bool containsMasks, - MaskPosition::Ptr maskPosition) const { - - return createNewStickerSet(userId, name, title, emojis, pngSticker, "", containsMasks, maskPosition); -} - -bool Api::addStickerToSet(std::int64_t userId, const std::string& name, const std::string& emojis, - boost::variant pngSticker, boost::variant tgsSticker, MaskPosition::Ptr maskPosition) const { - vector args; - args.reserve(6); - - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("emojis", emojis); - if (pngSticker.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(pngSticker); - args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("png_sticker", boost::get(pngSticker)); - } - if (tgsSticker.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(tgsSticker); - args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("tgs_sticker", boost::get(tgsSticker)); - } - if (maskPosition != nullptr) { - args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); - } - - return sendRequest("addStickerToSet", args).get("", false); -} - -bool Api::addStickerToSet(std::int64_t userId, const std::string& name, boost::variant pngSticker, - const std::string& emojis, MaskPosition::Ptr maskPosition) const { - - return addStickerToSet(userId, name, emojis, pngSticker, "", maskPosition); -} - -bool Api::setStickerPositionInSet(const string& sticker, std::uint32_t position) const { - vector args; - args.reserve(2); - args.emplace_back("sticker", sticker); - args.emplace_back("position", position); - return sendRequest("setStickerPositionInSet", args).get("", false); -} - -bool Api::deleteStickerFromSet(const string& sticker) const { - vector args; - args.reserve(1); - args.emplace_back("sticker", sticker); - return sendRequest("deleteStickerFromSet", args).get("", false); -} - -bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant thumb) const { - vector args; - args.reserve(3); - - args.emplace_back("name", name); - args.emplace_back("user_id", userId); - if (thumb.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("thumb", boost::get(thumb)); - } - - return sendRequest("setStickerSetThumb", args).get("", false); -} - -Message::Ptr Api::sendVideo(std::int64_t chatId, boost::variant video, bool supportsStreaming, std::int32_t duration, std::int32_t width, std::int32_t height, boost::variant thumb, const string &caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { - vector args; - args.reserve(12); - args.emplace_back("chat_id", chatId); - if (video.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(video); - args.emplace_back("video", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("video", boost::get(video)); - } - if (supportsStreaming) { - args.emplace_back("supports_streaming", supportsStreaming); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (width) { - args.emplace_back("width", width); - } - if (height) { - args.emplace_back("height", height); - } - if (thumb.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - auto thumbStr = boost::get(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); - } - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (disableNotification){ - args.emplace_back("disable_notification", disableNotification); - } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); -} - -Message::Ptr Api::sendAnimation(std::int64_t chatId, boost::variant animation, std::int32_t duration, std::int32_t width, std::int32_t height, boost::variant thumb, const string& caption, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { - vector args; - args.reserve(11); - args.emplace_back("chat_id", chatId); - if (animation.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(animation); - args.emplace_back("animation", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("animation", boost::get(animation)); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (width) { - args.emplace_back("width", width); - } - if (height) { - args.emplace_back("height", height); - } - if (thumb.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - auto thumbStr = boost::get(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); - } - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (disableNotification){ - args.emplace_back("disable_notification", disableNotification); - } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args)); } Message::Ptr Api::sendVideoNote(std::int64_t chatId, boost::variant videoNote, std::int64_t replyToMessageId, bool disableNotification, std::int32_t duration, std::int32_t length, boost::variant thumb, const GenericReply::Ptr replyMarkup) const { @@ -561,54 +422,6 @@ vector Api::sendMediaGroup(std::int64_t chatId, const vector(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); } -Message::Ptr Api::sendVoice(std::int64_t chatId, boost::variant voice, const string &caption, int duration, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { - vector args; - args.reserve(8); - args.emplace_back("chat_id", chatId); - if (voice.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(voice); - args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("voice", boost::get(voice)); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (duration){ - args.emplace_back("duration", duration); - } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (disableNotification){ - args.emplace_back("disable_notification", disableNotification); - } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args)); -} - -Message::Ptr Api::sendGame(std::int64_t chatId, const std::string& gameShortName, std::int32_t replyToMessageId, const InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification) const { - vector args; - args.reserve(5); - args.emplace_back("chat_id", chatId); - args.emplace_back("game_short_name", gameShortName); - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - if (disableNotification){ - args.emplace_back("disable_notification", disableNotification); - } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendGame", args)); -} - Message::Ptr Api::sendLocation(std::int64_t chatId, float latitude, float longitude, std::uint32_t livePeriod, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.reserve(7); @@ -624,7 +437,7 @@ Message::Ptr Api::sendLocation(std::int64_t chatId, float latitude, float longit if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification){ + if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendLocation", args)); @@ -668,21 +481,6 @@ Message::Ptr Api::stopMessageLiveLocation(std::int64_t chatId, std::int32_t mess return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); } -bool Api::setChatStickerSet(std::int64_t chatId, const string& stickerSetName) const { - vector args; - args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("sticker_set_name ", stickerSetName); - return sendRequest("setChatStickerSet", args).get("", false); -} - -bool Api::deleteChatStickerSet(std::int64_t chatId) const { - vector args; - args.reserve(1); - args.emplace_back("chat_id", chatId); - return sendRequest("deleteChatStickerSet", args).get("", false); -} - Message::Ptr Api::sendVenue(std::int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, const string& foursquareType, bool disableNotification, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector args; args.reserve(10); @@ -703,7 +501,7 @@ Message::Ptr Api::sendVenue(std::int64_t chatId, float latitude, float longitude if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification){ + if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args)); @@ -727,290 +525,114 @@ Message::Ptr Api::sendContact(std::int64_t chatId, const string& phoneNumber, co if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - if (disableNotification){ + if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendContact", args)); } -void Api::sendChatAction(std::int64_t chatId, const string& action) const { - vector args; - args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("action", action); - sendRequest("sendChatAction", args); -} - -UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, std::int32_t offset, std::int32_t limit) const { - vector args; - args.reserve(3); - args.emplace_back("user_id", userId); - if (offset) { - args.emplace_back("offset", offset); - } - limit = max(1, min(100, limit)); - args.emplace_back("limit", limit); - return _tgTypeParser.parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); -} - -File::Ptr Api::getFile(const string &fileId) const { +Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, + bool isAnonymous, const std::string& type, bool allowsMultipleAnswers, + std::int32_t correctOptionId, bool isClosed, bool disableNotification, + std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { vector args; - args.reserve(1); - args.emplace_back("file_id", fileId); - return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args)); -} + args.reserve(11); -bool Api::leaveChat(std::int64_t chatId) const { - vector args; - args.reserve(1); args.emplace_back("chat_id", chatId); - return sendRequest("leaveChat", args).get("", false); -} - -Chat::Ptr Api::getChat(std::int64_t chatId) const { - vector args; - args.reserve(1); - args.emplace_back("chat_id", chatId); - return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args)); -} - -vector Api::getChatAdministrators(std::int64_t chatId) const { - vector args; - args.reserve(1); - args.emplace_back("chat_id", chatId); - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); -} - -int32_t Api::getChatMembersCount(std::int64_t chatId) const { - vector args; - args.reserve(1); - args.emplace_back("chat_id", chatId); - return sendRequest("getChatMembersCount", args).get("", 0); -} - -bool Api::answerCallbackQuery(const string & callbackQueryId, const string & text, bool showAlert, const string &url, std::int32_t cacheTime) const { - vector args; - args.reserve(5); - args.emplace_back("callback_query_id", callbackQueryId); - if (!text.empty()) { - args.emplace_back("text", text); - } - if (showAlert) { - args.emplace_back("show_alert", showAlert); - } - if (!url.empty()) { - args.emplace_back("url", url); + args.emplace_back("question", question); + args.emplace_back("options", _tgTypeParser.parseArray([] (const std::string& option) -> std::string { + return StringTools::urlEncode(option); + }, options)); + if (!isAnonymous) { + args.emplace_back("is_anonymous", isAnonymous); } - if (cacheTime) { - args.emplace_back("cache_time", cacheTime); + if (!type.empty()) { + args.emplace_back("type", type); } - return sendRequest("answerCallbackQuery", args).get("", false); -} - -Message::Ptr Api::editMessageText(const string& text, std::int64_t chatId, std::int32_t messageId, const string& inlineMessageId, - const string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const { - - vector args; - args.reserve(7); - args.emplace_back("text", text); - if (chatId) { - args.emplace_back("chat_id", chatId); + if (allowsMultipleAnswers) { + args.emplace_back("allows_multiple_answers", allowsMultipleAnswers); } - if (messageId) { - args.emplace_back("message_id", messageId); + if (correctOptionId != 0) { + args.emplace_back("correct_option_id", correctOptionId); } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); + if (isClosed) { + args.emplace_back("is_closed", isClosed); } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); } - if (disableWebPagePreview) { - args.emplace_back("disable_web_page_preview", disableWebPagePreview); + if (replyToMessageId != 0) { + args.emplace_back("reply_to_message_id", replyToMessageId); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - ptree p = sendRequest("editMessageText", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } + + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); } -Message::Ptr Api::editMessageCaption(std::int64_t chatId, std::int32_t messageId, const string& caption, - const string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, + bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { - vector args; - args.reserve(5); - if (chatId) { - args.emplace_back("chat_id", chatId); - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - ptree p = sendRequest("editMessageCaption", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } + return sendPoll(chatId, question, options, true, "", false, 0, false, disableNotification, replyToMessageId, replyMarkup); } -Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messageId, const string& inlineMessageId, - const GenericReply::Ptr replyMarkup) const { - +Message::Ptr Api::sendDice(std::int64_t chatId, bool disableNotification, std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup) const { vector args; args.reserve(4); - if (chatId) { - args.emplace_back("chat_id", chatId); - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - ptree p = sendRequest("editMessageReplyMarkup", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } -} - -Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId, - GenericReply::Ptr replyMarkup) const { - vector args; - args.reserve(5); - args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); - if (chatId) { - args.emplace_back("chat_id", chatId); - } - if (messageId) { - args.emplace_back("message_id", messageId); + args.emplace_back("chat_id", chatId); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); + if (replyToMessageId != 0) { + args.emplace_back("reply_to_message_id", replyToMessageId); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - ptree p = sendRequest("editMessageMedia", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } + + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args)); } -ChatMember::Ptr Api::getChatMember(std::int64_t chatId, std::int64_t userId) const { +void Api::sendChatAction(std::int64_t chatId, const string& action) const { vector args; args.reserve(2); args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - return _tgTypeParser.parseJsonAndGetChatMember(sendRequest("getChatMember", args)); + args.emplace_back("action", action); + sendRequest("sendChatAction", args); } -vector Api::getUpdates(std::int32_t offset, std::int32_t limit, std::int32_t timeout, const StringArrayPtr &allowedUpdates) const { +UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, std::int32_t offset, std::int32_t limit) const { vector args; - args.reserve(4); + args.reserve(3); + args.emplace_back("user_id", userId); if (offset) { args.emplace_back("offset", offset); } limit = max(1, min(100, limit)); args.emplace_back("limit", limit); - if (timeout) { - args.emplace_back("timeout", timeout); - } - if (allowedUpdates != nullptr) { - string allowedUpdatesJson = _tgTypeParser.parseArray( - [](const string &s)->string { - return s; - }, *allowedUpdates); - args.emplace_back("allowed_updates", allowedUpdatesJson); - } - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); + return _tgTypeParser.parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); } -void Api::setWebhook(const string& url, const InputFile::Ptr certificate, std::int32_t maxConnection, const StringArrayPtr &allowedUpdates) const { +File::Ptr Api::getFile(const string& fileId) const { vector args; - args.reserve(4); - if (!url.empty()) { - args.emplace_back("url", url); - } - if (certificate != nullptr) { - args.emplace_back("certificate", certificate->data, true, certificate->mimeType, certificate->fileName); - } - if (maxConnection != 40) { - args.emplace_back("max_connections", maxConnection); - } - if (allowedUpdates != nullptr) { - auto allowedUpdatesJson = _tgTypeParser.parseArray( - [](const string &s)->string { - return s; - }, *allowedUpdates); - args.emplace_back("allowed_updates", allowedUpdatesJson); - } - - sendRequest("setWebhook", args); -} - -bool Api::deleteWebhook() const { - return sendRequest("deleteWebhook").get("", false); + args.reserve(1); + args.emplace_back("file_id", fileId); + return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args)); } -WebhookInfo::Ptr Api::getWebhookInfo() const { - ptree p = sendRequest("getWebhookInfo"); +string Api::downloadFile(const string& filePath, const std::vector& args) const { + string url(_url); + url += "/file/bot"; + url += _token; + url += "/"; + url += filePath; - if (!p.get_child_optional("url")) { - return nullptr; - } - if (p.get("url","") != string("")) { - return _tgTypeParser.parseJsonAndGetWebhookInfo(p); - } - else { - return nullptr; - } -} + string serverResponse = _httpClient.makeRequest(url, args); -bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector& results, - std::int32_t cacheTime, bool isPersonal, const string& nextOffset, const string& switchPmText, const string& switchPmParameter) const { - vector args; - args.reserve(7); - args.emplace_back("inline_query_id", inlineQueryId); - string resultsJson = _tgTypeParser.parseArray(&TgTypeParser::parseInlineQueryResult, results); - args.emplace_back("results", resultsJson); - if (cacheTime) { - args.emplace_back("cache_time", cacheTime); - } - if (isPersonal) { - args.emplace_back("is_personal", isPersonal); - } - if (!nextOffset.empty()) { - args.emplace_back("next_offset", nextOffset); - } - if (!switchPmText.empty()) { - args.emplace_back("switch_pm_text", switchPmText); - } - if (!switchPmParameter.empty()) { - args.emplace_back("switch_pm_parameter", switchPmParameter); - } - return sendRequest("answerInlineQuery", args).get("", false); + return serverResponse; } bool Api::kickChatMember(std::int64_t chatId, std::int64_t userId, std::uint64_t untilDate) const { @@ -1031,6 +653,7 @@ bool Api::unbanChatMember(std::int64_t chatId, std::int64_t userId) const { args.emplace_back("user_id", userId); return sendRequest("unbanChatMember", args).get("", false); } + bool Api::restrictChatMember(std::int64_t chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, std::uint64_t untilDate) const { vector args; @@ -1086,7 +709,7 @@ bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t user return sendRequest("setChatAdministratorCustomTitle", args).get("", false); } -bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const{ +bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const { vector args; args.reserve(2); args.emplace_back("chat_id", chatId); @@ -1150,144 +773,531 @@ bool Api::unpinChatMessage(std::int64_t chatId) const { return sendRequest("unpinChatMessage", args).get("", false); } -Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool force, bool disableEditMessage, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const { +bool Api::leaveChat(std::int64_t chatId) const { vector args; - args.reserve(7); - args.emplace_back("user_id", userId); - args.emplace_back("score", score); - if (force) { - args.emplace_back("force", force); - } - if (disableEditMessage) { - args.emplace_back("disable_edit_message", disableEditMessage); - } - if (chatId){ - args.emplace_back("chat_id", chatId); - } - if (messageId){ - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()){ - args.emplace_back("inline_message_id", inlineMessageId); - } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("setGameScore", args)); -} + args.reserve(1); + args.emplace_back("chat_id", chatId); + return sendRequest("leaveChat", args).get("", false); +} + +Chat::Ptr Api::getChat(std::int64_t chatId) const { + vector args; + args.reserve(1); + args.emplace_back("chat_id", chatId); + return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args)); +} + +vector Api::getChatAdministrators(std::int64_t chatId) const { + vector args; + args.reserve(1); + args.emplace_back("chat_id", chatId); + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); +} + +int32_t Api::getChatMembersCount(std::int64_t chatId) const { + vector args; + args.reserve(1); + args.emplace_back("chat_id", chatId); + return sendRequest("getChatMembersCount", args).get("", 0); +} + +ChatMember::Ptr Api::getChatMember(std::int64_t chatId, std::int64_t userId) const { + vector args; + args.reserve(2); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + return _tgTypeParser.parseJsonAndGetChatMember(sendRequest("getChatMember", args)); +} + +bool Api::setChatStickerSet(std::int64_t chatId, const string& stickerSetName) const { + vector args; + args.reserve(2); + args.emplace_back("chat_id", chatId); + args.emplace_back("sticker_set_name ", stickerSetName); + return sendRequest("setChatStickerSet", args).get("", false); +} + +bool Api::deleteChatStickerSet(std::int64_t chatId) const { + vector args; + args.reserve(1); + args.emplace_back("chat_id", chatId); + return sendRequest("deleteChatStickerSet", args).get("", false); +} + +bool Api::answerCallbackQuery(const string& callbackQueryId, const string& text, bool showAlert, const string& url, std::int32_t cacheTime) const { + vector args; + args.reserve(5); + args.emplace_back("callback_query_id", callbackQueryId); + if (!text.empty()) { + args.emplace_back("text", text); + } + if (showAlert) { + args.emplace_back("show_alert", showAlert); + } + if (!url.empty()) { + args.emplace_back("url", url); + } + if (cacheTime) { + args.emplace_back("cache_time", cacheTime); + } + return sendRequest("answerCallbackQuery", args).get("", false); +} + +bool Api::setMyCommands(const std::vector& commands) const { + vector args; + args.reserve(5); + + string commandsJson = _tgTypeParser.parseArray(&TgTypeParser::parseBotCommand, commands); + args.emplace_back("commands", commandsJson); + + return sendRequest("setMyCommands", args).get("", false); +} + +std::vector Api::getMyCommands() const { + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands")); +} + +Message::Ptr Api::editMessageText(const string& text, std::int64_t chatId, std::int32_t messageId, const string& inlineMessageId, + const string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const { + + vector args; + args.reserve(7); + args.emplace_back("text", text); + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (disableWebPagePreview) { + args.emplace_back("disable_web_page_preview", disableWebPagePreview); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + ptree p = sendRequest("editMessageText", args); + if (p.get_child_optional("message_id")) { + return _tgTypeParser.parseJsonAndGetMessage(p); + } else { + return nullptr; + } +} + +Message::Ptr Api::editMessageCaption(std::int64_t chatId, std::int32_t messageId, const string& caption, + const string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { + vector args; + args.reserve(5); + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + ptree p = sendRequest("editMessageCaption", args); + if (p.get_child_optional("message_id")) { + return _tgTypeParser.parseJsonAndGetMessage(p); + } else { + return nullptr; + } +} + +Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId, + GenericReply::Ptr replyMarkup) const { + + vector args; + args.reserve(5); + args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + ptree p = sendRequest("editMessageMedia", args); + if (p.get_child_optional("message_id")) { + return _tgTypeParser.parseJsonAndGetMessage(p); + } else { + return nullptr; + } +} + +Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messageId, const string& inlineMessageId, + const GenericReply::Ptr replyMarkup) const { + + vector args; + args.reserve(4); + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + ptree p = sendRequest("editMessageReplyMarkup", args); + if (p.get_child_optional("message_id")) { + return _tgTypeParser.parseJsonAndGetMessage(p); + } else { + return nullptr; + } +} + +Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { + vector args; + args.reserve(3); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args)); +} + +void Api::deleteMessage(std::int64_t chatId, std::int32_t messageId) const { + sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) }); +} + +Message::Ptr Api::sendSticker(std::int64_t chatId, boost::variant sticker, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { + vector args; + args.reserve(5); + args.emplace_back("chat_id", chatId); + if (sticker.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(sticker); + args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("sticker", boost::get(sticker)); + } + if (replyToMessageId) { + args.emplace_back("reply_to_message_id", replyToMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendSticker", args)); +} + +StickerSet::Ptr Api::getStickerSet(const string& name) const { + vector args; + args.reserve(1); + args.emplace_back("name", name); + return _tgTypeParser.parseJsonAndGetStickerSet(sendRequest("getStickerSet", args)); +} + +File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSticker) const { + vector args; + args.reserve(2); + args.emplace_back("user_id", userId); + args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName); + return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); +} + +bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, + const std::string& emojis, boost::variant pngSticker, boost::variant tgsSticker, + bool containsMasks, MaskPosition::Ptr maskPosition) const { + vector args; + args.reserve(8); + + args.emplace_back("user_id", userId); + args.emplace_back("name", name); + args.emplace_back("title", title); + args.emplace_back("emojis", emojis); + if (pngSticker.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(pngSticker); + args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("png_sticker", boost::get(pngSticker)); + } + if (tgsSticker.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(tgsSticker); + args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("tgs_sticker", boost::get(tgsSticker)); + } + if (containsMasks) { + args.emplace_back("contains_mask", containsMasks); + } + if (maskPosition != nullptr) { + args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); + } + + return sendRequest("createNewStickerSet", args).get("", false); +} + +bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, + boost::variant pngSticker, const std::string& emojis, bool containsMasks, + MaskPosition::Ptr maskPosition) const { + + return createNewStickerSet(userId, name, title, emojis, pngSticker, "", containsMasks, maskPosition); +} + +bool Api::addStickerToSet(std::int64_t userId, const std::string& name, const std::string& emojis, + boost::variant pngSticker, boost::variant tgsSticker, MaskPosition::Ptr maskPosition) const { + vector args; + args.reserve(6); + + args.emplace_back("user_id", userId); + args.emplace_back("name", name); + args.emplace_back("emojis", emojis); + if (pngSticker.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(pngSticker); + args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("png_sticker", boost::get(pngSticker)); + } + if (tgsSticker.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(tgsSticker); + args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("tgs_sticker", boost::get(tgsSticker)); + } + if (maskPosition != nullptr) { + args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); + } -vector Api::getGameHighScores(std::int64_t userId, std::int32_t score, bool force, bool disableEditMessage, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const { + return sendRequest("addStickerToSet", args).get("", false); +} + +bool Api::addStickerToSet(std::int64_t userId, const std::string& name, boost::variant pngSticker, + const std::string& emojis, MaskPosition::Ptr maskPosition) const { + + return addStickerToSet(userId, name, emojis, pngSticker, "", maskPosition); +} + +bool Api::setStickerPositionInSet(const string& sticker, std::uint32_t position) const { vector args; - args.reserve(7); + args.reserve(2); + args.emplace_back("sticker", sticker); + args.emplace_back("position", position); + return sendRequest("setStickerPositionInSet", args).get("", false); +} + +bool Api::deleteStickerFromSet(const string& sticker) const { + vector args; + args.reserve(1); + args.emplace_back("sticker", sticker); + return sendRequest("deleteStickerFromSet", args).get("", false); +} + +bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant thumb) const { + vector args; + args.reserve(3); + + args.emplace_back("name", name); args.emplace_back("user_id", userId); - args.emplace_back("score", score); - if (force) { - args.emplace_back("force", force); + if (thumb.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get(thumb); + args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("thumb", boost::get(thumb)); } - if (disableEditMessage) { - args.emplace_back("disable_edit_message", disableEditMessage); + + return sendRequest("setStickerSetThumb", args).get("", false); +} + +bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector& results, + std::int32_t cacheTime, bool isPersonal, const string& nextOffset, const string& switchPmText, const string& switchPmParameter) const { + vector args; + args.reserve(7); + args.emplace_back("inline_query_id", inlineQueryId); + string resultsJson = _tgTypeParser.parseArray(&TgTypeParser::parseInlineQueryResult, results); + args.emplace_back("results", resultsJson); + if (cacheTime) { + args.emplace_back("cache_time", cacheTime); } - if (chatId) { - args.emplace_back("chat_id", chatId); + if (isPersonal) { + args.emplace_back("is_personal", isPersonal); } - if (messageId) { - args.emplace_back("message_id", messageId); + if (!nextOffset.empty()) { + args.emplace_back("next_offset", nextOffset); } - if (!inlineMessageId.empty()){ - args.emplace_back("inline_message_id", inlineMessageId); + if (!switchPmText.empty()) { + args.emplace_back("switch_pm_text", switchPmText); } - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args)); -} - -void Api::deleteMessage(std::int64_t chatId, std::int32_t messageId) const { - sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) }); + if (!switchPmParameter.empty()) { + args.emplace_back("switch_pm_parameter", switchPmParameter); + } + return sendRequest("answerInlineQuery", args).get("", false); } -Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, - bool isAnonymous, const std::string& type, bool allowsMultipleAnswers, - std::int32_t correctOptionId, bool isClosed, bool disableNotification, - std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendInvoice(std::int64_t chatId, const std::string& title, const std::string& description, const std::string& payload, + const std::string& providerToken, const std::string& startParameter, const std::string& currency, const std::vector& prices, + const std::string& providerData, const std::string& photoUrl, std::int32_t photoSize, + std::int32_t photoWidth, std::int32_t photoHeight, bool needName, + bool needPhoneNumber, bool needEmail, bool needShippingAddress, + bool sendPhoneNumberToProvider, bool sendEmailToProvider, bool isFlexible, + std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; - args.reserve(11); - + args.reserve(23); args.emplace_back("chat_id", chatId); - args.emplace_back("question", question); - args.emplace_back("options", _tgTypeParser.parseArray([] (const std::string& option) -> std::string { - return StringTools::urlEncode(option); - }, options)); - if (!isAnonymous) { - args.emplace_back("is_anonymous", isAnonymous); + args.emplace_back("title", title); + args.emplace_back("description", description); + args.emplace_back("payload", payload); + args.emplace_back("provider_token", providerToken); + args.emplace_back("start_parameter", startParameter); + args.emplace_back("currency", currency); + args.emplace_back("prices", _tgTypeParser.parseArray(&TgTypeParser::parseLabeledPrice, prices)); + if (!providerData.empty()) { + args.emplace_back("provider_data", providerData); } - if (!type.empty()) { - args.emplace_back("type", type); + if (!photoUrl.empty()) { + args.emplace_back("photo_url", photoUrl); } - if (allowsMultipleAnswers) { - args.emplace_back("allows_multiple_answers", allowsMultipleAnswers); + if (photoSize) { + args.emplace_back("photo_size", photoSize); } - if (correctOptionId != 0) { - args.emplace_back("correct_option_id", correctOptionId); + if (photoWidth) { + args.emplace_back("photo_width", photoWidth); } - if (isClosed) { - args.emplace_back("is_closed", isClosed); + if (photoHeight) { + args.emplace_back("photo_height", photoHeight); } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); + if (needName) { + args.emplace_back("need_name", needName); } - if (replyToMessageId != 0) { + if (needPhoneNumber) { + args.emplace_back("need_phone_number", needPhoneNumber); + } + if (needEmail) { + args.emplace_back("need_email", needEmail); + } + if (needShippingAddress) { + args.emplace_back("need_shipping_address", needShippingAddress); + } + if (sendPhoneNumberToProvider) { + args.emplace_back("send_phone_number_to_provider", sendPhoneNumberToProvider); + } + if (sendEmailToProvider) { + args.emplace_back("send_email_to_provider", sendEmailToProvider); + } + if (isFlexible) { + args.emplace_back("is_flexible", isFlexible); + } + if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendInvoice", args)); } -Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, - bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { - - return sendPoll(chatId, question, options, true, "", false, 0, false, disableNotification, replyToMessageId, replyMarkup); +bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector& shippingOptions, const std::string& errorMessage) const { + vector args; + args.reserve(4); + args.emplace_back("shipping_query_id", shippingQueryId); + args.emplace_back("ok", ok); + if (!shippingOptions.empty()) { + args.emplace_back("shipping_options", _tgTypeParser.parseArray(&TgTypeParser::parseShippingOption, shippingOptions)); + } + if (!errorMessage.empty()) { + args.emplace_back("error_message", errorMessage); + } + return sendRequest("answerShippingQuery", args).get("", false); } -Message::Ptr Api::sendDice(std::int64_t chatId, bool disableNotification, std::int32_t replyToMessageId, - GenericReply::Ptr replyMarkup) const { +bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage) const { vector args; - args.reserve(4); + args.reserve(3); + args.emplace_back("pre_checkout_query_id", preCheckoutQueryId); + args.emplace_back("ok", ok); + if (!errorMessage.empty()) { + args.emplace_back("error_message", errorMessage); + } + return sendRequest("answerPreCheckoutQuery", args).get("", false); +} +Message::Ptr Api::sendGame(std::int64_t chatId, const std::string& gameShortName, std::int32_t replyToMessageId, const InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification) const { + vector args; + args.reserve(5); args.emplace_back("chat_id", chatId); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (replyToMessageId != 0) { + args.emplace_back("game_short_name", gameShortName); + if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args)); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendGame", args)); } -Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { +Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool force, bool disableEditMessage, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const { vector args; - args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); - if (replyMarkup){ - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + args.reserve(7); + args.emplace_back("user_id", userId); + args.emplace_back("score", score); + if (force) { + args.emplace_back("force", force); } - return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args)); + if (disableEditMessage) { + args.emplace_back("disable_edit_message", disableEditMessage); + } + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("setGameScore", args)); } -bool Api::setMyCommands(const std::vector& commands) const { +vector Api::getGameHighScores(std::int64_t userId, std::int32_t score, bool force, bool disableEditMessage, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const { vector args; - args.reserve(5); - - string commandsJson = _tgTypeParser.parseArray(&TgTypeParser::parseBotCommand, commands); - args.emplace_back("commands", commandsJson); - - return sendRequest("setMyCommands",args).get("",false); -} - -std::vector Api::getMyCommands() const { - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands")); + args.reserve(7); + args.emplace_back("user_id", userId); + args.emplace_back("score", score); + if (force) { + args.emplace_back("force", force); + } + if (disableEditMessage) { + args.emplace_back("disable_edit_message", disableEditMessage); + } + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args)); } ptree Api::sendRequest(const string& method, const vector& args) const { @@ -1313,19 +1323,4 @@ ptree Api::sendRequest(const string& method, const vector& args) con throw TgException("tgbot-cpp library can't parse json response. " + string(e.what())); } } - -string Api::downloadFile(const string& filePath, const std::vector& args) const { - string url(_url); - url += "/file/bot"; - url += _token; - url += "/"; - url += filePath; - - string serverResponse = _httpClient.makeRequest(url, args); - - return serverResponse; -} - - - } -- cgit v1.2.3