email) { $channels[] = 'mail'; } return $channels; } public function toMail($notifiable) { $kit = new EventInviteKit; $mail = (new \Illuminate\Notifications\Messages\MailMessage) ->subject('Call for Participation — '.$this->event->title) ->greeting('Hello '.($notifiable->name ?: 'there').',') ->line('"'.$this->event->title.'" is live on Academeet and open for registration.') ->line('The attached card is ready to share — WhatsApp status, department groups, notice boards. Every scan opens a WhatsApp chat with the registration message ready.') ->action('View event page', route('events.show', $this->event)) ->line('Direct registration link: '.$kit->link($this->event)); try { $mail->attach($kit->image($this->event), [ 'as' => 'call-for-participation-'.$this->event->slug.'.png', 'mime' => 'image/png', ]); } catch (\Throwable $e) { report($e); // card render failure must not block the email } return $mail; } public function toWhatsApp($notifiable) { $kit = new EventInviteKit; $caption = $kit->shareMessage($this->event); $mediaId = $this->uploadCard($kit); if (! $mediaId) { // No card — the link alone still does the job. return ['text' => $caption]; } $service = app(WhatsAppService::class); try { $response = $service->sendImage($notifiable->phone, $mediaId, $caption); } catch (WhatsAppApiException $exception) { if (! $service->failedOnWindow($exception)) { throw $exception; } $response = $exception; } if ($service->failedOnWindow($response)) { // Outside the window free-form media is refused; the text template // at least gets the link there. return [ 'template' => 'event_published', 'parameters' => [ $this->event->title, $kit->link($this->event), ], ]; } return null; // already delivered } public function toArray($notifiable) { $kit = new EventInviteKit; return [ 'data' => [ 'meeting_title' => 'Share your event', 'message' => 'Registration card ready for '.$this->event->title, 'event_id' => $this->event->id, 'invite_link' => $kit->link($this->event), ], ]; } protected function uploadCard(EventInviteKit $kit): ?string { try { return app(WhatsAppService::class)->uploadMedia( $kit->image($this->event), 'image/png' ); } catch (\Throwable $e) { report($e); // a missing card must not swallow the link Log::warning('Event invite card unavailable for WhatsApp delivery.', [ 'event_id' => $this->event->id, 'error' => $e->getMessage(), ]); return null; } } }