AsyncTelegram2

Loading...
Searching...
No Matches
InlineKeyboard.h
Go to the documentation of this file.
1
2#ifndef INLINE_KEYBOARD
3#define INLINE_KEYBOARD
4
5#define ARDUINOJSON_USE_LONG_LONG 1
6#define ARDUINOJSON_DECODE_UNICODE 1
7#include <ArduinoJson.h>
8// #include <functional>
9#include "DataStructures.h"
10
11 enum InlineKeyboardButtonType {
12 KeyboardButtonURL = 1,
13 KeyboardButtonQuery = 2
14};
15
16
17 class InlineKeyboard
18{
19 typedef void(*CallbackType)(const TBMessage &msg);
20//using CallbackType = std::function<void(const TBMessage &msg)>;
21
22 struct InlineButton{
23 char *btnName;
24 CallbackType argCallback;
25 InlineButton *nextButton;
26} ;
27
28 public:
29 InlineKeyboard();
30 InlineKeyboard(const String& keyboard);
31 ~InlineKeyboard();
32
33 // Get total number of keyboard buttons
34 int getButtonsNumber() ;
35
36 // add a new empty row of buttons
37 // return:
38 // true if no error occurred
39 bool addRow(void);
40
41 // add a button in the current row
42 // params:
43 // text : the text displayed as button label
44 // command: URL (if buttonType is CTBotKeyboardButtonURL)
45 // callback query data (if buttonType is CTBotKeyboardButtonQuery)
46 // return:
47 // true if no error occurred
48 bool addButton(const char* text, const char* command, InlineKeyboardButtonType buttonType, CallbackType onClick = nullptr);
49
50 // generate a string that contains the inline keyboard formatted in a JSON structure.
51 // Useful for CTBot::sendMessage()
52 // returns:
53 // the JSON of the inline keyboard
54 String getJSON(void) const ;
55 String getJSONPretty(void) const;
56
57 inline void clear() {
58 m_json = "{\"inline_keyboard\":[[]]}\"";
59 }
60
61 private:
62 friend class AsyncTelegram2;
63 String m_json;
64 String m_name;
65
66 uint8_t m_buttonsCounter = 0;
67 InlineButton *_firstButton = nullptr;
68 InlineButton *_lastButton = nullptr;
69
70 // Check if a callback function has to be called for a button query reply message
71 void checkCallback(const TBMessage &msg) ;
72
73};
74
75
76
77#endif
DataStructures.h
InlineKeyboardButtonType
InlineKeyboardButtonType
Definition: InlineKeyboard.h:11
KeyboardButtonQuery
@ KeyboardButtonQuery
Definition: InlineKeyboard.h:13
KeyboardButtonURL
@ KeyboardButtonURL
Definition: InlineKeyboard.h:12
AsyncTelegram2
Definition: AsyncTelegram2.h:94
InlineKeyboard
Definition: InlineKeyboard.h:18
InlineKeyboard::addButton
bool addButton(const char *text, const char *command, InlineKeyboardButtonType buttonType, CallbackType onClick=nullptr)
Definition: InlineKeyboard.cpp:35
InlineKeyboard::~InlineKeyboard
~InlineKeyboard()
Definition: InlineKeyboard.cpp:9
InlineKeyboard::addRow
bool addRow(void)
Definition: InlineKeyboard.cpp:11
InlineKeyboard::InlineKeyboard
InlineKeyboard(const String &keyboard)
InlineKeyboard::clear
void clear()
Definition: InlineKeyboard.h:57
InlineKeyboard::InlineKeyboard
InlineKeyboard()
Definition: InlineKeyboard.cpp:4
InlineKeyboard::getButtonsNumber
int getButtonsNumber()
Definition: InlineKeyboard.cpp:86
InlineKeyboard::getJSON
String getJSON(void) const
Definition: InlineKeyboard.cpp:91
InlineKeyboard::getJSONPretty
String getJSONPretty(void) const
Definition: InlineKeyboard.cpp:96
TBMessage
Definition: DataStructures.h:51