PhpBotFramework  1.0.0
A framework for Telegram Bots' APIs.
Public Member Functions | Protected Attributes | List of all members
DanySpin97\PhpBotFramework\InlineKeyboard Class Reference

Inline Keyboard handler that create and handle inline keyboard buttons. More...

Public Member Functions

 __construct (CoreBot $bot=null, array $buttons=array())
 Create an inline keyboard object. More...
 
get ($clear_keyboard=true)
 Get a JSON-serialized object containg the inline keyboard. More...
 
getArray ($clean_keyboard=true)
 Get the array containing the buttons. (Use this method when adding keyboard to inline query results) More...
 
 addLevelButtons (array ... $buttons)
 Add buttons for the current row of buttons. More...
 
 clearKeyboard ()
 Remove all the buttons from the current inline keyboard.
 
getBackButton ($json_serialized=true)
 Get a simple Back button with back as callback_data. More...
 
getBackSkipKeyboard ()
 Get a Back and a Skip buttons inthe same row. More...
 
getChooseLanguageKeyboard ($json_serialized=true)
 Get button for each language. More...
 
getCompositeListKeyboard ($index, $list, $prefix)
 

Protected Attributes

 $inline_keyboard
 Store the array of InlineKeyboardButton.
 
 $bot
 Store a reference to the bot that is using this inline keyboard.
 

Detailed Description

Inline Keyboard handler that create and handle inline keyboard buttons.

It stores the inline keyboard buttons added until get() is called. It also provides some basic button to get, like Menu and Back buttons plus the dynamic-keyboard for menu browsing.

Constructor & Destructor Documentation

§ __construct()

DanySpin97\PhpBotFramework\InlineKeyboard::__construct ( CoreBot  $bot = null,
array  $buttons = array() 
)

Create an inline keyboard object.

Parameters
$botThe bot that owns this object.
$buttonsButtons passed as inizialization.
Returns
The object created with the buttons passed.

Member Function Documentation

§ addLevelButtons()

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

Add buttons for the current row of buttons.

Each array sent as parameter require a text key and one another key (as specified here between:

  • 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. Each row allows 8 buttons per row and 12 columns. Use this function with this syntax:

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

If you want to add more than a button, use this syntax:

addLevelButtons(['text' => 'Button 1', 'url' => 'https://telegram.me/gamedev_ita'], ['text' => 'Button 2', 'url' => 'https://telegram.me/animewallpaper']);
Parameters
...$buttonsOne or more arrays, each one represent a button.

§ get()

& DanySpin97\PhpBotFramework\InlineKeyboard::get (   $clear_keyboard = true)

Get a JSON-serialized object containg the inline keyboard.

Parameters
$clear_keyboardRemove all the buttons from this object.
Returns
JSON-serialized string with the buttons.

§ getArray()

& DanySpin97\PhpBotFramework\InlineKeyboard::getArray (   $clean_keyboard = true)

Get the array containing the buttons. (Use this method when adding keyboard to inline query results)

Parameters
$clean_keyboardRemove all the button from this object.
Returns
An array containing the buttons.

§ getBackButton()

& DanySpin97\PhpBotFramework\InlineKeyboard::getBackButton (   $json_serialized = true)

Get a simple Back button with back as callback_data.

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

§ getBackSkipKeyboard()

& DanySpin97\PhpBotFramework\InlineKeyboard::getBackSkipKeyboard ( )

Get a Back and a Skip buttons inthe same row.

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

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

§ getChooseLanguageKeyboard()

& DanySpin97\PhpBotFramework\InlineKeyboard::getChooseLanguageKeyboard (   $json_serialized = true)

Get button for each language.

Create a button for each language contained in $localization['languages'] variable of $bot object. The button will be one per row. The text will be the language and the language localizatated for the current user with a slash between them. The callback data for each button will be "cl/key" where key is the key in $localization['languages'].

Parameters
$json_serializedGet a JSON-serialized string or an array.
Returns
The buttons in the selected type.

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