From 032feb6cdd4dc7d9e2584d452b80b521f5b4ea4e Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 16 Oct 2020 17:21:17 -0700 Subject: [PATCH] Fix new hunt submission to not rely on global python state 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 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/turbot/actions.py b/turbot/actions.py index bf64c73..06e2d58 100644 --- a/turbot/actions.py +++ b/turbot/actions.py @@ -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 +} -- 2.43.0