Skip to main content

Messages

Message

Class

Message(channel: str, text: Optional[str] = '', blocks: Optional[Union[List[Block], Block]] = None, attachments: Optional[List[Attachment]] = None, thread_ts: Optional[str] = None, mrkdwn: bool = True, unfurl_links: Optional[bool] = None, unfurl_media: Optional[bool] = None)

A Slack message object that can be converted to a JSON string for use with the Slack message API.

Arguments

ArgumentTypeDescription
channelstrthe Slack channel to send the message to, e.g. "#general".
textOptional[str]markdown text to send in the message. If blocks are provided
then this is a fallback to display in notifications.
blocksOptional[Union[List[Block], Block]]a list of Blocks to form the contents
of the message instead of the contents of text.
attachmentsOptional[List[Attachment]]a list of
Attachments
that form the secondary contents of the message (deprecated).
thread_tsOptional[str]the timestamp ID of another unthreaded message that will
become the parent message of this message (now a reply in a thread).
mrkdwnboolif True the contents of text will be rendered as markdown
rather than plain text.
unfurl_linksOptional[bool]if True, links in the message will be automatically
unfurled.
unfurl_mediaOptional[bool]if True, media from links (e.g. images) will
automatically unfurl.

Raises: InvalidUsageException: in the event that the items passed to blocks are not valid Blocks.

ResponseType

Class

Types of messages that can be sent via WebhookMessage.

WebhookMessage

Class

WebhookMessage(text: Optional[str] = None, attachments: Optional[List[Attachment]] = None, blocks: Optional[Union[List[Block], Block]] = None, response_type: Union[ResponseType, str] = None, replace_original: Optional[bool] = None, delete_original: Optional[bool] = None, unfurl_links: Optional[bool] = None, unfurl_media: Optional[bool] = None, metadata: Optional[Dict[str, Any]] = None, headers: Optional[Dict[str, str]] = None)

Messages sent via the Slack WebhookClient takes different arguments than those sent via the regular WebClient.

See: https://github.com/slackapi/python-slack-sdk/blob/7e71b73/slack_sdk/webhook/client.py#L28

Arguments

ArgumentTypeDescription
textOptional[str]markdown text to send in the message. If blocks are provided
then this is a fallback to display in notifications.
attachmentsOptional[List[Attachment]]a list of
Attachments
that form the secondary contents of the message (deprecated).
blocksOptional[Union[List[Block], Block]]a list of Blocks to form the contents
of the message instead of the contents of text.
response_typeUnion[ResponseType, str]one of ResponseType.EPHEMERAL or ResponseType.IN_CHANNEL.
Ephemeral messages are shown only to the requesting user whereas
"in-channel" messages are shown to all channel participants.
replace_orginalNonewhen True, the message triggering this response will be
replaced by this messaage. Mutually exclusive with delete_original.
delete_originalOptional[bool]when True, the original message triggering this response
will be deleted, and any content of this message will be posted as a
new message. Mutually exclusive with replace_orginal.
unfurl_linksOptional[bool]if True, links in the message will be automatically
unfurled.
unfurl_mediaOptional[bool]if True, media from links (e.g. images) will
automatically unfurl.
metadataOptional[Dict[str, Any]]additional metadata to attach to the message.
headresNoneHTTP request headers to include with the message.

Errors

ErrorWhen
InvalidUsageErrorwhen any of the passed fields fail validation.