X-Git-Url: https://git.cworth.org/git?p=turbot;a=blobdiff_plain;f=turbot%2Fblocks.py;h=dde2cfb913d3bcddd76e1c44da9f465587aeb081;hp=5222e87e0433d248c2805ca0973396c411165dd2;hb=4f287a0e6b54f57529162c555c2502b3726d1edd;hpb=3201514c9991ffcd1ceefa57ce180a095af7ba0a diff --git a/turbot/blocks.py b/turbot/blocks.py index 5222e87..dde2cfb 100644 --- a/turbot/blocks.py +++ b/turbot/blocks.py @@ -1,3 +1,8 @@ +def divider_block(): + return { + "type": "divider" + } + def text_block(body): return { "text": { @@ -6,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", @@ -29,10 +41,24 @@ def button_block(label, name): "value": name } -def input_block(label, name, placeholder): + 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", "block_id": name, + "optional": optional, "element": { "type": "plain_text_input", "action_id": name, @@ -46,3 +72,28 @@ def input_block(label, name, placeholder): "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 + )