Utils that allows to get from a user some values using inline keyboard inside a longman/telegram-bot command.
Install this package through Composer.
Edit your project's composer.json
file to require californiamountainsnake/longmantelegrambot-inline-keyboard-selection
:
{
"name": "yourproject/yourproject",
"type": "project",
"require": {
"php": "^7.3",
"californiamountainsnake/longmantelegrambot-inline-keyboard-selection": "*"
}
}
and run composer update
run this command in your command line:
composer require californiamountainsnake/longmantelegrambot-inline-keyboard-selection
- Create the lang file
telegrambot/keyboard_selection
:
<?php
return [
'selected_value_prefix' => '☑ ',
'button_clear' => 'Reset',
'button_all' => 'All',
'button_ok' => 'OK',
'wrong_value_single' => 'Wrong value! Select one value from the keyboard.',
'wrong_value_multiple' => 'Wrong value! Select one or more values from the keyboard.',
'nothing_selected_error' => 'You select nothing! Select one or more values from the keyboard.',
];
- Use trait in your bot command:
<?php
class MyCommand extends \Longman\TelegramBot\Commands\Command {
use OneSelection;
public function execute(): ServerResponse
{
$isSelected = $this->oneSelection(
'my_one_selection_1',
[
'value1' => 'name1',
'value2' => 'name2',
],
'Please, select one value!',
$this->getMessage()->getText(),
true
);
if (!$isSelected) {
return $this->emptyResponse();
}
return $this->sendTextMessage (\print_r($this->getOneSelectionResult('my_one_selection_1'), true));
}
}