block_kit_builder

block_util

Holds utility methods for building a block.

src.block_kit_builder.block_util.get_checkmark(task_completed: bool) → str

Returns a check mark emoji indicating the completed task status. If the task is complete, then a white check mark is returned. If not, an empty white square is.

Parameters

task_completed (bool) – Whether or not the task was complete.

Returns

A checkmark emoji string based on whether or not the task was completed.

Return type

str

src.block_kit_builder.block_util.get_information_block(info_link: str, info_text: str) → dict

Returns an information block, which is a section with an info icon followed by linked text.

Parameters
  • info_link (str) – The link the block redirects the user to.

  • info_text (str) – The link text.

Returns

A dict in the format of a context block.

Return type

dict

src.block_kit_builder.block_util.get_onboarding_block() → list

Constructs an onboarding block, which contains information on different channels and a link to the CodeDevils website.

Returns

The onboarding message block as a list.

Return type

list

src.block_kit_builder.block_util.get_task_block(text: str, info_link: str, info_text: str) → list

Returns a task block, which is comprised of a paragraph of text followed by an information link at the bottom.

Parameters
  • text (str) – Markdown-supported text to display in the paragraph.

  • info_link (str) – The link associated with the task block.

  • info_text (str) – The link text.

Returns

An array of blocks formatted for a block payload.

Return type

list

src.block_kit_builder.block_util.get_text_block_with_accessory(text_object: src.block_kit_builder.composition_object.text_object.TextObject, accessory: src.block_kit_builder.block_element.block_element.BlockElement) → dict

Returns a text block with an accessory.

Parameters
  • text_object (TextObject) – The text block object.

  • accessory (LayoutBlock) – The accessory object.

Returns

The text block with an accessory layout block.

Return type

dict

src.block_kit_builder.block_util.get_text_block_with_image(text: str, image_url: str, alt_text: str) → dict

Returns a text block with an image to the right of it.

Parameters
  • text (str) – The text in the text block.

  • image_url (str) – The URL to the image.

  • alt_text (str) – Alternate text (appears on image hover).

Returns

The block as a dict.

Return type

dict

block_generator

class src.block_kit_builder.block_generator.BlockGenerator(config, channel=None)

Constructs block payloads that act as formatted messages for Slack. For more information on blocks, see https://api.slack.com/block-kit.

get_message_payload(blocks: list, view_type: str = None) → dict

Returns a message block payload used to post messages in a specific channel.

Parameters
  • blocks (list) – The blocks to be inserted into the message payload.

  • view_type (str, optional) – Used to determine the type of block for a view publish, defaults to None

Returns

The message payload as a dict.

Return type

dict

get_welcome_block(channel: str) → dict

Sends the welcome message to the user.

Parameters

channel (str) – The channel ID of the user as a string.

Returns

The response from the message payload.

Return type

dict