mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Remove deprecated Slack attachments framework (#38139)
This commit is contained in:
parent
0b0e323632
commit
53e162c922
@ -24,7 +24,6 @@ import homeassistant.helpers.template as template
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_ATTACHMENTS = "attachments"
|
|
||||||
ATTR_BLOCKS = "blocks"
|
ATTR_BLOCKS = "blocks"
|
||||||
ATTR_BLOCKS_TEMPLATE = "blocks_template"
|
ATTR_BLOCKS_TEMPLATE = "blocks_template"
|
||||||
ATTR_FILE = "file"
|
ATTR_FILE = "file"
|
||||||
@ -52,11 +51,7 @@ DATA_FILE_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
DATA_TEXT_ONLY_SCHEMA = vol.Schema(
|
DATA_TEXT_ONLY_SCHEMA = vol.Schema(
|
||||||
{
|
{vol.Optional(ATTR_BLOCKS): list, vol.Optional(ATTR_BLOCKS_TEMPLATE): list}
|
||||||
vol.Optional(ATTR_ATTACHMENTS): list,
|
|
||||||
vol.Optional(ATTR_BLOCKS): list,
|
|
||||||
vol.Optional(ATTR_BLOCKS_TEMPLATE): list,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
DATA_SCHEMA = vol.All(
|
DATA_SCHEMA = vol.All(
|
||||||
@ -196,15 +191,12 @@ class SlackNotificationService(BaseNotificationService):
|
|||||||
except ClientError as err:
|
except ClientError as err:
|
||||||
_LOGGER.error("Error while uploading file message: %s", err)
|
_LOGGER.error("Error while uploading file message: %s", err)
|
||||||
|
|
||||||
async def _async_send_text_only_message(
|
async def _async_send_text_only_message(self, targets, message, title, blocks):
|
||||||
self, targets, message, title, attachments, blocks
|
|
||||||
):
|
|
||||||
"""Send a text-only message."""
|
"""Send a text-only message."""
|
||||||
tasks = {
|
tasks = {
|
||||||
target: self._client.chat_postMessage(
|
target: self._client.chat_postMessage(
|
||||||
channel=target,
|
channel=target,
|
||||||
text=message,
|
text=message,
|
||||||
attachments=attachments,
|
|
||||||
blocks=blocks,
|
blocks=blocks,
|
||||||
icon_emoji=self._icon,
|
icon_emoji=self._icon,
|
||||||
link_names=True,
|
link_names=True,
|
||||||
@ -242,15 +234,6 @@ class SlackNotificationService(BaseNotificationService):
|
|||||||
|
|
||||||
# Message Type 1: A text-only message
|
# Message Type 1: A text-only message
|
||||||
if ATTR_FILE not in data:
|
if ATTR_FILE not in data:
|
||||||
attachments = data.get(ATTR_ATTACHMENTS, {})
|
|
||||||
if attachments:
|
|
||||||
_LOGGER.warning(
|
|
||||||
"Attachments are deprecated and part of Slack's legacy API; "
|
|
||||||
"support for them will be dropped in 0.114.0. In most cases, "
|
|
||||||
"Blocks should be used instead: "
|
|
||||||
"https://www.home-assistant.io/integrations/slack/"
|
|
||||||
)
|
|
||||||
|
|
||||||
if ATTR_BLOCKS_TEMPLATE in data:
|
if ATTR_BLOCKS_TEMPLATE in data:
|
||||||
blocks = _async_templatize_blocks(self.hass, data[ATTR_BLOCKS_TEMPLATE])
|
blocks = _async_templatize_blocks(self.hass, data[ATTR_BLOCKS_TEMPLATE])
|
||||||
elif ATTR_BLOCKS in data:
|
elif ATTR_BLOCKS in data:
|
||||||
@ -259,7 +242,7 @@ class SlackNotificationService(BaseNotificationService):
|
|||||||
blocks = {}
|
blocks = {}
|
||||||
|
|
||||||
return await self._async_send_text_only_message(
|
return await self._async_send_text_only_message(
|
||||||
targets, message, title, attachments, blocks
|
targets, message, title, blocks
|
||||||
)
|
)
|
||||||
|
|
||||||
# Message Type 2: A message that uploads a remote file
|
# Message Type 2: A message that uploads a remote file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user