Cppgram  1.0.0
Easy and modern C++14 Telegram Bot API wrapper
Public Member Functions | Private Attributes | List of all members
Keyboard Class Reference

An helper class to create inline keyboard. More...

#include <keyboard.hpp>

Public Member Functions

 Keyboard ()
 Default constructor for the function. More...
 
bool addButton (const std::string &text, const std::string &data, const EButton &button_type)
 Add a button by passing directly the data. More...
 
bool addButton (const types::KeyboardButton &new_button)
 Add a button by passing a KeyboardButton. More...
 
bool addButton (const std::vector< types::KeyboardButton > &new_buttons)
 Add button by passing a vector of KeyboardButton. More...
 
unsigned short changeRow ()
 The button will be added to the next row from now on. More...
 
void clearKeyboard ()
 Clear the inline keyboard of the object.
 
void get (std::string &reply_markup, const bool &clear_keyboard=true)
 Get keyboard as string. More...
 

Private Attributes

Json::FastWriter writer
 Get keyboard as Json. More...
 

Detailed Description

An helper class to create inline keyboard.

Create inline keyboard, get the reply markup with getKeyboard and pass this to api methods. Each method will check for errors (like missing text in button that will result in an API error). The buttons will be added in the same row in sequence; when the (Telegram) limit of 8 buttons in a row is reached, the buttons will be added to the next row. To change row manually call changeRow().

Constructor & Destructor Documentation

◆ Keyboard()

Keyboard ( )

Default constructor for the function.

Returns
An empty object

Member Function Documentation

◆ addButton() [1/3]

bool addButton ( const std::string &  text,
const std::string &  data,
const EButton button_type 
)

Add a button by passing directly the data.

Parameters
textText label
dataData of the button (depends on the type)
buttonTypeType of the button
Returns
True on success

◆ addButton() [2/3]

bool addButton ( const types::KeyboardButton new_button)

Add a button by passing a KeyboardButton.

Parameters
newButtonThe button to add
Returns
True on success

◆ addButton() [3/3]

bool addButton ( const std::vector< types::KeyboardButton > &  new_buttons)

Add button by passing a vector of KeyboardButton.

Parameters
newButtons
Returns

◆ changeRow()

unsigned short changeRow ( )

The button will be added to the next row from now on.

Returns

◆ get()

void get ( std::string &  reply_markup,
const bool &  clear_keyboard = true 
)

Get keyboard as string.

Pass a string that will be filled with the keyboard

Parameters
reply_markupThe string that will be filled
clearKeyboardClear keyboard after passing it

Member Data Documentation

◆ writer

Json::FastWriter writer
private

Get keyboard as Json.

This method has to be used in answerInlineQuery, cause it accepts only non JSON-serialized value

Returns
The keyboard as JSON

The documentation for this class was generated from the following file: