From d70d1e13037880ad2504ff34f1685caf3cbadca9 Mon Sep 17 00:00:00 2001 From: Josh Nichols Date: Sun, 21 Aug 2016 14:54:28 -0400 Subject: [PATCH] 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 --- homeassistant/components/notify/slack.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/notify/slack.py b/homeassistant/components/notify/slack.py index 99d0c4ef663..39ca0197d0f 100644 --- a/homeassistant/components/notify/slack.py +++ b/homeassistant/components/notify/slack.py @@ -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")