From c1be44997378659bd6dd4d303dcbcbb889aee0de Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 12 Oct 2020 21:28:38 -0700 Subject: [PATCH] Implement a first skeleton of the app_home_opened event This is just a stub page now, but it will eventually be populated with open hunts and puzzles and links to the various channels. --- turbot_lambda/turbot_lambda.py | 65 ++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/turbot_lambda/turbot_lambda.py b/turbot_lambda/turbot_lambda.py index 19aee47..b8853b3 100644 --- a/turbot_lambda/turbot_lambda.py +++ b/turbot_lambda/turbot_lambda.py @@ -83,16 +83,69 @@ def turbot_event_handler(event, context): body = json.loads(event['body']) + type = body['type'] + + if type == 'url_verification': + return url_verification_handler(body) + if type == 'event_callback': + return event_callback_handler(body) + return error("Unknown event type: {}".format(type)) + +def url_verification_handler(body): + # First, we have to properly respond to url_verification # challenges or else Slack won't let us configure our URL as an # event handler. - if (body['type'] == 'url_verification'): - return { - 'statusCode': 200, - 'body': body['challenge'] - } + challenge = body['challenge'] + + return { + 'statusCode': 200, + 'body': challenge + } - return error("Event not yet implemented") +def event_callback_handler(body): + type = body['event']['type'] + + if type == 'app_home_opened': + return app_home_opened_handler(body) + return error("Unknown event type: {}".format(type)) + +def app_home_opened_handler(body): + slack_client.views_publish(user_id=body['event']['user'], + view={ + "type": "home", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "A simple stack of blocks for the simple sample Block Kit Home tab." + } + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Action A", + "emoji": True + } + }, + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Action B", + "emoji": True + } + } + ] + } + ] + }) + return "OK" def turbot_slash_command(event, context): """Implementation for Slack slash commands. -- 2.43.0