]> git.cworth.org Git - turbot/commitdiff
Parse block_actions payload and farm out to turbot.actions.new_hunt function
authorCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 21:42:21 +0000 (14:42 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 22:06:32 +0000 (15:06 -0700)
Again, putting the action function into its own file for easier organization.

turbot/actions.py [new file with mode: 0644]
turbot_lambda/turbot_lambda.py

diff --git a/turbot/actions.py b/turbot/actions.py
new file mode 100644 (file)
index 0000000..8103c5d
--- /dev/null
@@ -0,0 +1,8 @@
+def new_hunt(payload):
+
+    print("In new_hunt function")
+
+    return {
+        'statusCode': 200,
+        'body': 'OK'
+    }
index ba8d06db20c66e4ada2d8a0dabc1279ecea4dd4d..b8d55ad4fcfadb3c60118d7407bed7582fcb6518 100644 (file)
@@ -1,6 +1,7 @@
 from urllib.parse import parse_qs
 from turbot.rot import rot
-from turbot import views
+import turbot.views
+import turbot.actions
 from slack import WebClient
 import boto3
 import requests
@@ -116,7 +117,7 @@ def event_callback_handler(body):
 
 def app_home_opened_handler(body):
     user_id = body['event']['user']
-    view = views.home(user_id, body)
+    view = turbot.views.home(user_id, body)
     slack_client.views_publish(user_id=user_id, view=view)
     return "OK"
 
@@ -145,7 +146,31 @@ def turbot_interactive(payload):
     a shortcut or some other interactive element that our app has made
     available to the user."""
 
-    print("In turbot_interactive, payload is: {}".format(str(payload)))
+    type = payload['type']
+
+    if type == 'block_actions':
+        return turbot_block_action(payload)
+    return error("Unrecognized interactive type: {}".format(type))
+
+def turbot_block_action(payload):
+    """Handler for Slack interactive block actions
+
+    Specifically, those that have a payload type of 'block_actions'"""
+
+    actions = payload['actions']
+
+    if len(actions) != 1:
+        return error("No support for multiple actions ({}) in a single request"
+                     .format(len(actions)))
+
+    action = actions[0]
+
+    atype = action['type']
+    avalue = action['value']
+
+    if atype == 'button' and avalue == 'new_hunt':
+        return turbot.actions.new_hunt(payload)
+    return error("Unknown action of type/value: {}/{}".format(atype, avalue))
 
 def turbot_slash_command(body):
     """Implementation for Slack slash commands.