argument('url'); // @phpstan-ignore-line $secret = $this->option('secret') ?? $config->get('maxbot.webhook_secret'); $types = $this->option('types'); if (!filter_var($url, FILTER_VALIDATE_URL)) { $this->error('Invalid URL provided.'); return self::FAILURE; } $updateTypes = null; if (is_array($types) && !empty($types)) { $updateTypes = []; foreach ($types as $type) { try { $updateTypes[] = UpdateType::from($type); } catch (\ValueError $e) { $this->error("Invalid update type: $type"); return self::FAILURE; } } } $this->info('Subscribing to webhook...'); $this->line("URL: $url"); if ($secret) { $this->line("Secret: " . str_repeat('*', strlen($secret))); } if ($updateTypes) { $this->line("Update types: " . implode(', ', array_map(fn($type) => $type->value, $updateTypes))); } else { $this->line("Update types: All (default)"); } try { $result = $api->subscribe($url, $secret, $updateTypes); if ($result->success) { $this->info('✅ Successfully subscribed to webhook!'); return self::SUCCESS; } else { $this->error('❌ Failed to subscribe to webhook.'); $this->line("Response: $result->message"); return self::FAILURE; } } catch (Throwable $e) { Log::error("Webhook subscription error: {$e->getMessage()}", [ 'exception' => $e, ]); $this->error("❌ Webhook subscription error: {$e->getMessage()}"); return self::FAILURE; } } }