Commit 7147b12f authored by MBoretto's avatar MBoretto

adding example for Inline keyboard

parent e5b6d415
...@@ -13,6 +13,7 @@ namespace Longman\TelegramBot\Commands\UserCommands; ...@@ -13,6 +13,7 @@ namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand; use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\InlineKeyboardMarkup; use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
use Longman\TelegramBot\Entities\InlineKeyboardButton;
/** /**
* User "/inlinekeyboard" command * User "/inlinekeyboard" command
...@@ -22,8 +23,8 @@ class InlinekeyboardCommand extends UserCommand ...@@ -22,8 +23,8 @@ class InlinekeyboardCommand extends UserCommand
/**#@+ /**#@+
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $name = 'inlinekeyboard'; protected $name = 'Inlinekeyboard';
protected $description = 'Show a custom inline keybord with reply markup'; protected $description = 'Show inline keyboard';
protected $usage = '/inlinekeyboard'; protected $usage = '/inlinekeyboard';
protected $version = '0.0.1'; protected $version = '0.0.1';
/**#@-*/ /**#@-*/
...@@ -34,104 +35,18 @@ class InlinekeyboardCommand extends UserCommand ...@@ -34,104 +35,18 @@ class InlinekeyboardCommand extends UserCommand
public function execute() public function execute()
{ {
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = []; $inline_keyboard = [
$data['chat_id'] = $chat_id; new InlineKeyboardButton(['text' => 'inline', 'switch_inline_query' => 'true']),
$data['text'] = 'Press a Button:'; new InlineKeyboardButton(['text' => 'callback', 'callback_data' => 'identifier']),
new InlineKeyboardButton(['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot']),
//Keyboard examples
$inline_keyboards = [];
//0
$inline_keyboard[] = [
[
'text' => '<',
'callback_data' => 'go_left'
],
[
'text' => '^',
'callback_data' => 'go_up'
],
[
'text' => '>',
'callback_data' => 'go_right'
]
];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//1
$inline_keyboard[] = [
[
'text' => 'open google.com',
'url' => 'google.com'
],
[
'text' => 'open youtube.com',
'url' => 'youtube.com'
]
];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//2
$inline_keyboard[] = [
[
'text' => 'search \'test\' inline',
'switch_inline_query' => 'test'
],
[
'text' => 'search \'cats\' inline',
'switch_inline_query' => 'cats'
]
]; ];
$inline_keyboard[] = [ $data = [
[ 'chat_id' => $message->getChat()->getId(),
'text' => 'search \'earth\' inline', 'text' => 'inline keyboard',
'switch_inline_query' => 'earth' 'reply_markup' => new InlineKeyboardMarkup(['inline_keyboard' => [$inline_keyboard]]),
],
]; ];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
//3
$inline_keyboard[] = [
[
'text' => 'open url',
'url' => 'https://github.com/akalongman/php-telegram-bot'
]
];
$inline_keyboard[] = [
[
'text' => 'switch to inline',
'switch_inline_query' => 'thumb up'
]
];
$inline_keyboard[] = [
[
'text' => 'send callback query',
'callback_data' => 'thumb up'
],
[
'text' => 'send callback query (no alert)',
'callback_data' => 'thumb down'
]
];
$inline_keyboards[] = $inline_keyboard;
unset($inline_keyboard);
$data['reply_markup'] = new InlineKeyboardMarkup(
[
'inline_keyboard' => $inline_keyboards[3],
]
);
return Request::sendMessage($data); return Request::sendMessage($data);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment