diff options
Diffstat (limited to 'src/Api.cpp')
-rw-r--r-- | src/Api.cpp | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index 9996108..19681f7 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<bool>("", false); } + 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); @@ -981,28 +982,17 @@ bool Api::unbanChatMember(int64_t chatId, int32_t userId) const { args.emplace_back("user_id", userId); return sendRequest("unbanChatMember", args).get<bool>("", 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<HttpReqArg> 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<bool>("", false); } @@ -1036,6 +1026,14 @@ bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo, return sendRequest("promoteChatMember", args).get<bool>("", false); } +bool Api::setChatPermissions(int64_t chatId, ChatPermissions::Ptr permissions) const{ + vector<HttpReqArg> args; + args.reserve(2); + args.emplace_back("chat_id", chatId); + args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); + return sendRequest("setChatPermissions", args).get<bool>("", false); +} + string Api::exportChatInviteLink(int64_t chatId) const { vector<HttpReqArg> args; args.reserve(1); @@ -1142,6 +1140,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<std::string> options, bool disable_notification, int32_t reply_to_message_id,GenericReply::Ptr reply_markup) const { + vector<HttpReqArg> 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<HttpReqArg> 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<HttpReqArg>& args) const { string url = "https://api.telegram.org/bot"; url += _token; |