I’m working on a Telegram bot and I’m not happy with how big the keyboard buttons are. Right now, I’ve got buttons like this:
$keyboardButtons = ['⬅️', 'Button', '🏛'];
They look too chunky on the screen. I’ve heard about something called resize_keyboard
that might help, but I’m not sure how to use it.
Here’s what my current code looks like:
$response = sendTelegramMessage([
'chat_id' => $userId,
'text' => 'Choose an option:',
'reply_markup' => json_encode([
'keyboard' => [$keyboardButtons]
])
]);
print_r($response);
Does anyone know how I can make these buttons smaller and more compact? I’d really appreciate some help figuring this out. Thanks!
hey john, have u tried using inline keyboards? they’re way more flexible n look way better imo. u can customize size, layout, everything. just replace ‘keyboard’ with ‘inline_keyboard’ in ur code. might take a bit to figure out but its worth it trust me
I’ve dealt with this issue before, and I can confirm that resize_keyboard
is indeed the way to go. Here’s how you can implement it:
$response = sendTelegramMessage([
'chat_id' => $userId,
'text' => 'Choose an option:',
'reply_markup' => json_encode([
'keyboard' => [$keyboardButtons],
'resize_keyboard' => true
])
]);
By adding ‘resize_keyboard’ => true to your reply_markup, you’re telling Telegram to make the keyboard as compact as possible. This should significantly reduce the size of your buttons.
Another tip: if you want even more control over the layout, you can use ‘one_time_keyboard’ => true. This makes the keyboard disappear after a button is pressed, which can be useful for cleaner interactions.
Remember, the effectiveness can vary depending on the user’s device and settings, but it generally makes a noticeable difference. Give it a try and see how it works for your specific use case!
The resize_keyboard
option is definitely the way to go for more compact buttons. I’ve implemented this in several of my Telegram bots with great results. Here’s a slight modification to your code that should work:
$response = sendTelegramMessage([
'chat_id' => $userId,
'text' => 'Choose an option:',
'reply_markup' => json_encode([
'keyboard' => [$keyboardButtons],
'resize_keyboard' => true,
'selective' => false
])
]);
The ‘selective’ => false parameter ensures the resized keyboard applies to all users. This combination usually results in a much sleeker interface. If you’re still not satisfied with the size, you might want to consider using inline keyboards instead, which offer more customization options.