Custom Telegram Bot Dynamic Keyboard Setup

How can I append a custom button to my Telegram Bot’s dynamic keyboard? For instance, extend the database buttons list with an extra button.

$dbResult = mysqli_query($conn, "SELECT name FROM tunes");
$keys = [];
if (mysqli_num_rows($dbResult) > 0) {
    while ($item = mysqli_fetch_assoc($dbResult)) {
        $keys[] = [$item['name']];
    }
    $keys[] = ['ExtraOption'];
    sendTelegramCommand('sendMessage', [
        'chat_id' => $chatId,
        'text' => "Select your track.",
        'reply_markup' => json_encode(['keyboard' => $keys])
    ]);
}

During my work with Telegram bots using dynamic keyboards, I encountered similar challenges and found that careful handling of both database and static buttons is essential. I learned that appending an additional option required not only proper encoding but also attention to array structure. In my case, ensuring that each button array was consistent prevented unexpected behavior. Experimenting with sending debug output helped me understand whether the keyboard structure was transmitted correctly. Additionally, revisiting the Telegram Bot API documentation clarified that proper json_encode usage is crucial for a seamless user experience.

In working on a similar project with custom Telegram bot keyboards, I found that appending an extra reusable option is simpler than it might appear. I make sure to verify that the dynamic button list is correctly built and then add the static button outside of the loop. Using print checks along the way for confirmation is beneficial. Additionally, ensuring that the JSON is properly encoded before sending it to the Telegram API is key. This method of merging database-driven content with a fixed button element proved reliable in my experience.