Skip to content

Commit 2c6f092

Browse files
authored
feat: Add email provider (#78)
* feat: Add email provider * Update pusher settings * Update FCM settings
1 parent 3580c66 commit 2c6f092

File tree

14 files changed

+359
-50
lines changed

14 files changed

+359
-50
lines changed

.github/workflows/python-publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Upload Python Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
deploy:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.x'
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install setuptools wheel twine
25+
- name: Build and publish
26+
env:
27+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
python setup.py sdist bdist_wheel
31+
twine upload dist/*

.github/workflows/tests.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
tests:
11+
name: Python ${{ matrix.python-version }}
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest]
17+
python-version: [3.6, 3.7, 3.8, 3.9]
18+
19+
services:
20+
redis:
21+
image: redis:alpine
22+
ports:
23+
- 6379:6379
24+
steps:
25+
- uses: actions/checkout@v2
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip wheel setuptools tox
33+
- name: Run tox targets for ${{ matrix.python-version }}
34+
run: |
35+
ENV_PREFIX=$(tr -C -d "0-9" <<< "${{ matrix.python-version }}")
36+
TOXENV=$(tox --listenvs | grep "^py$ENV_PREFIX" | tr '\n' ',') python -m tox
37+
coverage:
38+
needs: [ tests ]
39+
name: coverage
40+
runs-on: ubuntu-latest
41+
services:
42+
redis:
43+
image: redis:alpine
44+
ports:
45+
- 6379:6379
46+
steps:
47+
- uses: actions/checkout@v2
48+
- name: Set up Python 3.9
49+
uses: actions/setup-python@v2
50+
with:
51+
python-version: 3.9
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip wheel setuptools tox
55+
- name: Generate coverage report
56+
run: TOXENV=py39-django32 python -m tox
57+
- uses: paambaati/codeclimate-action@v3.0.0
58+
env:
59+
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_TEST_REPORTER_ID }}
60+
61+
lint:
62+
name: Lint
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v2
66+
- name: Set up Python
67+
uses: actions/setup-python@v2
68+
with:
69+
python-version: 3.9
70+
- name: Install dependencies
71+
run: |
72+
python -m pip install --upgrade pip tox
73+
- name: Run lint
74+
run: tox -e lint

docs/backends.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ because the heavylifting and execution environment is handled by AWS.
115115

116116
set ``NOTIFICATIONS_DELIVERY_BACKEND`` to ``notifications.backends.AwsSqsLambda``
117117

118+
This backend uses ``boto3`` under the hood; so make sure your AWS credentials are configured e.g::
119+
120+
export AWS_ACCESS_KEY_ID=xxxx
121+
export AWS_SECRET_ACCESS_KEY=xxxx
122+
export AWS_DEFAULT_REGION=xxxx
123+
118124
Clone the `lambda worker repository`_ and run::
119125

120126
npm install
@@ -144,7 +150,15 @@ are endless. see the `Serverless documentation for AWS`_ for more information.
144150

145151
``settings.py``
146152

147-
Declare the Django settings for the lambda function
153+
Declare the Django settings for the lambda function.
154+
155+
After setting these variables deploy the serverless stack to AWS::
156+
157+
serverless deploy --stage <your-stage>
158+
159+
Then update your settings with the generated sqs queue url::
160+
161+
settings.NOTIFICATIONS_SQS_QUEUE_URL = 'xxxxxx' # autogenerated SQS url
148162

149163

150164
Synchronous

docs/configuration.rst

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,4 @@ The retry interval (in seconds) between each retry
6161

6262
``Default=5``
6363

64-
The maximum number of retries for a notification.
65-
66-
67-
68-
``NOTIFICATIONS_WEBSOCKET_EVENT_NAME``
69-
--------------------------------------
70-
71-
``Default='notifs_websocket_message'``
72-
73-
The ``type`` value of the messages that are going to received by the django notifs websocket consumer.
74-
In most cases, you don't need to change this setting.
75-
76-
77-
78-
``NOTIFICATIONS_WEBSOCKET_URL_PARAM``
79-
--------------------------------------
80-
81-
``Default = 'room_name'``
82-
83-
The WebSocket URL param name.
84-
It's also used to construct the WebSocket URL.
85-
See the :ref:`Advanced usage <Notification channels>` section for more information.
64+
The maximum number of retries for a notification

docs/providers.rst

Lines changed: 188 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,205 @@ and contain the logic for delivery that payload to an external service.
99

1010
Below are the list of supported providers:
1111

12-
``Slack``
13-
---------
1412

15-
settings::
13+
Email
14+
=====
1615

17-
NOTIFICATIONS_SLACK_BOT_TOKEN # Slack notification bot token
16+
The email provider uses the standard ``django.core.mail`` module.
17+
This opens up support for multiple ESP's (Mailjet, Mailchimp, sendgrid etc)
1818

19-
Single payload::
19+
name: ``'email'``
20+
21+
22+
Installation
23+
------------
24+
25+
Optional dependency for django-anymail::
26+
27+
pip install django-notifs[anymail]
28+
29+
30+
Settings
31+
--------
32+
33+
If you use ``django-anymail`` or a custom Email backend, all you have to do configure the settings as you'd
34+
normally do and the email provider should pick it up.
35+
36+
37+
Payload
38+
-------
39+
40+
Single::
41+
42+
{
43+
'subject': 'The subject line of the email',
44+
'body': 'The body text. This should be a plain text message',
45+
'from_email': 'The sender’s address',
46+
'to': 'A list or tuple of recipient addresses',
47+
'bcc': 'A list or tuple of addresses used in the “Bcc” header when sending the email',
48+
'attachments': 'A list of attachments to put on the message',
49+
'headers': 'A dictionary of extra headers to put on the message'.
50+
'cc': 'A list or tuple of recipient addresses used in the “Cc” header when sending the email',
51+
'reply_to': 'A list or tuple of recipient addresses used in the “Reply-To” header when sending the email',
52+
**extra_esp,
53+
54+
}
55+
56+
``extra_esp`` is any extra data that you want to pass to your custom Email backend.
57+
58+
59+
|
60+
|
61+
62+
63+
Slack
64+
=====
65+
66+
name: ``'slack'``
67+
68+
69+
Installation
70+
------------
71+
72+
::
73+
74+
pip install django-notifs[slack]
75+
76+
Settings
77+
--------
78+
79+
::
80+
81+
NOTIFICATIONS_SLACK_BOT_TOKEN=xxxxxxx
82+
83+
Payload
84+
-------
85+
86+
Single::
2087

2188
{
2289
'channel': '#slack-channel-name',
2390
'text': 'message',
2491
}
2592

26-
Pusher,
27-
Google FCM,
28-
django-channels,
93+
94+
|
95+
|
96+
97+
Pusher Channels
98+
===============
99+
100+
name: ``'pusher_channels'``
101+
102+
Installation
103+
------------
104+
105+
::
106+
107+
pip install django-notifs[pusher_channels]
108+
109+
Settings
110+
--------
111+
112+
::
113+
114+
NOTIFICATIONS_PUSHER_CHANNELS_URL=https://<app_id>:<app_secret>@api-eu.pusher.com/apps/0000000
115+
116+
Payload
117+
-------
118+
119+
Single::
120+
121+
{
122+
'channel': 'channel_name',
123+
'name': 'event_name',
124+
'data': {},
125+
}
126+
127+
|
128+
|
129+
130+
FCM (Firebase Web push)
131+
=======================
132+
133+
name: ``'fcm_web'``
134+
135+
Settings
136+
--------
137+
138+
::
139+
140+
NOTIFICATIONS_FCM_KEY=xxxxxxx
141+
142+
Payload
143+
-------
144+
145+
Single::
146+
147+
{
148+
'title': 'notification title',
149+
'body': 'body',
150+
'click_action': 'https://example.com',
151+
'icon': 'icon,
152+
'to': 'user_token',
153+
}
154+
155+
|
156+
|
157+
158+
django-channels
159+
===============
160+
161+
name: ``'django_channels'``
162+
163+
Installation
164+
------------
165+
166+
::
167+
168+
pip install django-notifs[channels]
169+
170+
Settings
171+
--------
172+
173+
``NOTIFICATIONS_WEBSOCKET_EVENT_NAME``
174+
--------------------------------------
175+
176+
``Default='notifs_websocket_message'``
177+
178+
The ``type`` value of the messages that are going to received by the django notifs websocket consumer.
179+
In most cases, you don't need to change this setting.
180+
181+
``NOTIFICATIONS_WEBSOCKET_URL_PARAM``
182+
--------------------------------------
183+
184+
``Default = 'room_name'``
185+
186+
The WebSocket URL param name.
187+
It's also used to construct the WebSocket URL.
188+
See the :ref:`Advanced usage <Notification channels>` section for more information.
189+
190+
Context
191+
-------
192+
::
193+
194+
{
195+
'destination': 'Group/channel name'
196+
}
197+
198+
199+
Payload
200+
-------
201+
202+
Single::
203+
204+
{
205+
'type': settings.NOTIFICATIONS_WEBSOCKET_EVENT_NAME, # or a custom event name
206+
'message': {},
207+
}
29208

30209
Writing custom Providers
31-
--------------------------------
210+
========================
32211

33212
Sometimes, the inbuilt providers are not sufficient to handle every use case.
34213

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ or::
8787

8888
.. note::
8989
The provider takes care of sending the payload in the most efficient way.
90-
(Some providers like ``pusher`` have a bulk api for delivering multiple notifications in a single batch).
90+
(Some providers like ``pusher_channels`` have a bulk api for delivering multiple notifications in a single batch).
9191

9292

9393
Notification Model

0 commit comments

Comments
 (0)