*/ class IncidentUpdatedNotification extends Notification { use Queueable; /** * The incident update. * * @var \CachetHQ\Cachet\Models\IncidentUpdate */ protected $update; /** * Create a new notification instance. * * @param \CachetHQ\Cachet\Models\IncidentUpdate $update * * @return void */ public function __construct(IncidentUpdate $update) { $this->update = AutoPresenter::decorate($update); } /** * Get the notification's delivery channels. * * @param mixed $notifiable * * @return string[] */ public function via($notifiable) { return ['mail', 'nexmo', 'slack']; } /** * Get the mail representation of the notification. * * @param mixed $notifiable * * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { $content = trans('notifications.incident.update.mail.content', [ 'name' => $this->update->incident->name, 'time' => $this->update->created_at_diff, ]); return (new MailMessage()) ->subject(trans('notifications.incident.update.mail.subject')) ->greeting(trans('notifications.incident.update.mail.title', [ 'name' => $this->update->incident->name, 'new_status' => $this->update->human_status, ])) ->line($content) ->action(trans('notifications.incident.update.mail.action'), cachet_route('incident', [$this->update->incident])) ->line($this->update->raw_message) ->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)])) ->line(trans('cachet.subscriber.manage.manage_at_link', ['link' => cachet_route('subscribe.manage', $notifiable->verify_code)])); } /** * Get the Nexmo / SMS representation of the notification. * * @param mixed $notifiable * * @return \Illuminate\Notifications\Messages\NexmoMessage */ public function toNexmo($notifiable) { $content = trans('notifications.incident.update.sms.content', [ 'name' => $this->update->incident->name, ]); return (new NexmoMessage())->content($content); } /** * Get the Slack representation of the notification. * * @param mixed $notifiable * * @return \Illuminate\Notifications\Messages\SlackMessage */ public function toSlack($notifiable) { $content = trans('notifications.incident.update.slack.content', [ 'name' => $this->update->incident->name, 'new_status' => $this->update->human_status, ]); $status = 'info'; if ($this->update->status === Incident::FIXED) { $status = 'success'; } elseif ($this->update->status === Incident::WATCHED) { $status = 'warning'; } else { $status = 'error'; } return (new SlackMessage()) ->$status() ->content($content) ->attachment(function ($attachment) use ($content, $notifiable) { $attachment->title(trans('notifications.incident.update.slack.title', [ 'name' => $this->update->incident->name, 'new_status' => $this->update->human_status, ])) ->timestamp($this->update->getWrappedObject()->created_at) ->fields(array_filter([ 'ID' => "#{$this->update->id}", 'Link' => $this->update->permalink, ])) ->footer(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)])); }); } }