Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Console\Commands;
- use GuzzleHttp\Client;
- use Illuminate\Console\Command;
- class SetTelegramBotsWebhook extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'tg:wh';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Set Telegram Bots Webhook';
- private $actionUrl = 'https://api.telegram.org/bot%s/%s%s';
- /**
- * @var Client
- */
- private $http;
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- $this->http = new Client(['verify' => false]);
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- \array_map(function ($bot) {
- try {
- $this->http->get(\sprintf($this->actionUrl, $bot['token'], 'deleteWebhook', ''));
- $response = $this->http->get(
- \sprintf(
- $this->actionUrl,
- $bot['token'],
- 'setWebhook',
- '?' . http_build_query([
- 'url' => route($bot['webhook_url'])
- ])
- )
- );
- $this->info($response->getBody()->getContents());
- } catch (\Exception $exception) {
- $this->warn($exception->getMessage());
- }
- }, config('telegram.bots'));
- }
- }
Add Comment
Please, Sign In to add comment