Mad Notifications
Mad Notifications app for django to send notifications to the user
Quick start
-
Add "mad_notifications" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
...
'mad_notifications',
]
-
Include the notifications URLconf in your project urls.py like this:
path('notifications/', include('mad_notifications.api.urls')),
-
Run python manage.py migrate
to create the notifications models.
Usage
Shorthand method
from mad_notifications.shorthand import newNotification
return newNotification(
user=user,
title="",
content="",
template_slug = None,
data = {},
actions = {}
)
Notification Class
from mad_notifications.notification import Notification
notification = Notification(
user = user,
title = "New Order",
content = "You have a new order!",
data = {
'order': order_data,
},
actions = {
'click_action': "ORDER_SCREEN"
},
template = email_template,
)
notification.notify()
Overriding default
MAD_NOTIFICATIONS_USER_NOTIFICATION_CONFIG_MODEL = "mad_notifications.UserNotificationConfig"
MAD_NOTIFICATIONS_NOTIFICATION_MODEL = "mad_notifications.Notification"
MAD_NOTIFICATIONS_TEMPLATE_MODEL = "mad_notifications.NotificationTemplate"
MAD_NOTIFICATIONS_DEVICE_MODEL = "mad_notifications.Device"
MAD_NOTIFICATIONS_DEFAULT_SMS_PROVIDER = "Twilio"
TWILIO_ACCOUNT_SID = ""
TWILIO_ACCOUNT_AUTH_TOKEN = ""
TWILIO_ACCOUNT_PHONE_NUMBER = ""
TELNYX_API_KEY = ""
TELNYX_MESSAGING_PROFILE = ""
TELNYX_FROM_PHONE_NUMBER = ""
MAD_NOTIFICATIONS = {
"FIREBASE_MOBILE_PUSH_NOTIFICATION_CLASS": "mad_notifications.senders.firebase.FirebaseMobilePushNotification",
"EMAIL_NOTIFICATION_CLASS": "mad_notifications.senders.email.EmailNotification",
"TWILIO_NOTIFICATION_CLASS": "mad_notifications.senders.twilio.TwilioNotification",
"TELNYX_NOTIFICATION_CLASS": "mad_notifications.senders.telnyx.TelnyxNotification",
"USER_NOTIFICATION_CONFIG_ADMIN_CLASS": "mad_notifications.admin.UserNotificationConfigAdmin",
"NOTIFICATION_TEMPLATE_ADMIN_CLASS": "mad_notifications.admin.NotificationTemplateAdmin",
"DEVICE_ADMIN_CLASS": "mad_notifications.admin.DeviceAdmin",
"NOTIFICATION_ADMIN_CLASS": "mad_notifications.admin.NotificationAdmin",
}
Developer Guide
Setting up a new provider
Create logic in ~/senders/PROVIDER.py
and call via tasks in ~/notify/PROVIDER.py