ensureSecret(); if ($host === '' || $secret === '') { return false; } $webhookUrl = rtrim((string) config('app.url'), '/').'/api/chat/support-message-notify'; try { $response = Http::timeout(8)->post('https://'.$host.'/api/projects/set-webhook', [ 'api_key' => $chatApiKey, 'webhook_url' => $webhookUrl, 'webhook_secret' => $secret, ]); return $response->successful(); } catch (\Throwable $e) { Log::warning('chat webhook register failed', [ 'host' => $host, 'error' => $e->getMessage(), ]); return false; } } public function ensureSecret(): string { $existing = trim((string) Controller::Config('chat_webhook_secret')); if ($existing !== '') { return $existing; } $secret = Str::random(48); $row = Setting::where('key', 'chat_webhook_secret')->first(); if ($row) { if (trim((string) $row->value) === '') { $row->value = $secret; $row->save(); } else { return (string) $row->value; } } else { Setting::create([ 'key' => 'chat_webhook_secret', 'value' => $secret, 'title_fa' => 'رمز وب‌هوک چت', 'is_active' => true, 'can_edit' => 0, 'description' => 'رمز مشترک بین لاراول و سرور چت برای اعلان پیام پشتیبانی. فقط سرور؛ در صورت خالی بودن به‌صورت خودکار ساخته می‌شود.', 'type' => 'text', ]); } return $secret; } }