From c912fac6016ec582ac3bfeec642a9b758562c994 Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Tue, 27 Dec 2016 15:17:11 +0300 Subject: upgrade existing inline type and create new --- src/TgTypeParser.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 174afe9..6bd77a7 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -552,10 +552,10 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos result->id = data.get("id"); result->title = data.get("title", ""); - result->messageText = data.get("message_text", ""); - result->parseMode = data.get("parse_mode", ""); - result->disableWebPagePreview = data.get("disable_web_page_preview", false); - result->thumbUrl = data.get("thumb_url", ""); + //result->messageText = data.get("message_text", ""); + //result->parseMode = data.get("parse_mode", ""); + //result->disableWebPagePreview = data.get("disable_web_page_preview", false); + //result->thumbUrl = data.get("thumb_url", ""); return result; } @@ -570,10 +570,10 @@ std::string TgTypeParser::parseInlineQueryResult(const InlineQueryResult::Ptr& o appendToJson(result, "id", object->id); appendToJson(result, "type", object->type); appendToJson(result, "title", object->title); - appendToJson(result, "message_text", object->messageText); - appendToJson(result, "parse_mode", object->parseMode); - appendToJson(result, "disable_web_page_preview", object->disableWebPagePreview); - appendToJson(result, "thumb_url", object->thumbUrl); + //appendToJson(result, "message_text", object->messageText); + //appendToJson(result, "parse_mode", object->parseMode); + //appendToJson(result, "disable_web_page_preview", object->disableWebPagePreview); + //appendToJson(result, "thumb_url", object->thumbUrl); if (object->type == InlineQueryResultArticle::TYPE){ result += parseInlineQueryResultArticle(static_pointer_cast(object)); -- cgit v1.2.3 From 9c60e1f40132b2cf2190de55e057c442a2934440 Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Tue, 27 Dec 2016 19:52:26 +0300 Subject: add parse types to JSON part1 --- src/TgTypeParser.cpp | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 6bd77a7..ea176b0 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -49,6 +49,7 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { result->username = data.get("username", ""); result->firstName = data.get("first_name", ""); result->lastName = data.get("last_name", ""); + result->allMembersAreAdministrators = data.get("all_members_are_administrators", false); return result; } @@ -108,6 +109,7 @@ MessageEntity::Ptr TgTypeParser::parseJsonAndGetEntity(const ptree& data) const{ result->offset=data.get("offset"); result->length=data.get("length"); result->url=data.get("url", ""); + result->user = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); return result; } @@ -208,6 +210,8 @@ Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const ptree& data) const { Audio::Ptr result(new Audio); result->fileId = data.get("file_id"); result->duration = data.get("duration"); + result->performer = data.get("performer", ""); + result->title = data.get("title", ""); result->mimeType = data.get("mime_type", ""); result->fileSize = data.get("file_size", 0); return result; @@ -260,6 +264,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const { result->width = data.get("width"); result->height = data.get("height"); result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->emoji = data.get("emoji"); result->fileSize = data.get("file_size", 0); return result; } @@ -274,6 +279,7 @@ string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "emoji", object->emoji); appendToJson(result, "file_size", object->fileSize); result.erase(result.length() - 1); result += '}'; @@ -400,6 +406,28 @@ string TgTypeParser::parseUserProfilePhotos(const UserProfilePhotos::Ptr& object return result; } +File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& data) const { + File::Ptr result(new File); + result->fileId = data.get("file_id"); + result->filePath = data.get("file_size", 0); + result->filePath = data.get("file_path", ""); + return result; +} + +string TgTypeParser::parseFile(const File::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "file_id", object->fileId); + appendToJson(result, "file_size", object->fileSize); + appendToJson(result, "file_path", object->filePath); + result.erase(result.length() - 1); + result += '}'; + return result; +} + ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const { ReplyKeyboardMarkup::Ptr result(new ReplyKeyboardMarkup); for (const pair& item : data.find("keyboard")->second) { @@ -442,6 +470,47 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt return result; } +KeyboardButton::Ptr TgTypeParser::parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const { + KeyboardButton::Ptr result(new KeyboardButton); + result->text = data.get("text"); + result->requestContact = data.get("request_contact", false); + result->requestLocation = data.get("request_location", false); + return result; +} + +std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "text", object->text); + appendToJson(result, "request_contact", object->requestContact); + appendToJson(result, "request_location", object->requestLocation); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +ReplyKeyboardRemove::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const { + ReplyKeyboardRemove::Ptr result(new ReplyKeyboardRemove); + result->selective = data.get("selective", false); + return result; +} + +std::string TgTypeParser::parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "remove_keyboard", object->removeKeyboard); + appendToJson(result, "selective", object->selective); + result.erase(result.length() - 1); + result += '}'; + return result; +} + ReplyKeyboardHide::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const { ReplyKeyboardHide::Ptr result(new ReplyKeyboardHide); result->selective = data.get("selective"); @@ -480,6 +549,46 @@ std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const { return result; } +ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const { + ChatMember::Ptr result(new ChatMember); + result->user = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); + result->status = data.get("status"); + return result; +} + +std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "user", parseUser(object->user)); + appendToJson(result, "status", object->status); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const { + ResponseParameters::Ptr result(new ResponseParameters); + result->migrateToChatId = data.get("migrate_to_chat_id", 0); + result->retryAfter = data.get("retry_after", 0); + return result; +} + +std::string TgTypeParser::parseResponseParameters(const ResponseParameters::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "migrate_to_chat_id", object->migrateToChatId); + appendToJson(result, "retry_after", object->retryAfter); + result.erase(result.length() - 1); + result += '}'; + return result; +} + GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const { if (data.find("force_reply") != data.not_found()) { return static_pointer_cast(parseJsonAndGetForceReply(data)); @@ -511,6 +620,7 @@ InlineQuery::Ptr TgTypeParser::parseJsonAndGetInlineQuery(const boost::property_ InlineQuery::Ptr result(new InlineQuery); result->id = data.get("id"); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->location = tryParseJson(&TgTypeParser::parseJsonAndGetLocation, data, "location"); result->query = data.get("query"); result->offset = data.get("offset"); @@ -525,6 +635,7 @@ std::string TgTypeParser::parseInlineQuery(const InlineQuery::Ptr& object) const result += '{'; appendToJson(result, "id", object->id); appendToJson(result, "from", parseUser(object->from)); + appendToJson(result, "location", parseLocation(object->location)); appendToJson(result, "query", object->query); appendToJson(result, "offset", object->offset); result.erase(result.length() - 1); @@ -536,6 +647,19 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos string type = data.get("type"); InlineQueryResult::Ptr result; + /*if (type == InlineQueryResultCachedAudio::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultArticle(data)); + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + } else if (type == InlineQueryResultCachedDocument::TYPE) { + + }*/ if (type == InlineQueryResultArticle::TYPE) { result = static_pointer_cast(parseJsonAndGetInlineQueryResultArticle(data)); } else if (type == InlineQueryResultPhoto::TYPE) { @@ -753,6 +877,8 @@ CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::prope result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->message = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "message"); result->inlineMessageId = data.get("inline_message_id", ""); + result->chatInstance = data.get("chat_instance"); + result->gameShortName = data.get("game_short_name", ""); result->data = data.get("data", ""); return result; } @@ -768,6 +894,8 @@ std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) c appendToJson(result, "from", parseUser(object->from)); appendToJson(result, "message", parseMessage(object->message)); appendToJson(result, "inline_message_id", object->inlineMessageId); + appendToJson(result, "chat_instance", object->chatInstance); + appendToJson(result, "game_short_name", object->gameShortName); appendToJson(result, "data", object->data); result.erase(result.length() - 1); result += '}'; @@ -809,6 +937,7 @@ InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(cons result->url = data.get("url", ""); result->callbackData = data.get("callback_data", ""); result->switchInlineQuery = data.get("switch_inline_query", ""); + result->switchInlineQueryCurrentChat = data.get("switch_inline_query_current_chat", ""); return result; } std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const { @@ -821,6 +950,45 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton:: appendToJson(result, "url", object->url); appendToJson(result, "callback_data", object->callbackData); appendToJson(result, "switch_inline_query", object->switchInlineQuery); + appendToJson(result, "switch_inline_query_current_chat", object->switchInlineQueryCurrentChat); + result.erase(result.length() - 1); + result += '}'; + return result; +} + +WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const { + WebhookInfo::Ptr result(new WebhookInfo); + result->url = data.get("url"); + result->hasCustomCertificate = data.get("has_custom_certificate"); + result->pendingUpdateCount = data.get("pending_update_count"); + result->lastErrorDate = data.get("last_error_date", 0); + result->lastErrorMessage = data.get("last_error_message", ""); + result->maxConnections = data.get("max_connections", 0); + result->allowedUpdates = parseJsonAndGetArray( + [](const boost::property_tree::ptree& innerData)->std::string { + return innerData.get(""); + } + , data); + return result; +} + +std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "url", object->url); + appendToJson(result, "has_custom_certificate", object->hasCustomCertificate); + appendToJson(result, "pending_update_count", object->pendingUpdateCount); + appendToJson(result, "last_error_date", object->lastErrorDate); + appendToJson(result, "last_error_message", object->lastErrorMessage); + appendToJson(result, "max_connections", object->maxConnections); + appendToJson(result, "allowed_updates", + parseArray([](const std::string &s)->std::string { + return s; + } + , object->allowedUpdates)); result.erase(result.length() - 1); result += '}'; return result; -- cgit v1.2.3 From 187311fc635c843f10c275c7e230543b5f67e703 Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Wed, 28 Dec 2016 19:05:44 +0300 Subject: add parse types to JSON part2 --- src/TgTypeParser.cpp | 631 +++++++++++++++++++++++++++++++++++++--- src/types/InlineQueryResult.cpp | 32 ++ 2 files changed, 627 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index ea176b0..939d339 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -342,8 +342,8 @@ string TgTypeParser::parseContact(const Contact::Ptr& object) const { Location::Ptr TgTypeParser::parseJsonAndGetLocation(const ptree& data) const { Location::Ptr result(new Location); - result->longitude = data.get("longitude"); - result->latitude = data.get("latitude"); + result->longitude = data.get("longitude", 0); + result->latitude = data.get("latitude", 0); return result; } @@ -364,6 +364,9 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const ptree& data) const { Update::Ptr result(new Update); result->updateId = data.get("update_id"); result->message = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "message"); + result->editedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message"); + result->channelPost = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "channel_post"); + result->editedChannelPost = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_channel_post"); result->inlineQuery = tryParseJson(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query"); result->chosenInlineResult = tryParseJson(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result"); result->callbackQuery = tryParseJson(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query"); @@ -378,6 +381,9 @@ string TgTypeParser::parseUpdate(const Update::Ptr& object) const { result += '{'; appendToJson(result, "update_id", object->updateId); appendToJson(result, "message", parseMessage(object->message)); + appendToJson(result, "edited_message", parseMessage(object->editedMessage)); + appendToJson(result, "channel_post", parseMessage(object->channelPost)); + appendToJson(result, "edited_channel_post", parseMessage(object->editedChannelPost)); appendToJson(result, "inline_query", parseInlineQuery(object->inlineQuery)); appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult)); appendToJson(result, "callback_query", parseCallbackQuery(object->callbackQuery)); @@ -647,21 +653,38 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos string type = data.get("type"); InlineQueryResult::Ptr result; - /*if (type == InlineQueryResultCachedAudio::TYPE) { - result = static_pointer_cast(parseJsonAndGetInlineQueryResultArticle(data)); - } else if (type == InlineQueryResultCachedDocument::TYPE) { - - } else if (type == InlineQueryResultCachedDocument::TYPE) { - - } else if (type == InlineQueryResultCachedDocument::TYPE) { - + if (type == InlineQueryResultCachedAudio::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedAudio(data)); } else if (type == InlineQueryResultCachedDocument::TYPE) { - - } else if (type == InlineQueryResultCachedDocument::TYPE) { - - }*/ - if (type == InlineQueryResultArticle::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedDocument(data)); + } else if (type == InlineQueryResultCachedGif::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedGif(data)); + } else if (type == InlineQueryResultCachedMpeg4Gif::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedMpeg4Gif(data)); + } else if (type == InlineQueryResultCachedPhoto::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedPhoto(data)); + } else if (type == InlineQueryResultCachedSticker::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedSticker(data)); + } else if (type == InlineQueryResultCachedVideo::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedVideo(data)); + } else if (type == InlineQueryResultCachedVoice::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultCachedVoice(data)); + } else if (type == InlineQueryResultArticle::TYPE) { result = static_pointer_cast(parseJsonAndGetInlineQueryResultArticle(data)); + } else if (type == InlineQueryResultAudio::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultAudio(data)); + } else if (type == InlineQueryResultContact::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultContact(data)); + } else if (type == InlineQueryResultGame::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultGame(data)); + } else if (type == InlineQueryResultDocument::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultDocument(data)); + } else if (type == InlineQueryResultLocation::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultLocation(data)); + } else if (type == InlineQueryResultVenue::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultVenue(data)); + } else if (type == InlineQueryResultVoice::TYPE) { + result = static_pointer_cast(parseJsonAndGetInlineQueryResultVoice(data)); } else if (type == InlineQueryResultPhoto::TYPE) { result = static_pointer_cast(parseJsonAndGetInlineQueryResultPhoto(data)); } else if (type == InlineQueryResultGif::TYPE) { @@ -676,10 +699,9 @@ InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boos result->id = data.get("id"); result->title = data.get("title", ""); - //result->messageText = data.get("message_text", ""); - //result->parseMode = data.get("parse_mode", ""); - //result->disableWebPagePreview = data.get("disable_web_page_preview", false); - //result->thumbUrl = data.get("thumb_url", ""); + result->caption = data.get("caption", ""); + result->replyMarkup = tryParseJson(&TgTypeParser::parseJsonAndGetInlineKeyboardMarkup, data, "reply_markup"); + result->inputMessageContent = tryParseJson(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content"); return result; } @@ -694,34 +716,246 @@ std::string TgTypeParser::parseInlineQueryResult(const InlineQueryResult::Ptr& o appendToJson(result, "id", object->id); appendToJson(result, "type", object->type); appendToJson(result, "title", object->title); - //appendToJson(result, "message_text", object->messageText); - //appendToJson(result, "parse_mode", object->parseMode); - //appendToJson(result, "disable_web_page_preview", object->disableWebPagePreview); - //appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "caption", object->caption); + appendToJson(result, "reply_markup", parseInlineKeyboardMarkup(object->replyMarkup)); + appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent)); - if (object->type == InlineQueryResultArticle::TYPE){ + if (object->type == InlineQueryResultCachedAudio::TYPE) { + result += parseInlineQueryResultCachedAudio(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedDocument::TYPE) { + result += parseInlineQueryResultCachedDocument(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedGif::TYPE) { + result += parseInlineQueryResultCachedGif(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedMpeg4Gif::TYPE) { + result += parseInlineQueryResultCachedMpeg4Gif(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedPhoto::TYPE) { + result += parseInlineQueryResultCachedPhoto(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedSticker::TYPE) { + result += parseInlineQueryResultCachedSticker(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedVideo::TYPE) { + result += parseInlineQueryResultCachedVideo(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultCachedVoice::TYPE) { + result += parseInlineQueryResultCachedVoice(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultArticle::TYPE) { result += parseInlineQueryResultArticle(static_pointer_cast(object)); - } else if (object->type == InlineQueryResultPhoto::TYPE){ + } + else if (object->type == InlineQueryResultAudio::TYPE) { + result += parseInlineQueryResultAudio(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultContact::TYPE) { + result += parseInlineQueryResultContact(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultGame::TYPE) { + result += parseInlineQueryResultGame(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultDocument::TYPE) { + result += parseInlineQueryResultDocument(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultLocation::TYPE) { + result += parseInlineQueryResultLocation(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultVenue::TYPE) { + result += parseInlineQueryResultVenue(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultVoice::TYPE) { + result += parseInlineQueryResultVoice(static_pointer_cast(object)); + } + else if (object->type == InlineQueryResultPhoto::TYPE) { result += parseInlineQueryResultPhoto(static_pointer_cast(object)); - } else if (object->type == InlineQueryResultGif::TYPE){ + } + else if (object->type == InlineQueryResultGif::TYPE) { result += parseInlineQueryResultGif(static_pointer_cast(object)); - } else if (object->type == InlineQueryResultMpeg4Gif::TYPE){ + } + else if (object->type == InlineQueryResultMpeg4Gif::TYPE) { result += parseInlineQueryResultMpeg4Gif(static_pointer_cast(object)); - } else if (object->type == InlineQueryResultVideo::TYPE){ + } + else if (object->type == InlineQueryResultVideo::TYPE) { result += parseInlineQueryResultVideo(static_pointer_cast(object)); } - + result.erase(result.length() - 1); result += '}'; return result; } +InlineQueryResultCachedAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedAudio::Ptr result(new InlineQueryResultCachedAudio); + result->audioFileId = data.get("audio_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "audio_file_id", object->audioFileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultCachedDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedDocument::Ptr result(new InlineQueryResultCachedDocument); + result->documentFileId = data.get("document_file_id"); + result->description = data.get("description", ""); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "document_file_id", object->documentFileId); + appendToJson(result, "description", object->description); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedGif::Ptr result(new InlineQueryResultCachedGif); + result->gifFileId = data.get("gif_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "gif_file_id", object->gifFileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedMpeg4Gif::Ptr result(new InlineQueryResultCachedMpeg4Gif); + result->mpeg4FileId = data.get("mpeg4_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "mpeg4_file_id", object->mpeg4FileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedPhoto::Ptr result(new InlineQueryResultCachedPhoto); + result->photoFileId = data.get("photo_file_id"); + result->description = data.get("description", ""); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "photo_file_id", object->photoFileId); + appendToJson(result, "description", object->description); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedSticker::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedSticker::Ptr result(new InlineQueryResultCachedSticker); + result->stickerFileId = data.get("sticker_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "sticker_file_id", object->stickerFileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultCachedVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedVideo::Ptr result(new InlineQueryResultCachedVideo); + result->videoFileId = data.get("video_file_id"); + result->description = data.get("description", ""); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "video_file_id", object->videoFileId); + appendToJson(result, "description", object->description); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultCachedVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultCachedVoice::Ptr result(new InlineQueryResultCachedVoice); + result->voiceFileId = data.get("voice_file_id"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "voice_file_id", object->voiceFileId); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + InlineQueryResultArticle::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). InlineQueryResultArticle::Ptr result(new InlineQueryResultArticle); result->url = data.get("url", ""); result->hideUrl = data.get("hide_url", false); result->description = data.get("description", ""); + result->thumbUrl = data.get("thumb_url", ""); result->thumbWidth = data.get("thumb_width", 0); result->thumbHeight = data.get("thumb_height", 0); return result; @@ -737,20 +971,203 @@ std::string TgTypeParser::parseInlineQueryResultArticle(const InlineQueryResultA appendToJson(result, "url", object->url); appendToJson(result, "hide_url", object->hideUrl); appendToJson(result, "description", object->description); + appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumb_width", object->thumbWidth); + appendToJson(result, "thumb_height", object->thumbHeight); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultAudio::Ptr result(new InlineQueryResultAudio); + result->audioUrl = data.get("audio_url"); + result->performer = data.get("performer", ""); + result->audioDuration = data.get("audio_duration", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "audio_url", object->audioUrl); + appendToJson(result, "performer", object->performer); + appendToJson(result, "audio_duration", object->audioDuration); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultContact::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultContact(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultContact::Ptr result(new InlineQueryResultContact); + result->phoneNumber = data.get("phone_number"); + result->firstName = data.get("first_name"); + result->lastName = data.get("last_name", ""); + result->thumbUrl = data.get("thumb_url", ""); + result->thumbWidth = data.get("thumb_width", 0); + result->thumbHeight = data.get("thumb_height", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "phone_number", object->phoneNumber); + appendToJson(result, "first_name", object->firstName); + appendToJson(result, "last_name", object->lastName); + appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumb_width", object->thumbWidth); + appendToJson(result, "thumb_height", object->thumbHeight); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultGame::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultGame::Ptr result(new InlineQueryResultGame); + result->gameShortName = data.get("game_short_name"); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "game_short_name", object->gameShortName); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultDocument::Ptr result(new InlineQueryResultDocument); + result->documentUrl = data.get("document_url"); + result->mimeType = data.get("mime_type"); + result->description = data.get("description", ""); + result->thumbUrl = data.get("thumb_url", ""); + result->thumbWidth = data.get("thumb_width", 0); + result->thumbHeight = data.get("thumb_height", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "document_url", object->documentUrl); + appendToJson(result, "mime_type", object->mimeType); + appendToJson(result, "description", object->description); + appendToJson(result, "thumb_url", object->thumbUrl); appendToJson(result, "thumb_width", object->thumbWidth); appendToJson(result, "thumb_height", object->thumbHeight); // The last comma will be erased by parseInlineQueryResult(). return result; } +InlineQueryResultLocation::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultLocation::Ptr result(new InlineQueryResultLocation); + result->latitude = data.get("latitude"); + result->longitude = data.get("longitude"); + result->thumbUrl = data.get("thumb_url", ""); + result->thumbWidth = data.get("thumb_width", 0); + result->thumbHeight = data.get("thumb_height", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); + appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumb_width", object->thumbWidth); + appendToJson(result, "thumb_height", object->thumbHeight); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + + +InlineQueryResultVenue::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultVenue::Ptr result(new InlineQueryResultVenue); + result->latitude = data.get("latitude"); + result->longitude = data.get("longitude"); + result->address = data.get("address"); + result->foursquareId = data.get("foursquare_id", ""); + result->thumbUrl = data.get("thumb_url", ""); + result->thumbWidth = data.get("thumb_width", 0); + result->thumbHeight = data.get("thumb_height", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); + appendToJson(result, "address", object->address); + appendToJson(result, "foursquare_id", object->foursquareId); + appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumb_width", object->thumbWidth); + appendToJson(result, "thumb_height", object->thumbHeight); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + +InlineQueryResultVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). + InlineQueryResultVoice::Ptr result(new InlineQueryResultVoice); + result->voiceUrl = data.get("voice_url"); + result->voiceDuration = data.get("voice_duration", 0); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInlineQueryResult(), so I don't add + // curly brackets to the result string. + string result; + appendToJson(result, "voice_url", object->voiceUrl); + appendToJson(result, "voice_duration", object->voiceDuration); + // The last comma will be erased by parseInlineQueryResult(). + return result; +} + InlineQueryResultPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). InlineQueryResultPhoto::Ptr result(new InlineQueryResultPhoto); result->photoUrl = data.get("photo_url", ""); + result->thumbUrl = data.get("thumb_url"); result->photoWidth = data.get("photo_width", 0); result->photoHeight = data.get("photo_height", 0); result->description = data.get("description", ""); - result->caption = data.get("caption", ""); return result; } @@ -762,10 +1179,10 @@ std::string TgTypeParser::parseInlineQueryResultPhoto(const InlineQueryResultPho // curly brackets to the result string. string result; appendToJson(result, "photo_url", object->photoUrl); + appendToJson(result, "thumb_url", object->thumbUrl); appendToJson(result, "photo_width", object->photoWidth); appendToJson(result, "photo_height", object->photoHeight); appendToJson(result, "description", object->description); - appendToJson(result, "caption", object->caption); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -776,7 +1193,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->caption = data.get("caption", ""); + result->thumbUrl = data.get("thumb_url"); return result; } std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const { @@ -789,7 +1206,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, "caption", object->caption); + appendToJson(result, "thumb_url", object->thumbUrl); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -800,7 +1217,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->caption = data.get("caption", ""); + result->thumbUrl = data.get("thumb_url"); return result; } @@ -814,7 +1231,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, "caption", object->caption); + appendToJson(result, "thumb_url", object->thumbUrl); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -824,7 +1241,8 @@ InlineQueryResultVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVideo( InlineQueryResultVideo::Ptr result(new InlineQueryResultVideo); result->videoUrl = data.get("video_url"); result->mimeType = data.get("mime_type"); - result->videoWidth = data.get("video_height", 0); + result->thumbUrl = data.get("thumb_url"); + result->videoWidth = data.get("video_width", 0); result->videoHeight = data.get("video_height", 0); result->videoDuration = data.get("video_duration", 0); result->description = data.get("description", ""); @@ -840,6 +1258,7 @@ std::string TgTypeParser::parseInlineQueryResultVideo(const InlineQueryResultVid string result; appendToJson(result, "video_url", object->videoUrl); appendToJson(result, "mime_type", object->mimeType); + appendToJson(result, "thumb_url", object->thumbUrl); appendToJson(result, "video_width", object->videoWidth); appendToJson(result, "video_height", object->videoHeight); appendToJson(result, "video_duration", object->videoDuration); @@ -852,6 +1271,8 @@ ChosenInlineResult::Ptr TgTypeParser::parseJsonAndGetChosenInlineResult(const bo ChosenInlineResult::Ptr result(new ChosenInlineResult); result->resultId = data.get("result_id"); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->location = tryParseJson(&TgTypeParser::parseJsonAndGetLocation, data, "location"); + result->inlineMessageId = data.get("inline_message_id", ""); result->query = data.get("query"); return result; } @@ -994,6 +1415,144 @@ std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const return result; } +InputMessageContent::Ptr TgTypeParser::parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const { + InputMessageContent::Ptr result; + // define InputMessageContent type + + string tMessageText = data.get("message_text", ""); + float tLatitude = data.get("latitude", 1000); // latitude belong (-90,90) + string tTitle = data.get("title", ""); + string tPnoneNumber = data.get("phone_number", ""); + + if (tMessageText != std::string("")) { + result = static_pointer_cast(parseJsonAndGetInputTextMessageContent(data)); + } else if (tTitle !=std::string("")) { + result = static_pointer_cast(parseJsonAndGetInputVenueMessageContent(data)); + } else if (tLatitude != 1000) { + result = static_pointer_cast(parseJsonAndGetInputLocationMessageContent(data)); + } else if (tPnoneNumber!= std::string("")) { + result = static_pointer_cast(parseJsonAndGetInputContactMessageContent(data)); + } + + return result; +} + +std::string TgTypeParser::parseInputMessageContent(const InputMessageContent::Ptr& object) const { + if (!object){ + return ""; + } + + string result; + result += '{'; + + if (object->type == std::string("InputTextMessageContent")) { + result += parseInputTextMessageContent(static_pointer_cast(object)); + } + else if (object->type == std::string("InputLocationMessageContent")) { + result += parseInputLocationMessageContent(static_pointer_cast(object)); + } + else if (object->type == std::string("InputVenueMessageContent")) { + result += parseInputVenueMessageContent(static_pointer_cast(object)); + } + else if (object->type == std::string("InputContactMessageContent")) { + result += parseInputContactMessageContent(static_pointer_cast(object)); + } + + result.erase(result.length() - 1); + result += '}'; + return result; +} + +InputTextMessageContent::Ptr TgTypeParser::parseJsonAndGetInputTextMessageContent(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). + InputTextMessageContent::Ptr result(new InputTextMessageContent); + result->messageText = data.get("message_text"); + result->parseMode = data.get("parse_mode", ""); + result->disableWebPagePreview = data.get("disable_web_page_preview", false); + return result; +} + +std::string TgTypeParser::parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInputMessageContent() + string result; + appendToJson(result, "message_text", object->messageText); + appendToJson(result, "parse_mode", object->parseMode); + appendToJson(result, "disable_web_page_preview", object->disableWebPagePreview); + // The last comma will be erased by parseInputMessageContent(). + return result; +} + +InputLocationMessageContent::Ptr TgTypeParser::parseJsonAndGetInputLocationMessageContent(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). + InputLocationMessageContent::Ptr result(new InputLocationMessageContent); + result->latitude = data.get("latitude"); + result->longitude = data.get("longitude"); + return result; +} + +std::string TgTypeParser::parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInputMessageContent() + string result; + appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); + // The last comma will be erased by parseInputMessageContent(). + return result; +} + +InputVenueMessageContent::Ptr TgTypeParser::parseJsonAndGetInputVenueMessageContent(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). + InputVenueMessageContent::Ptr result(new InputVenueMessageContent); + result->latitude = data.get("latitude"); + result->longitude = data.get("longitude"); + result->title = data.get("title"); + result->address = data.get("address"); + result->foursquareId = data.get("foursquare_id", ""); + return result; +} + +std::string TgTypeParser::parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInputMessageContent() + string result; + appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); + appendToJson(result, "title", object->title); + appendToJson(result, "address", object->address); + appendToJson(result, "foursquare_id", object->foursquareId); + // The last comma will be erased by parseInputMessageContent(). + return result; +} + +InputContactMessageContent::Ptr TgTypeParser::parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). + InputContactMessageContent::Ptr result(new InputContactMessageContent); + result->phoneNumber = data.get("phone_number"); + result->firstName = data.get("first_name"); + result->lastName = data.get("last_name", ""); + return result; +} + +std::string TgTypeParser::parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const { + if (!object){ + return " "; + } + // This function will be called by parseInputMessageContent() + string result; + appendToJson(result, "phone_number", object->phoneNumber); + appendToJson(result, "first_name", object->firstName); + appendToJson(result, "last_name", object->lastName); + // The last comma will be erased by parseInputMessageContent(). + return result; +} + void TgTypeParser::appendToJson(string& json, const string& varName, const string& value) const { if (value.empty()) { return; diff --git a/src/types/InlineQueryResult.cpp b/src/types/InlineQueryResult.cpp index be1f14a..9f90e19 100644 --- a/src/types/InlineQueryResult.cpp +++ b/src/types/InlineQueryResult.cpp @@ -1,6 +1,22 @@ // // Created by Andrea Giove on 27/03/16. // + +#include "tgbot/types/InlineQueryResultCachedAudio.h" +#include "tgbot/types/InlineQueryResultCachedDocument.h" +#include "tgbot/types/InlineQueryResultCachedGif.h" +#include "tgbot/types/InlineQueryResultCachedMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultCachedPhoto.h" +#include "tgbot/types/InlineQueryResultCachedSticker.h" +#include "tgbot/types/InlineQueryResultCachedVideo.h" +#include "tgbot/types/InlineQueryResultCachedVoice.h" +#include "tgbot/types/InlineQueryResultAudio.h" +#include "tgbot/types/InlineQueryResultContact.h" +#include "tgbot/types/InlineQueryResultGame.h" +#include "tgbot/types/InlineQueryResultDocument.h" +#include "tgbot/types/InlineQueryResultLocation.h" +#include "tgbot/types/InlineQueryResultVenue.h" +#include "tgbot/types/InlineQueryResultVoice.h" #include "tgbot/types/InlineQueryResultArticle.h" #include "tgbot/types/InlineQueryResultGif.h" #include "tgbot/types/InlineQueryResultMpeg4Gif.h" @@ -9,8 +25,24 @@ using namespace TgBot; +const std::string InlineQueryResultCachedAudio::TYPE = "cached_audio"; +const std::string InlineQueryResultCachedDocument::TYPE = "cached_document"; +const std::string InlineQueryResultCachedGif::TYPE = "cached_gif"; +const std::string InlineQueryResultCachedMpeg4Gif::TYPE = "cached_mpeg4gif"; +const std::string InlineQueryResultCachedPhoto::TYPE = "cached_photo"; +const std::string InlineQueryResultCachedSticker::TYPE = "cached_sticker"; +const std::string InlineQueryResultCachedVideo::TYPE = "cached_video"; +const std::string InlineQueryResultCachedVoice::TYPE = "cached_voice"; + const std::string InlineQueryResultArticle::TYPE = "article"; +const std::string InlineQueryResultAudio::TYPE = "audio"; +const std::string InlineQueryResultContact::TYPE = "contact"; +const std::string InlineQueryResultGame::TYPE = "game"; +const std::string InlineQueryResultDocument::TYPE = "document"; const std::string InlineQueryResultGif::TYPE = "gif"; +const std::string InlineQueryResultLocation::TYPE = "location"; const std::string InlineQueryResultMpeg4Gif::TYPE = "mpeg4_gif"; const std::string InlineQueryResultPhoto::TYPE = "photo"; +const std::string InlineQueryResultVenue::TYPE = "venue"; const std::string InlineQueryResultVideo::TYPE = "video"; +const std::string InlineQueryResultVoice::TYPE = "voice"; -- cgit v1.2.3 From 33e4184338cc7b9ecd8af36ee0ecaff74020356c Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Thu, 29 Dec 2016 17:50:00 +0300 Subject: Rename ReplyKeyboardHide to ReplyKeyboardRemove --- src/TgTypeParser.cpp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 939d339..6b0914b 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -517,25 +517,6 @@ std::string TgTypeParser::parseReplyKeyboardRemove(const ReplyKeyboardRemove::Pt return result; } -ReplyKeyboardHide::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const { - ReplyKeyboardHide::Ptr result(new ReplyKeyboardHide); - result->selective = data.get("selective"); - return result; -} - -std::string TgTypeParser::parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const { - if (!object) { - return ""; - } - string result; - result += '{'; - appendToJson(result, "hide_keyboard", object->hideKeyboard); - appendToJson(result, "selective", object->selective); - result.erase(result.length() - 1); - result += '}'; - return result; -} - ForceReply::Ptr TgTypeParser::parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const { ForceReply::Ptr result(new ForceReply); result->selective = data.get("selective"); @@ -598,8 +579,8 @@ std::string TgTypeParser::parseResponseParameters(const ResponseParameters::Ptr& GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const { if (data.find("force_reply") != data.not_found()) { return static_pointer_cast(parseJsonAndGetForceReply(data)); - } else if (data.find("hide_keyboard") != data.not_found()) { - return static_pointer_cast(parseJsonAndGetReplyKeyboardHide(data)); + } else if (data.find("remove_keyboard") != data.not_found()) { + return static_pointer_cast(parseJsonAndGetReplyKeyboardRemove(data)); } else if (data.find("keyboard") != data.not_found()) { return static_pointer_cast(parseJsonAndGetReplyKeyboardMarkup(data)); } else if (data.find("inline_keyboard") != data.not_found()) { @@ -613,8 +594,8 @@ std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) con } if (dynamic_pointer_cast(object) != nullptr) { return parseForceReply(static_pointer_cast(object)); - } else if (dynamic_pointer_cast(object) != nullptr) { - return parseReplyKeyboardHide(static_pointer_cast(object)); + } else if (dynamic_pointer_cast(object) != nullptr) { + return parseReplyKeyboardRemove(static_pointer_cast(object)); } else if (dynamic_pointer_cast(object) != nullptr){ return parseReplyKeyboardMarkup(static_pointer_cast(object)); } else if (dynamic_pointer_cast(object) != nullptr){ -- cgit v1.2.3 From 2d7d1a269383ec1db99b6759f9c58ba08d1d29fe Mon Sep 17 00:00:00 2001 From: Konstantin Kukin Date: Fri, 30 Dec 2016 11:38:22 +0300 Subject: add Webhook functions --- src/Api.cpp | 36 +++++++++++++++++++++++++++++++++++- src/TgTypeParser.cpp | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index 54cb692..c4baa2b 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -381,16 +381,50 @@ vector Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo return TgTypeParser::getInstance().parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); } -void Api::setWebhook(const string& url, const InputFile::Ptr& certificate) const { +void Api::setWebhook(const string& url, const InputFile::Ptr& certificate, int32_t maxConnection, const StringArrayPtr &allowedUpdates) const { vector args; if (!url.empty()) args.push_back(HttpReqArg("url", url)); if (certificate != nullptr) args.push_back(HttpReqArg("certificate", certificate->data, true, certificate->mimeType, certificate->fileName)); + if (maxConnection!=40) + args.push_back(HttpReqArg("max_connections", maxConnection)); + + if (allowedUpdates!=nullptr) + { + string allowedUpdatesJson = TgTypeParser::getInstance().parseArray( + [](const std::string &s)->std::string { + return s; + }, *allowedUpdates); + args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson)); + } sendRequest("setWebhook", args); } +bool Api::deleteWebhook() const +{ + ptree p = sendRequest("deleteWebhook"); + return p.get("", false); +} + +WebhookInfo::Ptr Api::getWebhookInfo() const +{ + ptree p = sendRequest("getWebhookInfo"); + + if (!p.get_child_optional("url")) + return nullptr; + + if (p.get("url","")!=string("")) + { + return TgTypeParser::getInstance().parseJsonAndGetWebhookInfo(p); + } + else + { + return nullptr; + } +} + void Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, int32_t cacheTime, bool isPersonal, const std::string& nextOffset) const { vector args; diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 6b0914b..71da2ac 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1370,7 +1370,7 @@ WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_ [](const boost::property_tree::ptree& innerData)->std::string { return innerData.get(""); } - , data); + , data, "allowed_updates"); return result; } -- cgit v1.2.3 From a071ebee5b2f6c418e7f3916bd6f50b152aaf300 Mon Sep 17 00:00:00 2001 From: kukin-konstantin Date: Fri, 30 Dec 2016 14:07:32 +0300 Subject: edit Message type --- src/TgTypeParser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 71da2ac..20b8ea2 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -120,8 +120,11 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->date = data.get("date"); result->chat = parseJsonAndGetChat(data.find("chat")->second); 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->forwardDate = data.get("forward_date", 0); result->replyToMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message"); + result->editDate = data.get("edit_date", 0); result->text = data.get("text", ""); result->entities = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetEntity, data, "entities"); result->audio = tryParseJson