diff options
author | Konstantin Kukin <kukin.konstantin@gmail.com> | 2016-12-30 11:38:22 +0300 |
---|---|---|
committer | Konstantin Kukin <kukin.konstantin@gmail.com> | 2016-12-30 11:38:36 +0300 |
commit | 2d7d1a269383ec1db99b6759f9c58ba08d1d29fe (patch) | |
tree | 4b6e1422b0675a344f3c83165b6bd9a61caff99b /src/Api.cpp | |
parent | 33e4184338cc7b9ecd8af36ee0ecaff74020356c (diff) |
add Webhook functions
Diffstat (limited to 'src/Api.cpp')
-rw-r--r-- | src/Api.cpp | 36 |
1 files changed, 35 insertions, 1 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; |