X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=turbot%2Fblocks.py;h=dde2cfb913d3bcddd76e1c44da9f465587aeb081;hb=4f287a0e6b54f57529162c555c2502b3726d1edd;hp=661cff37287d0fbee5a9fddb37220f7c8ef17630;hpb=fc6a00f58bfc526e327c41bf989275b824004a88;p=turbot diff --git a/turbot/blocks.py b/turbot/blocks.py index 661cff3..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", @@ -54,28 +74,26 @@ def input_block(label, name, placeholder, optional=False): } def multi_select_block(label, name, placeholder, options, default=None): - return { - "type": "section", - "block_id": name, - "text": { - "type": "mrkdwn", - "text": "*{}*".format(label) + + multi_select = { + "action_id": name, + "type": "multi_static_select", + "placeholder": { + "type": "plain_text", + "text": placeholder }, - "accessory": { - "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 - ] - } + "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 + )