forked from riga/law
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add slack contrib package for chat notifications.
- Loading branch information
Showing
6 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
slack | ||
===== | ||
|
||
.. automodule:: law.contrib.slack | ||
|
||
.. contents:: | ||
|
||
|
||
Class ``NotifySlackParameter`` | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. autoclass:: NotifySlackParameter | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
# flake8: noqa | ||
|
||
""" | ||
Slack contrib functionality. | ||
""" | ||
|
||
|
||
__all__ = ["NotifySlackParameter"] | ||
|
||
|
||
# provisioning imports | ||
from law.contrib.slack.parameter import NotifySlackParameter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Slack notification. | ||
""" | ||
|
||
|
||
from law.config import Config | ||
from law.parameter import NotifyParameter | ||
|
||
|
||
class NotifySlackParameter(NotifyParameter): | ||
|
||
@staticmethod | ||
def notify(title, parts, token=None, channel=None, **kwargs): | ||
import slackclient | ||
|
||
cfg = Config.instance() | ||
|
||
if not token: | ||
token = cfg.get("notifications", "slack_token") | ||
if not channel: | ||
channel = cfg.get("notifications", "slack_channel") | ||
|
||
if token and channel: | ||
# minimal markup | ||
text = "*{}*\n\n".format(title) | ||
for key, value in parts: | ||
text += "_{}_: {}\n".format(key, value) | ||
|
||
sc = slackclient.SlackClient(token) | ||
sc.api_call( | ||
"chat.postMessage", | ||
channel=channel, | ||
text=text, | ||
) | ||
|
||
def get_transport(self): | ||
return { | ||
"func": self.notify, | ||
"raw": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters