1 from turbot.blocks import input_block
4 def new_hunt(turb, payload):
5 """Handler for the action of user pressing the new_hunt button"""
9 "private_metadata": "new_hunt",
10 "title": { "type": "plain_text", "text": "New Hunt" },
11 "submit": { "type": "plain_text", "text": "Create" },
13 input_block("Hunt name", "name", "Name of the hunt"),
14 input_block("Hunt ID", "slug", "Short prefix for hunt (no spaces)"),
15 input_block("Hunt URL", "url", "External URL of hunt")
19 result = turb.slack_client.views_open(trigger_id=payload['trigger_id'],
22 submission_handlers[result['view']['id']] = new_hunt_submission
29 def new_hunt_submission(turb, payload):
30 """Handler for the user submitting the new hunt modal
32 This is the modal view presented to the user by the new_hunt
35 state = payload['view']['state']['values']
36 name = state['name']['name']['value']
37 slug = state['slug']['slug']['value']
38 url = state['url']['url']['value']
40 response = turb.slack_client.conversations_create(name=slug)
42 if not response['ok']:
43 print("Error creating channel for hunt {}: {}"
44 .format(name, str(response)))
49 user_id = payload['user']['id']
50 channel_id = response['channel']['id']
52 turb.hunts_table = turb.db.Table("hunts")
53 turb.hunts_table.put_item(
55 'channel_id': channel_id,
63 turb.slack_client.conversations_invite(channel=channel_id, users=user_id)
69 def view_submission(turb, payload):
71 """Handler for Slack interactive view submission
73 Specifically, those that have a payload type of 'view_submission'"""
75 view_id = payload['view']['private_metadata']
77 if view_id in submission_handlers:
78 return submission_handlers[view_id](turb, payload)
80 print("Error: Unknown view ID: {}".format(view_id))
91 submission_handlers = {
92 "new_hunt": new_hunt_submission