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 ++++++++++ src/TgTypeParser.cpp | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 276 insertions(+) (limited to 'src') 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)); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 1b80d7f..c442600 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -85,6 +85,7 @@ User::Ptr TgTypeParser::parseJsonAndGetUser(const ptree& data) const { result->firstName = data.get("first_name"); result->lastName = data.get("last_name", ""); result->username = data.get("username", ""); + result->languageCode = data.get("language_code", ""); return result; } @@ -98,6 +99,7 @@ string TgTypeParser::parseUser(const User::Ptr& object) const { appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); appendToJson(result, "username", object->username); + appendToJson(result, "language_code", object->languageCode); result.erase(result.length() - 1); result += '}'; return result; @@ -135,6 +137,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->contact = tryParseJson(&TgTypeParser::parseJsonAndGetContact, data, "contact"); result->location = tryParseJson(&TgTypeParser::parseJsonAndGetLocation, data, "location"); result->newChatMember = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_participant"); + result->newChatMembers = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_members"); result->leftChatMember = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "left_chat_participant"); result->newChatTitle = data.get("new_chat_title", ""); result->newChatPhoto = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetPhotoSize, data, "new_chat_photo"); @@ -173,6 +176,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "contact", parseContact(object->contact)); appendToJson(result, "location", parseLocation(object->location)); appendToJson(result, "new_chat_member", parseUser(object->newChatMember)); + appendToJson(result, "new_chat_members", parseArray(&TgTypeParser::parseUser, object->newChatMembers)); appendToJson(result, "left_chat_member", parseUser(object->leftChatMember)); appendToJson(result, "new_chat_title", object->newChatTitle); appendToJson(result, "new_chat_photo", parseArray(&TgTypeParser::parsePhotoSize, object->newChatPhoto)); @@ -322,6 +326,32 @@ string TgTypeParser::parseVideo(const Video::Ptr& object) const { return result; } +VideoNote::Ptr TgTypeParser::parseJsonAndGetVideoNote(const ptree& data) const { + VideoNote::Ptr result(new VideoNote); + result->fileId = data.get("file_id"); + result->length = data.get("length"); + result->duration = data.get("duration"); + result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->fileSize = data.get("file_size", 0); + return result; +} + +string TgTypeParser::parseVideoNote(const VideoNote::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "file_id", object->fileId); + appendToJson(result, "length", object->length); + appendToJson(result, "duration", object->duration); + appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "file_size", object->fileSize); + result += '}'; + result.erase(); + return result; +} + Contact::Ptr TgTypeParser::parseJsonAndGetContact(const ptree& data) const { auto result(make_shared()); result->phoneNumber = data.get("phone_number"); @@ -1178,6 +1208,7 @@ InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(cons result->gifUrl = data.get("gif_url", ""); result->gifWidth = data.get("gif_width", 0); result->gifHeight = data.get("gif_height", 0); + result->gifDuration = data.get("gif_duration", 0); result->thumbUrl = data.get("thumb_url"); return result; } @@ -1191,6 +1222,7 @@ std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif:: appendToJson(result, "gif_url", object->gifUrl); appendToJson(result, "gif_width", object->gifWidth); appendToJson(result, "gif_height", object->gifHeight); + appendToJson(result, "gif_duration", object->gifDuration); appendToJson(result, "thumb_url", object->thumbUrl); // The last comma will be erased by parseInlineQueryResult(). return result; @@ -1202,6 +1234,7 @@ InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpe result->mpeg4Url = data.get("mpeg4_url"); result->mpeg4Width = data.get("mpeg4_width", 0); result->mpeg4Height = data.get("mpeg4_height", 0); + result->mpeg4Duration = data.get("mpeg4_duration", 0); result->thumbUrl = data.get("thumb_url"); return result; } @@ -1216,6 +1249,7 @@ std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResult appendToJson(result, "mpeg4_url", object->mpeg4Url); appendToJson(result, "mpeg4_width", object->mpeg4Width); appendToJson(result, "mpeg4_height", object->mpeg4Height); + appendToJson(result, "mpeg4_duration", object->mpeg4Duration); appendToJson(result, "thumb_url", object->thumbUrl); // The last comma will be erased by parseInlineQueryResult(). return result; @@ -1539,6 +1573,204 @@ std::string TgTypeParser::parseInputContactMessageContent(const InputContactMess return result; } +Invoice::Ptr TgTypeParser::parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const { + auto result(make_shared()); + result->title = data.get("title"); + result->description = data.get("description"); + result->startParameter = data.get("start_parameter"); + result->currency = data.get("currency"); + result->totalAmount = data.get("total_amount"); + return result; +} + +std::string TgTypeParser::parseInvoice(const Invoice::Ptr& object) const { + if (!object) { + return " "; + } + string result; + result += '{'; + appendToJson(result, "title", object->title); + appendToJson(result, "description", object->description); + appendToJson(result, "start_parameter", object->startParameter); + appendToJson(result, "currency", object->currency); + appendToJson(result, "total_amount", object->totalAmount); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +LabeledPrice::Ptr TgTypeParser::parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const { + auto result(make_shared()); + result->label = data.get("label"); + result->amount = data.get("amount"); + return result; +} + +string TgTypeParser::parseLabeledPrice(const LabeledPrice::Ptr& object) const { + std::string result; + result += '{'; + appendToJson(result, "label", object->label); + appendToJson(result, "amount", object->amount); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +OrderInfo::Ptr TgTypeParser::parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const { + auto result(make_shared()); + result->name = data.get("name", ""); + result->phoneNumber = data.get("phone_number", ""); + result->email = data.get("email", ""); + result->shippingAddress = tryParseJson(&TgTypeParser::parseJsonAndGetShippingAddress, data, "shipping_address"); + return result; +} + +string TgTypeParser::parseOrderInfo(const OrderInfo::Ptr& object) const { + if (!object) { + return " "; + } + std::string result; + result += '{'; + if (!object->name.empty()) { + appendToJson(result, "name", object->name); + } + if (!object->phoneNumber.empty()) { + appendToJson(result, "phone_number", object->phoneNumber); + } + if (!object->email.empty()) { + appendToJson(result, "email", object->email); + } + if (!object->shippingAddress) { + result += R"("shipping_address":)"; + result += parseShippingAddress(object->shippingAddress); + result += ","; + } + result.erase(result.length() - 1); + result += '}'; + return result; +} + +PreCheckoutQuery::Ptr TgTypeParser::parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const { + auto result(make_shared()); + result->id = data.get("id"); + result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); + result->currency = data.get("currency"); + result->totalAmount = data.get("total_amount"); + return result; +} + +string TgTypeParser::parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const { + std::string result; + result += '{'; + appendToJson(result, "id", object->id); + result += R"("user":)"; + result += parseUser(object->from); + result += ","; + appendToJson(result, "currency", object->currency); + appendToJson(result, "total_amount", object->totalAmount); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +ShippingAddress::Ptr TgTypeParser::parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const { + ShippingAddress::Ptr result; + result->countryCode = data.get("country_code"); + result->state = data.get("state", ""); + result->city = data.get("city"); + result->streetLine1 = data.get("street_line1"); + result->streetLine2 = data.get("street_line2"); + result->postCode = data.get("post_code"); + return result; +} + +string TgTypeParser::parseShippingAddress(const ShippingAddress::Ptr& object) const { + std::string result; + result += '{'; + appendToJson(result, "country_code", object->countryCode); + if (!object->state.empty()) { + appendToJson(result, "state", object->state); + } + appendToJson(result, "city", object->city); + appendToJson(result, "street_line1", object->streetLine1); + appendToJson(result, "street_line2", object->streetLine2); + appendToJson(result, "post_code", object->postCode); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +ShippingOption::Ptr TgTypeParser::parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const { + auto result(make_shared()); + result->id = data.get("id"); + result->title = data.get("title"); + result->prices = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetLabeledPrice, data, "prices"); + return result; +} + +string TgTypeParser::parseShippingOption(const ShippingOption::Ptr& object) const { + std::string result; + result += '{'; + appendToJson(result, "id", object->id); + appendToJson(result, "title", object->title); + result.erase(result.length() - 1); + result += R"("prices":)"; + result += parseArray(&TgTypeParser::parseLabeledPrice, object->prices); + result += '}'; + return result; +} + +ShippingQuery::Ptr TgTypeParser::parseJsonAndGetShippingQuery(const boost::property_tree::ptree& data) const { + auto result(make_shared()); + result->id = data.get("id"); + result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->invoicePayload = data.get("invoice_payload"); + result->shippingAddress = tryParseJson(&TgTypeParser::parseJsonAndGetShippingAddress, data, "shipping_address"); + return result; +} + +string TgTypeParser::parseShippingQuery(const ShippingQuery::Ptr& object) const { + string result; + result += '{'; + appendToJson(result, "id", object->id); + result += R"("from":)"; + result += parseUser(object->from); + result += ","; + appendToJson(result, "invoice_payload", object->invoicePayload); + result += R"("shipping_address":)"; + result += parseShippingAddress(object->shippingAddress); + result += ","; + result.erase(result.length() - 1); + result += '}'; + return result; +} + +SuccessfulPayment::Ptr TgTypeParser::parseJsonAndGetSucessfulPayment(const boost::property_tree::ptree& data) const { + auto result(make_shared()); + result->currency = data.get("currency"); + result->totalAmount = data.get("total_amount"); + result->invoicePayload = data.get("invoice_payload"); + result->shippingOptionId = data.get("shipping_option_id"); + result->orderInfo = tryParseJson(&TgTypeParser::parseJsonAndGetOrderInfo, data, "order_info"); + return result; +} + +std::string TgTypeParser::parseSucessfulPayment(const SuccessfulPayment::Ptr& object) const { + string result; + result += '{'; + appendToJson(result, "currency", object->currency); + appendToJson(result, "total_amount", object->totalAmount); + appendToJson(result, "invoice_payload", object->invoicePayload); + appendToJson(result, "shipping_option_id", object->shippingOptionId); + result += R"("order_info":)"; + result += parseOrderInfo(object->orderInfo); + result += ","; + result.erase(result.length() - 1); + result += '}'; + return result; +} + + void TgTypeParser::appendToJson(string& json, const string& varName, const string& value) const { if (value.empty()) { return; -- cgit v1.2.3 From fbdbc4d5d3cd61086500d2406f3345da55627a56 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 27 May 2018 13:53:14 +0900 Subject: Message max length is 4096 UTF8 characters --- src/EventHandler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index 32efe3e..ba0ce54 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -26,9 +26,9 @@ void EventHandler::handleMessage(const Message::Ptr message) const { _broadcaster->broadcastAnyMessage(message); if (StringTools::startsWith(message->text, "/")) { - uint32_t splitPosition; - uint32_t spacePosition = message->text.find(' '); - uint32_t atSymbolPosition = message->text.find('@'); + uint16_t splitPosition; + uint16_t spacePosition = message->text.find(' '); + uint16_t atSymbolPosition = message->text.find('@'); if (spacePosition == message->text.npos) { if (atSymbolPosition == message->text.npos) { splitPosition = message->text.size(); -- 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 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/TgTypeParser.cpp | 37 +++++++++++++--- 2 files changed, 142 insertions(+), 11 deletions(-) (limited to 'src') 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) }); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index c442600..9a48de5 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -50,6 +50,12 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { result->firstName = data.get("first_name", ""); result->lastName = data.get("last_name", ""); result->allMembersAreAdministrators = data.get("all_members_are_administrators", false); + result->photo = tryParseJson(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo"); + result->description = data.get("description", ""); + result->inviteLink = data.get("invite_link", ""); + result->pinnedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); + result->stickerSetName = data.get("sticker_set_name", ""); + result->canSetStickerSet = data.get("can_set_sticker_set", false); return result; } @@ -107,10 +113,10 @@ string TgTypeParser::parseUser(const User::Ptr& object) const { MessageEntity::Ptr TgTypeParser::parseJsonAndGetEntity(const ptree& data) const{ auto result(make_shared()); - result->type=data.get("type"); - result->offset=data.get("offset"); - result->length=data.get("length"); - result->url=data.get("url", ""); + result->type = data.get("type"); + result->offset = data.get("offset"); + result->length = data.get("length"); + result->url = data.get("url", ""); result->user = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); return result; } @@ -571,7 +577,21 @@ std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const { ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const { auto result(make_shared()); result->user = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); - result->status = data.get("status"); + result->status = data.get("status", ""); + result->untilDate = data.get("until_date", 0); + result->canBeEdited = data.get("can_be_edited", false); + result->canChangeInfo = data.get("can_change_info", false); + result->canPostMessages = data.get("can_post_messages", false); + result->canEditMessages = data.get("can_edit_messages", false); + result->canDeleteMessages = data.get("can_delete_messages", false); + result->canInviteUsers = data.get("can_invite_users", false); + result->canRestrictMembers = data.get("can_restrict_members", false); + result->canPinMessages = data.get("can_pin_messages", false); + result->canPromoteMembers = data.get("can_promote_messages", false); + result->canSendMessages = data.get("can_send_messages", false); + result->canSendMediaMessages = data.get("can_send_media_messages", false); + result->canSendOtherMessages = data.get("can_send_other_messages", false); + result->canAddWebPagePreviews = data.get("can_add_web_page_previews", false); return result; } @@ -588,6 +608,13 @@ std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const { return result; } +ChatPhoto::Ptr TgTypeParser::parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const { + auto result(make_shared()); + result->smallFileId = data.get("small_file_id", ""); + result->bigFileId = data.get("big_file_id", ""); + return result; +} + ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const { auto result(make_shared()); result->migrateToChatId = data.get("migrate_to_chat_id", 0); -- 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 +- src/TgTypeParser.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') 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)); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 9a48de5..0facf93 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -53,7 +53,7 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { result->photo = tryParseJson(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo"); result->description = data.get("description", ""); result->inviteLink = data.get("invite_link", ""); - result->pinnedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); + result->pinnedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); result->stickerSetName = data.get("sticker_set_name", ""); result->canSetStickerSet = data.get("can_set_sticker_set", false); -- cgit v1.2.3 From c81f7d9d7a4fe9dc3b48b92fad633bd5c44b8e74 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 27 May 2018 17:50:32 +0900 Subject: Bot API 3.3 update --- src/TgTypeParser.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 0facf93..fafe94f 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -47,7 +47,7 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { } result->title = data.get("title", ""); result->username = data.get("username", ""); - result->firstName = data.get("first_name", ""); + result->firstName = data.get("first_name", ""); result->lastName = data.get("last_name", ""); result->allMembersAreAdministrators = data.get("all_members_are_administrators", false); result->photo = tryParseJson(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo"); @@ -88,6 +88,7 @@ string TgTypeParser::parseChat(const Chat::Ptr& object) const { User::Ptr TgTypeParser::parseJsonAndGetUser(const ptree& data) const { auto result(make_shared()); result->id = data.get("id"); + result->isBot = data.get("is_bot", false); result->firstName = data.get("first_name"); result->lastName = data.get("last_name", ""); result->username = data.get("username", ""); @@ -102,6 +103,7 @@ string TgTypeParser::parseUser(const User::Ptr& object) const { string result; result += '{'; appendToJson(result, "id", object->id); + appendToJson(result, "is_bot", object->isBot); appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); appendToJson(result, "username", object->username); @@ -130,9 +132,11 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->forwardFrom = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "forward_from"); result->forwardFromChat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "forward_from_chat"); result->forwardFromMessageId = data.get("forward_from_message_id", 0); + result->forwardSignature = data.get("forward_signature", ""); result->forwardDate = data.get("forward_date", 0); result->replyToMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message"); result->editDate = data.get("edit_date", 0); + result->authorSignature = data.get("author_signature", ""); result->text = data.get("text", ""); result->entities = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetEntity, data, "entities"); result->audio = tryParseJson