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
This commit is contained in:
Erik J. Olson 2020-08-14 08:07:04 -05:00 committed by GitHub
parent 5c9f29c43a
commit 91ead3be50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}