From 0a23662568043cde609216287ef7323e281ea764 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 13 Oct 2020 12:38:46 -0700 Subject: [PATCH] stash --- turbot/views.py | 40 ++++++++++++++++++++++++++++++++++ turbot_lambda/turbot_lambda.py | 38 ++++---------------------------- 2 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 turbot/views.py diff --git a/turbot/views.py b/turbot/views.py new file mode 100644 index 0000000..95b7b08 --- /dev/null +++ b/turbot/views.py @@ -0,0 +1,40 @@ +def home(user_id, body): + """Returns a view to be published as the turbot home tab for user_id + + The body argument is a dictionary as provided by the Slack request. + The return value is a dictionary suitable to be published to the + Slack views_publish API.""" + + return { + "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 + } + } + ] + } + ] + } diff --git a/turbot_lambda/turbot_lambda.py b/turbot_lambda/turbot_lambda.py index e3efa6d..ba8d06d 100644 --- a/turbot_lambda/turbot_lambda.py +++ b/turbot_lambda/turbot_lambda.py @@ -1,5 +1,6 @@ from urllib.parse import parse_qs from turbot.rot import rot +from turbot import views from slack import WebClient import boto3 import requests @@ -114,40 +115,9 @@ def event_callback_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 - } - } - ] - } - ] - }) + user_id = body['event']['user'] + view = views.home(user_id, body) + slack_client.views_publish(user_id=user_id, view=view) return "OK" def turbot_interactive_or_slash_command(event, context): -- 2.45.2