E-mail
, Slack
and SMS
notificationsNotification
class. 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, ...).via
method that specify on which channels the notification will be delivered. Notifications may be sent on the mail
, database
, broadcast
, slack
and vonage
channels. More details on this later. When sending the notification it will be automatically sent to each channel.via
method should returns a list of the channels you want your notification to be delivered on. This method receives a notifiable
instance.Notification
class:database
channel cannot be used with those notifications because no Notifiable entity is attached to it.Notification
class to send notification:notify()
method:Notifiable
to allow notifications to be sent to them. The most common use case is to set User
model as Notifiable
as we often need to send notifications to users.Notifiable
mixin to it:user.notify()
method.route_notification_for_{driver}
method.mail
driver you can define:email
field or if you want to add some logic to get the recipient email.Queueable
class 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_mail
method on the notification class to specify how to build the email notification content.config/mail.py
. For more information about options to build mail notifications, please check out Mailable options.to_slack
method on the notification class to specify how to build the slack notification content.SlackComponent
takes different options to configure your notification:url
or icon
that will be displayed as the sender.file_type
, name
, and title
. This uses a different API endpoint so some previous methods may not be used.channels:read
, chat:write:bot
, chat:write:user
and files:write:user
permission scopes. If your token does not have these scopes then parts of this feature will not work.config/notifications.py
file as SLACK_TOKEN
environment variable. Or you can configure different tokens (with eventually different scopes) per notifications.slackblocks
python API to handle Block Kit formatting.block()
option. Once again you can chain as many blocks as you want.slackblocks
documentation and more information in Slack blocks list.slackblocks
, but most of them should be there.route_notification_for_slack
method on your notifiable to return eitherroute
methodchannel name
, a channel ID
or a webhook URL
.#
in the name as in the example. Based on this name a reverse lookup will be made to find the corresponding Slack channel ID. If you want to avoid this extra call, you can get the channel ID in your Slack workspace (right click on a Slack channel > Copy Name > the ID is at the end of url)vonage
Python client.VONAGE_KEY
and VONAGE_SECRET
credentials in notifications.py
configuration file:sms_from
which 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_vonage
method on the notification class to specify how to build the sms notification content.sms_from
number can be overriden inside the notification class:route_notification_for_vonage
method on your notifiable to return a phone number or a list of phone numbers to send the notification to.route
methodNotifiable
entities. The notification is stored in a notifications
table. This table will contain information such as the notification type as well as a JSON data structure that describes the notification.to_database
method on the notification class to specify how to build the notification content that will be persisted.str
, dict
or JSON
data (as it will be saved into a TEXT
column in the notifications table). You also need to add database
channel to the via
method to enable database notification storage.notifications
table.DatabaseNotification
and has the following fields:id
is the primary key of the model (defined with UUID4)type
will store the notification type as a string (e.g. WelcomeNotification
)read_at
is the timestamp indicating when notification has been readdata
is the serialized representation of to_database()
notifiable
is the relationship returning the Notifiable
entity a notification belongs to (e.g. User
)created_at
, updated_at
timestampsnotifications
relationship that will returns the notifications for the entity:mark_as_read
and mark_as_unread
methodsMasonite ORM
models, meaning you can for example make more complex queries to fetch notifications, directly on the model.CanBroadcast
class and specify the broadcast_on
methodto_broadcast
method on the notification class to specify how to build the notification content that will be broadcastedbroadcast_on
method but you can override this per notifiable by implementing route_notification_for_broadcast
method on your notifiable:send
and queue
.get_data()
method will be available and will return the data defined in the to_voice()
method of the notification.fail_silently
parameter is enabled, notifications sending will not raise exceptions if an error occurs.via()
method of the notification can be overriden at send:channels
parameter we can send to other channels (if correctly defined in notification class):