]> git.cworth.org Git - turbot/blob - turbot/blocks.py
cfef7f6a76ecf481224043d5a52b41565f46280b
[turbot] / turbot / blocks.py
1 def divider_block():
2     return {
3         "type": "divider"
4     }
5
6 def text_block(body):
7     return {
8         "text": {
9             "type": "mrkdwn",
10             "text": body
11         }
12     }
13
14 def section_block(block):
15     return {
16         "type": "section",
17         **block
18     }
19
20 def actions_block(*elements):
21     return {
22         "type": "actions",
23         "elements": list(elements)
24     }
25
26 def button_block(label, name):
27     return {
28         "type": "button",
29         "text": {
30             "type": "plain_text",
31             "text": label,
32             "emoji": True
33         },
34         "value": name
35     }
36
37 def accessory_block(main, accessory):
38     return {
39         **main,
40         "accessory": {
41             **accessory
42         }
43     }
44
45 def input_block(label, name, placeholder, optional=False):
46     return {
47         "type": "input",
48         "block_id": name,
49         "optional": optional,
50         "element": {
51             "type": "plain_text_input",
52             "action_id": name,
53             "placeholder": {
54                 "type": "plain_text",
55                 "text": placeholder,
56             }
57         },
58         "label": {
59             "type": "plain_text",
60             "text": label
61         }
62     }
63
64 def multi_select_block(label, name, placeholder, options, default=None):
65     return {
66         "type": "section",
67         "block_id": name,
68         "text": {
69             "type": "mrkdwn",
70             "text": "*{}*".format(label)
71         },
72         "accessory": {
73             "action_id": name,
74             "type": "multi_static_select",
75             "placeholder": {
76                 "type": "plain_text",
77                 "text": placeholder
78             },
79             "options": [
80                 {
81                     "text": {
82                         "type": "plain_text",
83                         "text": option
84                     },
85                     "value": option
86                 } for option in options
87             ]
88         }
89     }