Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This file is part of the TelegramBot package.
- *
- * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Longman\TelegramBot\Commands\SystemCommands;
- use Longman\TelegramBot\Commands\SystemCommand;
- use Longman\TelegramBot\Request;
- /**
- * Callback query command
- *
- * This command handles all callback queries sent via inline keyboard buttons.
- *
- * @see InlinekeyboardCommand.php
- */
- class CallbackqueryCommand extends SystemCommand
- {
- /**
- * @var string
- */
- protected $name = 'callbackquery';
- /**
- * @var string
- */
- protected $description = 'Reply to callback query';
- /**
- * @var string
- */
- protected $version = '1.1.1';
- /**
- * Command execute method
- *
- * @return \Longman\TelegramBot\Entities\ServerResponse
- * @throws \Longman\TelegramBot\Exception\TelegramException
- */
- public function execute()
- {
- $callback_query = $this->getCallbackQuery();
- $callback_query_id = $callback_query->getId();
- $callback_data = $callback_query->getData();
- $message = $callback_query->getMessage();
- $message_id = $message->getMessageId();
- $chat = $message->getChat();
- $chat_id = $chat->getId();
- if ($callback_data == "menu1") {
- $inline_keyboard = new InlineKeyboard(
- [
- ['text' => 'SubMenu1', 'callback_data' => 'submenu1'],
- ],
- [
- ['text' => 'SubMenu2', 'callback_data' => 'submenu2'],
- ],[
- ['text' => '[Delete Post]', 'callback_data' => 'del-msg'],
- ['text' => '[<<== Back]', 'callback_data' => 'menu'],
- ]);
- $data = [
- 'chat_id' => $chat_id,
- reply_markup' => $inline_keyboard,
- ];
- return Request::sendMessage($data);
- }
- if ($callback_data == "menu2") {
- $inline_keyboard = new InlineKeyboard(
- [
- ['text' => 'SubMenu1', 'callback_data' => 'submenu1'],
- ],
- [
- ['text' => 'SubMenu2', 'callback_data' => 'submenu2'],
- ],[
- ['text' => '[Delete Post]', 'callback_data' => 'del-msg'],
- ['text' => '[<<== Back]', 'callback_data' => 'menu'],
- ]);
- $data = [
- 'chat_id' => $chat_id,
- reply_markup' => $inline_keyboard,
- ];
- return Request::sendMessage($data);
- }
- if ($callback_data == "menu") {
- $inline_keyboard = new InlineKeyboard(
- [
- ['text' => 'Menu1', 'callback_data' => 'menu1'],
- ],
- [
- ['text' => 'Menu2', 'callback_data' => 'menu2'],
- ],[
- ['text' => '[Delete Post]', 'callback_data' => 'del-msg'],
- ]);
- $data = [
- 'chat_id' => $chat_id,
- reply_markup' => $inline_keyboard,
- ];
- return Request::sendMessage($data);
- }
- if ($callback_data == "del-msg") {
- $deldata = [
- 'chat_id' => $chat_id,
- 'message_id' => $message_id
- ];
- return Request::deleteMessage($deldata);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement