75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* This file is part of the TelegramBot package.
|
|
*
|
|
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Longman\TelegramBot\Commands\UserCommands;
|
|
|
|
use Longman\TelegramBot\Commands\UserCommand;
|
|
use Longman\TelegramBot\Entities\InlineKeyboard;
|
|
use Longman\TelegramBot\Request;
|
|
|
|
/**
|
|
* User "/inlinekeyboard" command
|
|
*
|
|
* Display an inline keyboard with a few buttons.
|
|
*/
|
|
class InlinekeyboardCommand extends UserCommand
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $name = 'inlinekeyboard';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $description = 'Show inline keyboard';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $usage = '/inlinekeyboard';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $version = '0.1.0';
|
|
|
|
/**
|
|
* Command execute method
|
|
*
|
|
* @return \Longman\TelegramBot\Entities\ServerResponse
|
|
* @throws \Longman\TelegramBot\Exception\TelegramException
|
|
*/
|
|
public function execute()
|
|
{
|
|
$chat_id = $this->getMessage()->getChat()->getId();
|
|
|
|
$switch_element = random_int(0, 9) < 5 ? 'true' : 'false';
|
|
|
|
$inline_keyboard = new InlineKeyboard(
|
|
[
|
|
['text' => 'inline', 'switch_inline_query' => $switch_element],
|
|
['text' => 'inline current chat', 'switch_inline_query_current_chat' => $switch_element],
|
|
], [
|
|
['text' => 'callback', 'callback_data' => 'identifier'],
|
|
['text' => 'open url', 'url' => 'https://github.com/php-telegram-bot/core'],
|
|
]
|
|
);
|
|
|
|
$data = [
|
|
'chat_id' => $chat_id,
|
|
'text' => 'inline keyboard',
|
|
'reply_markup' => $inline_keyboard,
|
|
];
|
|
|
|
return Request::sendMessage($data);
|
|
}
|
|
}
|