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
14};
15
16
18{
19 typedef void(*CallbackType)(const TBMessage &msg);
20//using CallbackType = std::function<void(const TBMessage &msg)>;
21
22struct InlineButton{
23 char *btnName;
24 CallbackType argCallback;
25 InlineButton *nextButton;
26} ;
27
28public:
30 InlineKeyboard(const String& keyboard);
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
61private:
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
InlineKeyboardButtonType
@ KeyboardButtonQuery
@ KeyboardButtonURL
bool addButton(const char *text, const char *command, InlineKeyboardButtonType buttonType, CallbackType onClick=nullptr)
bool addRow(void)
InlineKeyboard(const String &keyboard)
String getJSON(void) const
String getJSONPretty(void) const