Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Api\Telegram;
  4.  
  5. use App\Models\Country;
  6. use App\Models\Translate;
  7. use Illuminate\Http\Request;
  8. use App\Http\Controllers\Controller;
  9. use TelegramBot\Api\Exception;
  10. use TelegramBot\Api\Types\Inline\InlineKeyboardMarkup;
  11.  
  12. class InfoController extends Controller
  13. {
  14. public function info($bot, $message) {
  15.  
  16. try {
  17.  
  18. $text = $message->getText();
  19.  
  20. $text = str_replace('/info','', $text);
  21.  
  22. $data = Translate::where('name', 'LIKE', "%$text%")
  23. ->where('language', '=', 'ru')
  24. ->orWhere('alias', 'LIKE', "%$text%")
  25. ->first();
  26.  
  27. if(empty($data)) {
  28.  
  29. $keyboard = new InlineKeyboardMarkup(
  30. [
  31. [
  32. ['text' => 'Перейти на сайт', 'url' => 'http://xxxxxxx.xxx' . route('xxxxxxx', null, false)],
  33. ]
  34. ]
  35. );
  36. $bot->sendMessage($message->getChat()->getId(), "К сожалению ничего не найдено. Уточните поиск или посетите наш сайт\n", false, false, null, $keyboard);
  37. return;
  38. }
  39.  
  40. $detail = Country::where('information_id', '=', $data->information_id)
  41. ->where('country', '=', 'ru')
  42. ->first();
  43.  
  44. $buttons = array([
  45. ['text' => 'Отзывы', 'url' => 'http://xxxxxxx.xxx' . route('site.comments', ['xxxxxxx' => $data->alias], false)],
  46. ['text' => 'Читать обзор', 'url' => 'http://xxxxxxx.xxx' . route('info.show', ['alias' => $data->alias], false)],
  47. ]);
  48.  
  49. $link = "";
  50.  
  51. if (!empty($detail)) {
  52.  
  53. $buttons[0][] = ['text' => 'Перейти на сайт', 'url' => $detail->url_play];
  54. $link = "<a href='$detail->url_play'>Перейти на сайт</a>\n";
  55. }
  56.  
  57. $keyboard = new InlineKeyboardMarkup(
  58. $buttons
  59. );
  60.  
  61. $textMessage = "<b>" . $data->name . "</b>\n". $link . $data->description;
  62.  
  63. $bot->sendMessage($message->getChat()->getId(), $textMessage, 'HTML', true, null, $keyboard);
  64.  
  65. } catch (Exception $e) {
  66. $e->getMessage();
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement