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.