summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOleg Morozenkov <omorozenkov@gmail.com>2016-04-17 23:22:52 +0300
committerOleg Morozenkov <omorozenkov@gmail.com>2016-04-17 23:22:52 +0300
commit53418361401958da5cfa3741a8f79687e103c94a (patch)
tree447c7ba83c868066f59d7c10391723a29cdcb58f /src
parent5d73c438a57b5d0c0846972febc13c1710461185 (diff)
parent9ba69d7e87c9b8ff9997294b68550852ef0274b8 (diff)
Merge pull request #22 from aadeg/master
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp179
-rw-r--r--src/TgTypeParser.cpp89
2 files changed, 252 insertions, 16 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index 6419780..c882304 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -38,13 +38,20 @@ User::Ptr Api::getMe() const {
return TgTypeParser::getInstance().parseJsonAndGetUser(sendRequest("getMe"));
}
+<<<<<<< HEAD
Message::Ptr Api::sendMessage(int64_t chatId, const string& text, bool disableWebPagePreview, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, const string& parseMode) const {
+=======
+Message::Ptr Api::sendMessage(int64_t chatId, const string& text, bool disableWebPagePreview, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
+>>>>>>> 9ba69d7e87c9b8ff9997294b68550852ef0274b8
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("text", text));
if (disableWebPagePreview) {
args.push_back(HttpReqArg("disable_web_page_preview", disableWebPagePreview));
}
+ if (disableNotification){
+ args.push_back(HttpReqArg("disable_notification", disableNotification));
+ }
if (replyToMessageId) {
args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
}
@@ -57,15 +64,18 @@ Message::Ptr Api::sendMessage(int64_t chatId, const string& text, bool disableWe
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendMessage", args));
}
-Message::Ptr Api::forwardMessage(int64_t chatId, int64_t fromChatId, int32_t messageId) const {
+Message::Ptr Api::forwardMessage(int64_t chatId, int64_t fromChatId, int32_t messageId, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("from_chat_id", fromChatId));
args.push_back(HttpReqArg("message_id", messageId));
+ if (disableNotification){
+ args.push_back(HttpReqArg("disable_notification", disableNotification));
+ }
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("forwardMessage", args));
}
-Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr& photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr& photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName));
@@ -78,10 +88,13 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr& photo, const s
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("sendPhoto", args));
}
-Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("photo", photoId));
@@ -94,42 +107,63 @@ Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string&
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("sendPhoto", args));
}
-Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr& audio, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName));
if (duration) {
args.push_back(HttpReqArg("duration", duration));
}
+ if (!performer.empty()){
+ args.push_back(HttpReqArg("performer", performer));
+ }
+ if (!title.empty()){
+ args.push_back(HttpReqArg("title", title));
+ }
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("sendAudio", args));
}
-Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("audio", audioId));
if (duration) {
args.push_back(HttpReqArg("duration", duration));
}
+ if (!performer.empty()){
+ args.push_back(HttpReqArg("performer", performer));
+ }
+ if (!title.empty()){
+ args.push_back(HttpReqArg("title", title));
+ }
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("sendAudio", args));
}
-Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("document", document->data, true, document->mimeType, document->fileName));
@@ -139,10 +173,13 @@ Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr& document, i
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("sendDocument", args));
}
-Message::Ptr Api::sendDocument(int64_t chatId, const string& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendDocument(int64_t chatId, const string& document, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("document", document));
@@ -152,10 +189,13 @@ Message::Ptr Api::sendDocument(int64_t chatId, const string& document, int32_t r
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("sendDocument", args));
}
-Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("sticker", sticker->data, true, sticker->mimeType, sticker->fileName));
@@ -165,10 +205,13 @@ Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr& sticker, int
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("sendSticker", args));
}
-Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("sticker", stickerId));
@@ -178,10 +221,13 @@ Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t r
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("sendSticker", args));
}
-Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("video", video->data, true, video->mimeType, video->fileName));
@@ -191,10 +237,13 @@ Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr& video, int32_t
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("sendVideo", args));
}
-Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("video", videoId));
@@ -204,10 +253,51 @@ Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, int32_t reply
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("sendVideo", args));
}
-Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup) const {
+Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr& voice, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ args.push_back(HttpReqArg("voice", voice->data, true, voice->mimeType, voice->fileName));
+ if (duration){
+ args.push_back(HttpReqArg("duration", duration));
+ }
+ 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("sendVideo", args));
+}
+
+Message::Ptr Api::sendVoice(int64_t chatId, const std::string& voiceId, int duration, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ args.push_back(HttpReqArg("voice", voiceId));
+ if (duration){
+ args.push_back(HttpReqArg("duration", duration));
+ }
+ 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("sendVideo", args));
+}
+
+Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId, const GenericReply::Ptr& replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("latitude", latitude));
@@ -218,9 +308,52 @@ Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude,
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("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<HttpReqArg> 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<HttpReqArg> 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<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
@@ -252,9 +385,13 @@ vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo
return TgTypeParser::getInstance().parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args));
}
-void Api::setWebhook(const string& url) const {
+void Api::setWebhook(const string& url, const InputFile::Ptr& certificate) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("url", url));
+ if (!url.empty())
+ args.push_back(HttpReqArg("url", url));
+ if (certificate != nullptr)
+ args.push_back(HttpReqArg("certificate", certificate->data, true, certificate->mimeType, certificate->fileName));
+
sendRequest("setWebhook", args);
}
@@ -270,6 +407,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<HttpReqArg> 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<HttpReqArg> 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<HttpReqArg>& args) const {
string url = "https://api.telegram.org/bot";
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 6672c04..f58bca5 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -350,6 +350,7 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const ptree& data) const {
result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message");
result->inlineQuery = tryParseJson<InlineQuery>(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query");
result->chosenInlineResult = tryParseJson<ChosenInlineResult>(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result");
+ result->callbackQuery = tryParseJson<CallbackQuery>(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query");
return result;
}
@@ -363,6 +364,7 @@ string TgTypeParser::parseUpdate(const Update::Ptr& object) const {
appendToJson(result, "message", parseMessage(object->message));
appendToJson(result, "inline_query", parseInlineQuery(object->inlineQuery));
appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult));
+ appendToJson(result, "callback_query", parseCallbackQuery(object->callbackQuery));
result.erase(result.length() - 1);
result += '}';
return result;
@@ -473,8 +475,10 @@ GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::propert
return static_pointer_cast<GenericReply>(parseJsonAndGetForceReply(data));
} else if (data.find("hide_keyboard") != data.not_found()) {
return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardHide(data));
- } else {
+ } else if (data.find("keyboard") != data.not_found()) {
return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardMarkup(data));
+ } else if (data.find("inline_keyboard") != data.not_found()) {
+ return static_pointer_cast<GenericReply>(parseJsonAndGetInlineKeyboardMarkup(data));
}
}
@@ -486,8 +490,10 @@ std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) con
return parseForceReply(static_pointer_cast<ForceReply>(object));
} else if (dynamic_pointer_cast<ReplyKeyboardHide>(object) != nullptr) {
return parseReplyKeyboardHide(static_pointer_cast<ReplyKeyboardHide>(object));
- } else {
+ } else if (dynamic_pointer_cast<ReplyKeyboardMarkup>(object) != nullptr){
return parseReplyKeyboardMarkup(static_pointer_cast<ReplyKeyboardMarkup>(object));
+ } else if (dynamic_pointer_cast<InlineKeyboardMarkup>(object) != nullptr){
+ return parseInlineKeyboardMarkup(static_pointer_cast<InlineKeyboardMarkup>(object));
}
}
@@ -731,6 +737,85 @@ std::string TgTypeParser::parseChosenInlineResult(const ChosenInlineResult::Ptr&
return result;
}
+CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const {
+ CallbackQuery::Ptr result(new CallbackQuery);
+ result->id = data.get<string>("id");
+ result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
+ result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message");
+ result->inlineMessageId = data.get<string>("inline_message_id", "");
+ result->data = data.get<string>("data", "");
+ return result;
+}
+
+std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) const {
+ if (!object){
+ return "";
+ }
+
+ string result;
+ result += '{';
+ appendToJson(result, "id", object->id);
+ appendToJson(result, "from", parseUser(object->from));
+ appendToJson(result, "message", parseMessage(object->message));
+ appendToJson(result, "inline_message_id", object->inlineMessageId);
+ appendToJson(result, "data", object->data);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+InlineKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const {
+ InlineKeyboardMarkup::Ptr result(new InlineKeyboardMarkup);
+ for (const boost::property_tree::ptree::value_type& item : data.find("inline_keyboard")->second){
+ result->inlineKeyboard.push_back(parseJsonAndGetArray<InlineKeyboardButton>(&TgTypeParser::parseJsonAndGetInlineKeyboardButton, item.second));
+ }
+ return result;
+}
+
+std::string TgTypeParser::parseInlineKeyboardMarkup(const InlineKeyboardMarkup::Ptr& object) const {
+ if (!object){
+ return "";
+ }
+ string result;
+ result += '{';
+ result += "\"inline_keyboard\":[";
+ for (vector<InlineKeyboardButton::Ptr>& item : object->inlineKeyboard){
+ result += '[';
+ for (InlineKeyboardButton::Ptr& innerItem : item){
+ result += parseInlineKeyboardButton(innerItem);
+ result += ',';
+ }
+ result.erase(result.length() - 1);
+ result += "],";
+ }
+ result.erase(result.length() - 1);
+ result += "]}";
+ return result;
+}
+
+InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const {
+ InlineKeyboardButton::Ptr result(new InlineKeyboardButton);
+ result->text = data.get<string>("text");
+ result->url = data.get<string>("url", "");
+ result->callbackData = data.get<string>("callback_data", "");
+ result->switchInlineQuery = data.get<string>("switch_inline_query", "");
+ return result;
+}
+std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const {
+ if (!object){
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "text", object->text);
+ appendToJson(result, "url", object->url);
+ appendToJson(result, "callback_data", object->callbackData);
+ appendToJson(result, "switch_inline_query", object->switchInlineQuery);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
void TgTypeParser::appendToJson(string& json, const string& varName, const string& value) const {
if (value.empty()) {
return;