summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsebest <sebest@seba.seba>2020-05-25 15:49:44 -0300
committersebest <sebest@seba.seba>2020-05-25 15:49:44 -0300
commitffc3c38882d669ea6b2abeea5c0f7c7b322fa6e7 (patch)
tree0394904a1d5c09662825e77ee9ad6ec137b8ee64 /src
parent6436825328cd3bf4a1c964bc84638bc93cfaff1e (diff)
* add SetMyCommand to the api
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp18
-rw-r--r--src/TgTypeParser.cpp17
2 files changed, 35 insertions, 0 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index 6e01807..0a08353 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -1155,6 +1155,22 @@ Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const Inlin
return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args));
}
+bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands) const {
+
+ vector<HttpReqArg> args;
+ args.reserve(5);
+
+ string commandsJson = _tgTypeParser.parseArray<BotCommand>(&TgTypeParser::parseBotCommand, commands);
+ args.emplace_back("commands", commandsJson);
+
+ return sendRequest("setMyCommands",args).get<bool>("",false);
+}
+
+std::vector<BotCommand::Ptr> Api::getMyCommands() const
+{
+ return _tgTypeParser.parseJsonAndGetArray<BotCommand>(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands"));
+}
+
ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) const {
string url = "https://api.telegram.org/bot";
url += _token;
@@ -1189,4 +1205,6 @@ string Api::downloadFile(const string& filePath, const std::vector<HttpReqArg>&
return serverResponse;
}
+
+
}
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 06a2b2a..95c60c9 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -2026,6 +2026,23 @@ string TgTypeParser::parseLabeledPrice(const LabeledPrice::Ptr& object) const {
return result;
}
+BotCommand::Ptr TgTypeParser::parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const {
+ auto result(make_shared<BotCommand>());
+ result->command = data.get("command", "");
+ result->description = data.get("description","");
+ return result;
+}
+
+string TgTypeParser::parseBotCommand(const BotCommand::Ptr& object) const {
+ std::string result;
+ result += '{';
+ appendToJson(result, "command", object->command);
+ appendToJson(result, "description", object->description);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
OrderInfo::Ptr TgTypeParser::parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const {
auto result(make_shared<OrderInfo>());
result->name = data.get<string>("name", "");