]> git.cworth.org Git - turbot/commitdiff
Implement a first skeleton of the app_home_opened event
authorCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 04:28:38 +0000 (21:28 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 04:40:18 +0000 (21:40 -0700)
This is just a stub page now, but it will eventually be populated with
open hunts and puzzles and links to the various channels.

turbot_lambda/turbot_lambda.py

index 19aee47aa74005575b970d8f40a60fdd34657c06..b8853b36cc33ebfb050955d47d8f798c30149e0f 100644 (file)
@@ -83,16 +83,69 @@ def turbot_event_handler(event, context):
 
     body = json.loads(event['body'])
 
+    type = body['type']
+
+    if type == 'url_verification':
+        return url_verification_handler(body)
+    if type == 'event_callback':
+        return event_callback_handler(body)
+    return error("Unknown event type: {}".format(type))
+
+def url_verification_handler(body):
+
     # First, we have to properly respond to url_verification
     # challenges or else Slack won't let us configure our URL as an
     # event handler.
-    if (body['type'] == 'url_verification'):
-        return {
-            'statusCode': 200,
-            'body': body['challenge']
-        }
+    challenge = body['challenge']
+
+    return {
+        'statusCode': 200,
+        'body': challenge
+    }
 
-    return error("Event not yet implemented")
+def event_callback_handler(body):
+    type = body['event']['type']
+
+    if type == 'app_home_opened':
+        return app_home_opened_handler(body)
+    return error("Unknown event type: {}".format(type))
+
+def app_home_opened_handler(body):
+    slack_client.views_publish(user_id=body['event']['user'],
+                               view={
+                                   "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
+                                                   }
+                                               }
+                                           ]
+                                       }
+                                   ]
+                               })
+    return "OK"
 
 def turbot_slash_command(event, context):
     """Implementation for Slack slash commands.