diff options
author | JellyBrick <shlee1503@naver.com> | 2018-07-27 18:39:57 +0900 |
---|---|---|
committer | JellyBrick <shlee1503@naver.com> | 2018-07-27 18:39:57 +0900 |
commit | e6c475bd21df4dfd083d09ff0074758aec340e89 (patch) | |
tree | ff5ddf64c11fbc46f59f6143e486a82acc444358 | |
parent | 9966efd8a5e006f5ba548c34ae3072000a150193 (diff) |
Bot API 4.0 - Part 4
-rw-r--r-- | include/tgbot/Api.h | 25 | ||||
-rw-r--r-- | src/Api.cpp | 79 |
2 files changed, 77 insertions, 27 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index e926732..0966b29 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -108,7 +108,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendPhoto(int64_t chatId, boost::variant<InputFile::Ptr, std::string> photo, const std::string& caption = "", int32_t replyToMessageId = 0, + Message::Ptr sendPhoto(int64_t chatId, const 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; /** @@ -119,20 +119,22 @@ public: * @param duration Duration of sent audio in seconds. * @param performer Performer * @param title Track name + * @param thumb Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_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, 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, + Message::Ptr sendAudio(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> audio, const std::string &caption = "", int32_t duration = 0, + const std::string& performer = "", const std::string& title = "", const boost::variant<InputFile::Ptr, std::string> thumb = "", 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 document Document to send. + * @param thumb Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. * @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. @@ -140,7 +142,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(int64_t chatId, boost::variant<InputFile::Ptr, std::string> document, const std::string &caption = "", int32_t replyToMessageId = 0, + Message::Ptr sendDocument(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> document, const boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string &caption = "", int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -213,7 +215,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendSticker(int64_t chatId, boost::variant<InputFile::Ptr, std::string> sticker, int32_t replyToMessageId = 0, + Message::Ptr sendSticker(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> sticker, int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** @@ -281,6 +283,7 @@ public: * @param duration Optional. Duration of sent video in seconds * @param width Optional. Video width * @param height Optional. Video height + * @param thumb Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. * @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. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. @@ -288,7 +291,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - 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 = "", + Message::Ptr sendVideo(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming = false, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string& caption = "", int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -301,6 +304,7 @@ public: * @param duration Optional. Duration of sent animation in seconds. * @param width Optional. Animation width. * @param height Optional. Animation height. + * @param thumb Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. * @param caption Optional. Animation caption (may also be used when resending animation by file_id), 0-200 characters * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. @@ -308,7 +312,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent Message is returned. */ - Message::Ptr sendAnimation(int64_t chatId, boost::variant<InputFile::Ptr, std::string> animation, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "", + Message::Ptr sendAnimation(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> animation, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const boost::variant<InputFile::Ptr, std::string> thumb, 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 messages. On success, the sent Message is returned. @@ -318,11 +322,12 @@ public: * @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 thumb Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>. * @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, 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; + Message::Ptr sendVideoNote(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> videoNote, int64_t replyToMessageId = 0, bool disableNotification = false, + int32_t duration = 0, int32_t length = 0, const boost::variant<InputFile::Ptr, std::string> thumb = "", GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * @brief Use this method to send a group of photos or videos as an album. @@ -347,7 +352,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVoice(int64_t chatId, boost::variant<InputFile::Ptr, std::string> voice, const std::string& caption = "", int duration = 0, int32_t replyToMessageId = 0, + Message::Ptr sendVoice(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> voice, 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; /** diff --git a/src/Api.cpp b/src/Api.cpp index 14f4ec1..ff0b31b 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -75,7 +75,7 @@ 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, boost::variant<InputFile::Ptr, std::string> photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendPhoto(int64_t chatId, const 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); @@ -103,9 +103,9 @@ Message::Ptr Api::sendPhoto(int64_t chatId, boost::variant<InputFile::Ptr, std:: return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -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 { +Message::Ptr Api::sendAudio(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> audio, const string &caption, int32_t duration, const string& performer, const string& title, const boost::variant<InputFile::Ptr, std::string> thumb, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; - args.reserve(10); + args.reserve(11); args.emplace_back("chat_id", chatId); if (audio.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(audio); @@ -125,6 +125,15 @@ Message::Ptr Api::sendAudio(int64_t chatId, boost::variant<InputFile::Ptr, std:: if (!title.empty()){ args.emplace_back("title", title); } + if (thumb.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(thumb); + args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + auto thumbStr = boost::get<std::string>(thumb); + if (!thumbStr.empty()) { + args.emplace_back("thumb", thumbStr); + } + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -140,9 +149,9 @@ Message::Ptr Api::sendAudio(int64_t chatId, boost::variant<InputFile::Ptr, std:: return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -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 { +Message::Ptr Api::sendDocument(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> document, const boost::variant<InputFile::Ptr, std::string> thumb, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; - args.reserve(7); + args.reserve(8); args.emplace_back("chat_id", chatId); if (document.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(document); @@ -150,6 +159,15 @@ Message::Ptr Api::sendDocument(int64_t chatId, boost::variant<InputFile::Ptr, st } else /* std::string */ { args.emplace_back("document", boost::get<std::string>(document)); } + if (thumb.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(thumb); + args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + auto thumbStr = boost::get<std::string>(thumb); + if (!thumbStr.empty()) { + args.emplace_back("thumb", thumbStr); + } + } if (!caption.empty()) { args.emplace_back("caption", caption); } @@ -258,7 +276,7 @@ bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, return sendRequest("answerPreCheckoutQuery", args).get<bool>("", false); } -Message::Ptr Api::sendSticker(int64_t chatId, boost::variant<InputFile::Ptr, std::string> sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendSticker(int64_t chatId, const 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); @@ -295,7 +313,7 @@ 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, boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const { +bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, const 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); @@ -317,7 +335,7 @@ 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, boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { +bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const 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); @@ -351,9 +369,9 @@ bool Api::deleteStickerPositionInSet(const string& sticker) const { return sendRequest("setStickerPositionInSet", args).get<bool>("", false); } -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 { +Message::Ptr Api::sendVideo(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const boost::variant<InputFile::Ptr, std::string> thumb, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; - args.reserve(11); + args.reserve(12); args.emplace_back("chat_id", chatId); if (video.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(video); @@ -373,6 +391,15 @@ Message::Ptr Api::sendVideo(int64_t chatId, boost::variant<InputFile::Ptr, std:: if (height) { args.emplace_back("height", height); } + if (thumb.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(thumb); + args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + auto thumbStr = boost::get<std::string>(thumb); + if (!thumbStr.empty()) { + args.emplace_back("thumb", thumbStr); + } + } if (!caption.empty()) { args.emplace_back("caption", caption); } @@ -391,9 +418,9 @@ Message::Ptr Api::sendVideo(int64_t chatId, boost::variant<InputFile::Ptr, std:: return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendAnimation(int64_t chatId, boost::variant<InputFile::Ptr, std::string> animation, int32_t duration, int32_t width, int32_t height, const string& caption, int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { +Message::Ptr Api::sendAnimation(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> animation, int32_t duration, int32_t width, int32_t height, const boost::variant<InputFile::Ptr, std::string> thumb, const string& caption, int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector<HttpReqArg> args; - args.reserve(10); + args.reserve(11); args.emplace_back("chat_id", chatId); if (animation.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(animation); @@ -410,6 +437,15 @@ Message::Ptr Api::sendAnimation(int64_t chatId, boost::variant<InputFile::Ptr, s if (height) { args.emplace_back("height", height); } + if (thumb.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(thumb); + args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + auto thumbStr = boost::get<std::string>(thumb); + if (!thumbStr.empty()) { + args.emplace_back("thumb", thumbStr); + } + } if (!caption.empty()) { args.emplace_back("caption", caption); } @@ -428,9 +464,9 @@ 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 boost::variant<InputFile::Ptr, std::string> 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 boost::variant<InputFile::Ptr, std::string> thumb, const GenericReply::Ptr replyMarkup) const { vector<HttpReqArg> args; - args.reserve(7); + args.reserve(8); args.emplace_back("chat_id", chatId); if (videoNote.which() == 0 /* InputFile::Ptr */) { auto file = boost::get<InputFile::Ptr>(videoNote); @@ -447,13 +483,22 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const boost::variant<InputFile:: if (length) { args.emplace_back("length", length); } + if (thumb.which() == 0 /* InputFile::Ptr */) { + auto file = boost::get<InputFile::Ptr>(thumb); + args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + auto thumbStr = boost::get<std::string>(thumb); + if (!thumbStr.empty()) { + args.emplace_back("thumb", thumbStr); + } + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideoNote", args)); } vector<Message::Ptr> Api::sendMediaGroup(int64_t chatId, const vector<InputMedia::Ptr>& media, bool disableNotification, int32_t replyToMessageId) const { @@ -472,7 +517,7 @@ Message::Ptr Api::sendVoice(int64_t chatId, const boost::variant<InputFile::Ptr, args.reserve(8); args.emplace_back("chat_id", chatId); if (voice.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get<InputFile::Ptr>(videoNote); + auto file = boost::get<InputFile::Ptr>(video); args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); } else /* std::string */ { args.emplace_back("voice", boost::get<std::string>(voice)); @@ -798,7 +843,7 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons } } -Message::Ptr editMessageMedia(InputMedia::Ptr media, int64_t chatId, int32_t messageId, const std::string& inlineMessageId, +Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, int64_t chatId, int32_t messageId, const std::string& inlineMessageId, GenericReply::Ptr replyMarkup) const { vector<HttpReqArg> args; |