From 67a543eb596b68a166d7f790ea27d5d4e70e10b7 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sat, 26 Mar 2016 19:16:34 +0100 Subject: Updated Message class --- include/tgbot/types/Message.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include/tgbot') diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index daedf03..ea53cf3 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -114,6 +114,8 @@ public: */ Video::Ptr video; + // TODO voice + /** * Optional. Message is a shared contact, information about the contact. */ @@ -158,6 +160,27 @@ public: * Optional. Text description of the photo or the video. */ std::string caption; + + /** + * Optional. Service message: the supergroup has been created. + */ + bool supergroupChatCreated; + + /** + * Optional. Service message: the channel has been created. + */ + bool channelChatCreated; + + /** + * Optional. The group has been migrated to a supergroup with the specified identifier, not exceeding 1e13 by absolute value. + */ + int64_t migrateToChatId; + + /** + * Optional. The supergroup has been migrated from a group with the specified identifier, not exceeding 1e13 by absolute value + */ + int64_t migrateFromChatId; + }; } -- cgit v1.2.3 From f889903cd7132ce39e81da15d2f335ac511b2e1f Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sun, 27 Mar 2016 11:16:28 +0200 Subject: Add new types and new event broadcaster for support the inline mode. --- include/tgbot/EventBroadcaster.h | 44 ++++++++++++++---- include/tgbot/EventHandler.h | 42 ++++++++++------- include/tgbot/TgTypeParser.h | 24 ++++++++++ include/tgbot/types/ChosenInlineResult.h | 40 ++++++++++++++++ include/tgbot/types/InlineQuery.h | 46 ++++++++++++++++++ include/tgbot/types/InlineQueryResult.h | 62 +++++++++++++++++++++++++ include/tgbot/types/InlineQueryResultArticle.h | 54 +++++++++++++++++++++ include/tgbot/types/InlineQueryResultGif.h | 50 ++++++++++++++++++++ include/tgbot/types/InlineQueryResultMpeg4Gif.h | 46 ++++++++++++++++++ include/tgbot/types/InlineQueryResultPhoto.h | 54 +++++++++++++++++++++ include/tgbot/types/InlineQueryResultVideo.h | 55 ++++++++++++++++++++++ include/tgbot/types/Update.h | 12 +++++ 12 files changed, 504 insertions(+), 25 deletions(-) create mode 100644 include/tgbot/types/ChosenInlineResult.h create mode 100644 include/tgbot/types/InlineQuery.h create mode 100644 include/tgbot/types/InlineQueryResult.h create mode 100644 include/tgbot/types/InlineQueryResultArticle.h create mode 100644 include/tgbot/types/InlineQueryResultGif.h create mode 100644 include/tgbot/types/InlineQueryResultMpeg4Gif.h create mode 100644 include/tgbot/types/InlineQueryResultPhoto.h create mode 100644 include/tgbot/types/InlineQueryResultVideo.h (limited to 'include/tgbot') diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h index 3ec8865..d97dbbb 100644 --- a/include/tgbot/EventBroadcaster.h +++ b/include/tgbot/EventBroadcaster.h @@ -29,6 +29,8 @@ #include #include "tgbot/types/Message.h" +#include "tgbot/types/InlineQuery.h" +#include "tgbot/types/ChosenInlineResult.h" namespace TgBot { @@ -44,6 +46,8 @@ friend EventHandler; public: typedef std::function MessageListener; + typedef std::function InlineQueryListener; + typedef std::function ChosenInlineResultListener; /** * Registers listener which receives all messages which the bot can ever receive. @@ -78,13 +82,29 @@ public: _onNonCommandMessageListeners.push_back(listener); } + inline void onInlineQuery(const InlineQueryListener& listener) { + _onInlineQueryListeners.push_back(listener); + } + + inline void onChosenInlineResult(const ChosenInlineResultListener& listener){ + _onChosenInlineResultListeners.push_back(listener); + } + private: - inline void broadcastAnyMessage(const Message::Ptr& message) const { - for (const MessageListener& item : _onAnyMessageListeners) { - item(message); + template + inline void broadcast(const std::vector& listeners, const ObjectType& object) const { + if (!object) + return; + + for (const ListenerType& item : listeners) { + item(object); } } + inline void broadcastAnyMessage(const Message::Ptr& message) const { + broadcast(_onAnyMessageListeners, message); + } + inline bool broadcastCommand(const std::string command, const Message::Ptr& message) const { std::map::const_iterator iter = _onCommandListeners.find(command); if (iter == _onCommandListeners.end()) { @@ -95,21 +115,27 @@ private: } inline void broadcastUnknownCommand(const Message::Ptr& message) const { - for (const MessageListener& item : _onUnknownCommandListeners) { - item(message); - } + broadcast(_onUnknownCommandListeners, message); } inline void broadcastNonCommandMessage(const Message::Ptr& message) const { - for (const MessageListener& item : _onNonCommandMessageListeners) { - item(message); - } + broadcast(_onNonCommandMessageListeners, message); + } + + inline void broadcastInlineQuery(const InlineQuery::Ptr& query) const { + broadcast(_onInlineQueryListeners, query); + } + + inline void broadcastChosenInlineResult(const ChosenInlineResult::Ptr& result) const { + broadcast(_onChosenInlineResultListeners, result); } std::vector _onAnyMessageListeners; std::map _onCommandListeners; std::vector _onUnknownCommandListeners; std::vector _onNonCommandMessageListeners; + std::vector _onInlineQueryListeners; + std::vector _onChosenInlineResultListeners; }; } diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h index bb277a8..aee230a 100644 --- a/include/tgbot/EventHandler.h +++ b/include/tgbot/EventHandler.h @@ -31,34 +31,44 @@ namespace TgBot { class EventHandler { -public: - explicit EventHandler(const EventBroadcaster* broadcaster) : _broadcaster(broadcaster) { - } - - inline void handleUpdate(const Update::Ptr& update) const { + inline void handleMessage(const Message::Ptr& message){ _broadcaster->broadcastAnyMessage(update->message); - if (StringTools::startsWith(update->message->text, "/")) { + + if (StringTools::startsWith(message->text, "/")) { unsigned long splitPosition; - unsigned long spacePosition = update->message->text.find(' '); - unsigned long atSymbolPosition = update->message->text.find('@'); - if (spacePosition == update->message->text.npos) { - if (atSymbolPosition == update->message->text.npos) { - splitPosition = update->message->text.size(); + unsigned long spacePosition = message->text.find(' '); + unsigned long atSymbolPosition = message->text.find('@'); + if (spacePosition == message->text.npos) { + if (atSymbolPosition == message->text.npos) { + splitPosition = message->text.size(); } else { splitPosition = atSymbolPosition; } - } else if (atSymbolPosition == update->message->text.npos) { + } else if (atSymbolPosition == message->text.npos) { splitPosition = spacePosition; } else { splitPosition = std::min(spacePosition, atSymbolPosition); } - std::string command = update->message->text.substr(1, splitPosition - 1); - if (!_broadcaster->broadcastCommand(command, update->message)) { - _broadcaster->broadcastUnknownCommand(update->message); + std::string command = message->text.substr(1, splitPosition - 1); + if (!_broadcaster->broadcastCommand(command, message)) { + _broadcaster->broadcastUnknownCommand(message); } } else { - _broadcaster->broadcastNonCommandMessage(update->message); + _broadcaster->broadcastNonCommandMessage(message); } + }; + +public: + explicit EventHandler(const EventBroadcaster* broadcaster) : _broadcaster(broadcaster) { + } + + inline void handleUpdate(const Update::Ptr& update) const { + if (update->inlineQuery != NULL) + _broadcaster->broadcastInlineQuery(update->inlineQuery); + if (update->chosenInlineResult != NULL) + _broadcaster->broadcastChosenInlineResult(update->chosenInlineResult); + if (update->message != NULL) + handleMessag(update->message); } private: diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 670e35e..f52d106 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -44,6 +44,14 @@ #include "tgbot/types/ReplyKeyboardHide.h" #include "tgbot/types/ForceReply.h" #include "tgbot/types/GenericReply.h" +#include "tgbot/types/InlineQuery.h" +#include "tgbot/types/InlineQueryResult.h" +#include "tgbot/types/InlineQueryResultArticle.h" +#include "tgbot/types/InlineQueryResultPhoto.h" +#include "tgbot/types/InlineQueryResultGif.h" +#include "tgbot/types/InlineQueryResultMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultVideo.h" +#include "tgbot/types/ChosenInlineResult.h" namespace TgBot { @@ -90,6 +98,22 @@ public: std::string parseForceReply(const ForceReply::Ptr& object) const; GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const; std::string parseGenericReply(const GenericReply::Ptr& object) const; + InlineQuery::Ptr parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const; + std::string parseInlineQuery(const InlineQuery::Ptr& object) const; + InlineQueryResult::Ptr parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResult(const InlineQueryResult::Ptr& object) const; + InlineQueryResultArticle::Ptr parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const; + InlineQueryResultPhoto::Ptr parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const; + InlineQueryResultGif::Ptr parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const; + InlineQueryResultMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultMpeg4Gif(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultMpeg4Gif(const InlineQueryResultMpeg4Gif::Ptr& object) const; + InlineQueryResultVideo::Ptr parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const; + std::string parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const; + ChosenInlineResult::Ptr parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const; + std::string parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const; inline boost::property_tree::ptree parseJson(const std::string& json) const { boost::property_tree::ptree tree; diff --git a/include/tgbot/types/ChosenInlineResult.h b/include/tgbot/types/ChosenInlineResult.h new file mode 100644 index 0000000..3c71496 --- /dev/null +++ b/include/tgbot/types/ChosenInlineResult.h @@ -0,0 +1,40 @@ +// +// Created by Andrea Giove on 27/03/16. +// + +#ifndef TGBOT_CHOSENINLINERESULT_H +#define TGBOT_CHOSENINLINERESULT_H + +#include +#include + +#include "tgbot/types/User.h" + +namespace TgBot { + +/** + * This object represents a result of an inline query that was chosen by the user and sent to their chat partner. + * @ingroup types + */ +class ChosenInlineResult { +public: + typedef std::shared_ptr Ptr; + + /** + * The unique identifier for the result that was chosen. + */ + std::string resultId; + + /** + * The user that chose the result. + */ + User::Ptr user; + + /** + * The query that was used to obtain the result. + */ + std::string query; +}; +} + +#endif //TGBOT_CHOSENINLINERESULT_H diff --git a/include/tgbot/types/InlineQuery.h b/include/tgbot/types/InlineQuery.h new file mode 100644 index 0000000..a469ea7 --- /dev/null +++ b/include/tgbot/types/InlineQuery.h @@ -0,0 +1,46 @@ +// +// Created by Andrea Giove on 26/03/16. +// + +#ifndef TGBOT_INLINEQUERY_H +#define TGBOT_INLINEQUERY_H + +#include +#include + +#include "tgbot/types/User.h" + +namespace TgBot { + +/** + * This object represents an incoming inline query. + * @ingroup types + */ +class InlineQuery { +public: + typedef std::shared_ptr Ptr; + + /** + * Unique query identifier. + */ + std::string id; + + /** + * Sender. + */ + User::Ptr from; + + /** + * Text of the query. + */ + std::string query; + + /** + * Offset of the results to be returned. + */ + std::string offset; +}; + +} + +#endif //TGBOT_INLINEQUERY_H diff --git a/include/tgbot/types/InlineQueryResult.h b/include/tgbot/types/InlineQueryResult.h new file mode 100644 index 0000000..b8309dc --- /dev/null +++ b/include/tgbot/types/InlineQueryResult.h @@ -0,0 +1,62 @@ +// +// Created by Andrea Giove on 26/03/16. +// + +#ifndef TGBOT_INLINEQUERYRESULT_H +#define TGBOT_INLINEQUERYRESULT_H + +#include +#include + +namespace TgBot { + +/** + * This abstract class is base of all inline query results. + * @ingroup types + */ +class InlineQueryResult { +public: + typedef std::shared_ptr Ptr; + + virtual ~InlineQueryResult() { } + + /** + * Type of the result. + */ + std::string type; + + /** + * Unique identifier for this result. (1-64 bytes) + */ + std::string id; + + /** + * Optional. Title of the result. + */ + std::string title; + + /** + * Text of the message t be sent. (1-4096 characters) + */ + std::string messageText; + + /** + * Optional. Send Markdown or HTML, if you want Telegram apps to + * show bold, italic, fixed-width text or inline URLs in your bot's message. + */ + std::string parseMode; + + /** + * Optional. Disables link previews for links in the send message. + */ + bool disableWebPagePreview; + + /** + * Optional. Url of the thumbnail for the result. + */ + std::string thumbUrl; + +}; +} + +#endif //TGBOT_INLINEQUERYRESULT_H diff --git a/include/tgbot/types/InlineQueryResultArticle.h b/include/tgbot/types/InlineQueryResultArticle.h new file mode 100644 index 0000000..9d0b043 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultArticle.h @@ -0,0 +1,54 @@ +// +// Created by Andrea Giove on 26/03/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTARTICLE_H +#define TGBOT_INLINEQUERYRESULTARTICLE_H + +#include +#include + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to an article of web page. + * @ingroup types + */ +class InlineQueryResultArticle : public InlineQueryResult { +public: + static const std::string TYPE = "article"; + + typedef std::shared_ptr Ptr; + + InlineQueryResultArticle() : type(TYPE) {}; + + /** + * Optional. URL of the result. + */ + std::string url; + + /** + * Optional. Pass True if you don't want the URL to be shown in the message. + */ + bool hideUrl; + + /** + * Optional. Short description of the result. + */ + std::string description; + + /** + * Optional. Thumbnail width. + */ + int32_t thumbWidth; + + /** + * Optinal. Thumbnail height + */ + int32_t thumbHeight; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTARTICLE_H diff --git a/include/tgbot/types/InlineQueryResultGif.h b/include/tgbot/types/InlineQueryResultGif.h new file mode 100644 index 0000000..06e63ae --- /dev/null +++ b/include/tgbot/types/InlineQueryResultGif.h @@ -0,0 +1,50 @@ +// +// Created by Andrea Giove on 27/03/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTGIF_H +#define TGBOT_INLINEQUERYRESULTGIF_H + +#include +#include + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to an animated GIF file. + * @ingroup types + */ +class InlineQueryResultGif : public InlineQueryResult { +public: + static const std::string TYPE = "gif"; + + typedef std::shared_ptr Ptr; + + InlineQueryResultGif() : type(TYPE) {}; + + /** + * A valid URL for the GIF file. + */ + std::string gifUrl; + + /** + * Optional. Width of the GIF. + */ + int32_t gifWidth; + + /** + * Optional. Height of the GIF. + */ + int32_t gifHeight; + + /** + * Optional. Caption for the GIF file to be sent. + */ + std::string caption; + +}; +} + +#endif //TGBOT_INLINEQUERYRESULTGIF_H diff --git a/include/tgbot/types/InlineQueryResultMpeg4Gif.h b/include/tgbot/types/InlineQueryResultMpeg4Gif.h new file mode 100644 index 0000000..170b0fa --- /dev/null +++ b/include/tgbot/types/InlineQueryResultMpeg4Gif.h @@ -0,0 +1,46 @@ +// +// Created by Andrea Giove on 27/03/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTMPEG4GIF_H +#define TGBOT_INLINEQUERYRESULTMPEG4GIF_H + +namespace TgBot { + +/** + * Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). + * @ingroup types + */ +class InlineQueryResultMpeg4Gif : public InlineQueryResult { +public: + static const std::string TYPE = "mpeg4_gif"; + + typedef std::shared_ptr Ptr; + + InlineQueryResultMpeg4Gif() : type(TYPE) {}; + + /** + * A valid URL for the MP4 file. + */ + std::string mpeg4Url; + + /** + * Optional. Video width. + */ + int32_t mpeg4Width; + + /** + * Optional. Video height. + */ + int32_t mpeg4Height; + + /** + * Optional. Caption of the MPEG-4 file to be sent. + */ + std::string caption; + + +}; +} + +#endif //TGBOT_INLINEQUERYRESULTMPEG4GIF_H diff --git a/include/tgbot/types/InlineQueryResultPhoto.h b/include/tgbot/types/InlineQueryResultPhoto.h new file mode 100644 index 0000000..07e1f35 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultPhoto.h @@ -0,0 +1,54 @@ +// +// Created by Andrea Giove on 26/03/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTPHOTO_H +#define TGBOT_INLINEQUERYRESULTPHOTO_H + +#include +#include + +#include "tgbot/types/InlineQueryResult.h" + +namespace TgBot { + +/** + * Represents a link to a photo. + * @ingroup types + */ +class InlineQueryResultPhoto : public InlineQueryResult { +public: + static const std::string TYPE = "photo"; + + typedef std::shared_ptr Ptr; + + InlineQueryResultPhoto() : type(TYPE) {}; + + /** + * A valid URL of the photo. + */ + std::string photoUrl; + + /** + * Optional. Width of the photo. + */ + int32_t photoWidth; + + /** + * Optional. Height of the photo. + */ + int32_t photoHeight; + + /** + * Optional. Short description of the result. + */ + std::string description; + + /** + * Optional. Caption of the photo to be sent. + */ + std::string caption; +}; +} + +#endif //TGBOT_INLINEQUERYRESULTPHOTO_H diff --git a/include/tgbot/types/InlineQueryResultVideo.h b/include/tgbot/types/InlineQueryResultVideo.h new file mode 100644 index 0000000..f3e5029 --- /dev/null +++ b/include/tgbot/types/InlineQueryResultVideo.h @@ -0,0 +1,55 @@ +// +// Created by Andrea Giove on 27/03/16. +// + +#ifndef TGBOT_INLINEQUERYRESULTVIDEO_H +#define TGBOT_INLINEQUERYRESULTVIDEO_H + +namespace TgBot { + +/** + * Represents link to a page containing an embedded video player or a video file. + * @ingroup types + */ +class InlineQueryResultVideo : public InlineQueryResult { +public: + static const std::string TYPE = "video"; + + typedef std::shared_ptr Ptr; + + InlineQueryResultVideo() : type(TYPE) {}; + + /** + * A valid URL for the embedded video player or video file. + */ + std::string videoUrl; + + /** + * Mime type of the content of video url, "text/html" or "video/mp4". + */ + std::string mimeType; + + /** + * Optional. Video width. + */ + int32_t videoWidth; + + /** + * Optional. Video height. + */ + int32_t videoHeight; + + /** + * Optional. Video duration. + */ + int32_t videoDuration; + + /** + * Optional. Short description of the result. + */ + std::string description; + +}; +} + +#endif //TGBOT_INLINEQUERYRESULTVIDEO_H diff --git a/include/tgbot/types/Update.h b/include/tgbot/types/Update.h index 9bf3a19..9ae8d73 100644 --- a/include/tgbot/types/Update.h +++ b/include/tgbot/types/Update.h @@ -26,6 +26,8 @@ #include #include "tgbot/types/Message.h" +#include "tgbot/types/InlineQuery.h" +#include "tgbot/types/ChosenInlineResult.h" namespace TgBot { @@ -47,6 +49,16 @@ public: * Optional. New incoming message of any kind — text, photo, sticker, etc. */ Message::Ptr message; + + /** + * Optional. New incoming inline query + */ + InlineQuery::Ptr inlineQuery; + + /** + * Optional. The result of an inline query that was chosen by a user and sent to their chat partner. + */ + ChosenInlineResult::Ptr chosenInlineResult; }; } -- cgit v1.2.3 From d2baea74a0ac09db992ab36a861d09caccdab697 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sun, 27 Mar 2016 16:31:11 +0200 Subject: Add answerInlineQuery method --- include/tgbot/Api.h | 14 ++++++++++++++ include/tgbot/net/HttpReqArg.h | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'include/tgbot') 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 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& args = std::vector()) 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 +#include #include @@ -42,6 +43,22 @@ public: { } + template + HttpReqArg(const std::string& name, const std::vector& list, function 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. */ -- cgit v1.2.3 From 405d973af3460ee2860d01c7169cf6749fa98b07 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Sun, 27 Mar 2016 18:24:03 +0200 Subject: Fixed compilation errors --- include/tgbot/Api.h | 2 +- include/tgbot/EventHandler.h | 6 +++--- include/tgbot/net/HttpReqArg.h | 17 +---------------- include/tgbot/types/InlineQueryResultArticle.h | 6 ++++-- include/tgbot/types/InlineQueryResultGif.h | 6 ++++-- include/tgbot/types/InlineQueryResultMpeg4Gif.h | 6 ++++-- include/tgbot/types/InlineQueryResultPhoto.h | 6 ++++-- include/tgbot/types/InlineQueryResultVideo.h | 6 ++++-- 8 files changed, 25 insertions(+), 30 deletions(-) (limited to 'include/tgbot') diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 96dc683..22dbe30 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -242,7 +242,7 @@ public: * @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 results, + void answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset=""); private: diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h index aee230a..64f74cd 100644 --- a/include/tgbot/EventHandler.h +++ b/include/tgbot/EventHandler.h @@ -31,8 +31,8 @@ namespace TgBot { class EventHandler { - inline void handleMessage(const Message::Ptr& message){ - _broadcaster->broadcastAnyMessage(update->message); + void handleMessage(const Message::Ptr& message) const { + _broadcaster->broadcastAnyMessage(message); if (StringTools::startsWith(message->text, "/")) { unsigned long splitPosition; @@ -68,7 +68,7 @@ public: if (update->chosenInlineResult != NULL) _broadcaster->broadcastChosenInlineResult(update->chosenInlineResult); if (update->message != NULL) - handleMessag(update->message); + handleMessage(update->message); } private: diff --git a/include/tgbot/net/HttpReqArg.h b/include/tgbot/net/HttpReqArg.h index 5056e6c..5aa60fd 100644 --- a/include/tgbot/net/HttpReqArg.h +++ b/include/tgbot/net/HttpReqArg.h @@ -25,6 +25,7 @@ #include #include +#include #include @@ -43,22 +44,6 @@ public: { } - template - HttpReqArg(const std::string& name, const std::vector& list, function 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/include/tgbot/types/InlineQueryResultArticle.h b/include/tgbot/types/InlineQueryResultArticle.h index 9d0b043..484ee30 100644 --- a/include/tgbot/types/InlineQueryResultArticle.h +++ b/include/tgbot/types/InlineQueryResultArticle.h @@ -18,11 +18,13 @@ namespace TgBot { */ class InlineQueryResultArticle : public InlineQueryResult { public: - static const std::string TYPE = "article"; + static const std::string TYPE; typedef std::shared_ptr Ptr; - InlineQueryResultArticle() : type(TYPE) {}; + InlineQueryResultArticle() { + this->type = TYPE; + } /** * Optional. URL of the result. diff --git a/include/tgbot/types/InlineQueryResultGif.h b/include/tgbot/types/InlineQueryResultGif.h index 06e63ae..ef82f29 100644 --- a/include/tgbot/types/InlineQueryResultGif.h +++ b/include/tgbot/types/InlineQueryResultGif.h @@ -18,11 +18,13 @@ namespace TgBot { */ class InlineQueryResultGif : public InlineQueryResult { public: - static const std::string TYPE = "gif"; + static const std::string TYPE; typedef std::shared_ptr Ptr; - InlineQueryResultGif() : type(TYPE) {}; + InlineQueryResultGif() { + this->type = TYPE; + } /** * A valid URL for the GIF file. diff --git a/include/tgbot/types/InlineQueryResultMpeg4Gif.h b/include/tgbot/types/InlineQueryResultMpeg4Gif.h index 170b0fa..9807e51 100644 --- a/include/tgbot/types/InlineQueryResultMpeg4Gif.h +++ b/include/tgbot/types/InlineQueryResultMpeg4Gif.h @@ -13,11 +13,13 @@ namespace TgBot { */ class InlineQueryResultMpeg4Gif : public InlineQueryResult { public: - static const std::string TYPE = "mpeg4_gif"; + static const std::string TYPE; typedef std::shared_ptr Ptr; - InlineQueryResultMpeg4Gif() : type(TYPE) {}; + InlineQueryResultMpeg4Gif() { + this->type = TYPE; + } /** * A valid URL for the MP4 file. diff --git a/include/tgbot/types/InlineQueryResultPhoto.h b/include/tgbot/types/InlineQueryResultPhoto.h index 07e1f35..63491f8 100644 --- a/include/tgbot/types/InlineQueryResultPhoto.h +++ b/include/tgbot/types/InlineQueryResultPhoto.h @@ -18,11 +18,13 @@ namespace TgBot { */ class InlineQueryResultPhoto : public InlineQueryResult { public: - static const std::string TYPE = "photo"; + static const std::string TYPE; typedef std::shared_ptr Ptr; - InlineQueryResultPhoto() : type(TYPE) {}; + InlineQueryResultPhoto() { + this->type = TYPE; + } /** * A valid URL of the photo. diff --git a/include/tgbot/types/InlineQueryResultVideo.h b/include/tgbot/types/InlineQueryResultVideo.h index f3e5029..0062d36 100644 --- a/include/tgbot/types/InlineQueryResultVideo.h +++ b/include/tgbot/types/InlineQueryResultVideo.h @@ -13,11 +13,13 @@ namespace TgBot { */ class InlineQueryResultVideo : public InlineQueryResult { public: - static const std::string TYPE = "video"; + static const std::string TYPE; typedef std::shared_ptr Ptr; - InlineQueryResultVideo() : type(TYPE) {}; + InlineQueryResultVideo() { + this->type = TYPE; + }; /** * A valid URL for the embedded video player or video file. -- cgit v1.2.3 From 37e31a89337afd947e41794eeaf78c9d1d2d0b73 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Tue, 29 Mar 2016 14:30:55 +0200 Subject: Included new classes in tgbot.h --- include/tgbot/tgbot.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/tgbot') diff --git a/include/tgbot/tgbot.h b/include/tgbot/tgbot.h index f377d1e..34dc0a9 100644 --- a/include/tgbot/tgbot.h +++ b/include/tgbot/tgbot.h @@ -45,6 +45,14 @@ #include "tgbot/types/User.h" #include "tgbot/types/UserProfilePhotos.h" #include "tgbot/types/Video.h" +#include "tgbot/types/InlineQuery.h" +#include "tgbot/types/InlineQueryResult.h" +#include "tgbot/types/InlineQueryResultArticle.h" +#include "tgbot/types/InlineQueryResultGif.h" +#include "tgbot/types/InlineQueryResultMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultPhoto.h" +#include "tgbot/types/InlineQueryResultVideo.h" +#include "tgbot/types/ChosenInlineResult.h" #include "tgbot/tools/StringTools.h" #include "tgbot/net/HttpClient.h" #include "tgbot/net/HttpParser.h" -- cgit v1.2.3 From de33e2e08049c3698920789f769b7f361414f4b0 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Tue, 29 Mar 2016 17:13:38 +0200 Subject: Edited answerInlineQuery --- include/tgbot/Api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/tgbot') diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 22dbe30..66f41b5 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -243,7 +243,7 @@ public: * @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& results, - int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset=""); + int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset="") const; private: boost::property_tree::ptree sendRequest(const std::string& method, const std::vector& args = std::vector()) const; -- cgit v1.2.3 From 184f0ae9b304a56e044394a96e4ccc45200840c4 Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Tue, 29 Mar 2016 21:24:29 +0200 Subject: Added constructors --- include/tgbot/types/InlineQueryResult.h | 4 ++++ include/tgbot/types/InlineQueryResultArticle.h | 3 +++ include/tgbot/types/InlineQueryResultGif.h | 2 ++ include/tgbot/types/InlineQueryResultMpeg4Gif.h | 2 ++ include/tgbot/types/InlineQueryResultPhoto.h | 2 ++ include/tgbot/types/InlineQueryResultVideo.h | 3 +++ 6 files changed, 16 insertions(+) (limited to 'include/tgbot') diff --git a/include/tgbot/types/InlineQueryResult.h b/include/tgbot/types/InlineQueryResult.h index b8309dc..d3eb968 100644 --- a/include/tgbot/types/InlineQueryResult.h +++ b/include/tgbot/types/InlineQueryResult.h @@ -18,6 +18,10 @@ class InlineQueryResult { public: typedef std::shared_ptr Ptr; + InlineQueryResult() { + this->disableWebPagePreview = false; + } + virtual ~InlineQueryResult() { } /** diff --git a/include/tgbot/types/InlineQueryResultArticle.h b/include/tgbot/types/InlineQueryResultArticle.h index 484ee30..c903255 100644 --- a/include/tgbot/types/InlineQueryResultArticle.h +++ b/include/tgbot/types/InlineQueryResultArticle.h @@ -24,6 +24,9 @@ public: InlineQueryResultArticle() { this->type = TYPE; + this->hideUrl = false; + this->thumbHeight = 0; + this->thumbWidth = 0; } /** diff --git a/include/tgbot/types/InlineQueryResultGif.h b/include/tgbot/types/InlineQueryResultGif.h index ef82f29..8892f56 100644 --- a/include/tgbot/types/InlineQueryResultGif.h +++ b/include/tgbot/types/InlineQueryResultGif.h @@ -24,6 +24,8 @@ public: InlineQueryResultGif() { this->type = TYPE; + this->gifWidth = 0; + this->gifHeight = 0; } /** diff --git a/include/tgbot/types/InlineQueryResultMpeg4Gif.h b/include/tgbot/types/InlineQueryResultMpeg4Gif.h index 9807e51..0ba80aa 100644 --- a/include/tgbot/types/InlineQueryResultMpeg4Gif.h +++ b/include/tgbot/types/InlineQueryResultMpeg4Gif.h @@ -19,6 +19,8 @@ public: InlineQueryResultMpeg4Gif() { this->type = TYPE; + this->mpeg4Width = 0; + this->mpeg4Height = 0; } /** diff --git a/include/tgbot/types/InlineQueryResultPhoto.h b/include/tgbot/types/InlineQueryResultPhoto.h index 63491f8..1c333f6 100644 --- a/include/tgbot/types/InlineQueryResultPhoto.h +++ b/include/tgbot/types/InlineQueryResultPhoto.h @@ -24,6 +24,8 @@ public: InlineQueryResultPhoto() { this->type = TYPE; + this->photoWidth = 0; + this->photoHeight = 0; } /** diff --git a/include/tgbot/types/InlineQueryResultVideo.h b/include/tgbot/types/InlineQueryResultVideo.h index 0062d36..6449c6d 100644 --- a/include/tgbot/types/InlineQueryResultVideo.h +++ b/include/tgbot/types/InlineQueryResultVideo.h @@ -19,6 +19,9 @@ public: InlineQueryResultVideo() { this->type = TYPE; + this->videoWidth = 0; + this->videoHeight = 0; + this->videoDuration = 0; }; /** -- cgit v1.2.3 From b937e88dd43a7708f40af6a3c333046e3121a77a Mon Sep 17 00:00:00 2001 From: Andrea Giove Date: Wed, 30 Mar 2016 14:13:17 +0200 Subject: Fixed ChosenInlineResult issue --- include/tgbot/types/ChosenInlineResult.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/tgbot') diff --git a/include/tgbot/types/ChosenInlineResult.h b/include/tgbot/types/ChosenInlineResult.h index 3c71496..c6d730e 100644 --- a/include/tgbot/types/ChosenInlineResult.h +++ b/include/tgbot/types/ChosenInlineResult.h @@ -28,7 +28,7 @@ public: /** * The user that chose the result. */ - User::Ptr user; + User::Ptr from; /** * The query that was used to obtain the result. -- cgit v1.2.3