summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkukin-konstantin <kukin.konstantin@gmail.com>2017-01-10 17:07:34 +0300
committerkukin-konstantin <kukin.konstantin@gmail.com>2017-01-10 17:07:34 +0300
commitf3aba5cb3cca0f99f2a39d61acd960a836295593 (patch)
treee265993fc4382aadb87eb1ecfd3baa48e4dfa72e
parent429dd74b583e0ac52d50142be493cba532ca017d (diff)
fix ReplyKeyboardMarkup
-rw-r--r--include/tgbot/types/KeyboardButton.h4
-rw-r--r--include/tgbot/types/ReplyKeyboardMarkup.h11
-rw-r--r--src/TgTypeParser.cpp23
3 files changed, 17 insertions, 21 deletions
diff --git a/include/tgbot/types/KeyboardButton.h b/include/tgbot/types/KeyboardButton.h
index 637aced..204c579 100644
--- a/include/tgbot/types/KeyboardButton.h
+++ b/include/tgbot/types/KeyboardButton.h
@@ -31,12 +31,12 @@ public:
* Optional. If True, the user's phone number will be sent as a contact
* when the button is pressed. Available in private chats only
*/
- bool requestContact;
+ bool requestContact = false;
/**
* Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only.
*/
- bool requestLocation;
+ bool requestLocation = false;
};
}
diff --git a/include/tgbot/types/ReplyKeyboardMarkup.h b/include/tgbot/types/ReplyKeyboardMarkup.h
index 92d850e..f6e50db 100644
--- a/include/tgbot/types/ReplyKeyboardMarkup.h
+++ b/include/tgbot/types/ReplyKeyboardMarkup.h
@@ -28,6 +28,7 @@
#include <memory>
#include "tgbot/types/GenericReply.h"
+#include "tgbot/types/KeyboardButton.h"
namespace TgBot {
@@ -41,25 +42,25 @@ public:
typedef std::shared_ptr<ReplyKeyboardMarkup> Ptr;
/**
- * Array of button rows, each represented by an Array of Strings.
+ * Array of button rows, each represented by an Array of KeyboardButton.
*/
- std::vector<std::vector<std::string>> keyboard;
+ std::vector<std::vector<KeyboardButton::Ptr>> keyboard;
/**
* Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
*/
- bool resizeKeyboard;
+ bool resizeKeyboard = false;
/**
* Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false.
*/
- bool oneTimeKeyboard;
+ bool oneTimeKeyboard = false;
/**
* Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
* Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard.
*/
- bool selective;
+ bool selective = false;
};
}
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 45124e2..0952d75 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -442,16 +442,12 @@ string TgTypeParser::parseFile(const File::Ptr& object) const {
ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const {
ReplyKeyboardMarkup::Ptr result(new ReplyKeyboardMarkup);
- for (const pair<const string, ptree>& item : data.find("keyboard")->second) {
- vector<string> array;
- for (const pair<const string, ptree>& innerItem : item.second) {
- array.push_back(innerItem.second.data());
- }
- result->keyboard.push_back(array);
+ for (const boost::property_tree::ptree::value_type& item : data.find("keyboard")->second){
+ result->keyboard.push_back(parseJsonAndGetArray<KeyboardButton>(&TgTypeParser::parseJsonAndGetKeyboardButton, item.second));
}
- result->resizeKeyboard = data.get<bool>("resize_keyboard");
- result->oneTimeKeyboard = data.get<bool>("one_time_keyboard");
- result->selective = data.get<bool>("selective");
+ result->resizeKeyboard = data.get<bool>("resize_keyboard", false);
+ result->oneTimeKeyboard = data.get<bool>("one_time_keyboard", false);
+ result->selective = data.get<bool>("selective", false);
return result;
}
@@ -462,12 +458,11 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt
string result;
result += '{';
result += "\"keyboard\":[";
- for (vector<string>& item : object->keyboard) {
+ for (vector<KeyboardButton::Ptr>& item : object->keyboard) {
result += '[';
- for (string& innerItem : item) {
- result += '"';
- result += innerItem;
- result += "\",";
+ for (KeyboardButton::Ptr& innerItem : item) {
+ result += parseKeyboardButton(innerItem);
+ result += ',';
}
result.erase(result.length() - 1);
result += "],";