name, 'parameters' => [...]] or ['text' => '...']. */ public function send($notifiable, Notification $notification) { if (empty($notifiable->phone) || is_null($notifiable->phone_verified_at)) { return; } if (! is_null($notifiable->whatsapp_optout_at ?? null)) { return; } $message = $notification->toWhatsApp($notifiable); if (! $message) { return; } $service = app(WhatsAppService::class); // When a notification offers both, the free-form text is the one worth // sending — it reads like the conversation the person is already in. // Templates are the fallback for when the 24-hour service window has // closed and Meta refuses free-form messages. if (isset($message['text'])) { try { $response = $service->sendText($notifiable->phone, $message['text']); } catch (WhatsAppApiException $exception) { if (! isset($message['template']) || ! $service->failedOnWindow($exception)) { throw $exception; } $response = $exception; } if (! isset($message['template']) || ! $service->failedOnWindow($response)) { return; } } if (isset($message['template'])) { $service->sendTemplate( $notifiable->phone, $message['template'], $message['parameters'] ?? [] ); } } }