utils.utils

Type validation and block payload generation utility module.

slack_blockkit.utils.utils.get_blocks(*blocks) → List[dict]

Takes arguments of Block objects and generates a list of blocks ready to be inserted into a message payload.

Parameters

blocks – An argument list of Block objects. Objects will be inserted top to bottom as they appear in this list.

Returns

A list of the dict representations of block objects.

Raises

AttributeError – If one of more of the blocks is an invalid block format.

slack_blockkit.utils.utils.get_validated_input(value, ptype: Type, min_length: int = None, max_length: int = None, required: bool = False, equality_fields: list = None, btype_fields: list = None)

Validates an input using a max length and equality field constraint. If either are not met, then this method raises an attribute error.

Parameters
  • value – The value of the input.

  • ptype (Type) – The value’s type.

  • min_length (int) – The min length the input value can be, defaults to None. If None, min length is not validated.

  • max_length (int) – The max length the input value can be, defaults to None. If None, max length is not validated.

  • required (bool) – Whether this param is required.

  • equality_fields (list) – A list of fields that the input value must be equal to, defaults to None. If not specified, the validation is not made.

  • btype_fields (list) – A list of btype fields that the object must match if it is a Block.

Raises

AttributeError – Raised if any of the above criteria are not met.

slack_blockkit.utils.utils.test_blocks_online(*blocks)

Utility that take a set of blocks and opens up the online slack blockkit builder. This will print out a message with a URL. Copy the URL into a browser and it will open the Slack Block Builder with the blocks you entered as parameters.

Example

>>> from slack_blockkit.layout_block import SectionBlock
>>> from slack_blockkit.composition_object import PlainTextObject
>>> from slack_blockkit.utils import test_blocks_online
>>> ...
>>> section1 = SectionBlock(text=PlainTextObject(text="Section 1"))
>>> section2 = SectionBlock(text=PlainTextObject(text="Section 2"))
>>> test_blocks_online(section1, section2)
Parameters

blocks – A list of block or dict objects.

Raises

AttributeError – If one of more of the blocks is an invalid block format.