]> git.cworth.org Git - turbot/blobdiff - turbot/blocks.py
Modify multi_select_block to use accessory_block, section_block, and text_block
[turbot] / turbot / blocks.py
index a18c0558a072cb18e7284123b4311d55a2537916..dde2cfb913d3bcddd76e1c44da9f465587aeb081 100644 (file)
@@ -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,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",
@@ -47,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
+    )