TestCommand.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\TCommands;
  3. use Illuminate\Support\Facades\Log;
  4. use Telegram\Bot\Actions;
  5. use Telegram\Bot\Commands\Command;
  6. /**
  7. * Class TestCommand.
  8. */
  9. class TestCommand extends Command
  10. {
  11. /**
  12. * @var string Command Name
  13. */
  14. protected $name = 'test';
  15. /**
  16. * @var array Command Aliases
  17. */
  18. protected $aliases = ['listcommands'];
  19. /**
  20. * @var string Command Description
  21. */
  22. protected $description = 'Проверка';
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function handle($arguments)
  27. {
  28. Log::info(['tbot' => $arguments]);
  29. $text = 'Привет';
  30. $this->replyWithMessage(compact('text'));
  31. $this->replyWithChatAction(['action' => Actions::TYPING]);
  32. $telegram_user = \Telegram::getWebhookUpdates()['message'];
  33. // Log::info([$telegram_user]);
  34. //
  35. $text = sprintf('%s: %s'.PHP_EOL, 'Ваш номер чата', $telegram_user['from']['id']);
  36. if (isset($telegram_user['from']['username'])){
  37. $text .= sprintf('%s: %s'.PHP_EOL, 'Ваше имя пользователя в телеграм', $telegram_user['from']['username']);
  38. }
  39. // Log::info($text);
  40. $this->replyWithMessage(compact('text'));
  41. $updateId = \Telegram::getWebhookUpdates()['update_id']+1;
  42. \Telegram::getWebhookUpdates(['offset'=>$updateId]);
  43. }
  44. }