- if (channel_name == "directmessage"):
- requests.post(response_url,
- json = {"text": result},
- headers = {"Content-type": "application/json"})
+ type = payload['type']
+
+ if type == 'block_actions':
+ return turbot_block_action(turb, payload)
+ if type == 'view_submission':
+ return turbot.interaction.view_submission(turb, payload)
+ if type == 'shortcut':
+ return turbot_shortcut(turb, payload)
+ return error("Unrecognized interactive type: {}".format(type))
+
+def turbot_block_action(turb, 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 in turbot.interaction.actions
+ and avalue in turbot.interaction.actions[atype]
+ ):
+ return turbot.interaction.actions[atype][avalue](turb, payload)
+ return error("Unknown action of type/value: {}/{}".format(atype, avalue))
+
+def turbot_shortcut(turb, payload):
+ """Handler for Slack shortcuts
+
+ These are invoked as either global or message shortcuts by a user."""
+
+ print("In turbot_shortcut, payload is: {}".format(str(payload)))
+
+ return error("Shortcut interactions not yet implemented")
+
+def turbot_slash_command(turb, body):
+ """Implementation for Slack slash commands.
+
+ This parses the request and arguments and farms out to
+ supporting functions to implement all supported slash commands.
+ """
+
+ command = body['command'][0]
+ if 'text' in body:
+ args = body['text'][0]