mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix Slack "invalid_blocks_format" bug (#43875)
* Fix Slack "invalid_blocks_format" bug * Fix optional params * Fix one more optional param * Update manifest
This commit is contained in:
parent
4c7e17c5c6
commit
69a438e2fc
@ -404,6 +404,7 @@ homeassistant/components/simplisafe/* @bachya
|
||||
homeassistant/components/sinch/* @bendikrb
|
||||
homeassistant/components/sisyphus/* @jkeljo
|
||||
homeassistant/components/sky_hub/* @rogerselwyn
|
||||
homeassistant/components/slack/* @bachya
|
||||
homeassistant/components/slide/* @ualex73
|
||||
homeassistant/components/sma/* @kellerza
|
||||
homeassistant/components/smappee/* @bsmappee
|
||||
|
@ -3,5 +3,5 @@
|
||||
"name": "Slack",
|
||||
"documentation": "https://www.home-assistant.io/integrations/slack",
|
||||
"requirements": ["slackclient==2.5.0"],
|
||||
"codeowners": []
|
||||
"codeowners": ["@bachya"]
|
||||
}
|
||||
|
@ -198,17 +198,21 @@ class SlackNotificationService(BaseNotificationService):
|
||||
_LOGGER.error("Error while uploading file message: %s", err)
|
||||
|
||||
async def _async_send_text_only_message(
|
||||
self, targets, message, title, blocks, username, icon
|
||||
self,
|
||||
targets,
|
||||
message,
|
||||
title,
|
||||
*,
|
||||
username=None,
|
||||
icon=None,
|
||||
blocks=None,
|
||||
):
|
||||
"""Send a text-only message."""
|
||||
message_dict = {
|
||||
"blocks": blocks,
|
||||
"link_names": True,
|
||||
"text": message,
|
||||
"username": username,
|
||||
}
|
||||
message_dict = {"link_names": True, "text": message}
|
||||
|
||||
if username:
|
||||
message_dict["username"] = username
|
||||
|
||||
icon = icon or self._icon
|
||||
if icon:
|
||||
if icon.lower().startswith(("http://", "https://")):
|
||||
icon_type = "url"
|
||||
@ -217,6 +221,9 @@ class SlackNotificationService(BaseNotificationService):
|
||||
|
||||
message_dict[f"icon_{icon_type}"] = icon
|
||||
|
||||
if blocks:
|
||||
message_dict["blocks"] = blocks
|
||||
|
||||
tasks = {
|
||||
target: self._client.chat_postMessage(**message_dict, channel=target)
|
||||
for target in targets
|
||||
@ -256,15 +263,15 @@ class SlackNotificationService(BaseNotificationService):
|
||||
elif ATTR_BLOCKS in data:
|
||||
blocks = data[ATTR_BLOCKS]
|
||||
else:
|
||||
blocks = {}
|
||||
blocks = None
|
||||
|
||||
return await self._async_send_text_only_message(
|
||||
targets,
|
||||
message,
|
||||
title,
|
||||
blocks,
|
||||
username=data.get(ATTR_USERNAME, self._username),
|
||||
icon=data.get(ATTR_ICON, self._icon),
|
||||
blocks=blocks,
|
||||
)
|
||||
|
||||
# Message Type 2: A message that uploads a remote file
|
||||
|
Loading…
x
Reference in New Issue
Block a user