-
-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
fixed the tests here |
@girardinsamuel I modified this a bit. Now a notification class takes a basic Now a notification class must inherit from different utility classes to do things. To send an email it will inherit from the normal Mailable class to build a mailable. It can also inherit from a This is an example of a notification class: class OneTimePassword(Notification, Mailable, Textable):
def to_mail(self, notifiable):
return (
self
.to(notifiable.email)
.subject("Masonite 4")
.from_("[email protected]")
.text(f"Hello {notifiable.name}")
)
def to_vonage(self, notifiable):
return self.text_message("Welcome !").to('6314870798').from_("33123456789")
def via(self, notifiable):
return ["vonage"] Notice it inherits from a view different classes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did another complete code review. Also manually tested this feature and with some changes i already did i think it works really well. Before i do more manual testing i just did another code review where we need to talk about a few things i commented on.
Also need to remove the queuing stuff. I think we'll have to revisit that in the future
There is also some TODO we need to address.
Once those changes are made i can retest some of the other features like the database notifications and broadcast drivers
I will take a look and make changes beginning of next week ! |
Yeaaahhhhh 🚀 |
Fixes #32
Specs
mail
notificationslack
notificationsdatabase
driver to save notifications in databasebroadcast
driver to broadcast notificationsvonage
driver (ex Nexmo) to send SMS notificationsNotifiable
mixin to set app models notifiable (such as User).Documentation
Doc has been written here MasoniteFramework/docs#131, so most of it could be taken from this PR when writing M4 docs 🚀
TLDR
We can create a notification with
craft notification Welcome
.We can send it via the different drivers either by resolving
notification
:or by sending to a
Notifiable
entity (such as User):A notification is built this way:
meaning that for each driver we should define a
to_{driver}
explaining how to build the notification. We have access to the notifiable here (e.g. our user instance for non anonymous notifications).The
via()
explains through which drivers it should be sent. You can run any logic you want here because you have access to notifiable ! Of course when sending notification, it can be overriden :If you want to queue the notification sending operation you can subclass the notification with
ShouldQueue
, that's it. For each driver, the sending job will be pushed onto the queue.If you want to store notifications in database also, it's done as a driver also. You should first create the notifs table
craft notification:table
. The default name isnotifications
but can be overriden in the config. Then update your notification:then
Adding new notification channels/drivers is really easy, all we need is to create a new driver and register it. It should implement send() and queue() methods and can use config/notifications.py to store its own config.
TODO
finish adding queuing for all drivers(postponed)