PhpBotFramework  2.0.2
A framework for Telegram Bots' APIs.
Functions | Variables
InlineKeyboard

Handle an inline keyboard to send along with messages. More...

Functions

 PhpBotFramework\Entities\InlineKeyboard::__construct (array $buttons=array())
 Create an inline keyboard object. More...
 
string PhpBotFramework\Entities\InlineKeyboard::get (bool $clear_keyboard=true)
 Get a JSON object containing the inline keyboard. More...
 
array PhpBotFramework\Entities\InlineKeyboard::getArray (bool $clean_keyboard=true)
 Get the array containing the buttons. More...
 
 PhpBotFramework\Entities\InlineKeyboard::addLevelButtons (array ... $buttons)
 Add buttons for the current row. More...
 
 PhpBotFramework\Entities\InlineKeyboard::addButton (string $text, string $data_type, string $data)
 Add a button. More...
 
 PhpBotFramework\Entities\InlineKeyboard::changeRow ()
 Change row for the current keyboard. More...
 
 PhpBotFramework\Entities\InlineKeyboard::clearKeyboard ()
 Clear inline keyboard.
 
 PhpBotFramework\Entities\InlineKeyboard::addListKeyboard (int $index, int $list, $prefix='list')
 Add a list keyboard. More...
 
 PhpBotFramework\Localization\Button::__construct (CoreBot &$bot, array $buttons=array())
 Create an inline keyboard object with localizated buttons. More...
 
string array PhpBotFramework\Localization\Button::getBackButton (bool $json_serialized=true)
 Get a simple Back button with back as callback_data. More...
 
string array PhpBotFramework\Localization\Button::getBackSkipKeyboard (bool $json_serialized=true)
 Get a Back and a Skip buttons inthe same row. More...
 
string array PhpBotFramework\Localization\Button::getChooseLanguageKeyboard (string $prefix='cl', bool $json_serialized=true)
 Get various buttons for set various languages. More...
 

Variables

 PhpBotFramework\Entities\InlineKeyboard::$inline_keyboard
 Stores the array of InlineKeyboardButton.
 
 PhpBotFramework\Localization\Button::$bot
 Stores a reference to the bot that's using the inline keyboard.
 

Detailed Description

Handle an inline keyboard to send along with messages.

Function Documentation

◆ __construct() [1/2]

PhpBotFramework\Localization\Button::__construct ( CoreBot $bot,
array  $buttons = array() 
)

Create an inline keyboard object with localizated buttons.

Parameters
CoreBot$botReferences to the bot that's using the inline keyboard.
array$buttonsButtons passed as inizialization.

◆ __construct() [2/2]

PhpBotFramework\Entities\InlineKeyboard::__construct ( array  $buttons = array())

Create an inline keyboard object.

Parameters
array$buttonsButtons to add to the inline keyboard.

◆ addButton()

PhpBotFramework\Entities\InlineKeyboard::addButton ( string  $text,
string  $data_type,
string  $data 
)

Add a button.

The button will be added next to the last one or in the next row if the bot has reached the limit of buttons per row.

Each row allows eight buttons per row and a maximum of twelve columns.

addButton('Click me!', 'url', 'https://telegram.me');

Parameters
string$textText showed on the button.
string$data_typeThe type of the button data. Select one from these types.
  • url
  • callback_data
  • switch_inline_query
  • switch_inline_query_current_chat
  • callback_game
string$dataData for the type selected.

◆ addLevelButtons()

PhpBotFramework\Entities\InlineKeyboard::addLevelButtons ( array ...  $buttons)

Add buttons for the current row.

Each array sent as parameter requires a text key and one another key (see here) like:

  • url
  • callback_data
  • switch_inline_query
  • switch_inline_query_current_chat
  • callback_game

Each call to this function add one or more button to a row. The next call add buttons on the next row.

There are twelve columns and eight buttons per row.

Let's see an example:

addLevelButtons(['text' => 'Click me!', 'url' => 'https://telegram.me']);

If you want to add more than a button:

addLevelButtons(['text' => 'Button 1', 'url' => 'https://telegram.me/gamedev_ita'], ['text' => 'Button 2', 'url' => 'https://telegram.me/animewallpaper']);
Parameters
array...$buttons One or more arrays which represents buttons.

◆ addListKeyboard()

PhpBotFramework\Entities\InlineKeyboard::addListKeyboard ( int  $index,
int  $list,
  $prefix = 'list' 
)

Add a list keyboard.

A list keyboard can be useful if you want separate data in multiple "pages" and allows users to navigate it easily. The keyboard is generated at runtime.

Parameters
int$indexThe current index of the list.
int$listThe length of the list.
string$prefixPrefix to add at each callback_data of the button. Eg.: 'list/1'.

◆ changeRow()

PhpBotFramework\Entities\InlineKeyboard::changeRow ( )

Change row for the current keyboard.

Change row where the buttons will be saved.

◆ get()

string PhpBotFramework\Entities\InlineKeyboard::get ( bool  $clear_keyboard = true)

Get a JSON object containing the inline keyboard.

Parameters
bool$clear_keyboardRemove all the buttons from this object.
Returns
string JSON object.

◆ getArray()

array PhpBotFramework\Entities\InlineKeyboard::getArray ( bool  $clean_keyboard = true)

Get the array containing the buttons.

Use this method when adding keyboard to inline query results.

Parameters
bool$clean_keyboardIf it's true, it'll clean the inline keyboard.
Returns
array An array containing the buttons.

◆ getBackButton()

string array PhpBotFramework\Localization\Button::getBackButton ( bool  $json_serialized = true)

Get a simple Back button with back as callback_data.

Parameters
$json_serializedreturn a json serialized string, or an array.
Returns
string|array A button with written "back".

◆ getBackSkipKeyboard()

string array PhpBotFramework\Localization\Button::getBackSkipKeyboard ( bool  $json_serialized = true)

Get a Back and a Skip buttons inthe same row.

Back button has callback_data "back" and Skip button has callback_data "skip".

Parameters
bool$json_serializedreturn a json serialized string, or an array.
Returns
string|array A button with written "back" and one with written "Skip".

◆ getChooseLanguageKeyboard()

string array PhpBotFramework\Localization\Button::getChooseLanguageKeyboard ( string  $prefix = 'cl',
bool  $json_serialized = true 
)

Get various buttons for set various languages.

Create a button for each language contained in $localization['languages'] variable of $bot object. There will be a button per row.

The button's label will include the target language and the current one. The callback data for each button will be "cl/key" where key is the key in $localization['languages'].

Parameters
$prefixPrefix followed by '/' and the language index (en, it..).
$json_serializedGet a JSON-serialized string or an array.
Returns
string|array The buttons in the selected type.