californiamountainsnake/longmantelegrambot-inline-keyboard-selection

This package is abandoned and no longer maintained. No replacement package was suggested.

Utils that allows to get from a user some values using inline keyboard inside a longman/telegram-bot command.

4.0.0 2021-03-16 18:06 UTC

This package is auto-updated.

Last update: 2022-05-29 22:54:03 UTC


README

Utils that allows to get from a user some values using inline keyboard inside a longman/telegram-bot command.

Install:

Require this package with Composer

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

or

run this command in your command line:

composer require californiamountainsnake/longmantelegrambot-inline-keyboard-selection

Usage

  1. 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.',
];
  1. 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));
    }
}