This gets rid of the original placeholder blocks which I had gotten
from a tutorial and replaces it with placeholders that look more like
what we are going to want, (a list of hunts and a button to create a
new hunt).
While doing this, we provide some utility functions to create blocks
to reduce the amount of boilerplate we need while constructing these
things.
+def text(body):
+ return {
+ "text": {
+ "type": "mrkdwn",
+ "text": body
+ }
+ }
+
+def section(block):
+ return {
+ "type": "section",
+ **block
+ }
+
+def actions(*elements):
+ return {
+ "type": "actions",
+ "elements": list(elements)
+ }
+
+def button(label):
+ return {
+ "type": "button",
+ "text": {
+ "type": "plain_text",
+ "text": label,
+ "emoji": True
+ }
+ }
+
def home(user_id, body):
"""Returns a view to be published as the turbot home tab for user_id
return {
"type": "home",
"blocks": [
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "A simple stack of blocks for the simple sample Block Kit Home tab."
- }
- },
- {
- "type": "actions",
- "elements": [
- {
- "type": "button",
- "text": {
- "type": "plain_text",
- "text": "Action A",
- "emoji": True
- }
- },
- {
- "type": "button",
- "text": {
- "type": "plain_text",
- "text": "Action B",
- "emoji": True
- }
- }
- ]
- }
+ section(text("This is (or soon will be) a list of available puzzle hunts)")),
+ actions(button("New hunt"))
]
}