From 66cbca3b206567ce62af42cab950696ef6f80adb Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 27 May 2018 02:27:44 +0900 Subject: Bot API 3.0 (Maks Mazurov (fox.cpp)) --- src/Api.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 31e08f3..5e39a9a 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -291,6 +291,50 @@ Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t durat return TgTypeParser::getInstance().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) { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("video_note", videoNote)); + if (disableNotification) { + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + if (duration) { + args.push_back(HttpReqArg("duration", duration)); + } + if (length) { + args.push_back(HttpReqArg("length", length)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); +} + +Message::Ptr Api::sendVideoNote(int64_t chatId, const std::string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("video_note", videoNote)); + if (disableNotification) { + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + if (duration) { + args.push_back(HttpReqArg("duration", duration)); + } + if (length) { + args.push_back(HttpReqArg("length", length)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); +} + Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); -- cgit v1.2.3 From 1deb50e9db6e1b668af8c993b449d59f001c8977 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 27 May 2018 16:35:52 +0900 Subject: Bot API 3.1 update --- src/Api.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 110 insertions(+), 6 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 5e39a9a..568ca71 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -609,7 +609,7 @@ vector Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo if (timeout) { args.push_back(HttpReqArg("timeout", timeout)); } - if (allowedUpdates!=nullptr) { + if (allowedUpdates != nullptr) { string allowedUpdatesJson = TgTypeParser::getInstance().parseArray( [](const std::string &s)->std::string { return s; @@ -625,10 +625,10 @@ void Api::setWebhook(const string& url, const InputFile::Ptr certificate, int32_ args.push_back(HttpReqArg("url", url)); if (certificate != nullptr) args.push_back(HttpReqArg("certificate", certificate->data, true, certificate->mimeType, certificate->fileName)); - if (maxConnection!=40) + if (maxConnection != 40) args.push_back(HttpReqArg("max_connections", maxConnection)); - if (allowedUpdates!=nullptr) + if (allowedUpdates != nullptr) { string allowedUpdatesJson = TgTypeParser::getInstance().parseArray( [](const std::string &s)->std::string { @@ -653,7 +653,7 @@ WebhookInfo::Ptr Api::getWebhookInfo() const if (!p.get_child_optional("url")) return nullptr; - if (p.get("url","")!=string("")) + if (p.get("url","") != string("")) { return TgTypeParser::getInstance().parseJsonAndGetWebhookInfo(p); } @@ -664,7 +664,7 @@ WebhookInfo::Ptr Api::getWebhookInfo() const } bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, - int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const { + int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const { vector args; args.push_back(HttpReqArg("inline_query_id", inlineQueryId)); string resultsJson = TgTypeParser::getInstance().parseArray(&TgTypeParser::parseInlineQueryResult, results); @@ -687,10 +687,13 @@ bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector< return sendRequest("answerInlineQuery", args).get("", false); } -bool Api::kickChatMember(int64_t chatId, int32_t userId) const { +bool Api::kickChatMember(int64_t chatId, int32_t userId, uint64_t untilDate) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("user_id", userId)); + if (untilDate) { + args.push_back(HttpReqArg("until_date", untilDate)); + } return sendRequest("kickChatMember", args).get("", false); } @@ -701,6 +704,107 @@ bool Api::unbanChatMember(int64_t chatId, int32_t userId) const { return sendRequest("unbanChatMember", args).get("", false); } +bool Api::restrictChatMember(int64_t chatId, int32_t userId, uint64_t untilDate, bool canSendMessages, + bool canSendMediaMessages, bool canSendOtherMessages, bool canAddWebPagePreviews) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + if (untilDate) { + args.push_back(HttpReqArg("until_date", untilDate)); + } + if (canSendMessages) { + args.push_back(HttpReqArg("can_send_messages", canSendMessages)); + } + if (canSendMediaMessages) { + args.push_back(HttpReqArg("can_send_media_messages", canSendMediaMessages)); + } + if (canSendOtherMessages) { + args.push_back(HttpReqArg("can_send_other_messages", canSendOtherMessages)); + } + if (canAddWebPagePreviews) { + args.push_back(HttpReqArg("can_add_web_page_previews", canAddWebPagePreviews)); + } + return sendRequest("restrictChatMember", args).get("", false); +} + +bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo, bool canPostMessages, + bool canEditMessages, bool canDeleteMessages, bool canInviteUsers, bool canPinMessages, bool canPromoteMembers) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + if (canChangeInfo) { + args.push_back(HttpReqArg("can_change_info", canChangeInfo)); + } + if (canPostMessages) { + args.push_back(HttpReqArg("can_post_messages", canPostMessages)); + } + if (canEditMessages) { + args.push_back(HttpReqArg("can_edit_messages", canEditMessages)); + } + if (canDeleteMessages) { + args.push_back(HttpReqArg("can_delete_messages", canDeleteMessages)); + } + if (canInviteUsers) { + args.push_back(HttpReqArg("can_invite_users", canInviteUsers)); + } + if (canPinMessages) { + args.push_back(HttpReqArg("can_pin_messages", canPinMessages)); + } + if (canPromoteMembers) { + args.push_back(HttpReqArg("can_promote_members", canPromoteMembers)); + } + return sendRequest("promoteChatMember", args).get("", false); +} + +std::string Api::exportChatInviteLink(int64_t chatId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + return sendRequest("exportChatInviteLink", args).get("", ""); +} + +bool Api::setChatPhoto(int64_t chatId, InputFile::Ptr photo) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName)); + return sendRequest("setChatPhoto", args).get("", false); +} + +bool Api::deleteChatPhoto(int64_t chatId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + return sendRequest("deleteChatPhoto", args).get("", false); +} + +bool Api::setChatTitle(int64_t chatId, std::string title) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("title", title)); + return sendRequest("setChatTitle", args).get("", false); +} + +bool Api::setChatDescription(int64_t chatId, std::string description) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("description", description)); + return sendRequest("setChatDescription", args).get("", false); +} + +bool Api::pinChatMessage(int64_t chatId, int32_t messageId, bool disableNotification) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("description", description)); + if (disableNotification) { + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + return sendRequest("pinChatMessage", args).get("", false); +} + +bool Api::unpinChatMessage(int64_t chatId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + return sendRequest("unpinChatMessage", args).get("", false); +} + void Api::deleteMessage(int64_t chatId, int32_t messageId) const { sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) }); } -- cgit v1.2.3 From 8206df62f7f9540a2f13ce31c85f8a1f2054bd56 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 27 May 2018 17:30:39 +0900 Subject: Fix build error (cross-reference) --- 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 568ca71..5b9c8e8 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -792,7 +792,7 @@ bool Api::setChatDescription(int64_t chatId, std::string description) const { bool Api::pinChatMessage(int64_t chatId, int32_t messageId, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); - args.push_back(HttpReqArg("description", description)); + args.push_back(HttpReqArg("message_id", messageId)); if (disableNotification) { args.push_back(HttpReqArg("disable_notification", disableNotification)); } -- cgit v1.2.3 From 94f8360629909e93e82417085db8381791c95c7b Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 27 May 2018 22:12:56 +0900 Subject: Bot API 3.2 update --- src/Api.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 29 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 5b9c8e8..91bab0d 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -109,7 +109,7 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr audio, const std::string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +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, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName)); @@ -137,7 +137,7 @@ Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr audio, const st return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const std::string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +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, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("audio", audioId)); @@ -165,7 +165,7 @@ Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const std::st return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("document", document->data, true, document->mimeType, document->fileName)); @@ -184,7 +184,7 @@ Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, co return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args)); } -Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("document", document)); @@ -235,7 +235,79 @@ Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t r return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args)); } -Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t duration, int32_t width, int32_t height, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +StickerSet::Ptr Api::getStickerSet(const string& name) const { + vector args; + args.push_back(HttpReqArg("name", name)); + return TgTypeParser::getInstance().parseJsonAndGetStickerSet(sendRequest("getStickerSet", args)); +} + +File::Ptr Api::uploadStickerFile(int32_t userId, const InputFile::Ptr pngSticker) const { + vector args; + args.push_back(HttpReqArg("user_id", userId)); + args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName)); + return TgTypeParser::getInstance().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 { + vector args; + args.push_back(HttpReqArg("user_id", userId)); + args.push_back(HttpReqArg("name", name)); + args.push_back(HttpReqArg("title", title)); + args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName)); + args.push_back(HttpReqArg("emojis", emojis)); + args.push_back(HttpReqArg("contains_mask", containsMasks)); + args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition))); + 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.push_back(HttpReqArg("user_id", userId)); + args.push_back(HttpReqArg("name", name)); + args.push_back(HttpReqArg("title", title)); + args.push_back(HttpReqArg("png_sticker", pngSticker)); + args.push_back(HttpReqArg("emojis", emojis)); + args.push_back(HttpReqArg("contains_mask", containsMasks)); + args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition))); + 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 { + vector args; + args.push_back(HttpReqArg("user_id", userId)); + args.push_back(HttpReqArg("name", name)); + args.push_back(HttpReqArg("title", title)); + args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName)); + args.push_back(HttpReqArg("emojis", emojis)); + args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition))); + 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.push_back(HttpReqArg("user_id", userId)); + args.push_back(HttpReqArg("name", name)); + args.push_back(HttpReqArg("title", title)); + args.push_back(HttpReqArg("png_sticker", pngSticker)); + args.push_back(HttpReqArg("emojis", emojis)); + args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition))); + return sendRequest("addStickerToSet", args).get("", false); +} + +bool Api::setStickerPositionInSet(const string& sticker, uint32_t position) const { + vector args; + args.push_back(HttpReqArg("sticker", sticker)); + args.push_back(HttpReqArg("position", position)); + return sendRequest("setStickerPositionInSet", args).get("", false); +} + +bool Api::deleteStickerPositionInSet(const string& sticker) const { + vector args; + args.push_back(HttpReqArg("sticker", sticker)); + return sendRequest("setStickerPositionInSet", args).get("", false); +} + +Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video", video->data, true, video->mimeType, video->fileName)); @@ -263,7 +335,7 @@ Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t duration, int32_t width, int32_t height, const std::string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video", videoId)); @@ -313,7 +385,7 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); } -Message::Ptr Api::sendVideoNote(int64_t chatId, const std::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) { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("video_note", videoNote)); @@ -335,7 +407,7 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const std::string &videoNote, in return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); } -Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("voice", voice->data, true, voice->mimeType, voice->fileName)); @@ -357,7 +429,7 @@ Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const st return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoice", args)); } -Message::Ptr Api::sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendVoice(int64_t chatId, const string& voiceId, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("voice", voiceId)); @@ -396,7 +468,7 @@ Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendLocation", args)); } -Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, std::string title, std::string address, std::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, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("latitude", latitude)); @@ -418,7 +490,7 @@ Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, std return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVenue", args)); } -Message::Ptr Api::sendContact(int64_t chatId, std::string phoneNumber, std::string firstName, std::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, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("phone_number", phoneNumber)); @@ -454,7 +526,7 @@ UserProfilePhotos::Ptr Api::getUserProfilePhotos(int32_t userId, int32_t offset, return TgTypeParser::getInstance().parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); } -File::Ptr Api::getFile(const std::string &fileId) const +File::Ptr Api::getFile(const string &fileId) const { vector args; args.push_back(HttpReqArg("file_id", fileId)); @@ -489,7 +561,7 @@ int32_t Api::getChatMembersCount(int64_t chatId) const return sendRequest("getChatMembersCount", args).get("", 0); } -bool Api::answerCallbackQuery(const std::string & callbackQueryId, const std::string & text, bool showAlert, const std::string &url, int32_t cacheTime) const +bool Api::answerCallbackQuery(const string & callbackQueryId, const string & text, bool showAlert, const string &url, int32_t cacheTime) const { vector args; args.push_back(HttpReqArg("callback_query_id", callbackQueryId)); @@ -508,8 +580,8 @@ bool Api::answerCallbackQuery(const std::string & callbackQueryId, const std::st return sendRequest("answerCallbackQuery", args).get("", false); } -Message::Ptr Api::editMessageText(const std::string& text, int64_t chatId, int32_t messageId, const std::string& inlineMessageId, - const std::string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::editMessageText(const string& text, int64_t chatId, int32_t messageId, const string& inlineMessageId, + const string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const { vector args; args.push_back(HttpReqArg("text", text)); @@ -539,8 +611,8 @@ Message::Ptr Api::editMessageText(const std::string& text, int64_t chatId, int32 } } -Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const std::string& caption, - const std::string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const string& caption, + const string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { vector args; if (chatId) { @@ -567,7 +639,7 @@ Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const st } -Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, const std::string& inlineMessageId, +Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, const string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { vector args; @@ -610,8 +682,8 @@ vector Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo args.push_back(HttpReqArg("timeout", timeout)); } if (allowedUpdates != nullptr) { - string allowedUpdatesJson = TgTypeParser::getInstance().parseArray( - [](const std::string &s)->std::string { + string allowedUpdatesJson = TgTypeParser::getInstance().parseArray( + [](const string &s)->string { return s; }, *allowedUpdates); args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson)); @@ -630,8 +702,8 @@ void Api::setWebhook(const string& url, const InputFile::Ptr certificate, int32_ if (allowedUpdates != nullptr) { - string allowedUpdatesJson = TgTypeParser::getInstance().parseArray( - [](const std::string &s)->std::string { + string allowedUpdatesJson = TgTypeParser::getInstance().parseArray( + [](const string &s)->string { return s; }, *allowedUpdates); args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson)); @@ -663,8 +735,8 @@ WebhookInfo::Ptr Api::getWebhookInfo() const } } -bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, - int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const { +bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector& results, + int32_t cacheTime, bool isPersonal, const string& nextOffset, const string& switchPmText, const string& switchPmParameter) const { vector args; args.push_back(HttpReqArg("inline_query_id", inlineQueryId)); string resultsJson = TgTypeParser::getInstance().parseArray(&TgTypeParser::parseInlineQueryResult, results); @@ -756,13 +828,13 @@ bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo, return sendRequest("promoteChatMember", args).get("", false); } -std::string Api::exportChatInviteLink(int64_t chatId) const { +string Api::exportChatInviteLink(int64_t chatId) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); return sendRequest("exportChatInviteLink", args).get("", ""); } -bool Api::setChatPhoto(int64_t chatId, InputFile::Ptr photo) const { +bool Api::setChatPhoto(int64_t chatId, const InputFile::Ptr photo) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName)); @@ -775,14 +847,14 @@ bool Api::deleteChatPhoto(int64_t chatId) const { return sendRequest("deleteChatPhoto", args).get("", false); } -bool Api::setChatTitle(int64_t chatId, std::string title) const { +bool Api::setChatTitle(int64_t chatId, const string& title) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("title", title)); return sendRequest("setChatTitle", args).get("", false); } -bool Api::setChatDescription(int64_t chatId, std::string description) const { +bool Api::setChatDescription(int64_t chatId, const string& description) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("description", description)); @@ -832,7 +904,7 @@ ptree Api::sendRequest(const string& method, const vector& args) con } } -std::string Api::downloadFile(const std::string& filePath, const std::vector& args) const { +string Api::downloadFile(const string& filePath, const std::vector& args) const { string url = "https://api.telegram.org/file/bot"; url += _token; url += "/"; -- cgit v1.2.3 From b0134ff90ccd4203721fd8d32c1d1bacaea8b47f Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Mon, 28 May 2018 02:27:25 +0900 Subject: Bot API 3.4 update --- src/Api.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 91bab0d..cb33058 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -451,11 +451,14 @@ Message::Ptr Api::sendVoice(int64_t chatId, const string& voiceId, const string return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoice", args)); } -Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { +Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, uint32_t livePeriod, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); args.push_back(HttpReqArg("latitude", latitude)); args.push_back(HttpReqArg("longitude", longitude)); + if (livePeriod) { + args.push_back(HttpReqArg("live_period", livePeriod)); + } if (replyToMessageId) { args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); } @@ -468,6 +471,55 @@ Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendLocation", args)); } +Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { + vector args; + args.push_back(HttpReqArg("latitude", latitude)); + args.push_back(HttpReqArg("longitude", longitude)); + if (chatId) { + args.push_back(HttpReqArg("chat_id", chatId)); + } + if (messageId) { + args.push_back(HttpReqArg("message_id", messageId)); + } + if (inlineMessageId) { + args.push_back(HttpReqArg("inline_message_id", inlineMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup))); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); +} + +Message::Ptr Api::editMessageLiveLocation(int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { + vector args; + if (chatId) { + args.push_back(HttpReqArg("chat_id", chatId)); + } + if (messageId) { + args.push_back(HttpReqArg("message_id", messageId)); + } + if (inlineMessageId) { + args.push_back(HttpReqArg("inline_message_id", inlineMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup))); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); +} + +bool Api::setChatStickerSet(int64_t chatId, const string& stickerSetName) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("sticker_set_name ", stickerSetName)); + return sendRequest("setChatStickerSet", args).get("", false); +} + +bool Api::deleteChatStickerSet(int64_t chatId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + 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 { vector args; args.push_back(HttpReqArg("chat_id", chatId)); -- cgit v1.2.3 From 981737b20b0db4914c667195b6584d14e9473e3d Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Mon, 28 May 2018 03:45:31 +0900 Subject: Bot API 3.5 update --- src/Api.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index cb33058..ca2f969 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -407,6 +407,16 @@ Message::Ptr Api::sendVideoNote(int64_t chatId, const string &videoNote, int64_t return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args)); } +vector Api::sendMediaGroup(int64_t chatId, const vector& media, bool disableNotification, int32_t replyToMessageId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + string mediaJson = TgTypeParser::getInstance().parseArray(&TgTypeParser::parseInputMedia, media); + args.push_back(HttpReqArg("media", mediaJson)); + args.push_back(HttpReqArg("disable_notification", disableNotification)); + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + return TgTypeParser::getInstance().parseJsonAndGetArray(&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, bool disableNotification) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); @@ -490,7 +500,7 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, int64 return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); } -Message::Ptr Api::editMessageLiveLocation(int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { +Message::Ptr Api::stopMessageLiveLocation(int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { vector args; if (chatId) { args.push_back(HttpReqArg("chat_id", chatId)); @@ -599,7 +609,7 @@ Chat::Ptr Api::getChat(int64_t chatId) const return TgTypeParser::getInstance().parseJsonAndGetChat(sendRequest("getChat", args)); } -std::vector Api::getChatAdministrators(int64_t chatId) const +vector Api::getChatAdministrators(int64_t chatId) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); -- cgit v1.2.3