From 9ba69d7e87c9b8ff9997294b68550852ef0274b8 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sun, 17 Apr 2016 22:09:52 +0200 Subject: Added new type: Venue, MessageEntity Update Message type Added new method: sendVenue, sendContact, kickChatMember, unbanChatMember --- src/Api.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index 3ae582c..55c0320 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -307,6 +307,46 @@ 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 = 0, const GenericReply::Ptr& replyMarkup) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("latitude", latitude)); + args.push_back(HttpReqArg("longitude", longitude)); + args.push_back(HttpReqArg("title", title)); + args.push_back(HttpReqArg("address", address)); + if (!foursquareId.empty()) { + args.push_back(HttpReqArg("foursquare_id", foursquareId)); + } + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + 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 { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("phone_number", phoneNumber)); + args.push_back(HttpReqArg("first_name", firstName)); + args.push_back(HttpReqArg("last_name", lastName)); + if (replyToMessageId) { + args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId)); + } + if (replyMarkup) { + args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup))); + } + if (disableNotification){ + args.push_back(HttpReqArg("disable_notification", disableNotification)); + } + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendContact", args)); +} + void Api::sendChatAction(int64_t chatId, const string& action) const { vector args; args.push_back(HttpReqArg("chat_id", chatId)); @@ -360,6 +400,20 @@ void Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector< sendRequest("answerInlineQuery", args); } +void Api::kickChatMember(int64_t chatId, int32_t userId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + sendRequest("kickChatMember", args); +} + +void Api::unbanChatMember(int64_t chatId, int32_t userId) const { + vector args; + args.push_back(HttpReqArg("chat_id", chatId)); + args.push_back(HttpReqArg("user_id", userId)); + sendRequest("unbanChatMember", args); +} + ptree Api::sendRequest(const string& method, const vector& args) const { string url = "https://api.telegram.org/bot"; -- cgit v1.2.3