feat: bot

This commit is contained in:
hashbro
2026-08-15 23:05:51 +08:00
parent 9049fdccad
commit 376b442880
26 changed files with 944 additions and 352 deletions
+2
View File
@@ -69,6 +69,7 @@ Route::prefix('admin')->name('admin.')->middleware('panel.host:admin')->group(fu
Route::get('agents', [AgentUserController::class, 'index'])->name('agents.index');
Route::get('agents/data', [AgentUserController::class, 'data'])->name('agents.data');
Route::post('agents', [AgentUserController::class, 'store'])->name('agents.store');
Route::post('agents/telegram-test', [AgentUserController::class, 'testTelegram'])->name('agents.telegramTest');
Route::put('agents/{agent}', [AgentUserController::class, 'update'])->name('agents.update');
Route::get('agents/{agent}/channels', [AgentUserController::class, 'channels'])->name('agents.channels');
@@ -91,6 +92,7 @@ Route::prefix('admin')->name('admin.')->middleware('panel.host:admin')->group(fu
Route::prefix('system')->name('system.')->group(function () {
Route::get('settings', [SystemSettingsController::class, 'index'])->name('settings.index');
Route::post('settings', [SystemSettingsController::class, 'update'])->name('settings.update');
Route::post('settings/telegram-test', [SystemSettingsController::class, 'testTelegram'])->name('settings.telegramTest');
Route::get('admins', [AdminUserController::class, 'index'])->name('admins.index');
Route::get('admins/data', [AdminUserController::class, 'data'])->name('admins.data');
+12 -22
View File
@@ -29,30 +29,20 @@ Artisan::command('tokenview:set-webhook {url?}', function (?string $url = null)
return 1;
})->purpose('Register Tokenview address-tracking webhook URL');
Artisan::command('telegram:set-webhook {url?} {--agent= : Agent user id}', function (?string $url = null) {
$agentId = $this->option('agent');
if ($agentId !== null && $agentId !== '') {
$agent = \App\Models\User::query()->find((int) $agentId);
if ($agent === null || ! $agent->hasTelegramBot()) {
$this->error('Agent not found or telegram bot_token/chat_id missing');
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;
}
$token = (string) $agent->bot_token;
$url = $url ?: rtrim((string) config('app.url'), '/').'/hooks/telegram/agent/'.$agent->id;
$secret = \App\Telegram\TelegramBotContext::webhookSecretFor($agent);
} else {
$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', '');
return 1;
}
$url = $url ?: rtrim((string) config('app.url'), '/').'/hooks/telegram';
$secret = (string) config('coruna.telegram.webhook_secret', '');
$payload = ['url' => $url];
$payload = [
'url' => $url,
'allowed_updates' => ['message', 'callback_query', 'my_chat_member'],
];
if ($secret !== '') {
$payload['secret_token'] = $secret;
}
@@ -68,7 +58,7 @@ Artisan::command('telegram:set-webhook {url?} {--agent= : Agent user id}', funct
$this->error('Failed: '.$resp->body());
return 1;
})->purpose('Register Telegram webhook (official or --agent=ID)');
})->purpose('Register the site Telegram webhook');
Artisan::command('xxbb:build {--channel-c=} {--random-c}', function () {
$channelC = trim((string) $this->option('channel-c'));
-2
View File
@@ -8,6 +8,4 @@ use Illuminate\Support\Facades\Route;
Route::middleware([SubstituteBindings::class])->group(function () {
Route::post('/hooks/tokenview', TokenviewWebhookController::class)->name('hooks.tokenview');
Route::post('/hooks/telegram', TelegramWebhookController::class)->name('hooks.telegram');
Route::post('/hooks/telegram/agent/{agent}', [TelegramWebhookController::class, 'agent'])
->name('hooks.telegram.agent');
});