summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Giove <andreagiove@outlook.com>2016-03-27 16:31:11 +0200
committerAndrea Giove <andreagiove@outlook.com>2016-03-27 16:31:11 +0200
commitd2baea74a0ac09db992ab36a861d09caccdab697 (patch)
tree35935e0f42891093de0d815622da901891f3941d
parentf889903cd7132ce39e81da15d2f335ac511b2e1f (diff)
Add answerInlineQuery method
-rw-r--r--include/tgbot/Api.h14
-rw-r--r--include/tgbot/net/HttpReqArg.h17
-rw-r--r--src/Api.cpp11
3 files changed, 42 insertions, 0 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index b33cd03..96dc683 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -35,6 +35,7 @@
#include "tgbot/types/InputFile.h"
#include "tgbot/types/UserProfilePhotos.h"
#include "tgbot/types/Update.h"
+#include "tgbot/types/InlineQueryResult.h"
namespace TgBot {
@@ -229,8 +230,21 @@ 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.
*/
+ // TODO Add support to self-signed certificate
void setWebhook(const std::string& url = "") const;
+ /**
+ * Use this method to send answers to an inline query.
+ * No mode that 50 results per query are allowed.
+ * @param inlineQueryId Unique identifier for the answered query.
+ * @param results Array of results for the inline query.
+ * @param cacheTime The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
+ * @param isPersonal Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.
+ * @param nextOffset Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.
+ */
+ void answerInlineQuery(const std::string inlineQueryId, const std::vector<InlineQueryResult::Ptr> results,
+ int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset="");
+
private:
boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const;
diff --git a/include/tgbot/net/HttpReqArg.h b/include/tgbot/net/HttpReqArg.h
index f0e4492..5056e6c 100644
--- a/include/tgbot/net/HttpReqArg.h
+++ b/include/tgbot/net/HttpReqArg.h
@@ -24,6 +24,7 @@
#define TGBOT_HTTPPARAMETER_H
#include <string>
+#include <vector>
#include <boost/lexical_cast.hpp>
@@ -42,6 +43,22 @@ public:
{
}
+ template<typename T>
+ HttpReqArg(const std::string& name, const std::vector<T>& list, function<std::string (const T&)> parsingFunction){
+ this->name = name;
+ value = "[";
+ for (const T& item : list){
+ value += parsingFunction(item);
+ value += ',';
+ }
+ value.erase(this->value.length() - 1);
+ value += ']';
+
+ isFile = false;
+ mimeType = "text/plain";
+ fileName = "";
+ }
+
/**
* Name of an argument.
*/
diff --git a/src/Api.cpp b/src/Api.cpp
index 2e27e1d..47c7882 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -255,6 +255,17 @@ void Api::setWebhook(const string& url) const {
sendRequest("setWebhook", args);
}
+void Api::answerInlineQuery(const std::string inlineQueryId, const std::vector<InlineQueryResult::Ptr> results,
+ int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset=""){
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("inline_query_id", inlineQueryId));
+ args.push_back(HttpReqArg("results", results, TgTypeParser::getInstance().parseInlineQueryResult));
+ args.push_back(HttpReqArg("cache_time", cacheTime));
+ args.push_back(HttpReqArg("is_personal", isPersonal));
+ args.push_back(HttpReqArg("next_offset", nextOffset));
+ sendRequest("answerInlineQuery", args);
+}
+
ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) const {
string url = "https://api.telegram.org/bot";