Skip to main content

Rich Text

Rich Text Elements (Primitives)

RichText

Class

RichText(text: str, bold: Optional[bool] = None, italic: Optional[bool] = None, strike: Optional[bool] = None, code: Optional[bool] = 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.
boldOptional[bool]whether to render the given text in bold font.
italicOptional[bool]whether to render the given text in italics.
strikeOptional[bool]whether to render the given text with a "strikethrough".
codeOptional[bool]whether to render the given text as an inline code snippet
(monospaced).

RichTextChannel

Class

RichTextChannel(channel_id: str, bold: Optional[bool] = None, italic: Optional[bool] = None, strike: Optional[bool] = None, highlight: Optional[bool] = None, client_highlight: Optional[bool] = None, unlink: Optional[bool] = 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).
boldOptional[bool]whether to render the given channel in bold font.
italicOptional[bool]whether to render the given channel in italics.
strikeOptional[bool]whether to render the given channel with a "strikethrough".
highlightOptional[bool]whether to give the channel a distinct highlight when rendered.
client_highlightOptional[bool]???
unlinkOptional[bool]whether to remove the link to the channel from the channel when
rendered.

RichTextEmoji

Class

RichTextEmoji(name: str)

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: Optional[str] = None, unsafe: Optional[bool] = None, bold: Optional[bool] = None, italic: Optional[bool] = None, strike: Optional[bool] = None, code: Optional[bool] = 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.
textOptional[str]the text to render with the link. If not provided, the raw URL
will be used.
unsafeOptional[bool]whether the link is "safe".
boldOptional[bool]whether to render the given text in bold font.
italicOptional[bool]whether to render the given text in italics.
strikeOptional[bool]whether to render the given text with a "strikethrough".
codeOptional[bool]whether to render the given text as an inline code snippet
(monospaced).

RichTextUser

Class

RichTextUser(user_id: str, bold: Optional[bool] = None, italic: Optional[bool] = None, strike: Optional[bool] = None, highlight: Optional[bool] = None, client_highlight: Optional[bool] = None, unlink: Optional[bool] = 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.
boldOptional[bool]whether to render the given user in bold font.
italicOptional[bool]whether to render the given user in italics.
strikeOptional[bool]whether to render the given user with a "strikethrough".
highlightOptional[bool]whether to give the user a distinct highlight when rendered.
client_highlightOptional[bool]???
unlinkOptional[bool]whether to remove the link to the user from the channel when
rendered.

RichTextUserGroup

Class

RichTextUserGroup(user_group_id: str, bold: Optional[bool] = None, italic: Optional[bool] = None, strike: Optional[bool] = None, highlight: Optional[bool] = None, client_highlight: Optional[bool] = None, unlink: Optional[bool] = 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.
boldOptional[bool]whether to render the given user in bold font.
italicOptional[bool]whether to render the given user in italics.
strikeOptional[bool]whether to render the given user with a "strikethrough".
highlightOptional[bool]whether to give the user a distinct highlight when rendered.
client_highlightOptional[bool]???
unlinkOptional[bool]whether to remove the link to the user from the channel when
rendered.

Rich Text Objects (Containers)

ListType

Class

An Enum that lists the available types of rich text lists.

  • ListType.BULLET: an unorderd (bulleted) list.
  • ListType.ORDERED: an ordered (numbered) list.

RichTextCodeBlock

Class

RichTextCodeBlock(elements: Union[RichTextElement, List[RichTextElement]], border: Optional[int] = 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
elementsUnion[RichTextElement, List[RichTextElement]]one or more rich text primitive objexts
(e.g. RichText).
borderOptional[int]the 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.

RichTextList

Class

RichTextList(style: Union[str, ListType], elements: Union[RichTextSection, List[RichTextSection]], indent: Optional[int] = None, offset: Optional[int] = 0, border: Optional[int] = 0)

Renders to a HTML list containing rich text elements.

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

Arguments

ArgumentTypeDescription
styleUnion[str, ListType]one of ListType.BULLET or ListType.ORDERED.
elementsUnion[RichTextSection, List[RichTextSection]]a list of (possibly nested) RichTextSection elements.
Each object in this list will be rendered as a list item.
indentOptional[int]indent (in pixels) of each list item.
offsetOptional[int]offset (in pixels) of each list item.
borderOptional[int]thickness (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.

RichTextQuote

Class

RichTextQuote(elements: Union[RichTextElement, List[RichTextElement]], border: Optional[int] = 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
elementsUnion[RichTextElement, List[RichTextElement]]one or more rich text primitive objexts
(e.g. RichText).
borderOptional[int]the thickness (in pixels) of the border around the code block.

RichTextSection

Class

RichTextSection(elements: Union[RichTextElement, List[RichTextElement]])

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
elementsUnion[RichTextElement, 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.