diff options
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | include/tgbot/Api.h | 150 | ||||
-rw-r--r-- | src/Api.cpp | 276 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 3 |
4 files changed, 68 insertions, 370 deletions
@@ -18,13 +18,8 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp). ## State -- [x] Bot API 3.0 -- [x] Bot API 3.1 -- [x] Bot API 3.2 -- [x] Bot API 3.3 -- [x] Bot API 3.4 -- [x] Bot API 3.5 -- [x] Bot API 3.6 +- [x] Bot API 3.0 ~ 3.6 +- [x] Bot API 4.0 (Implemented all APIs except 'Telegram Passport') ## Sample diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 480949e..b10a87a 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -108,21 +108,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendPhoto(int64_t chatId, InputFile::Ptr photo, const std::string& caption = "", int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; - - /** - * @brief Use this method to send photos. - * @param chatId Unique identifier for the target chat. - * @param photo Photo to send. Id of the photo that is already on the Telegram servers. - * @param caption Optional. Photo caption. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - * @param parseMode Optional. Set it to "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. - * @param disableNotification Optional. Sends the message silenty. - * @return On success, the sent message is returned. - */ - Message::Ptr sendPhoto(int64_t chatId, const std::string& photoId, const std::string& caption = "", int32_t replyToMessageId = 0, + Message::Ptr sendPhoto(int64_t chatId, boost::variant<InputFile::Ptr, std::string> photo, const std::string& caption = "", int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -139,25 +125,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(int64_t chatId, InputFile::Ptr audio, const std::string &caption = "", int32_t duration = 0, - const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), 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. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). - * @param chatId Unique identifier for the target chat. - * @param audio Id of the audio that is already on the Telegram servers. - * @param caption Audio caption, 0-200 characters - * @param duration Duration of sent audio in seconds. - * @param performer Performer - * @param title Track name - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - * @param parseMode Optional. Set it to "Markdown" or "HTML" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. - * @param disableNotification Optional. Sends the message silenty. - * @return On success, the sent message is returned. - */ - Message::Ptr sendAudio(int64_t chatId, const std::string& audioId, const std::string &caption = "", int32_t duration = 0, + Message::Ptr sendAudio(int64_t chatId, boost::variant<InputFile::Ptr, std::string> audio, const std::string &caption = "", int32_t duration = 0, const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; @@ -172,21 +140,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(int64_t chatId, InputFile::Ptr document, const std::string &caption = "", int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; - - /** - * @brief Use this method to send general files. - * @param chatId Unique identifier for the target chat. - * @param documentId of the document that is already on the Telegram servers. - * @param caption Document caption (may also be used when resending documents by file_id), 0-200 characters - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - * @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 sendDocument(int64_t chatId, const std::string& documentId, const std::string &caption = "", int32_t replyToMessageId = 0, + Message::Ptr sendDocument(int64_t chatId, boost::variant<InputFile::Ptr, std::string> document, const std::string &caption = "", int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -259,19 +213,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendSticker(int64_t chatId, InputFile::Ptr sticker, int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; - - /** - * @brief Use this method to send .webp stickers. - * @param chatId Unique identifier for the target chat. - * @param stickerId Id of the sticker that is already on the Telegram servers. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - * @param disableNotification Optional. Sends the message silenty. - * @return On success, the sent message is returned. - */ - Message::Ptr sendSticker(int64_t chatId, const std::string& stickerId, int32_t replyToMessageId = 0, + Message::Ptr sendSticker(int64_t chatId, boost::variant<InputFile::Ptr, std::string> sticker, int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** @@ -301,21 +243,7 @@ public: * @return Returns True on success. */ bool createNewStickerSet(int32_t userId, const std::string& name, const std::string& title, - InputFile::Ptr pngSticker, const std::string& emojis, bool containsMasks = false, MaskPosition::Ptr maskPosition = nullptr) const; - - /** - * @brief Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. - * @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_<bot username>”. <bot_username> is case insensitive. 1-64 characters. - * @param title Sticker set title, 1-64 characters. - * @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. 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. - * @param emojis One or more emoji corresponding to the sticker. - * @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(int32_t userId, const std::string& name, const std::string& title, - const std::string& pngSticker, const std::string& emojis, bool containsMasks = false, MaskPosition::Ptr maskPosition = nullptr) const; + boost::variant<InputFile::Ptr, std::string> 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. @@ -328,20 +256,7 @@ public: * @return Returns True on success. */ bool addStickerToSet(int32_t userId, const std::string& name, const std::string& title, - InputFile::Ptr pngSticker, const std::string& emojis, MaskPosition::Ptr maskPosition = nullptr) const; - - /** - * @brief Use this method to add a new sticker to a set created by the bot. - * @param userId User identifier of created sticker set owner. - * @param name Sticker set name. - * @param title Sticker set title, 1-64 characters. - * @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. 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. - * @param emojis One or more emoji corresponding to the sticker. - * @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces. - * @return Returns True on success. - */ - bool addStickerToSet(int32_t userId, const std::string& name, const std::string& title, - const std::string& pngSticker, const std::string& emojis, MaskPosition::Ptr maskPosition = nullptr) const; + boost::variant<InputFile::Ptr, std::string> 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. @@ -373,28 +288,10 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVideo(int64_t chatId, InputFile::Ptr video, bool supportsStreaming = false, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string& caption = "", + Message::Ptr sendVideo(int64_t chatId, boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming = false, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string& caption = "", int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) 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. - * @param videoId Id of the video that is already on the Telegram servers. - * @param supportsStreaming Optional. Pass True, if the uploaded video is suitable for streaming. - * @param duration Optional. Duration of sent video in seconds - * @param width Optional. Video width - * @param height Optional. Video height - * @param caption Optional. Video caption (may also be used when resending videos by file_id), 0-200 characters - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - * @param 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 sendVideo(int64_t chatId, const std::string& videoId, bool supportsStreaming = false, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string& caption = "", - int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; - - /** * @brief Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). * * Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. @@ -424,22 +321,8 @@ public: * @param replyMarkup Additional interface options. A 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 Message is returned. */ - Message::Ptr sendVideoNote(int64_t chatId, InputFile::Ptr videoNote, int64_t replyToMessageId = 0, bool disableNotification = false, - int32_t duration = 0, int32_t length = 0, GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; - - /** - * @brief Use this method to send video messages. On success, the sent Message is returned. - * @param chatId Unique identifier for the target chat. - * @param videoNote Id of the video note that exists on the Telegram servers. - * @param replyToMessageId If the message is a reply, ID of the original message. - * @param disableNotification Sends the message silently. Users will receive a notification with no sound. - * @param duration Duration of sent video in seconds. - * @param length Video width and height. - * @param replyMarkup Additional interface options. A 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 Message is returned. - */ - Message::Ptr sendVideoNote(int64_t chatId, const std::string& videoNote, int64_t replyToMessageId = 0, bool disableNotification = false, - int32_t duration = 0, int32_t length = 0, GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendVideoNote(int64_t chatId, boost::variant<InputFile::Ptr, std::string> videoNote, int64_t replyToMessageId = 0, bool disableNotification = false, + int32_t duration = 0, int32_t length = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * @brief Use this method to send a group of photos or videos as an album. @@ -468,21 +351,6 @@ public: GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), 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 voiceId Id of the voice that is already on the Telegram servers. - * @param caption Voice message caption, 0-200 characters - * @param duration Duration of send audio in seconds. - * @param replyToMessageId Optional. If the message is a reply, ID of the original message. - * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - * @param 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(int64_t chatId, const std::string& voiceId, const std::string& caption = "", int duration = 0, int32_t replyToMessageId = 0, - GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), 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. diff --git a/src/Api.cpp b/src/Api.cpp index d5a2488..0e82ab1 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -75,34 +75,16 @@ Message::Ptr Api::forwardMessage(int64_t chatId, int64_t fromChatId, int32_t mes return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args)); } -Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendPhoto(int64_t chatId, boost::variant<InputFile::Ptr, std::string> photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; args.reserve(7); args.emplace_back("chat_id", chatId); - args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName); - 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); + if (photo.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(photo); + args.emplace_back("photo", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("photo", boost::get<std::string>(photo)); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args)); -} - -Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { - vector<HttpReqArg> args; - args.reserve(7); - args.emplace_back("chat_id", chatId); - args.emplace_back("photo", photoId); if (!caption.empty()) { args.emplace_back("caption", caption); } @@ -121,43 +103,16 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr audio, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendAudio(int64_t chatId, boost::variant<InputFile::Ptr, std::string> audio, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; args.reserve(10); args.emplace_back("chat_id", chatId); - args.emplace_back("audio", audio->data, true, audio->mimeType, audio->fileName); - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (!performer.empty()){ - args.emplace_back("performer", performer); - } - if (!title.empty()){ - args.emplace_back("title", title); - } - 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); + if (audio.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(audio); + args.emplace_back("audio", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("audio", boost::get<std::string>(audio)); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args)); -} - -Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { - vector<HttpReqArg> args; - args.reserve(10); - args.emplace_back("chat_id", chatId); - args.emplace_back("audio", audioId); if (!caption.empty()) { args.emplace_back("caption", caption); } @@ -185,34 +140,16 @@ Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const string return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendDocument(int64_t chatId, boost::variant<InputFile::Ptr, std::string> document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; args.reserve(7); args.emplace_back("chat_id", chatId); - args.emplace_back("document", document->data, true, document->mimeType, document->fileName); - 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); + if (document.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(document); + args.emplace_back("document", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("document", boost::get<std::string>(document)); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDocument", args)); -} - -Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { - vector<HttpReqArg> args; - args.reserve(7); - args.emplace_back("chat_id", chatId); - args.emplace_back("document", document); if (!caption.empty()) { args.emplace_back("caption", caption); } @@ -321,28 +258,16 @@ bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, return sendRequest("answerPreCheckoutQuery", args).get<bool>("", false); } -Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendSticker(int64_t chatId, boost::variant<InputFile::Ptr, std::string> sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector<HttpReqArg> args; args.reserve(5); args.emplace_back("chat_id", chatId); - args.emplace_back("sticker", sticker->data, true, sticker->mimeType, sticker->fileName); - 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); + if (sticker.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(sticker); + args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("sticker", boost::get<std::string>(sticker)); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendSticker", args)); -} - -Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { - vector<HttpReqArg> args; - args.reserve(5); - args.emplace_back("chat_id", chatId); - args.emplace_back("sticker", stickerId); if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -370,30 +295,18 @@ File::Ptr Api::uploadStickerFile(int32_t userId, const InputFile::Ptr pngSticker return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); } -bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, InputFile::Ptr pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const { +bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const { vector<HttpReqArg> args; args.reserve(7); args.emplace_back("user_id", userId); args.emplace_back("name", name); args.emplace_back("title", title); - args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName); - args.emplace_back("emojis", emojis); - if (containsMasks) { - args.emplace_back("contains_mask", containsMasks); - } - if (maskPosition != nullptr) { - args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); + if (pngSticker.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(pngSticker); + args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("png_sticker", boost::get<std::string>(pngSticker)); } - return sendRequest("createNewStickerSet", args).get<bool>("", false); -} - -bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const { - vector<HttpReqArg> args; - args.reserve(7); - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("title", title); - args.emplace_back("png_sticker", pngSticker); args.emplace_back("emojis", emojis); if (containsMasks) { args.emplace_back("contains_mask", containsMasks); @@ -404,27 +317,18 @@ bool Api::createNewStickerSet(int32_t userId, const string& name, const string& return sendRequest("createNewStickerSet", args).get<bool>("", false); } -bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, InputFile::Ptr pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { +bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { vector<HttpReqArg> args; args.reserve(6); args.emplace_back("user_id", userId); args.emplace_back("name", name); args.emplace_back("title", title); - args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName); - args.emplace_back("emojis", emojis); - if (maskPosition != nullptr) { - args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); + if (pngSticker.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(pngSticker); + args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("png_sticker", boost::get<std::string>(pngSticker)); } - return sendRequest("addStickerToSet", args).get<bool>("", false); -} - -bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { - vector<HttpReqArg> args; - args.reserve(6); - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("title", title); - args.emplace_back("png_sticker", pngSticker); args.emplace_back("emojis", emojis); if (maskPosition != nullptr) { args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); @@ -447,46 +351,16 @@ bool Api::deleteStickerPositionInSet(const string& sticker) const { return sendRequest("setStickerPositionInSet", args).get<bool>("", false); } -Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendVideo(int64_t chatId, boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; args.reserve(11); args.emplace_back("chat_id", chatId); - args.emplace_back("video", video->data, true, video->mimeType, video->fileName); - 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 (!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); + if (video.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(video); + args.emplace_back("video", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("video", boost::get<std::string>(video)); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); -} - -Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { - vector<HttpReqArg> args; - args.reserve(11); - args.emplace_back("chat_id", chatId); - args.emplace_back("video", videoId); if (supportsStreaming) { args.emplace_back("supports_streaming", supportsStreaming); } @@ -522,7 +396,8 @@ Message::Ptr Api::sendAnimation(int64_t chatId, boost::variant<InputFile::Ptr, s args.reserve(10); args.emplace_back("chat_id", chatId); if (animation.which() == 0 /* InputFile::Ptr */) { - args.emplace_back("animation", boost::get<InputFile::Ptr>(animation)); + auto file = boost::get<InputFile::Ptr>(animation); + args.emplace_back("animation", file->data, true, file->mimeType, file->fileName); } else /* std::string */ { args.emplace_back("animation", boost::get<std::string>(animation)); } @@ -553,34 +428,16 @@ Message::Ptr Api::sendAnimation(int64_t chatId, boost::variant<InputFile::Ptr, s return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); } -Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendVideoNote(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) const { vector<HttpReqArg> args; args.reserve(7); args.emplace_back("chat_id", chatId); - args.emplace_back("video_note", videoNote); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (length) { - args.emplace_back("length", length); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); + if (videoNote.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(videoNote); + args.emplace_back("video_note", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("video_note", boost::get<std::string>(videoNote)); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); -} - -Message::Ptr Api::sendVideoNote(int64_t chatId, const string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) const { - vector<HttpReqArg> args; - args.reserve(7); - args.emplace_back("chat_id", chatId); - args.emplace_back("video_note", videoNote); if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } @@ -610,37 +467,16 @@ vector<Message::Ptr> Api::sendMediaGroup(int64_t chatId, const vector<InputMedia return _tgTypeParser.parseJsonAndGetArray<Message>(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); } -Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendVoice(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> voice, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; args.reserve(8); args.emplace_back("chat_id", chatId); - args.emplace_back("voice", voice->data, true, voice->mimeType, voice->fileName); - 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); + if (voice.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(videoNote); + args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("voice", boost::get<std::string>(voice)); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args)); -} - -Message::Ptr Api::sendVoice(int64_t chatId, const string& voiceId, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { - vector<HttpReqArg> args; - args.reserve(8); - args.emplace_back("chat_id", chatId); - args.emplace_back("voice", voiceId); if (!caption.empty()) { args.emplace_back("caption", caption); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 1bbc38e..ad200b3 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -693,11 +693,10 @@ string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const { case InputMedia::TYPE::AUDIO: appendToJson(result, "type", "audio"); break; - } + } appendToJson(result, "media", object->media); appendToJson(result, "caption", object->caption); appendToJson(result, "parse_mode", object->parseMode); - args.emplace_back("thumb", boost::get<std::string>(object->thumb)); if (object->width) { appendToJson(result, "width", object->width); } |