Skip to content

Commit 3580c66

Browse files
authored
feat: Add slack provider (#77)
1 parent db1da28 commit 3580c66

File tree

7 files changed

+41
-3
lines changed

7 files changed

+41
-3
lines changed

docs/providers.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ and contain the logic for delivery that payload to an external service.
99

1010
Below are the list of supported providers:
1111

12-
Slack,
12+
``Slack``
13+
---------
14+
15+
settings::
16+
17+
NOTIFICATIONS_SLACK_BOT_TOKEN # Slack notification bot token
18+
19+
Single payload::
20+
21+
{
22+
'channel': '#slack-channel-name',
23+
'text': 'message',
24+
}
25+
1326
Pusher,
1427
Google FCM,
1528
django-channels,

notifications/default_settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@
3333
NOTIFICATIONS_FCM_KEY = getattr(settings, 'NOTIFICATIONS_FCM_KEY', '')
3434
NOTIFICATIONS_PUSHER_URL = getattr(settings, 'NOTIFICATIONS_PUSHER_URL', '')
3535
NOTIFICATIONS_SQS_QUEUE_URL = getattr(settings, 'NOTIFICATIONS_SQS_QUEUE_URL', '')
36+
37+
NOTIFICATIONS_SLACK_BOT_TOKEN = getattr(settings, 'NOTIFICATIONS_SLACK_BOT_TOKEN', '')

notifications/providers/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@
1515
from .django_channels import DjangoChannelsProvider # noqa
1616
except ImportError:
1717
pass
18+
19+
try:
20+
from .slack import SlackNotificationProvider # noqa
21+
except ImportError:
22+
pass

notifications/providers/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ def providers(cls):
2222
def send(self, payload):
2323
raise NotImplementedError
2424

25-
@abc.abstractmethod
2625
def send_bulk(self, payloads):
27-
raise NotImplementedError
26+
for payload in payloads:
27+
self.send(payload)

notifications/providers/slack.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from . import BaseNotificationProvider
2+
3+
from notifications import default_settings as settings
4+
5+
from slack_sdk import WebClient
6+
7+
8+
class SlackNotificationProvider(BaseNotificationProvider):
9+
name = 'slack'
10+
11+
def __init__(self, context=dict()):
12+
self.slack_client = WebClient(token=settings.NOTIFICATIONS_SLACK_BOT_TOKEN)
13+
super().__init__(context=context)
14+
15+
def send(self, payload):
16+
self.slack_client.chat_postMessage(**payload)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ m2r2==0.2.7
88
pusher==3.0.0
99
pytz==2017.2
1010
requests==2.25.1
11+
slack_sdk==3.11.2
1112
Sphinx==3.5.1
1213
sphinx-rtd-theme==0.5.1

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
# Provider requirements
3131
'pusher': ['pusher>=3.0.0'],
32+
'slack': ['slack_sdk>=3.11.2']
3233
}
3334
EXCLUDE = ['notifs', 'tests', '*.tests', '*.tests.*', 'tests.*']
3435

0 commit comments

Comments
 (0)