Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make telegram keyboard button issue commands?

I just got acquainted with the keyboard buttons for telegram bots using the .KeyboardButton from the Telegram API documentation but I have an issue; so far I've only been able to design the buttons such that the output after clicking on the button is the same as it's caption/placeholder which is really not helpful for what I want to do.

I have commands set and all already so for example I want the output of a button labeled "Rules" to be /rules in order to initiate the command action instead of the bot output being "Rules". I'm working with Python although I'm open to anyone working on the same stuff in other languages.

like image 827
Emmanuel Batse Avatar asked Oct 17 '25 15:10

Emmanuel Batse


1 Answers

Clicking on a KeyboardButton will always result in sending a message containing the very same caption it holds. That's just how KeyboardButton in telegram works. So you would have to label your button "/rules".

As an alternative you can use InlineKeyboardButton instead. You can chose any label text you wish and provide additional callback_data. Clicking inlineKeyboardButton will not print any message but instead a callback query will be sent to your bot's script. This query can then be answered any way you wish.

like image 168
newsha Avatar answered Oct 20 '25 07:10

newsha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!