https://github.com/anyidea/django-user-notification
Send multiple types of notification messages to django users out of box.
https://github.com/anyidea/django-user-notification
aliyunsms dingtalk django notifications python
Last synced: 9 months ago
JSON representation
Send multiple types of notification messages to django users out of box.
- Host: GitHub
- URL: https://github.com/anyidea/django-user-notification
- Owner: anyidea
- License: apache-2.0
- Created: 2022-10-12T08:45:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-11T07:27:28.000Z (almost 2 years ago)
- Last Synced: 2025-01-11T14:50:29.564Z (over 1 year ago)
- Topics: aliyunsms, dingtalk, django, notifications, python
- Language: Python
- Homepage:
- Size: 145 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Authors: AUTHORS.rst
Awesome Lists containing this project
README
# Django user notification
[](https://github.com/wccdev/django-user-notification/actions/workflows/ci.yml)
[](https://github.com/anyidea/django-user-notification/blob/master/LICENSE)
[](https://django-user-notification.readthedocs.io/en/latest/?badge=latest)
[](https://pypi.python.org/pypi/django-user-notification)

[](https://www.djangoproject.com/)
[](https://python-poetry.org/)
[](https://github.com/psf/black)
Overview
-----
Django user notification is intended to provide a way to send multiple types of notification messages to django users out of box.
Documentation
-----
on the way...
Requirements
-----
* Python 3.8, 3.9, 3.10
* Django 3.1, 3.2, 4.0, 4.1, 4.2
Installation
-----
Install using `pip`...
pip install django-user-notification
Add `'tinymce'` and `'notification'` to your `INSTALLED_APPS` setting.
```python
INSTALLED_APPS = [
'django.contrib.admin',
...
'tinymce',
'notification',
]
```
Quick Start
-----
Let's take a look at a quick start of using Django user notification to send notification messages to users.
Run the `notification` migrations using:
python manage.py migrate notification
Add the following to your `settings.py` module:
```python
INSTALLED_APPS = [
... # Make sure to include the default installed apps here.
'tinymce',
'notification',
]
DJANGO_USER_NOTIFICATION = {
"aliyunsms": {
"access_key_id": "Your Access Key ID",
"access_key_secret": "Your Access Key Secret",
"sign_name": "Your Sign Name",
},
"dingtalkchatbot": {
"webhook": "Your Webhook URL",
},
"dingtalkworkmessage": {
"agent_id": "Your App Agent ID",
"app_key": "Your App Key",
"app_secret": "Your App Secret",
},
"dingtalktodotask": {
"app_key": "Your App Key",
"app_secret": "Your App Secret",
},
}
```
Let's send a notification
``` {.python}
from django.contrib.auth import get_user_model
from notification.backends import notify_by_email, notify_by_dingtalk_workmessage
User = get_user_model()
recipient = User.objects.first()
# send a dingtalk work message notification
notify_by_dingtalk_workmessage([recipient], phone_field="phone", title="This is a title", message="A test message")
# send a email notiofication
notify_by_email([recipient], title="This is a title", message="A test message")
```
Send Message With Template
--------------
`django-user-notification` support send notifications with custom template, To
specify a custom message template you can provide the `template_code`
and `context` parameters.
1) Create a template message with code named `TMP01` on django admin
2) Provide the `template_code` and `context` to `send` method:
``` {.python}
...
notify_by_email([recipient], template_code="TMP01", context={"content": "Hello"})
```
Supported backends
-----------------------------
- `DummyNotificationBackend`: send dummy message
- `EmailNotificationBackend`: send email notification.
- `WebsocketNotificationBackend`: send webdocket notification, need install extension: `channels`.
- `AliyunSMSNotificationBackend`: send aliyun sms notification, need install extension: `aliyunsms`.
- `DingTalkChatbotNotificationBackend`: send dingtalk chatbot notification.
- `DingTalkToDoTaskNotificationBackend`: send dingtalk todo tasks notification
- `DingTalkWorkMessageNotificationBackend`: send dingtalk work message notification.
- `WechatNotificationBackend`: planning...
Running the tests
-----------------
To run the tests against the current environment:
``` {.bash}
$ pytest tests/
```
Changelog
---------
### 0.7.0
- Initial release
Contributing
------------
As an open source project, we welcome contributions. The code lives on [GitHub](https://github.com/anyidea/django-user-notification/)