From e6c475bd21df4dfd083d09ff0074758aec340e89 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 27 Jul 2018 18:39:57 +0900 Subject: Bot API 4.0 - Part 4 --- src/Api.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 17 deletions(-) (limited to 'src/Api.cpp') 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 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 photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; args.reserve(7); args.emplace_back("chat_id", chatId); @@ -103,9 +103,9 @@ Message::Ptr Api::sendPhoto(int64_t chatId, boost::variant 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 audio, const string &caption, int32_t duration, const string& performer, const string& title, const boost::variant thumb, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; - args.reserve(10); + args.reserve(11); args.emplace_back("chat_id", chatId); if (audio.which() == 0 /* InputFile::Ptr */) { auto file = boost::get(audio); @@ -125,6 +125,15 @@ Message::Ptr Api::sendAudio(int64_t chatId, boost::variant(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 (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -140,9 +149,9 @@ Message::Ptr Api::sendAudio(int64_t chatId, boost::variant 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 document, const boost::variant thumb, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; - args.reserve(7); + args.reserve(8); args.emplace_back("chat_id", chatId); if (document.which() == 0 /* InputFile::Ptr */) { auto file = boost::get(document); @@ -150,6 +159,15 @@ Message::Ptr Api::sendDocument(int64_t chatId, boost::variant(document)); } + 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); } @@ -258,7 +276,7 @@ bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, return sendRequest("answerPreCheckoutQuery", args).get("", false); } -Message::Ptr Api::sendSticker(int64_t chatId, boost::variant sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendSticker(int64_t chatId, const boost::variant sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector 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 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 pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const { vector 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("", false); } -bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, boost::variant pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { +bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const boost::variant pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { vector 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("", false); } -Message::Ptr Api::sendVideo(int64_t chatId, boost::variant 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 video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const boost::variant thumb, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; - args.reserve(11); + args.reserve(12); args.emplace_back("chat_id", chatId); if (video.which() == 0 /* InputFile::Ptr */) { auto file = boost::get(video); @@ -373,6 +391,15 @@ Message::Ptr Api::sendVideo(int64_t chatId, boost::variant(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); } @@ -391,9 +418,9 @@ Message::Ptr Api::sendVideo(int64_t chatId, boost::variant 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 animation, int32_t duration, int32_t width, int32_t height, const boost::variant thumb, const string& caption, int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; - args.reserve(10); + args.reserve(11); args.emplace_back("chat_id", chatId); if (animation.which() == 0 /* InputFile::Ptr */) { auto file = boost::get(animation); @@ -410,6 +437,15 @@ Message::Ptr Api::sendAnimation(int64_t chatId, boost::variant(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); } @@ -428,9 +464,9 @@ Message::Ptr Api::sendAnimation(int64_t chatId, boost::variant 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 videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const boost::variant thumb, const GenericReply::Ptr replyMarkup) const { vector args; - args.reserve(7); + args.reserve(8); args.emplace_back("chat_id", chatId); if (videoNote.which() == 0 /* InputFile::Ptr */) { auto file = boost::get(videoNote); @@ -447,13 +483,22 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const boost::variant(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 (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 Api::sendMediaGroup(int64_t chatId, const vector& media, bool disableNotification, int32_t replyToMessageId) const { @@ -472,7 +517,7 @@ Message::Ptr Api::sendVoice(int64_t chatId, const boost::variant(videoNote); + auto file = boost::get(video); args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); } else /* std::string */ { args.emplace_back("voice", boost::get(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 args; -- cgit v1.2.3