]> git.cworth.org Git - turbot/commitdiff
Fix new hunt submission to not rely on global python state
authorCarl Worth <cworth@cworth.org>
Sat, 17 Oct 2020 00:21:17 +0000 (17:21 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 17 Oct 2020 00:23:13 +0000 (17:23 -0700)
It was only by accident that what I had written happened to work,
(apparently AWS reuses Lambda containers within a 30-minute window or
so). Obviously, I don't want to rely on anything like that, so instead
in this commit I take advantage of the "private_metadata" field that
Slack offers for me to pass data back and forth on a view and use that
to decide which function to invoke to handle view submission.

turbot/actions.py

index bf64c735ef0874e8e53bbbe3acc27f230f3a2336..06e2d58195dbb96d281fe828ad69e05af3149237 100644 (file)
@@ -1,13 +1,12 @@
 from turbot.blocks import input_block
 import uuid
 
-submission_handlers = {}
-
 def new_hunt(turb, payload):
     """Handler for the action of user pressing the new_hunt button"""
 
     view = {
         "type": "modal",
+        "private_metadata": "new_hunt",
         "title": { "type": "plain_text", "text": "New Hunt" },
         "submit": { "type": "plain_text", "text": "Create" },
         "blocks": [
@@ -59,7 +58,7 @@ def view_submission(turb, payload):
 
     Specifically, those that have a payload type of 'view_submission'"""
 
-    view_id = payload['view']['id']
+    view_id = payload['view']['private_metadata']
 
     if view_id in submission_handlers:
         return submission_handlers[view_id](turb, payload)
@@ -74,3 +73,7 @@ actions = {
         "new_hunt": new_hunt
     }
 }
+
+submission_handlers = {
+    "new_hunt": new_hunt_submission
+}