From 41f4ec8d04b07bb41a1eae1be8305218194e4a0e Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 13 Oct 2020 14:42:21 -0700 Subject: [PATCH] Parse block_actions payload and farm out to turbot.actions.new_hunt function Again, putting the action function into its own file for easier organization. --- turbot/actions.py | 8 ++++++++ turbot_lambda/turbot_lambda.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 turbot/actions.py diff --git a/turbot/actions.py b/turbot/actions.py new file mode 100644 index 0000000..8103c5d --- /dev/null +++ b/turbot/actions.py @@ -0,0 +1,8 @@ +def new_hunt(payload): + + print("In new_hunt function") + + return { + 'statusCode': 200, + 'body': 'OK' + } diff --git a/turbot_lambda/turbot_lambda.py b/turbot_lambda/turbot_lambda.py index ba8d06d..b8d55ad 100644 --- a/turbot_lambda/turbot_lambda.py +++ b/turbot_lambda/turbot_lambda.py @@ -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. -- 2.43.0