Finally starting to hook this Lambda up to our database for the first time.
import requests
import turbot.rot
-def rot(slack_client, body, args):
+def rot(turb, body, args):
"""Implementation of the /rot command
The args string should be as follows:
import turbot.views
-def app_home_opened(slack_client, body):
+def app_home_opened(turb, body):
user_id = body['event']['user']
- view = turbot.views.home(user_id, body)
- slack_client.views_publish(user_id=user_id, view=view)
+ print("In app_home_opened function")
+ view = turbot.views.home(turb, user_id, body)
+ turb.slack_client.views_publish(user_id=user_id, view=view)
return "OK"
events = {
"value": name
}
-def home(user_id, body):
+def home(turb, 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."""
+ response = turb.db.Table("hunts").scan()
+ hunts = response['Items']
+
return {
"type": "home",
"blocks": [
- section(text("This is (or soon will be) a list of "
- + "available puzzle hunts)")),
+ section(text("*Active hunts*")),
+ *[section(text(hunt['name'])) for hunt in hunts if hunt['active']],
actions(button("New hunt", "new_hunt"))
]
}
import requests
import json
import os
+from types import SimpleNamespace
import turbot.actions
import turbot.commands
slack_bot_token = response['Parameter']['Value']
slack_client = WebClient(slack_bot_token)
+db = boto3.resource('dynamodb')
+
+turb = SimpleNamespace()
+turb.slack_client = slack_client
+turb.db = db
+
def error(message):
"""Generate an error response for a Slack request
type = body['event']['type']
if type in turbot.events.events:
- return turbot.events.events[type](slack_client, body)
+ return turbot.events.events[type](turb, body)
return error("Unknown event type: {}".format(type))
def turbot_interactive_or_slash_command(event, context):
args = body['text'][0]
if command in turbot.commands.commands:
- return turbot.commands.commands[command](slack_client, body, args)
+ return turbot.commands.commands[command](turb, body, args)
return error("Command {} not implemented".format(command))