summaryrefslogtreecommitdiff
path: root/include/tgbot
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 /include/tgbot
parent33e4184338cc7b9ecd8af36ee0ecaff74020356c (diff)
add Webhook functions
Diffstat (limited to 'include/tgbot')
-rw-r--r--include/tgbot/Api.h18
-rw-r--r--include/tgbot/TgTypeParser.h14
2 files changed, 29 insertions, 3 deletions
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<std::vector<std::string>> 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<typename T>
- std::vector<T> parseJsonAndGetArray(std::function<T(const boost::property_tree::ptree&)> parseFunc, const boost::property_tree::ptree& data) const {
+ std::vector<T> parseJsonAndGetArray(std::function<T(const boost::property_tree::ptree&)> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const {
std::vector<T> result;
- for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : data) {
+ auto treeItem = data.find(keyName);
+ if (treeItem == data.not_found()) {
+ return result;
+ }
+ for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) {
result.push_back(parseFunc(innerTreeItem.second));
}
return result;
@@ -300,6 +304,8 @@ public:
template<typename T>
std::string parseArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::shared_ptr<T>>& objects) const {
+ if (objects.empty())
+ return "";
std::string result;
result += '[';
for (const std::shared_ptr<T>& item : objects) {
@@ -313,6 +319,8 @@ public:
template<typename T>
std::string parseArray(std::function<T(const T&)> parseFunc, const std::vector<T>& objects) const {
+ if (objects.empty())
+ return "";
std::string result;
result += '[';
for (const T& item : objects) {
@@ -326,6 +334,8 @@ public:
template<typename T>
std::string parse2DArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::vector<std::shared_ptr<T>>>& objects) const {
+ if (objects.empty())
+ return "";
std::string result;
result += '[';
for (const std::vector<std::shared_ptr<T>>& item : objects) {