Skip to main content

Rich text

RichText

Class

RichText(text: 'str', bold: 'bool | None' = None, italic: 'bool | None' = None, strike: 'bool | None' = None, code: 'bool | None' = None) -> 'None'

The core unit of the rich text API. Allows for the formatting of text with visual styles like bolding, italics and strikethroughs. Combined with higher-level containers like RichTextSection, RichText can be used to create complicated and deeply nested rich text within Slack messages.

Arguments

ArgumentTypeDescription
textstrthe text content to render.
boldbool | Nonewhether to render the given text in bold font.
italicbool | Nonewhether to render the given text in italics.
strikebool | Nonewhether to render the given text with a "strikethrough".
codebool | Nonewhether to render the given text as an inline code snippet
(monospaced).

RichTextChannel

Class

RichTextChannel(channel_id: 'str', bold: 'bool | None' = None, italic: 'bool | None' = None, strike: 'bool | None' = None, highlight: 'bool | None' = None, client_highlight: 'bool | None' = None, unlink: 'bool | None' = None) -> 'None'

Rich text rendering of a Slack channel (e.g. #general).

See: https://api.slack.com/reference/block-kit/blocks#channel-element-type

Arguments

ArgumentTypeDescription
channel_idstrthe ID of the channel to render. You can get this from
the channel settings or the URL (if using Slack in the browser).
boldbool | Nonewhether to render the given channel in bold font.
italicbool | Nonewhether to render the given channel in italics.
strikebool | Nonewhether to render the given channel with a "strikethrough".
highlightbool | Nonewhether to give the channel a distinct highlight when rendered.
client_highlightbool | Nonea Slack-internal rendering hint accompanying
mention-style elements. Rarely needed by app developers; pass
None (the default) unless you have a specific reason to set
it.
unlinkbool | Nonewhether to remove the link to the channel from the channel when
rendered.

RichTextCodeBlock

Class

RichTextCodeBlock(elements: 'RichTextElement | list[RichTextElement]', border: 'int | None' = None) -> 'None'

A rich text element for representing blocks of code in RichTextBlocks.

This is roughly equivalent to the triple-backtick code syntax in markdown.

See: https://api.slack.com/reference/block-kit/blocks#rich_text_preformatted.

Arguments

ArgumentTypeDescription
elementsRichTextElement | list[RichTextElement]one or more rich text primitive objexts
(e.g. RichText).
borderint | Nonethe thickness (in pixels) of the border around the code block.

Errors

ErrorWhen
InvalidUsageErrorif any of the items in elements aren't valid rich
text elements.

RichTextElement

Class

RichTextElement(type_: 'RichTextElementType') -> 'None'

Abstract base class for all rich text element classes.

These are the primitives that form the basis of rich text objects and the RichTextBlock.

RichTextEmoji

Class

RichTextEmoji(name: 'str') -> 'None'

A rich text element for displaying an emoji.

The emoji can either be one built in to Slack or a custom workspace emoji.

See: https://api.slack.com/reference/block-kit/blocks#emoji-element-type

Arguments

ArgumentTypeDescription
namestrthe unique name of the emoji to represent e.g. "wave".

Errors

ErrorWhen
InvalidUsageErrorif the emoji name provided is empty.

Class

RichTextLink(url: 'str', text: 'str | None' = None, unsafe: 'bool | None' = None, bold: 'bool | None' = None, italic: 'bool | None' = None, strike: 'bool | None' = None, code: 'bool | None' = None) -> 'None'

A rich text primitive to display links in text.

See: https://api.slack.com/reference/block-kit/blocks#link-element-type

Arguments

ArgumentTypeDescription
urlstrthe url which the link will point to.
textstr | Nonethe text to render with the link. If not provided, the raw URL
will be used.
unsafebool | Nonewhether the link is "safe".
boldbool | Nonewhether to render the given text in bold font.
italicbool | Nonewhether to render the given text in italics.
strikebool | Nonewhether to render the given text with a "strikethrough".
codebool | Nonewhether to render the given text as an inline code snippet
(monospaced).

RichTextList

Class

RichTextList(style: 'str | ListType', elements: 'RichTextSection | list[RichTextSection]', indent: 'int | None' = None, offset: 'int | None' = 0, border: 'int | None' = 0) -> 'None'

Renders to a HTML list containing rich text elements.

See: https://api.slack.com/reference/block-kit/blocks#rich_text_list.

Arguments

ArgumentTypeDescription
stylestr | ListTypeone of ListType.BULLET or ListType.ORDERED.
elementsRichTextSection | list[RichTextSection]a list of (possibly nested) RichTextSection elements.
Each object in this list will be rendered as a list item.
indentint | Noneindent (in pixels) of each list item.
offsetint | Noneoffset (in pixels) of each list item.
borderint | Nonethickness (in pixels) of the (optional) border around the list.

Errors

ErrorWhen
InvalidUsageErrorif style is not a valid ListType or any of the
items in elements isn't a valid RichTextSection.

RichTextObject

Class

RichTextObject(type_: 'RichTextObjectType') -> 'None'

Abstract class housing shared functionality of RichTextObjects.

Arguments

ArgumentTypeDescription
type_RichTextObjectTypethe type of rich text object this class is, from
RichTextObjectType.

RichTextQuote

Class

RichTextQuote(elements: 'RichTextElement | list[RichTextElement]', border: 'int | None' = None) -> 'None'

A rich text object for representing a block quote.

Block quotes are presented with a vertical bar to the left hand side of the text.

See: https://api.slack.com/reference/block-kit/blocks#rich_text_quote

Arguments

ArgumentTypeDescription
elementsRichTextElement | list[RichTextElement]one or more rich text primitive objexts
(e.g. RichText).
borderint | Nonethe thickness (in pixels) of the border around the code block.

RichTextSection

Class

RichTextSection(elements: 'RichTextElement | list[RichTextElement]') -> 'None'

The most basic rich text container object, which takes rich text elements and renders them when RichTextSection is passed to a RichTextBlock.

See: https://api.slack.com/reference/block-kit/blocks#rich_text_section.

Arguments

ArgumentTypeDescription
elementsRichTextElement | list[RichTextElement]one or more rich text elements that will form the content of the section.
e.g. RichText, RichTextLink.

Errors

ErrorWhen
InvalidUsageErrorif any of the items passed to elements isn't a valid
RichTextObject.

RichTextUser

Class

RichTextUser(user_id: 'str', bold: 'bool | None' = None, italic: 'bool | None' = None, strike: 'bool | None' = None, highlight: 'bool | None' = None, client_highlight: 'bool | None' = None, unlink: 'bool | None' = None) -> 'None'

Rich text element for representing users in RichTextBlocks.

See: https://api.slack.com/reference/block-kit/blocks#user-element-type.

Arguments

ArgumentTypeDescription
user_idstrthe Slack ID of the user in question, you can get these
from users' profiles or Slack client requests.
boldbool | Nonewhether to render the given user in bold font.
italicbool | Nonewhether to render the given user in italics.
strikebool | Nonewhether to render the given user with a "strikethrough".
highlightbool | Nonewhether to give the user a distinct highlight when rendered.
client_highlightbool | Nonea Slack-internal rendering hint accompanying
mention-style elements. Rarely needed by app developers; pass
None (the default) unless you have a specific reason to set
it.
unlinkbool | Nonewhether to remove the link to the user from the channel when
rendered.

RichTextUserGroup

Class

RichTextUserGroup(user_group_id: 'str', bold: 'bool | None' = None, italic: 'bool | None' = None, strike: 'bool | None' = None, highlight: 'bool | None' = None, client_highlight: 'bool | None' = None, unlink: 'bool | None' = None) -> 'None'

Rich text element for representing groups of users in RichTextBlocks`.

See: https://api.slack.com/reference/block-kit/blocks#user-element-type.

Arguments

ArgumentTypeDescription
user_group_idstrthe Slack ID of the user group being represented.
boldbool | Nonewhether to render the given user in bold font.
italicbool | Nonewhether to render the given user in italics.
strikebool | Nonewhether to render the given user with a "strikethrough".
highlightbool | Nonewhether to give the user a distinct highlight when rendered.
client_highlightbool | Nonea Slack-internal rendering hint accompanying
mention-style elements. Rarely needed by app developers; pass
None (the default) unless you have a specific reason to set
it.
unlinkbool | Nonewhether to remove the link to the user from the channel when
rendered.