/
itp_practice
/
itp_backend
Обзор
Документация
Войти
/
itp_practice
/
itp_backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
app/Console/Commands/TelegramWebhookCommand.php
42 строки
1 KB
vivanenko
add auth
21 май 2025, 16:49
21 май 2025, 16:49
408bda1
Код
Авторство
О чём код?
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\Http; class TelegramWebhookCommand extends Command { protected $signature = 'telegram:webhook {action=set}'; protected $description = 'Set or remove Telegram webhook'; public function handle(): void { $action = $this->argument('action'); $botToken = config('services.telegram.bot_token'); $webhookUrl = config('services.telegram.webhook_url'); if ($action === 'set') { $response = Http::post("https://api.telegram.org/bot{$botToken}/setWebhook", [ 'url' => $webhookUrl, 'allowed_updates' => ['message', 'callback_query'], ]); if ($response->successful()) { $this->info('Webhook set successfully!'); } else { $this->error('Failed to set webhook: ' . $response->body()); } } elseif ($action === 'remove') { $response = Http::post("https://api.telegram.org/bot{$botToken}/deleteWebhook"); if ($response->successful()) { $this->info('Webhook removed successfully!'); } else { $this->error('Failed to remove webhook: ' . $response->body()); } } else { $this->error('Invalid action. Use "set" or "remove".'); } } }