Advertisement
Hitmare

CallbackqueryCommand.php

Dec 24th, 2017
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.37 KB | None | 0 0
  1. <?php
  2. /**
  3.  * This file is part of the TelegramBot package.
  4.  *
  5.  * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Longman\TelegramBot\Commands\SystemCommands;
  11. use Longman\TelegramBot\Commands\SystemCommand;
  12. use Longman\TelegramBot\Request;
  13. /**
  14.  * Callback query command
  15.  *
  16.  * This command handles all callback queries sent via inline keyboard buttons.
  17.  *
  18.  * @see InlinekeyboardCommand.php
  19.  */
  20. class CallbackqueryCommand extends SystemCommand
  21. {
  22.     /**
  23.      * @var string
  24.      */
  25.     protected $name = 'callbackquery';
  26.     /**
  27.      * @var string
  28.      */
  29.     protected $description = 'Reply to callback query';
  30.     /**
  31.      * @var string
  32.      */
  33.     protected $version = '1.1.1';
  34.     /**
  35.      * Command execute method
  36.      *
  37.      * @return \Longman\TelegramBot\Entities\ServerResponse
  38.      * @throws \Longman\TelegramBot\Exception\TelegramException
  39.      */
  40.     public function execute()
  41.     {
  42.         $callback_query    = $this->getCallbackQuery();
  43.         $callback_query_id = $callback_query->getId();
  44.         $callback_data     = $callback_query->getData();
  45.         $message = $callback_query->getMessage();
  46.         $message_id = $message->getMessageId();
  47.         $chat = $message->getChat();
  48.         $chat_id = $chat->getId();
  49.  
  50.         if ($callback_data == "menu1") {
  51.             $inline_keyboard = new InlineKeyboard(
  52.             [
  53.                 ['text' => 'SubMenu1', 'callback_data' => 'submenu1'],
  54.             ],
  55.             [
  56.                 ['text' => 'SubMenu2', 'callback_data' => 'submenu2'],
  57.             ],[
  58.                 ['text' => '[Delete Post]', 'callback_data' => 'del-msg'],
  59.                 ['text' => '[<<== Back]', 'callback_data' => 'menu'],
  60.             ]);
  61.             $data = [
  62.                 'chat_id'      => $chat_id,
  63.                 reply_markup' => $inline_keyboard,
  64.             ];
  65.  
  66.             return Request::sendMessage($data);
  67.         }
  68.         if ($callback_data == "menu2") {
  69.             $inline_keyboard = new InlineKeyboard(
  70.             [
  71.                 ['text' => 'SubMenu1', 'callback_data' => 'submenu1'],
  72.             ],
  73.             [
  74.                 ['text' => 'SubMenu2', 'callback_data' => 'submenu2'],
  75.             ],[
  76.                 ['text' => '[Delete Post]', 'callback_data' => 'del-msg'],
  77.                 ['text' => '[<<== Back]', 'callback_data' => 'menu'],
  78.             ]);
  79.             $data = [
  80.                 'chat_id'      => $chat_id,
  81.                 reply_markup' => $inline_keyboard,
  82.             ];
  83.  
  84.             return Request::sendMessage($data);
  85.         }
  86.  
  87.         if ($callback_data == "menu") {
  88.              $inline_keyboard = new InlineKeyboard(
  89.        
  90.             [
  91.                 ['text' => 'Menu1', 'callback_data' => 'menu1'],
  92.             ],
  93.             [
  94.                 ['text' => 'Menu2', 'callback_data' => 'menu2'],
  95.             ],[
  96.                 ['text' => '[Delete Post]', 'callback_data' => 'del-msg'],
  97.            
  98.             ]);
  99.             $data = [
  100.                 'chat_id'      => $chat_id,
  101.                 reply_markup' => $inline_keyboard,
  102.             ];
  103.  
  104.             return Request::sendMessage($data);
  105.         }
  106.  
  107.         if ($callback_data == "del-msg") {
  108.            
  109.            $deldata = [
  110.            'chat_id' => $chat_id,
  111.            'message_id' => $message_id
  112.            ];
  113.        
  114.        
  115.        
  116.            return Request::deleteMessage($deldata);
  117.        }
  118.    }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement