summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrea Giove <andreagiove@outlook.com>2016-04-17 21:10:23 +0200
committerAndrea Giove <andreagiove@outlook.com>2016-04-17 21:10:23 +0200
commitd134bf795a293a641655630bdd8ad44b5b70c1ae (patch)
tree740a4c04dd2394150148b1c4bb1323bc2ba86d4b /include
parent730407e8df5031d19a097be4e3e597f2f3b868fd (diff)
Added implementation to Inline Keyboard and added a new event broadcaster
Diffstat (limited to 'include')
-rw-r--r--include/tgbot/EventBroadcaster.h19
-rw-r--r--include/tgbot/EventHandler.h2
-rw-r--r--include/tgbot/TgTypeParser.h9
-rw-r--r--include/tgbot/types/CallbackQuery.h52
-rw-r--r--include/tgbot/types/InlineKeyboardButton.h43
-rw-r--r--include/tgbot/types/InlineKeyboardMarkup.h32
-rw-r--r--include/tgbot/types/Update.h6
7 files changed, 163 insertions, 0 deletions
diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h
index d97dbbb..12daef3 100644
--- a/include/tgbot/EventBroadcaster.h
+++ b/include/tgbot/EventBroadcaster.h
@@ -31,6 +31,7 @@
#include "tgbot/types/Message.h"
#include "tgbot/types/InlineQuery.h"
#include "tgbot/types/ChosenInlineResult.h"
+#include "tgbot/types/CallbackQuery.h"
namespace TgBot {
@@ -48,6 +49,7 @@ public:
typedef std::function<void (const Message::Ptr&)> MessageListener;
typedef std::function<void (const InlineQuery::Ptr&)> InlineQueryListener;
typedef std::function<void (const ChosenInlineResult::Ptr&)> ChosenInlineResultListener;
+ typedef std::function<void (const CallbackQuery::Ptr&)> CallbackQueryListener;
/**
* Registers listener which receives all messages which the bot can ever receive.
@@ -82,14 +84,26 @@ public:
_onNonCommandMessageListeners.push_back(listener);
}
+ /**
+ * Registers listener which receives all the inline query.
+ * @param listener Listener.
+ */
inline void onInlineQuery(const InlineQueryListener& listener) {
_onInlineQueryListeners.push_back(listener);
}
+ /**
+ * Registers listener which receives all the chosen inline result.
+ * @param listener Listener.
+ */
inline void onChosenInlineResult(const ChosenInlineResultListener& listener){
_onChosenInlineResultListeners.push_back(listener);
}
+ inline void onCallbackQuery(const CallbackQueryListener& listener){
+ _onCallbackQueryListeners.push_back(listener);
+ }
+
private:
template<typename ListenerType, typename ObjectType>
inline void broadcast(const std::vector<ListenerType>& listeners, const ObjectType& object) const {
@@ -130,12 +144,17 @@ private:
broadcast<ChosenInlineResultListener, ChosenInlineResult::Ptr>(_onChosenInlineResultListeners, result);
}
+ inline void broadcastCallbackQuery(const CallbackQuery::Ptr& result) const {
+ broadcast<CallbackQueryListener, CallbackQuery::Ptr>(_onCallbackQueryListeners, result);
+ }
+
std::vector<MessageListener> _onAnyMessageListeners;
std::map<std::string, MessageListener> _onCommandListeners;
std::vector<MessageListener> _onUnknownCommandListeners;
std::vector<MessageListener> _onNonCommandMessageListeners;
std::vector<InlineQueryListener> _onInlineQueryListeners;
std::vector<ChosenInlineResultListener> _onChosenInlineResultListeners;
+ std::vector<CallbackQueryListener> _onCallbackQueryListeners;
};
}
diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h
index 64f74cd..63ecde3 100644
--- a/include/tgbot/EventHandler.h
+++ b/include/tgbot/EventHandler.h
@@ -67,6 +67,8 @@ public:
_broadcaster->broadcastInlineQuery(update->inlineQuery);
if (update->chosenInlineResult != NULL)
_broadcaster->broadcastChosenInlineResult(update->chosenInlineResult);
+ if (update->callbackQuery != NULL)
+ _broadcaster->broadcastCallbackQuery(update->callbackQuery);
if (update->message != NULL)
handleMessage(update->message);
}
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index f52d106..17e9553 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -52,6 +52,9 @@
#include "tgbot/types/InlineQueryResultMpeg4Gif.h"
#include "tgbot/types/InlineQueryResultVideo.h"
#include "tgbot/types/ChosenInlineResult.h"
+#include "tgbot/types/CallbackQuery.h"
+#include "tgbot/types/InlineKeyboardMarkup.h"
+#include "tgbot/types/InlineKeyboardButton.h"
namespace TgBot {
@@ -114,6 +117,12 @@ public:
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;
+ CallbackQuery::Ptr parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const;
+ std::string parseCallbackQuery(const CallbackQuery::Ptr& object) const;
+ InlineKeyboardMarkup::Ptr parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const;
+ std::string parseInlineKeyboardMarkup(const InlineKeyboardMarkup::Ptr& object) const;
+ InlineKeyboardButton::Ptr parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const;
+ std::string parseInlineKeyboardButton(const InlineKeyboardButton::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/CallbackQuery.h b/include/tgbot/types/CallbackQuery.h
new file mode 100644
index 0000000..5f6871d
--- /dev/null
+++ b/include/tgbot/types/CallbackQuery.h
@@ -0,0 +1,52 @@
+//
+// Created by Andrea Giove on 17/04/16.
+//
+
+#ifndef TGBOT_CALLBACKQUERY_H
+#define TGBOT_CALLBACKQUERY_H
+
+#include <memory>
+#include <string>
+
+#include "tgbot/types/User.h"
+#include "tgbot/types/Message.h"
+
+namespace TgBot {
+
+/**
+ * This object represents an incoming callback query from a callback button in an inline keyboard.
+ * @ingroup types
+ */
+class CallbackQuery {
+public:
+ typedef std::shared_ptr<CallbackQuery> Ptr;
+
+ /**
+ * Unique identifier for this query.
+ */
+ std::string id;
+
+ /**
+ * Sender.
+ */
+ User::Ptr from;
+
+ /**
+ * Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old.
+ */
+ Message::Ptr message;
+
+ /**
+ * Optional. Identifier of the message sent via the bot in inline mode, that originated the query.
+ */
+ std::string inlineMessageId;
+
+ /**
+ * Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
+ */
+ std::string data;
+
+};
+}
+
+#endif //TGBOT_CALLBACKQUERY_H
diff --git a/include/tgbot/types/InlineKeyboardButton.h b/include/tgbot/types/InlineKeyboardButton.h
new file mode 100644
index 0000000..1a71341
--- /dev/null
+++ b/include/tgbot/types/InlineKeyboardButton.h
@@ -0,0 +1,43 @@
+//
+// Created by Andrea Giove on 17/04/16.
+//
+
+#ifndef TGBOT_INLINEKEYBOARDBUTTON_H
+#define TGBOT_INLINEKEYBOARDBUTTON_H
+
+#include <string>
+#include <memory>
+
+namespace TgBot {
+
+/**
+ * This object represents one button of an inline keyboard. You must use exactly one of the optional fields.
+ * @ingroup types
+ */
+class InlineKeyboardButton {
+public:
+ typedef std::shared_ptr<InlineKeyboardButton> Ptr;
+
+ /**
+ * Label text on the button
+ */
+ std::string text;
+
+ /**
+ * Optional. HTTP url to be opened when button is pressed.
+ */
+ std::string url;
+
+ /**
+ * Optional. Data to be sent in a callback query to the bot when button is pressed.
+ */
+ std::string callbackData;
+
+ /**
+ * Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
+ */
+ std::string switchInlineQuery;
+};
+}
+
+#endif //TGBOT_INLINEKEYBOARDBUTTON_H
diff --git a/include/tgbot/types/InlineKeyboardMarkup.h b/include/tgbot/types/InlineKeyboardMarkup.h
new file mode 100644
index 0000000..9097fa5
--- /dev/null
+++ b/include/tgbot/types/InlineKeyboardMarkup.h
@@ -0,0 +1,32 @@
+//
+// Created by Andrea Giove on 17/04/16.
+//
+
+#ifndef TGBOT_INLINEKEYBOARDMARKUP_H
+#define TGBOT_INLINEKEYBOARDMARKUP_H
+
+#include <vector>
+#include <memory>
+
+#include "tgbot/types/GenericReply.h"
+#include "tgbot/types/InlineKeyboardButton.h"
+
+namespace TgBot {
+
+/**
+ * This object represents an inline keyboard that appears right next to the message it belongs to.
+ * @ingroup types
+ */
+class InlineKeyboardMarkup : public GenericReply {
+public:
+ typedef std::shared_ptr<InlineKeyboardMarkup> Ptr;
+
+ /**
+ * Array of button rows, each represented by an Array of InlineKeyboardButton objects.
+ */
+ std::vector<std::vector<InlineKeyboardButton::Ptr>> inlineKeyboard;
+
+};
+}
+
+#endif //TGBOT_INLINEKEYBOARDMARKUP_H
diff --git a/include/tgbot/types/Update.h b/include/tgbot/types/Update.h
index 9ae8d73..7a3c106 100644
--- a/include/tgbot/types/Update.h
+++ b/include/tgbot/types/Update.h
@@ -28,6 +28,7 @@
#include "tgbot/types/Message.h"
#include "tgbot/types/InlineQuery.h"
#include "tgbot/types/ChosenInlineResult.h"
+#include "tgbot/types/CallbackQuery.h"
namespace TgBot {
@@ -59,6 +60,11 @@ public:
* Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
*/
ChosenInlineResult::Ptr chosenInlineResult;
+
+ /**
+ * Optional. New incoming callback query.
+ */
+ CallbackQuery::Ptr callbackQuery;
};
}