From 6c2dc4d2eb84e7ba98f73332ccf95ffa5a7adf3f Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 27 Jul 2018 16:03:48 +0900 Subject: Bot API 4.0 - Part 1 --- src/Api.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 08f5fac..85ba050 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -517,7 +517,43 @@ Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, bool supports return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", 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) { +Message::Ptr Api::sendAnimation(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 { + vector args; + args.reserve(10); + args.emplace_back("chat_id", chatId); + if (animation.which() == 0 /* InputFile::Ptr */) { + args.emplace_back("animation", boost::get(animation)); + } 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 (!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)); +} + +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 { vector args; args.reserve(7); args.emplace_back("chat_id", chatId); @@ -540,7 +576,7 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr 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) { +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 args; args.reserve(7); args.emplace_back("chat_id", chatId); @@ -719,7 +755,7 @@ bool Api::deleteChatStickerSet(int64_t chatId) const { Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector args; - args.reserve(9); + args.reserve(10); args.emplace_back("chat_id", chatId); args.emplace_back("latitude", latitude); args.emplace_back("longitude", longitude); @@ -728,6 +764,9 @@ Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, con if (!foursquareId.empty()) { args.emplace_back("foursquare_id", foursquareId); } + if (!foursquareType.empty()) { + args.emplace_back("foursquare_type", foursquareType); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -740,13 +779,18 @@ Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, con return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args)); } -Message::Ptr Api::sendContact(int64_t chatId, const string& phoneNumber, const string& firstName, const string& lastName, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendContact(int64_t chatId, const string& phoneNumber, const string& firstName, const string& lastName, const string& vcard, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector args; - args.reserve(7); + args.reserve(8); args.emplace_back("chat_id", chatId); args.emplace_back("phone_number", phoneNumber); args.emplace_back("first_name", firstName); - args.emplace_back("last_name", lastName); + if (!lastName.empty()) { + args.emplace_back("last_name", lastName); + } + if (!vcard.empty()) { + args.emplace_back("vcard", vcard); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } -- cgit v1.2.3 From 941c97706cb5b81d5a2e44a827e8f6bf76a2c6bd Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 27 Jul 2018 17:40:44 +0900 Subject: Bot API 4.0 - Part 2 --- src/Api.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 85ba050..bd141d7 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -753,7 +753,7 @@ bool Api::deleteChatStickerSet(int64_t chatId) const { return sendRequest("deleteChatStickerSet", args).get("", false); } -Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, const string& foursquareType, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector args; args.reserve(10); args.emplace_back("chat_id", chatId); @@ -962,6 +962,32 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons } } +Message::Ptr Message::Ptr editMessageMedia(InputMedia::Ptr media, int64_t chatId, 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("editMessageCaption", args); + if (p.get_child_optional("message_id")) { + return _tgTypeParser.parseJsonAndGetMessage(p); + } else { + return nullptr; + } +} + ChatMember::Ptr Api::getChatMember(int64_t chatId, int32_t userId) const { vector args; args.reserve(2); -- cgit v1.2.3 From d4ebf6dc65bc97cab3aa147a8bfe398338c618da Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 27 Jul 2018 17:44:07 +0900 Subject: Fix missing include --- src/Api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index bd141d7..d5a2488 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -962,7 +962,7 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons } } -Message::Ptr Message::Ptr editMessageMedia(InputMedia::Ptr media, int64_t chatId, int32_t messageId, const std::string& inlineMessageId, +Message::Ptr editMessageMedia(InputMedia::Ptr media, int64_t chatId, int32_t messageId, const std::string& inlineMessageId, GenericReply::Ptr replyMarkup) const { vector args; -- cgit v1.2.3 From 85104c6a24a28d5a5eca05de4a5e59dd0059232d Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 27 Jul 2018 18:08:10 +0900 Subject: Bot API 4.0 - Part 3 --- src/Api.cpp | 276 ++++++++++++------------------------------------------------ 1 file changed, 56 insertions(+), 220 deletions(-) (limited to 'src/Api.cpp') 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 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); - 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(photo); + args.emplace_back("photo", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("photo", boost::get(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 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 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 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(audio); + args.emplace_back("audio", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("audio", boost::get(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 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 document, 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); - 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(document); + args.emplace_back("document", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("document", boost::get(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 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("", 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 sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector 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(sticker); + args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("sticker", boost::get(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 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 pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const { vector 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(pngSticker); + args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("png_sticker", boost::get(pngSticker)); } - return sendRequest("createNewStickerSet", args).get("", 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 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("", 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 pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { vector 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(pngSticker); + args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("png_sticker", boost::get(pngSticker)); } - return sendRequest("addStickerToSet", args).get("", false); -} - -bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { - vector 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("", 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 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 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(video); + args.emplace_back("video", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("video", boost::get(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 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(animation)); + 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)); } @@ -553,34 +428,16 @@ 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 { vector 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(videoNote); + args.emplace_back("video_note", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("video_note", boost::get(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 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 Api::sendMediaGroup(int64_t chatId, const vector(&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 voice, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector 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(videoNote); + args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); + } else /* std::string */ { + args.emplace_back("voice", boost::get(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 args; - args.reserve(8); - args.emplace_back("chat_id", chatId); - args.emplace_back("voice", voiceId); if (!caption.empty()) { args.emplace_back("caption", caption); } -- cgit v1.2.3 From 9966efd8a5e006f5ba548c34ae3072000a150193 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 27 Jul 2018 18:14:23 +0900 Subject: Fix build error --- src/Api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 0e82ab1..14f4ec1 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -816,7 +816,7 @@ Message::Ptr editMessageMedia(InputMedia::Ptr media, int64_t chatId, int32_t mes if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - ptree p = sendRequest("editMessageCaption", args); + ptree p = sendRequest("editMessageMedia", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); } else { -- cgit v1.2.3 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 From 6d1a96043c63f346b03df4c54d8200bc320ebe3e Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 27 Jul 2018 18:43:11 +0900 Subject: Fix 'default argument missing' --- src/Api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index ff0b31b..6b41947 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -517,7 +517,7 @@ Message::Ptr Api::sendVoice(int64_t chatId, const boost::variant(video); + 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)); -- cgit v1.2.3