summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Kukin <kukin.konstantin@gmail.com>2016-12-30 11:38:22 +0300
committerKonstantin Kukin <kukin.konstantin@gmail.com>2016-12-30 11:38:36 +0300
commit2d7d1a269383ec1db99b6759f9c58ba08d1d29fe (patch)
tree4b6e1422b0675a344f3c83165b6bd9a61caff99b /src
parent33e4184338cc7b9ecd8af36ee0ecaff74020356c (diff)
add Webhook functions
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp36
-rw-r--r--src/TgTypeParser.cpp2
2 files changed, 36 insertions, 2 deletions
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<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 InputFile::Ptr& certificate) const {
+void Api::setWebhook(const string& url, const InputFile::Ptr& certificate, int32_t maxConnection, const StringArrayPtr &allowedUpdates) const {
vector<HttpReqArg> 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<std::string>(
+ [](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<bool>("", false);
+}
+
+WebhookInfo::Ptr Api::getWebhookInfo() const
+{
+ ptree p = sendRequest("getWebhookInfo");
+
+ if (!p.get_child_optional("url"))
+ return nullptr;
+
+ if (p.get<string>("url","")!=string(""))
+ {
+ return TgTypeParser::getInstance().parseJsonAndGetWebhookInfo(p);
+ }
+ else
+ {
+ return nullptr;
+ }
+}
+
void Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
int32_t cacheTime, bool isPersonal, const std::string& nextOffset) const {
vector<HttpReqArg> 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<std::string>("");
}
- , data);
+ , data, "allowed_updates");
return result;
}