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 --- include/tgbot/Api.h | 18 +++++++++++++++++- include/tgbot/TgTypeParser.h | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'include/tgbot') diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 0a2b7bd..928a017 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -37,6 +37,7 @@ #include "tgbot/types/Update.h" #include "tgbot/types/InlineQueryResult.h" #include "tgbot/types/Venue.h" +#include "tgbot/types/WebhookInfo.h" namespace TgBot { @@ -48,6 +49,8 @@ class Bot; */ class Api { +typedef std::shared_ptr> StringArrayPtr; + friend class Bot; public: @@ -318,7 +321,20 @@ public: * Ports currently supported for Webhooks: 443, 80, 88, 8443. * @param url Optional. HTTPS url to send updates to. Use an empty string to remove webhook integration. */ - void setWebhook(const std::string& url = "", const InputFile::Ptr& certificate = nullptr) const; + void setWebhook(const std::string& url = "", const InputFile::Ptr& certificate = nullptr, int32_t maxConnection = 40, const StringArrayPtr &allowedUpdates = nullptr) const; + + /** + * Use this method to remove webhook integration if you decide to switch back to getUpdates. + * Returns True on success. Requires no parameters. + */ + bool deleteWebhook() const; + + /** + * Use this method to get current webhook status. + * Requires no parameters. On success, returns a WebhookInfo object. + * If the bot is using getUpdates, will return an object with the url field empty. + */ + WebhookInfo::Ptr getWebhookInfo() const; /** * Use this method to send answers to an inline query. diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 48f7338..89c6dec 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -260,9 +260,13 @@ public: } template - std::vector parseJsonAndGetArray(std::function parseFunc, const boost::property_tree::ptree& data) const { + std::vector parseJsonAndGetArray(std::function parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { std::vector result; - for (const std::pair& innerTreeItem : data) { + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { + return result; + } + for (const std::pair& innerTreeItem : treeItem->second) { result.push_back(parseFunc(innerTreeItem.second)); } return result; @@ -300,6 +304,8 @@ public: template std::string parseArray(TgTypeToJsonFunc parseFunc, const std::vector>& objects) const { + if (objects.empty()) + return ""; std::string result; result += '['; for (const std::shared_ptr& item : objects) { @@ -313,6 +319,8 @@ public: template std::string parseArray(std::function parseFunc, const std::vector& objects) const { + if (objects.empty()) + return ""; std::string result; result += '['; for (const T& item : objects) { @@ -326,6 +334,8 @@ public: template std::string parse2DArray(TgTypeToJsonFunc parseFunc, const std::vector>>& objects) const { + if (objects.empty()) + return ""; std::string result; result += '['; for (const std::vector>& item : objects) { -- cgit v1.2.3