Add support for notifying with Slack attachments. (#2914)
* Add support for notifying with Slack messages. When creating notifications, this allows you to pass in `attachments` with the `data`. It's an array of attachments as defined in https://api.slack.com/docs/message-attachments When passing in attachments, message is still required, but it's okay to be a blank string. * Split over multiple lines * Make sure attachments gets assigned, even if there isn't attachment data
This commit is contained in:
parent
f802d6bfa3
commit
d70d1e1303
1 changed files with 9 additions and 1 deletions
|
@ -51,7 +51,15 @@ class SlackNotificationService(BaseNotificationService):
|
||||||
import slacker
|
import slacker
|
||||||
|
|
||||||
channel = kwargs.get('target') or self._default_channel
|
channel = kwargs.get('target') or self._default_channel
|
||||||
|
data = kwargs.get('data')
|
||||||
|
if data:
|
||||||
|
attachments = data.get('attachments')
|
||||||
|
else:
|
||||||
|
attachments = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.slack.chat.post_message(channel, message, as_user=True)
|
self.slack.chat.post_message(channel, message,
|
||||||
|
as_user=True,
|
||||||
|
attachments=attachments)
|
||||||
except slacker.Error:
|
except slacker.Error:
|
||||||
_LOGGER.exception("Could not send slack notification")
|
_LOGGER.exception("Could not send slack notification")
|
||||||
|
|
Loading…
Add table
Reference in a new issue