mehrandvd
mehrandvd

Reputation: 9116

How to send a command by clicking a button in Telegram

How can I create a ReplyKeyboardButton in telegram with a specified text, which sends a specified command when it is being clicked.

For example the text is "Yes" and when I click yes, it sends /1 as a command. In the documentation creating a button just gets a text as input.

Following picture is from Telegram documentation which demonstrate the idea:

https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd

Upvotes: 3

Views: 7777

Answers (2)

Charles Okwuagwu
Charles Okwuagwu

Reputation: 10866

If you make it an inline-keyboard, each button can have an associated data-value along with the button text.

At present, regular buttons return their text as the reply value in a return message.

However, If you have a unique text or unique text+emoji as the text for each button, then your command processor code can simple do a switch-case on returned message-text

Upvotes: 2

91DarioDev
91DarioDev

Reputation: 1690

If you mean that when the user presses the button, the user actually sends a command, it is not possible. When the user presses a regular button (not inline) he just sends the text inside the button.

So the only way to do this is to write a command in the button or at least a command and parameters.

What you see in the picture is the bot that sends a message where you have to possibility to answer: pressing buttons or pressing commands in the message.

Anyway you can also use the same functions to handle a command and a button.

Upvotes: 2

Related Questions