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
| Argument | Type | Description |
|---|---|---|
text | str | the text content to render. |
bold | Optional[bool] | whether to render the given text in bold font. |
italic | Optional[bool] | whether to render the given text in italics. |
strike | Optional[bool] | whether to render the given text with a "strikethrough". |
code | Optional[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
| Argument | Type | Description |
|---|---|---|
channel_id | str | the ID of the channel to render. You can get this from the channel settings or the URL (if using Slack in the browser). |
bold | Optional[bool] | whether to render the given channel in bold font. |
italic | Optional[bool] | whether to render the given channel in italics. |
strike | Optional[bool] | whether to render the given channel with a "strikethrough". |
highlight | Optional[bool] | whether to give the channel a distinct highlight when rendered. |
client_highlight | Optional[bool] | ??? |
unlink | Optional[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
| Argument | Type | Description |
|---|---|---|
name | str | the unique name of the emoji to represent e.g. "wave". |
Errors
| Error | When |
|---|---|
InvalidUsageError | if the emoji name provided is empty. |
RichTextLink
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
| Argument | Type | Description |
|---|---|---|
url | str | the url which the link will point to. |
text | Optional[str] | the text to render with the link. If not provided, the raw URL will be used. |
unsafe | Optional[bool] | whether the link is "safe". |
bold | Optional[bool] | whether to render the given text in bold font. |
italic | Optional[bool] | whether to render the given text in italics. |
strike | Optional[bool] | whether to render the given text with a "strikethrough". |
code | Optional[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
| Argument | Type | Description |
|---|---|---|
user_id | str | the Slack ID of the user in question, you can get these from users' profiles or Slack client requests. |
bold | Optional[bool] | whether to render the given user in bold font. |
italic | Optional[bool] | whether to render the given user in italics. |
strike | Optional[bool] | whether to render the given user with a "strikethrough". |
highlight | Optional[bool] | whether to give the user a distinct highlight when rendered. |
client_highlight | Optional[bool] | ??? |
unlink | Optional[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
| Argument | Type | Description |
|---|---|---|
user_group_id | str | the Slack ID of the user group being represented. |
bold | Optional[bool] | whether to render the given user in bold font. |
italic | Optional[bool] | whether to render the given user in italics. |
strike | Optional[bool] | whether to render the given user with a "strikethrough". |
highlight | Optional[bool] | whether to give the user a distinct highlight when rendered. |
client_highlight | Optional[bool] | ??? |
unlink | Optional[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
| Argument | Type | Description |
|---|---|---|
elements | Union[RichTextElement, List[RichTextElement]] | one or more rich text primitive objexts (e.g. RichText). |
border | Optional[int] | the thickness (in pixels) of the border around the code block. |
Errors
| Error | When |
|---|---|
InvalidUsageError | if any of the items in elements aren't valid richtext 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
| Argument | Type | Description |
|---|---|---|
style | Union[str, ListType] | one of ListType.BULLET or ListType.ORDERED. |
elements | Union[RichTextSection, List[RichTextSection]] | a list of (possibly nested) RichTextSection elements.Each object in this list will be rendered as a list item. |
indent | Optional[int] | indent (in pixels) of each list item. |
offset | Optional[int] | offset (in pixels) of each list item. |
border | Optional[int] | thickness (in pixels) of the (optional) border around the list. |
Errors
| Error | When |
|---|---|
InvalidUsageError | if style is not a valid ListType or any of theitems 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
| Argument | Type | Description |
|---|---|---|
elements | Union[RichTextElement, List[RichTextElement]] | one or more rich text primitive objexts (e.g. RichText). |
border | Optional[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
| Argument | Type | Description |
|---|---|---|
elements | Union[RichTextElement, List[RichTextElement]] | one or more rich text elements that will form the content of the section. e.g. RichText, RichTextLink. |
Errors
| Error | When |
|---|---|
InvalidUsageError | if any of the items passed to elements isn't a validRichTextObject. |