]> git.cworth.org Git - turbot/commitdiff
stash
authorCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 19:38:46 +0000 (12:38 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 19:44:10 +0000 (12:44 -0700)
turbot/views.py [new file with mode: 0644]
turbot_lambda/turbot_lambda.py

diff --git a/turbot/views.py b/turbot/views.py
new file mode 100644 (file)
index 0000000..95b7b08
--- /dev/null
@@ -0,0 +1,40 @@
+def home(user_id, body):
+    """Returns a view to be published as the turbot home tab for user_id
+
+    The body argument is a dictionary as provided by the Slack request.
+    The return value is a dictionary suitable to be published to the
+    Slack views_publish API."""
+
+    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
+                        }
+                    }
+                ]
+            }
+        ]
+    }
index e3efa6de9e28567885ab9ddd6884a96ac7bb2e95..ba8d06db20c66e4ada2d8a0dabc1279ecea4dd4d 100644 (file)
@@ -1,5 +1,6 @@
 from urllib.parse import parse_qs
 from turbot.rot import rot
+from turbot import views
 from slack import WebClient
 import boto3
 import requests
@@ -114,40 +115,9 @@ def event_callback_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
-                                                   }
-                                               }
-                                           ]
-                                       }
-                                   ]
-                               })
+    user_id = body['event']['user']
+    view = views.home(user_id, body)
+    slack_client.views_publish(user_id=user_id, view=view)
     return "OK"
 
 def turbot_interactive_or_slash_command(event, context):