diff options
author | kukin-konstantin <kukin.konstantin@gmail.com> | 2016-12-30 17:24:35 +0300 |
---|---|---|
committer | kukin-konstantin <kukin.konstantin@gmail.com> | 2016-12-30 17:24:35 +0300 |
commit | 4f3a56bf7fcfae055d5f513ff86cf4e1e75e83b7 (patch) | |
tree | c0765300c365eecf9f87daddf977368f83f1e945 | |
parent | 9863c73094324724733787807c67f72542970b69 (diff) |
add leaveChat method
-rw-r--r-- | include/tgbot/Api.h | 17 | ||||
-rw-r--r-- | src/Api.cpp | 46 |
2 files changed, 52 insertions, 11 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index cabcd2a..4cb71a1 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -326,25 +326,32 @@ public: File::Ptr getFile(int32_t fileId) const; /** + * Use this method for your bot to leave a group, supergroup or channel. + * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) + * @return True on success + */ + bool leaveChat(int64_t chatId) const; + + /** * Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success. * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) * @return Chat object. */ - Chat::Ptr getChat(int32_t chatId) const; + Chat::Ptr getChat(int64_t chatId) const; /** * Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) * @return ChatMember object. */ - std::vector<ChatMember::Ptr> getChatAdministrators(int32_t chatId) const; + std::vector<ChatMember::Ptr> getChatAdministrators(int64_t chatId) const; /** * Use this method to get the number of members in a chat. Returns Int on success. * @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) * @return Int. */ - int32_t getChatMembersCount(int32_t chatId) const; + int32_t getChatMembersCount(int64_t chatId) const; /** * Use this method to get information about a member of a chat. Returns a ChatMember object on success. @@ -352,7 +359,9 @@ public: * @param userId Unique identifier of the target user * @return ChatMember object. */ - ChatMember::Ptr getChatMember(int32_t chatId, int32_t userId) const; + ChatMember::Ptr getChatMember(int64_t chatId, int32_t userId) const; + + bool answerCallbackQuery(const std::string & callbackQueryId, const std::string & text="", bool showAlert=false, const std::string &url="", int32_t cacheTime=0) const; /** * Use this method to receive incoming updates using long polling. diff --git a/src/Api.cpp b/src/Api.cpp index 673f368..2df8a50 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -417,28 +417,54 @@ File::Ptr Api::getFile(int32_t fileId) const return TgTypeParser::getInstance().parseJsonAndGetFile(sendRequest("getFile", args)); } -Chat::Ptr Api::getChat(int32_t chatId) const +bool Api::leaveChat(int64_t chatId) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("chat_id", chatId)); + return sendRequest("leaveChat", args).get<bool>("", false); +} + +Chat::Ptr Api::getChat(int64_t chatId) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); return TgTypeParser::getInstance().parseJsonAndGetChat(sendRequest("getChat", args)); } -std::vector<ChatMember::Ptr> Api::getChatAdministrators(int32_t chatId) const +std::vector<ChatMember::Ptr> Api::getChatAdministrators(int64_t chatId) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); return TgTypeParser::getInstance().parseJsonAndGetArray<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); } -int32_t Api::getChatMembersCount(int32_t chatId) const +int32_t Api::getChatMembersCount(int64_t chatId) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); return sendRequest("getChatMembersCount", args).get<int32_t>("", 0); } -ChatMember::Ptr Api::getChatMember(int32_t chatId, int32_t userId) const +bool Api::answerCallbackQuery(const std::string & callbackQueryId, const std::string & text, bool showAlert, const std::string &url, int32_t cacheTime) const +{ + vector<HttpReqArg> args; + args.push_back(HttpReqArg("callback_query_id", callbackQueryId)); + if (!text.empty()) { + args.push_back(HttpReqArg("text", text)); + } + if (showAlert) { + args.push_back(HttpReqArg("show_alert", showAlert)); + } + if (!url.empty()) { + args.push_back(HttpReqArg("url", url)); + } + if (cacheTime) { + args.push_back(HttpReqArg("cache_time", cacheTime)); + } + return sendRequest("answerCallbackQuery", args).get<bool>("", false); +} + +ChatMember::Ptr Api::getChatMember(int64_t chatId, int32_t userId) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("chat_id", chatId)); @@ -516,9 +542,15 @@ void Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector< args.push_back(HttpReqArg("inline_query_id", inlineQueryId)); string resultsJson = TgTypeParser::getInstance().parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results); args.push_back(HttpReqArg("results", resultsJson)); - args.push_back(HttpReqArg("cache_time", cacheTime)); - args.push_back(HttpReqArg("is_personal", isPersonal)); - args.push_back(HttpReqArg("next_offset", nextOffset)); + if (cacheTime) { + args.push_back(HttpReqArg("cache_time", cacheTime)); + } + if (isPersonal) { + args.push_back(HttpReqArg("is_personal", isPersonal)); + } + if (!nextOffset.empty()) { + args.push_back(HttpReqArg("next_offset", nextOffset)); + } sendRequest("answerInlineQuery", args); } |