Notificationclass. This class will act as the settings for your notification such as the delivery channels and the content of the notification for those different channels (mail, slack, sms, ...).
viamethod that specify on which channels the notification will be delivered. Notifications may be sent on the
vonagechannels. More details on this later. When sending the notification it will be automatically sent to each channel.
viamethod should returns a list of the channels you want your notification to be delivered on. This method receives a
Notifiableto allow notifications to be sent to them. The most common use case is to set
Notifiableas we often need to send notifications to users.
Notifiablemixin to it:
Queueableclass and it will automatically send your notifications into the queue to be processed later. This is a great way to speed up your application:
to_mailmethod on the notification class to specify how to build the email notification content.
to_slackmethod on the notification class to specify how to build the slack notification content.
SlackComponenttakes different options to configure your notification:
iconthat will be displayed as the sender.
title. This uses a different API endpoint so some previous methods may not be used.
SLACK_TOKENenvironment variable. Or you can configure different tokens (with eventually different scopes) per notifications.
block()option. Once again you can chain as many blocks as you want.
route_notification_for_slackmethod on your notifiable to return either
channel name, a
channel IDor a
sms_fromwhich is the phone number or name that your SMS will be sent from. You can generate a phone number for your application in the Vonage dashboard.
to_vonagemethod on the notification class to specify how to build the sms notification content.
sms_fromnumber can be overriden inside the notification class:
route_notification_for_vonagemethod on your notifiable to return a phone number or a list of phone numbers to send the notification to.
Notifiableentities. The notification is stored in a
notificationstable. This table will contain information such as the notification type as well as a JSON data structure that describes the notification.
to_databasemethod on the notification class to specify how to build the notification content that will be persisted.
JSONdata (as it will be saved into a
TEXTcolumn in the notifications table). You also need to add
databasechannel to the
viamethod to enable database notification storage.
DatabaseNotificationand has the following fields:
idis the primary key of the model (defined with UUID4)
typewill store the notification type as a string (e.g.
read_atis the timestamp indicating when notification has been read
datais the serialized representation of
notifiableis the relationship returning the
Notifiableentity a notification belongs to (e.g.
notificationsrelationship that will returns the notifications for the entity:
CanBroadcastclass and specify the
to_broadcastmethod on the notification class to specify how to build the notification content that will be broadcasted
broadcast_onmethod but you can override this per notifiable by implementing
route_notification_for_broadcastmethod on your notifiable:
get_data()method will be available and will return the data defined in the
to_voice()method of the notification.
fail_silentlyparameter is enabled, notifications sending will not raise exceptions if an error occurs.
via()method of the notification can be overriden at send:
channelsparameter we can send to other channels (if correctly defined in notification class):