telegramBot::replyKeyboardMarkup PHP Method

replyKeyboardMarkup() public method

Builds a custom keyboard markup.
public replyKeyboardMarkup ( array $keyboard, boolean $resize_keyboard = false, boolean $one_time_keyboard = false, boolean $selective = false ) : string
$keyboard array
$resize_keyboard boolean
$one_time_keyboard boolean
$selective boolean
return string
    public function replyKeyboardMarkup($keyboard, $resize_keyboard = false, $one_time_keyboard = false, $selective = false)
    {
        return json_encode(compact('keyboard', 'resize_keyboard', 'one_time_keyboard', 'selective'));
    }

Usage Example

// HERE YOUR TOKEN
//////////////////////////////////////////////////
echo "####################################\n";
echo "#          Telegram CLIENT         #\n";
echo "####################################\n\n";
$tg = new telegramBot($token);
$chat_id = null;
$guessed = false;
$sendQuestion = false;
$offset = 0;
echo "Get Bot Information:\n";
$updates = $tg->getMe();
echo json_encode($updates) . "\n";
// Custom keyboard
$customKeyboard = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['0']];
$reply_markup = $tg->replyKeyboardMarkup($customKeyboard, true, true);
do {
    // Get updates the bot has received
    // Offset to confirm previous updates
    $updates = $tg->pollUpdates($offset);
    if ($updates['ok'] && count($updates['result']) > 0) {
        foreach ($updates['result'] as $data) {
            if (is_null($chat_id)) {
                $chat_id = $data['message']['chat']['id'];
            }
            if (!$sendQuestion) {
                // sends an action 'typing'
                $tg->sendChatAction($chat_id, 'typing');
                // send message with a custom reply markup
                $tg->sendMessage($chat_id, 'Guess the number', null, false, null, $reply_markup);
                $sendQuestion = true;