High-level framework for notifications
Project description
High-level framework for notifications
This project is intended to provide a convenient way to send notifications using multiple notification backends (e.g., e-mail, SMS, push).
Setting up
To start using universal_notifications please add universal_notifications to INSTALLED_APPS in your Django project, and then migrate the app: ./manage.py migrate universal_notifications.
Basic usage
WebSocket notifications
To have Universal Notifications receive WS notifications (ie. to mark notification as received) add to your settings.py:
WS4REDIS_SUBSCRIBER = 'universal_notifications.backend.websockets.RedisSubscriber'
Simple example of using WS notifications:
class OrderShippedWS(WSNotification):
message = 'order_shipped'
serializer_class = OrderSerializer
# ... somewhere in a view
OrderShippedWS(item=order, receivers=[user], context={}).send()
E-mail notifications
class OrderShippedEmail(EmailNotification):
email_name = 'order_shipped'
email_subject = _('Order no. {{item.pk}} has been shipped.')
# ... somewhere in a view
OrderShippedEmail(item=order, receivers=[user], context={}).send()
E-mail notifications allow filtering e-mail addreses which are unsubscribed from receiving e-mails from your service. This can be achievied by setting the UNIVERSAL_NOTIFICATIONS_UNSUBSCRIBED_MODEL property in your project’s settings.
Sample UnsubscribedModel should at least contain the email property. As result, all addresses existing in UnsubscribedModel objects will not receive any e-mails.
SMS notifications
class OrderShippedSMS(SMSNotification):
message = _('Order no. {{item.pk}} has been shipped.')
def prepare_receivers(self):
return {x.shipping_address.phone for x in self.receivers}
# ... somewhere in a view
OrderShippedSMS(item=order, receivers=[user], context={}).send(
Push notifications
First of all, to use push notifications, you must provide a list of available devices linked to users. For more information, please check out sources.
- Supported platforms:
- To make push notifications work on all supported platforms, a few properties need to be set:
- UNIVERSAL_NOTIFICATIONS_MOBILE_APPS[app_id]
APNS_CERTIFICATE - APNS certificate file
FCM_API_KEY - Firebase API key
GCM_API_KEY - Google Cloud Messaging API key
GCM_POST_URL - Google Cloud Messaging post url
- Settings related to Apple Push Notification service:
APNS_HOST
APNS_PORT
APNS_FEEDBACK_HOST
APNS_FEEDBACK_PORT
APNS_ERROR_TIMEOUT
APNS_MAX_NOTIFICATION_SIZE
Simple example of use:
class OrderShippedPush(PushNotification):
message = _('Order no. {{item.pk}} has been shipped.')
# ... somewhere in a view
OrderShippedPush(item=order, receivers=[user], context={}).send()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for universal_notifications-0.6.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78eb43fb78299b2d74215ff1c8a1b57dc4b904d728f73af3a3717757c2931aad |
|
MD5 | 6dc7a48eabfbe16743e4e2523b548c82 |
|
BLAKE2b-256 | 1b2c1ac5688be89a4b2c456c8a59efd31dc265422aaa92d783fded7f0bd9049c |
Hashes for universal_notifications-0.6.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c2dd08b425eaa0354011181baf8c36f4301089a84a8d8488b99b3138ee07ddc |
|
MD5 | 6d058923077d5e0990b9831a64bda4db |
|
BLAKE2b-256 | a59cce5fe1fc116be21fcc92fcd29c7551e5f24a9975b30615e66e6e7266587c |