From f12de83563ec010b97c8fe2cefe4b529f57348db Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 16 Oct 2020 17:43:31 -0700 Subject: [PATCH] Create a new Slack channel when creating a hunt Using the slug of the hunt for the channel name. Some thoughts on improving this: * Should we modify the slug in some way to distinguish this as a hunt channel? * We should definitely do validation of the legality of the slug for a channel name. * We should invite the triggering user to the channel * We should put the hunt URL into the topic or description * Do we want to create a sheet for hunt channels or only for puzzle channels? --- turbot/actions.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/turbot/actions.py b/turbot/actions.py index 06e2d58..ca4aa02 100644 --- a/turbot/actions.py +++ b/turbot/actions.py @@ -37,10 +37,21 @@ def new_hunt_submission(turb, payload): slug = state['slug']['slug']['value'] url = state['url']['url']['value'] - table = turb.db.Table("hunts") - table.put_item( + response = turb.slack_client.conversations_create(name=slug) + + if not response['ok']: + print("Error creating channel for hunt {}: {}" + .format(name, str(response))) + return { + 'statusCode': 400 + } + + channel_id = response['channel']['id'] + + turb.hunts_table = turb.db.Table("hunts") + turb.hunts_table.put_item( Item={ - 'channel_id': "placeholder-" + str(uuid.uuid4()), + 'channel_id': channel_id, "active": True, "name": name, "slug": slug, -- 2.45.2