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:
Josh Nichols 2016-08-21 14:54:28 -04:00 committed by Paulus Schoutsen
parent f802d6bfa3
commit d70d1e1303

View file

@ -51,7 +51,15 @@ class SlackNotificationService(BaseNotificationService):
import slacker
channel = kwargs.get('target') or self._default_channel
data = kwargs.get('data')
if data:
attachments = data.get('attachments')
else:
attachments = None
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:
_LOGGER.exception("Could not send slack notification")