from turbot.blocks import input_block
import turbot.sheets
+import json
+import re
def new_hunt(turb, payload):
"""Handler for the action of user pressing the new_hunt button"""
"submit": { "type": "plain_text", "text": "Create" },
"blocks": [
input_block("Hunt name", "name", "Name of the hunt"),
- input_block("Hunt ID", "slug", "Short hunt prefix (no spaces)"),
+ input_block("Hunt ID", "slug", "Short hunt ID (no spaces)"),
input_block("Hunt URL", "url", "External URL of hunt",
optional=True)
],
slug = state['slug']['slug']['value']
url = state['url']['url']['value']
+ # Validate that the slug contains no invalid characters
+ if not re.match(r'[-_a-zA-Z0-9]+$', slug):
+ print("Slug field is invalid. Attmpting to return a clean error.")
+ return {
+ 'statusCode': 200,
+ 'headers': {
+ "Content-Type": "application/json"
+ },
+ 'body': json.dumps({
+ "response_action": "errors",
+ "errors": {
+ "slug": "Hunt ID can only contain letters, "
+ + "numbers, hyphens and underscores"
+ }
+ })
+ }
+
# Create a channel for the hunt
response = turb.slack_client.conversations_create(name=slug)