Advertisement
MyZik

Untitled

Jun 17th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. <?php
  2. namespace Longman\TelegramBot\Commands\UserCommands;
  3.  
  4. use Longman\TelegramBot\Commands\AdminCommands\PanelCommand;
  5. use Longman\TelegramBot\Commands\UserCommand;
  6. use Longman\TelegramBot\Conversation;
  7. use Longman\TelegramBot\DB;
  8. use Longman\TelegramBot\Entities\CallbackQuery;
  9. use Longman\TelegramBot\Entities\InlineKeyboard;
  10. use Longman\TelegramBot\Entities\InlineKeyboardButton;
  11. use Longman\TelegramBot\Entities\Keyboard;
  12. use Longman\TelegramBot\Entities\Update;
  13. use Longman\TelegramBot\Request;
  14.  
  15. class TestCommand extends UserCommand
  16. {
  17.     protected $name = 'test';
  18.     protected $description = 'Nur für den Test';
  19.     protected $usage = '/test';
  20.     protected $version = '1.0.0';
  21.     protected $need_mysql = true;
  22.     protected $conversation;
  23.  
  24.     /**
  25.      * Обработчик кнопки Refresh
  26.      *
  27.      * @param CallbackQuery $query
  28.      * @return \Longman\TelegramBot\Entities\ServerResponse
  29.      * @throws \Longman\TelegramBot\Exception\TelegramException
  30.      */
  31.     public static function refreshHandler(CallbackQuery $query) {
  32.         $callback_data = $query->getData();
  33.  
  34.         if ($callback_data !== 'refresh') {
  35.             return Request::emptyResponse();
  36.         }
  37.  
  38.         $keyboard = new InlineKeyboard([
  39.             ['text' => 'FAQ', 'callback_data' => 'faq'],
  40.             ['text' => 'Отзывы', 'callback_data' => 'reviews'],
  41.         ]);
  42.  
  43.         return Request::editMessageText([
  44.             'chat_id' => $query->getMessage()->getChat()->getId(),
  45.             'message_id' => $query->getMessage()->getMessageId(),
  46.             'text' => 'Текст сообщения',
  47.             'parse_mode' => 'Markdown',
  48.             'reply_markup' => $keyboard,
  49.         ]);
  50.     }
  51.  
  52.     /**
  53.      * @return \Longman\TelegramBot\Entities\ServerResponse
  54.      * @throws InlineKeyboardPaginationException
  55.      * @throws \Longman\TelegramBot\Exception\TelegramException
  56.      */
  57.     public function execute()
  58.     {
  59.         $message = $this->getMessage();
  60.         $chat    = $message->getChat();
  61.         $chat_id = $chat->getId();
  62.         $user_id = $message->getFrom()->getId();
  63.         $text    = trim($message->getText(true));
  64.         $pdo = DB::getPdo();
  65.  
  66.         ...
  67.  
  68.         if ($text === '') {
  69.             $data['text'] = 'Тыкните на кнопку, чтобы обновить текст сообщения и кнопки.';
  70.             $data['reply_markup'] = new InlineKeyboard([['text' => 'Обновить сообщение', 'callback_data' => 'refresh']]);
  71.  
  72.             return Request::sendMessage($data);
  73.         }
  74.  
  75.         $result = Request::emptyResponse();
  76.        
  77.         ...
  78.  
  79.         return $result;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement