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
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"
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.