withHeaders($headers)->post($baseUrl . '/api/sendText', [ 'session' => config('services.whatsapp.waha_session', 'default'), 'chatId' => $target . '@c.us', 'text' => $message, ]); if (!$response->successful()) { throw new RuntimeException('WAHA gagal mengirim pesan: HTTP ' . $response->status()); } return true; } $token = (string) config('services.whatsapp.fonnte_token'); if ($token === '') { throw new RuntimeException('FONNTE_TOKEN belum dikonfigurasi.'); } $response = Http::asForm()->timeout(8)->withHeaders([ 'Authorization' => $token, ])->post('https://api.fonnte.com/send', [ 'target' => $target, 'message' => $message, ]); if (!$response->successful()) { throw new RuntimeException('Fonnte gagal mengirim pesan: HTTP ' . $response->status()); } return true; } public static function configured(): bool { $provider = strtolower((string) config('services.whatsapp.provider', 'fonnte')); return $provider === 'waha' ? (string) config('services.whatsapp.waha_url') !== '' : (string) config('services.whatsapp.fonnte_token') !== ''; } public static function normalizePhone(string $phone): string { $phone = preg_replace('/\D+/', '', $phone) ?: ''; if (str_starts_with($phone, '0')) { $phone = '62' . substr($phone, 1); } if (!str_starts_with($phone, '62')) { $phone = '62' . ltrim($phone, '0'); } return $phone; } }