Granular notification strings. Closes #2303

This commit is contained in:
James Brooks 2017-01-09 18:41:51 +00:00
parent a81c87bed7
commit c1831d8559
8 changed files with 115 additions and 74 deletions

View File

@ -77,17 +77,17 @@ class ComponentStatusChangedNotification extends Notification
*/ */
public function toMail($notifiable) public function toMail($notifiable)
{ {
$content = trans('notifications.component.status_update.content', [ $content = trans('notifications.component.status_update.mail.content', [
'name' => $this->component->name, 'name' => $this->component->name,
'old_status' => $this->component->human_status, 'old_status' => $this->component->human_status,
'new_status' => trans("cachet.components.status.{$this->status}"), 'new_status' => trans("cachet.components.status.{$this->status}"),
]); ]);
return (new MailMessage()) return (new MailMessage())
->subject(trans('notifications.component.status_update.subject')) ->subject(trans('notifications.component.status_update.mail.subject'))
->greeting(trans('notifications.component.status_update.title')) ->greeting(trans('notifications.component.status_update.mail.title'))
->line($content) ->line($content)
->action('View', cachet_route('status-page')) ->action(trans('notifications.component.status_update.mail.action'), cachet_route('status-page'))
->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)])); ->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)]));
} }
@ -100,7 +100,7 @@ class ComponentStatusChangedNotification extends Notification
*/ */
public function toNexmo($notifiable) public function toNexmo($notifiable)
{ {
$content = trans('notifications.component.status_update.content', [ $content = trans('notifications.component.status_update.sms.content', [
'name' => $this->component->name, 'name' => $this->component->name,
'old_status' => $this->component->human_status, 'old_status' => $this->component->human_status,
'new_status' => trans("cachet.components.status.{$this->status}"), 'new_status' => trans("cachet.components.status.{$this->status}"),
@ -118,7 +118,7 @@ class ComponentStatusChangedNotification extends Notification
*/ */
public function toSlack($notifiable) public function toSlack($notifiable)
{ {
$content = trans('notifications.component.status_update.content', [ $content = trans('notifications.component.status_update.slack.content', [
'name' => $this->component->name, 'name' => $this->component->name,
'old_status' => $this->component->human_status, 'old_status' => $this->component->human_status,
'new_status' => trans("cachet.components.status.{$this->status}"), 'new_status' => trans("cachet.components.status.{$this->status}"),
@ -136,7 +136,7 @@ class ComponentStatusChangedNotification extends Notification
return (new SlackMessage()) return (new SlackMessage())
->$status() ->$status()
->content(trans('notifications.component.status_update.title')) ->content(trans('notifications.component.status_update.slack.title'))
->attachment(function ($attachment) use ($content, $notifiable) { ->attachment(function ($attachment) use ($content, $notifiable) {
$attachment->title($content, cachet_route('status-page')) $attachment->title($content, cachet_route('status-page'))
->fields(array_filter([ ->fields(array_filter([

View File

@ -69,15 +69,15 @@ class NewIncidentNotification extends Notification
*/ */
public function toMail($notifiable) public function toMail($notifiable)
{ {
$content = trans('notifications.incident.new.content', [ $content = trans('notifications.incident.new.mail.content', [
'name' => $this->incident->name, 'name' => $this->incident->name,
]); ]);
return (new MailMessage()) return (new MailMessage())
->subject(trans('notifications.incident.new.subject')) ->subject(trans('notifications.incident.new.mail.subject'))
->greeting(trans('notifications.incident.new.title', ['app_name' => Config::get('setting.app_name')])) ->greeting(trans('notifications.incident.new.mail.greeting', ['app_name' => Config::get('setting.app_name')]))
->line($content) ->line($content)
->action('View Incident', cachet_route('incident', [$this->incident])) ->action(trans('notifications.incident.new.mail.action'), cachet_route('incident', [$this->incident]))
->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)])); ->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)]));
} }
@ -90,11 +90,9 @@ class NewIncidentNotification extends Notification
*/ */
public function toNexmo($notifiable) public function toNexmo($notifiable)
{ {
$content = trans('notifications.incident.new.content', [ return (new NexmoMessage())->content(trans('notifications.incident.new.sms.content', [
'name' => $this->incident->name, 'name' => $this->incident->name,
]); ]));
return (new NexmoMessage())->content($content);
} }
/** /**
@ -106,8 +104,8 @@ class NewIncidentNotification extends Notification
*/ */
public function toSlack($notifiable) public function toSlack($notifiable)
{ {
$content = trans('notifications.incident.new.content', [ $content = trans('notifications.incident.new.slack.content', [
'name' => $this->incident->name, 'app_name' => Config::get('setting.app_name')
]); ]);
$status = 'info'; $status = 'info';
@ -122,9 +120,9 @@ class NewIncidentNotification extends Notification
return (new SlackMessage()) return (new SlackMessage())
->$status() ->$status()
->content(trans('notifications.incident.new.title', ['app_name' => Config::get('setting.app_name')])) ->content($content)
->attachment(function ($attachment) use ($content) { ->attachment(function ($attachment) use ($content) {
$attachment->title($content) $attachment->title(trans('notifications.incident.new.slack.title', [$this->incident->name]))
->timestamp($this->incident->getWrappedObject()->occurred_at) ->timestamp($this->incident->getWrappedObject()->occurred_at)
->fields(array_filter([ ->fields(array_filter([
'ID' => "#{$this->incident->id}", 'ID' => "#{$this->incident->id}",

View File

@ -69,19 +69,19 @@ class IncidentUpdatedNotification extends Notification
*/ */
public function toMail($notifiable) public function toMail($notifiable)
{ {
$content = trans('notifications.incident.update.content', [ $content = trans('notifications.incident.update.mail.content', [
'name' => $this->update->incident->name, 'name' => $this->update->incident->name,
'time' => $this->update->created_at_diff, 'time' => $this->update->created_at_diff,
]); ]);
return (new MailMessage()) return (new MailMessage())
->subject(trans('notifications.incident.update.subject')) ->subject(trans('notifications.incident.update.mail.subject'))
->greeting(trans('notifications.incident.update.title', [ ->greeting(trans('notifications.incident.update.mail.title', [
'name' => $this->update->incident->name, 'name' => $this->update->incident->name,
'new_status' => $this->update->human_status, 'new_status' => $this->update->human_status,
])) ]))
->line($content) ->line($content)
->action('View Incident', cachet_route('incident', [$this->update->incident])) ->action(trans('notifications.incident.update.mail.action'), cachet_route('incident', [$this->update->incident]))
->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)])); ->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)]));
} }
@ -94,7 +94,7 @@ class IncidentUpdatedNotification extends Notification
*/ */
public function toNexmo($notifiable) public function toNexmo($notifiable)
{ {
$content = trans('notifications.incident.update.content', [ $content = trans('notifications.incident.update.sms.content', [
'name' => $this->update->incident->name, 'name' => $this->update->incident->name,
]); ]);
@ -110,7 +110,7 @@ class IncidentUpdatedNotification extends Notification
*/ */
public function toSlack($notifiable) public function toSlack($notifiable)
{ {
$content = trans('notifications.incident.update.content', [ $content = trans('notifications.incident.update.slack.content', [
'name' => $this->update->incident->name, 'name' => $this->update->incident->name,
]); ]);
@ -126,12 +126,12 @@ class IncidentUpdatedNotification extends Notification
return (new SlackMessage()) return (new SlackMessage())
->$status() ->$status()
->content(trans('notifications.incident.update.title', [ ->content($content)
->attachment(function ($attachment) use ($content) {
$attachment->title(trans('notifications.incident.update.slack.title', [
'name' => $this->update->incident->name, 'name' => $this->update->incident->name,
'new_status' => $this->update->human_status, 'new_status' => $this->update->human_status,
])) ]))
->attachment(function ($attachment) use ($content) {
$attachment->title($content)
->timestamp($this->update->getWrappedObject()->created_at) ->timestamp($this->update->getWrappedObject()->created_at)
->fields(array_filter([ ->fields(array_filter([
'ID' => "#{$this->update->id}", 'ID' => "#{$this->update->id}",

View File

@ -68,16 +68,16 @@ class NewScheduleNotification extends Notification
*/ */
public function toMail($notifiable) public function toMail($notifiable)
{ {
$content = trans('notifications.schedule.new.content', [ $content = trans('notifications.schedule.new.mail.content', [
'name' => $this->schedule->name, 'name' => $this->schedule->name,
'date' => $this->schedule->scheduled_at_formatted, 'date' => $this->schedule->scheduled_at_formatted,
]); ]);
return (new MailMessage()) return (new MailMessage())
->subject(trans('notifications.schedule.new.subject')) ->subject(trans('notifications.schedule.new.mail.subject'))
->greeting(trans('notifications.schedule.new.title')) ->greeting(trans('notifications.schedule.new.mail.title'))
->line($content) ->line($content)
->action('View Schedule', cachet_route('schedule', [$this->schedule])) ->action(trans('notifications.schedule.new.mail.action'), cachet_route('schedule', [$this->schedule]))
->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)])); ->line(trans('cachet.subscriber.unsubscribe', ['link' => cachet_route('subscribe.unsubscribe', $notifiable->verify_code)]));
} }
@ -90,7 +90,7 @@ class NewScheduleNotification extends Notification
*/ */
public function toNexmo($notifiable) public function toNexmo($notifiable)
{ {
$content = trans('notifications.schedule.new.content', [ $content = trans('notifications.schedule.new.sms.content', [
'name' => $this->schedule->name, 'name' => $this->schedule->name,
'date' => $this->schedule->scheduled_at_formatted, 'date' => $this->schedule->scheduled_at_formatted,
]); ]);
@ -107,13 +107,13 @@ class NewScheduleNotification extends Notification
*/ */
public function toSlack($notifiable) public function toSlack($notifiable)
{ {
$content = trans('notifications.schedule.new.content', [ $content = trans('notifications.schedule.new.slack.content', [
'name' => $this->schedule->name, 'name' => $this->schedule->name,
'date' => $this->schedule->scheduled_at_formatted, 'date' => $this->schedule->scheduled_at_formatted,
]); ]);
return (new SlackMessage()) return (new SlackMessage())
->content(trans('notifications.schedule.new.title')) ->content(trans('notifications.schedule.new.slack.title'))
->attachment(function ($attachment) use ($content) { ->attachment(function ($attachment) use ($content) {
$attachment->title($content) $attachment->title($content)
->timestamp($this->schedule->getWrappedObject()->scheduled_at) ->timestamp($this->schedule->getWrappedObject()->scheduled_at)

View File

@ -47,9 +47,9 @@ class VerifySubscriptionNotification extends Notification
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage()) return (new MailMessage())
->subject(trans('notifications.subscriber.verify.subject')) ->subject(trans('notifications.subscriber.verify.mail.subject'))
->greeting(trans('notifications.subscriber.verify.title', ['app_name' => Config::get('setting.app_name')])) ->greeting(trans('notifications.subscriber.verify.mail.title', ['app_name' => Config::get('setting.app_name')]))
->action(trans('notifications.subscriber.verify.action'), cachet_route('subscribe.verify', ['code' => $notifiable->verify_code])) ->action(trans('notifications.subscriber.verify.mail.action'), cachet_route('subscribe.verify', ['code' => $notifiable->verify_code]))
->line(trans('notifications.subscriber.verify.content', ['app_name' => Config::get('setting.app_name')])); ->line(trans('notifications.subscriber.verify.mail.content', ['app_name' => Config::get('setting.app_name')]));
} }
} }

View File

@ -46,8 +46,8 @@ class SystemTestNotification extends Notification
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage()) return (new MailMessage())
->subject(trans('notifications.system.test.subject')) ->subject(trans('notifications.system.test.mail.subject'))
->greeting(trans('notifications.system.test.title')) ->greeting(trans('notifications.system.test.mail.title'))
->line(trans('notifications.system.test.content')); ->line(trans('notifications.system.test.mail.content'));
} }
} }

View File

@ -47,9 +47,9 @@ class InviteUserNotification extends Notification
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage()) return (new MailMessage())
->subject(trans('notifications.user.invite.subject')) ->subject(trans('notifications.user.invite.mail.subject'))
->greeting(trans('notifications.user.invite.title', ['app_name' => Config::get('setting.app_name')])) ->greeting(trans('notifications.user.invite.mail.title', ['app_name' => Config::get('setting.app_name')]))
->action(trans('notifications.user.invite.action'), cachet_route('signup.invite', [$notifiable->code])) ->action(trans('notifications.user.invite.mail.action'), cachet_route('signup.invite', [$notifiable->code]))
->line(trans('notifications.user.invite.content', ['app_name' => Config::get('setting.app_name')])); ->line(trans('notifications.user.invite.mail.content', ['app_name' => Config::get('setting.app_name')]));
} }
} }

View File

@ -12,54 +12,97 @@
return [ return [
'component' => [ 'component' => [
'status_update' => [ 'status_update' => [
'mail' => [
'subject' => 'Component Status Updated', 'subject' => 'Component Status Updated',
'title' => 'A component\'s status was updated!', 'greeting' => 'A component\'s status was updated!',
'content' => ':name status changed from :old_status to :new_status.', 'content' => ':name status changed from :old_status to :new_status.',
'action' => 'View',
],
'slack' => [
'title' => 'Component Status Updated',
'content' => ':name status changed from :old_status to :new_status.',
],
'sms' => [
'content' => ':name status changed from :old_status to :new_status.',
],
], ],
], ],
'incident' => [ 'incident' => [
'new' => [ 'new' => [
'mail' => [
'subject' => 'New Incident Reported', 'subject' => 'New Incident Reported',
'content' => ':name was reported', 'greeting' => 'A new incident was reported at :app_name.',
'title' => 'A new incident was reported at :app_name status page.', 'content' => 'Incident :name was reported',
'action' => 'View', 'action' => 'View',
], ],
'slack' => [
'title' => 'Incident :name Reported',
'content' => 'A new incident was reported at :app_name',
],
'sms' => [
'content' => 'A new incident was reported at :app_name.',
],
],
'update' => [ 'update' => [
'mail' => [
'subject' => 'Incident Updated', 'subject' => 'Incident Updated',
'content' => ':name was updated', 'content' => ':name was updated',
'title' => ':name was updated to :new_status', 'title' => ':name was updated to :new_status',
'action' => 'View', 'action' => 'View',
], ],
'slack' => [
'title' => ':name Updated',
'content' => ':name was updated to :new_status',
],
'sms' => [
'content' => 'Incident :name was updated',
],
],
], ],
'schedule' => [ 'schedule' => [
'new' => [ 'new' => [
'mail' => [
'subject' => 'New Schedule Created', 'subject' => 'New Schedule Created',
'content' => ':name was scheduled for :date', 'content' => ':name was scheduled for :date',
'title' => 'A new scheduled maintenance was created.', 'title' => 'A new scheduled maintenance was created.',
'action' => 'View', 'action' => 'View',
], ],
'slack' => [
'title' => 'New Schedule Created!.'
'content' => ':name was scheduled for :date',
],
'sms' => [
'content' => ':name was scheduled for :date',
],
],
], ],
'subscriber' => [ 'subscriber' => [
'verify' => [ 'verify' => [
'mail' => [
'subject' => 'Verify Your Subscription', 'subject' => 'Verify Your Subscription',
'content' => 'Click to verify your subscription to :app_name status page.', 'content' => 'Click to verify your subscription to :app_name status page.',
'title' => 'Verify your subscription to :app_name status page.', 'title' => 'Verify your subscription to :app_name status page.',
'action' => 'Verify', 'action' => 'Verify',
], ],
], ],
],
'system' => [ 'system' => [
'test' => [ 'test' => [
'mail' => [
'subject' => 'Ping from Cachet!', 'subject' => 'Ping from Cachet!',
'content' => 'This is a test notification from Cachet!', 'content' => 'This is a test notification from Cachet!',
'title' => '🔔', 'title' => '🔔',
], ],
], ],
],
'user' => [ 'user' => [
'invite' => [ 'invite' => [
'mail' => [
'subject' => 'Your invitation is inside...', 'subject' => 'Your invitation is inside...',
'content' => 'You have been invited to join :app_name status page.', 'content' => 'You have been invited to join :app_name status page.',
'title' => 'You\'re invited to join :app_name status page.', 'title' => 'You\'re invited to join :app_name status page.',
'action' => 'Accept', 'action' => 'Accept',
], ],
], ],
],
]; ];