Dimastik86
@Dimastik86
(isset($brain))?: die;

Как сделать выполнение команды нажатием кнопки?

['text' => ' Партнерка', 'callback_data'=>'/help']
например что нажимая на кнопку выполнялась команда /help

<?php

/**
 * This file is part of the PHP Telegram Bot example-bot package.
 * https://github.com/php-telegram-bot/example-bot/
 *
 * (c) PHP Telegram Bot Team
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Longman\TelegramBot\Commands\UserCommands;

/**
 * User "/keyboard" command
 *
 * Display a keyboard with a few buttons.
 */

use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;

class StreetCommand extends UserCommand
{
    /**
     * @var string
     */
    protected $name = 'street';

    /**
     * @var string
     */
    protected $description = 'Show a custom keyboard with reply markup';

    /**
     * @var string
     */
    protected $usage = '/street';

    /**
     * @var string
     */
    protected $version = '0.3.0';

    /**
     * Main command execution
     *
     * @return ServerResponse
     * @throws TelegramException
     */
    public function execute(): ServerResponse
    {
        /** @var Keyboard[] $keyboards */
        $keyboards = [];

//        // Simple digits
//        $keyboards[] = new Keyboard(
//            ['7', '8', '9'],
//            ['4', '5', '6'],
//            ['1', '2', '3'],
//            [' ', '0', ' ']
//        );
//
//        // Digits with operations
//        $keyboards[] = new Keyboard(
//            ['7', '8', '9', '+'],
//            ['4', '5', '6', '-'],
//            ['1', '2', '3', '*'],
//            [' ', '0', ' ', '/']
//        );
//
//        // Short version with 1 button per row
//        $keyboards[] = new Keyboard('A', 'B', 'C');
//
//        // Some different ways of creating rows and buttons
//        $keyboards[] = new Keyboard(
//            ['text' => 'A'],
//            'B',
//            ['C', 'D']
//        );

        // Buttons to perform Contact or Location sharing
        $keyboards[] = new Keyboard([

                ['text' => 'Send my contact', 'request_contact' => true],
                ['text' => 'Send my location', 'request_location' => true],
            ],[
                ['text' => ' Поиск', 'request_contact' => true],
                ['text' => ' Открыть', 'callback_data'=>'/butt1'],
                ['text' => ' Партнерка', 'callback_data'=>'/help']

        ]);

        // Shuffle our example keyboards and return a random one
        shuffle($keyboards);
        $keyboard = end($keyboards)
            ->setResizeKeyboard(true)
            ->setOneTimeKeyboard(true)
            ->setSelective(false);

        return $this->replyToChat('Press a Button!', [
            'reply_markup' => $keyboard,
        ]);
    }
}
  • Вопрос задан
  • 112 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
Бюро Цифровых Технологий Санкт-Петербург
от 120 000 до 180 000 ₽
03 мая 2024, в 00:45
1000 руб./за проект
02 мая 2024, в 23:56
2000 руб./за проект