feature
This commit is contained in:
@@ -1,8 +1,76 @@
|
||||
<?php
|
||||
|
||||
use App\Services\Tokenview\TokenviewClient;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->purpose('Display an inspiring quote');
|
||||
|
||||
Artisan::command('tokenview:set-webhook {url?}', function (?string $url = null) {
|
||||
/** @var TokenviewClient $client */
|
||||
$client = app(TokenviewClient::class);
|
||||
if (! $client->enabled()) {
|
||||
$this->error('TOKENVIEW_API_KEY is empty');
|
||||
|
||||
return 1;
|
||||
}
|
||||
$url = $url ?: rtrim((string) config('app.url'), '/').'/hooks/tokenview';
|
||||
$this->info('Setting webhook URL: '.$url);
|
||||
if ($client->setWebhookUrl($url)) {
|
||||
$this->info('OK');
|
||||
|
||||
return 0;
|
||||
}
|
||||
$this->error('Failed — check Tokenview API response / credentials');
|
||||
|
||||
return 1;
|
||||
})->purpose('Register Tokenview address-tracking webhook URL');
|
||||
|
||||
Artisan::command('telegram:set-webhook {url?}', function (?string $url = null) {
|
||||
$token = (string) config('nutgram.token', '');
|
||||
if ($token === '') {
|
||||
$this->error('TELEGRAM_BOT_TOKEN is empty');
|
||||
|
||||
return 1;
|
||||
}
|
||||
$url = $url ?: rtrim((string) config('app.url'), '/').'/hooks/telegram';
|
||||
$secret = (string) config('coruna.telegram.webhook_secret', '');
|
||||
$payload = ['url' => $url];
|
||||
if ($secret !== '') {
|
||||
$payload['secret_token'] = $secret;
|
||||
}
|
||||
$this->info('Setting Telegram webhook URL: '.$url);
|
||||
$resp = Http::timeout(20)
|
||||
->asJson()
|
||||
->post("https://api.telegram.org/bot{$token}/setWebhook", $payload);
|
||||
if ($resp->successful() && ($resp->json('ok') === true)) {
|
||||
$this->info('OK');
|
||||
|
||||
return 0;
|
||||
}
|
||||
$this->error('Failed: '.$resp->body());
|
||||
|
||||
return 1;
|
||||
})->purpose('Register Telegram bot webhook URL (/hooks/telegram)');
|
||||
|
||||
Artisan::command('coruna:channel-domains {--json}', function () {
|
||||
$domains = array_values(array_filter(config('coruna.channel_domains', [])));
|
||||
if ($this->option('json')) {
|
||||
$this->line(json_encode($domains, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
return 0;
|
||||
}
|
||||
if ($domains === []) {
|
||||
$this->warn('(empty)');
|
||||
|
||||
return 0;
|
||||
}
|
||||
foreach ($domains as $d) {
|
||||
$this->line($d);
|
||||
}
|
||||
|
||||
return 0;
|
||||
})->purpose('Print configured channel delivery domains (settings / env)');
|
||||
|
||||
Reference in New Issue
Block a user