mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
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
@ -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…
x
Reference in New Issue
Block a user