From 91ead3be50f061b2e0bcb7573f5158eedd3a91b9 Mon Sep 17 00:00:00 2001 From: "Erik J. Olson" Date: Fri, 14 Aug 2020 08:07:04 -0500 Subject: [PATCH] Add Slack url icon support (#38814) * Add support for slack bot icons via URL * Removed as_user property from message send * Use f-strings rather than concatenation * Don't span lines with complex expression --- homeassistant/components/slack/notify.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/slack/notify.py b/homeassistant/components/slack/notify.py index d5c784398cf..a06785e506f 100644 --- a/homeassistant/components/slack/notify.py +++ b/homeassistant/components/slack/notify.py @@ -193,14 +193,24 @@ class SlackNotificationService(BaseNotificationService): async def _async_send_text_only_message(self, targets, message, title, blocks): """Send a text-only message.""" + username = self._username + icon = self._icon + + if self._icon.lower().startswith(("http://", "https://")): + icon_type = "url" + else: + icon_type = "emoji" + tasks = { target: self._client.chat_postMessage( - channel=target, - text=message, - blocks=blocks, - icon_emoji=self._icon, - link_names=True, - username=self._username, + **{ + "channel": target, + "text": message, + "blocks": blocks, + "link_names": True, + "username": username, + f"icon_{icon_type}": icon, + } ) for target in targets }