File: /var/www/html/api.aianced.com/app/Services/MakeWebhookService.php
<?php
namespace App\Services;
use App\Models\Lead;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class MakeWebhookService
{
/**
* Fire the Make.com webhook for a new lead.
* Silently logs on failure — never throws.
*/
public function sendLead(Lead $lead): void
{
$url = config('aianced.make_webhook_url');
if (!$url) {
return; // Webhook not configured — skip silently
}
$summary = $lead->summary ?? [];
$payload = [
'name' => $lead->name,
'email' => $lead->email,
'phone' => $lead->phone ?? '',
'idea' => $lead->idea_text,
'product_type' => $summary['productType'] ?? '',
'features' => $summary['features'] ?? [],
];
$http = Http::timeout(10);
$apiKey = config('aianced.make_api_key');
if ($apiKey) {
$http = $http->withHeaders(['x-make-apikey' => $apiKey]);
}
try {
$response = $http->post($url, $payload);
if (!$response->successful()) {
Log::warning('Make.com webhook returned non-2xx', [
'status' => $response->status(),
'body' => $response->body(),
'lead_id' => $lead->id,
]);
}
} catch (\Throwable $e) {
Log::error('Make.com webhook failed', [
'error' => $e->getMessage(),
'lead_id' => $lead->id,
]);
}
}
}