From 23553bc251ca673137b684082a6f84062f053bd2 Mon Sep 17 00:00:00 2001 From: nitanmarcel Date: Tue, 19 Nov 2019 21:31:44 +0200 Subject: API 4.2 --- src/Api.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 6b41947..ae6ecee 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -276,6 +276,7 @@ bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, return sendRequest("answerPreCheckoutQuery", args).get("", false); } + 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); @@ -1143,6 +1144,43 @@ void Api::deleteMessage(int64_t chatId, int32_t messageId) const { sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) }); } +Message::Ptr Api::sendPoll(int64_t chat_id, std::string question, std::vector options, bool disable_notification, int32_t reply_to_message_id,GenericReply::Ptr reply_markup) const { + vector args; + args.reserve(6); + args.emplace_back("chat_id", chat_id); + args.emplace_back("question", question); + std::string json_array; + json_array = "["; + for(const auto &arr : options){ + json_array += "\"" + arr + "\"" + ","; + } + json_array.pop_back(); + json_array += "]"; + args.emplace_back("options", json_array); + + if (disable_notification){ + args.emplace_back("disable_notification", disable_notification); + } + if (reply_to_message_id!=0){ + args.emplace_back("reply_to_message_id", reply_to_message_id); + } + if (reply_markup){ + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(reply_markup)); + } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); +} + +Poll::Ptr Api::stopPoll(int64_t chatId, int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { + vector args; + args.reserve(3); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (replyMarkup){ + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args)); +} + ptree Api::sendRequest(const string& method, const vector& args) const { string url = "https://api.telegram.org/bot"; url += _token; -- cgit v1.2.3 From 084a6492103eff0d021562694c6869fdcce58261 Mon Sep 17 00:00:00 2001 From: nitanmarcel Date: Wed, 20 Nov 2019 21:04:11 +0200 Subject: API 4.4 --- src/Api.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index ae6ecee..ee8f36f 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -983,28 +983,17 @@ bool Api::unbanChatMember(int64_t chatId, int32_t userId) const { args.emplace_back("user_id", userId); 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 { +bool Api::restrictChatMember(int64_t chatId, int32_t userId, TgBot::ChatPermissions::Ptr permissions, + uint64_t untilDate) const { vector args; - args.reserve(7); + args.reserve(4); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); + args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); if (untilDate) { args.emplace_back("until_date", untilDate); } - if (canSendMessages) { - args.emplace_back("can_send_messages", canSendMessages); - } - if (canSendMediaMessages) { - args.emplace_back("can_send_media_messages", canSendMediaMessages); - } - if (canSendOtherMessages) { - args.emplace_back("can_send_other_messages", canSendOtherMessages); - } - if (canAddWebPagePreviews) { - args.emplace_back("can_add_web_page_previews", canAddWebPagePreviews); - } + return sendRequest("restrictChatMember", args).get("", false); } @@ -1038,6 +1027,14 @@ bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo, return sendRequest("promoteChatMember", args).get("", false); } +bool Api::setChatPermissions(int64_t chatId, ChatPermissions::Ptr permissions) const{ + vector args; + args.reserve(2); + args.emplace_back("chat_id", chatId); + args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); + return sendRequest("setChatPermissions", args).get("", false); +} + string Api::exportChatInviteLink(int64_t chatId) const { vector args; args.reserve(1); -- cgit v1.2.3