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