Styled Keyboards & Buttons

Raw MD
Create interactive inline buttons, reply keyboards, pagination, and multi-row grids.

Inline vs. Reply Keyboards

Telegram supports two types of interactive keyboards:

  • Inline Keyboards: Attached directly below specific messages. Tapping them triggers callback queries (callback_query) or opens external URLs.
  • Reply Keyboards: Displayed in place of the user's regular device keyboard. Tapping them sends regular text messages or requests special data (contacts, location, users).

Rich Inline Keyboard Grid Example

Interactive Inline Keyboard
bot('sendMessage', [
    'chat_id'      => $chatId,
    'text'         => "🎛 Control Panel Dashboard:
Select an option below:",
    'parse_mode'   => 'HTML',
    'reply_markup' => [
        'inline_keyboard' => [
            [
                ['text' => '💰 Balance', 'callback_data' => 'view_balance'],
                ['text' => '🎁 Daily Bonus', 'callback_data' => 'claim_bonus']
            ],
            [
                ['text' => '👥 Referrals', 'callback_data' => 'referrals'],
                ['text' => '🏆 Leaderboard', 'callback_data' => 'leaderboard']
            ],
            [
                ['text' => '🌐 Open Web App', 'web_app' => ['url' => 'https://botlify.cloud']],
                ['text' => '💬 Support', 'url' => 'https://t.me/botlify_support']
            ]
        ]
    ]
]);

Answering Callback Queries

When a user taps an inline button, always call answerCallbackQuery immediately to dismiss Telegram's loading spinner:

answerCallbackQuery
if (isset($update['callback_query'])) {
    $cb = $update['callback_query'];
    bot('answerCallbackQuery', [
        'callback_query_id' => $cb['id'],
        'text'              => 'Action processed successfully!',
        'show_alert'        => false
    ]);
}