Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 KB | None | 0 0
  1. <?php
  2.     include('vendor/autoload.php'); //Подключаем библиотеку
  3.     use Telegram\Bot\Api;
  4.  
  5.     $telegram = new Api('мой_токен'); //Устанавливаем токен, полученный у BotFather
  6.     $result = $telegram -> getWebhookUpdates(); //Передаем в переменную $result полную информацию о сообщении пользователя
  7.    
  8.     $text = $result["message"]["text"]; //Текст сообщения
  9.     $chat_id = $result["message"]["chat"]["id"]; //Уникальный идентификатор пользователя
  10.     $name = $result["message"]["from"]["username"]; //Юзернейм пользователя
  11.     $keyboard = [["Последние статьи"],["Картинка"],["Гифка"]]; //Клавиатура
  12.  
  13.     if($text){
  14.          if ($text == "/start") {
  15.             $reply = "Добро пожаловать в бота!";
  16.             $reply_markup = $telegram->replyKeyboardMarkup([ 'keyboard' => $keyboard, 'resize_keyboard' => true, 'one_time_keyboard' => false ]);
  17.             $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $reply_markup ]);
  18.         }elseif ($text == "/help") {
  19.             $reply = "Информация с помощью.";
  20.             $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply ]);
  21.         }elseif ($text == "Картинка") {
  22.             $url = "https://68.media.tumblr.com/6d830b4f2c455f9cb6cd4ebe5011d2b8/tumblr_oj49kevkUz1v4bb1no1_500.jpg";
  23.             $telegram->sendPhoto([ 'chat_id' => $chat_id, 'photo' => $url, 'caption' => "Описание." ]);
  24.         }elseif ($text == "Гифка") {
  25.             $url = "https://68.media.tumblr.com/bd08f2aa85a6eb8b7a9f4b07c0807d71/tumblr_ofrc94sG1e1sjmm5ao1_400.gif";
  26.             $telegram->sendDocument([ 'chat_id' => $chat_id, 'document' => $url, 'caption' => "Описание." ]);
  27.         }elseif ($text == "Последние статьи") {
  28.             $html=simplexml_load_file('http://netology.ru/blog/rss.xml');
  29.             foreach ($html->channel->item as $item) {
  30.          $reply .= "\xE2\x9E\xA1 ".$item->title." (<a href='".$item->link."'>читать</a>)\n";
  31.             }
  32.             $telegram->sendMessage([ 'chat_id' => $chat_id, 'parse_mode' => 'HTML', 'disable_web_page_preview' => true, 'text' => $reply ]);
  33.         }else{
  34.             $reply = "По запросу \"<b>".$text."</b>\" ничего не найдено.";
  35.             $telegram->sendMessage([ 'chat_id' => $chat_id, 'parse_mode'=> 'HTML', 'text' => $reply ]);
  36.         }
  37.     }else{
  38.         $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => "Отправьте текстовое сообщение." ]);
  39.     }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement