Answer the question
In order to leave comments, you need to log in
How to assign a command to the Telegram bot's menu button?
I am writing a bot.
I'm using PHP / Laravel / telegram-bot-sdk
When I command /start, the bot displays a message and a menu to select the language.
$languages = config('app.locales_assoc');
$keyboard = [];
$keyboardArray = [];
foreach ($languages as $language) {
array_push($keyboardArray, $language);
}
$keyboard[] = $keyboardArray;
$reply_markup = $this->telegram->replyKeyboardMarkup([
'keyboard' => $keyboard,
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => false
]);
$this->replyWithMessage(
[
'text' => trans('bot.greeting_lang'),
'reply_markup' => $reply_markup
]
);
/setLanguage Русский
Answer the question
In order to leave comments, you need to log in
You need to use an inline keyboard
$button_en = array('text' => 'English', 'callback_data' => '/lang_english');
$button_ru = array('text' => 'Русский', 'callback_data' => '/lang_russian');
$keyboard = array('inline_keyboard' => array(array($button_en, $button_ru)));
$params['reply_markup'] = json_encode($keyboard, TRUE);
This can be done using inline buttons
Or leave it as it is, but work with states.
For example, after clicking on /start, the bot enters the "language selection" state. After clicking on one of the buttons "Russian", "Ukrainian" and "English", check that you have indicated (pressed) one of the buttons, and did not enter arbitrary text, and if everything is fine, then change the state to waiting for the next command, display the corresponding text.
There were many questions about working with states, they are all on toster.ru
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question