X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=turbot%2Fblocks.py;h=dde2cfb913d3bcddd76e1c44da9f465587aeb081;hb=4f287a0e6b54f57529162c555c2502b3726d1edd;hp=27e69f4d6d9d61140a16e4fa71cd30fcfe9d75e3;hpb=94dcc9b3b2a1f0773a45e6dc7e7018afa9749e62;p=turbot diff --git a/turbot/blocks.py b/turbot/blocks.py index 27e69f4..dde2cfb 100644 --- a/turbot/blocks.py +++ b/turbot/blocks.py @@ -11,20 +11,27 @@ def text_block(body): } } -def section_block(block): - return { +def section_block(block, block_id=None): + + block = { "type": "section", **block } + if block_id: + block['block_id'] = block_id + + return block + def actions_block(*elements): return { "type": "actions", "elements": list(elements) } -def button_block(label, name): - return { +def button_block(label, name, extra=None): + + block = { "type": "button", "text": { "type": "plain_text", @@ -34,6 +41,19 @@ def button_block(label, name): "value": name } + if extra: + block['action_id'] = extra + + return block + +def accessory_block(main, accessory): + return { + **main, + "accessory": { + **accessory + } + } + def input_block(label, name, placeholder, optional=False): return { "type": "input", @@ -52,3 +72,28 @@ def input_block(label, name, placeholder, optional=False): "text": label } } + +def multi_select_block(label, name, placeholder, options, default=None): + + multi_select = { + "action_id": name, + "type": "multi_static_select", + "placeholder": { + "type": "plain_text", + "text": placeholder + }, + "options": [ + { + "text": { + "type": "plain_text", + "text": option + }, + "value": option + } for option in options + ] + } + + return accessory_block( + section_block(text_block("*{}*".format(label)), block_id=name), + multi_select + )