forked from slackapi/bolt-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Lazy Listener Functions slackapi#34 (slackapi#35)
* Implement Lazy Listener Functions slackapi#34 * Add unit tests * Remove test.pypi.org from instructions * Fix errors in Python 3.6 * Apply formtter to samples * Fix type hints
- Loading branch information
Showing
34 changed files
with
1,216 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
vendor/ | ||
vendor/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
rm -rf vendor && mkdir -p vendor/slack_bolt && cp -pr ../../slack_bolt/* vendor/slack_bolt/ | ||
pip install python-lambda -U | ||
lambda deploy \ | ||
--config-file lazy_aws_lambda_config.yaml \ | ||
--requirements requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# ------------------------------------------------ | ||
# instead of slack_bolt in requirements.txt | ||
import sys | ||
import time | ||
|
||
sys.path.insert(1, "vendor") | ||
# ------------------------------------------------ | ||
|
||
import logging | ||
|
||
from slack_bolt import App | ||
from slack_bolt.adapter.aws_lambda import SlackRequestHandler | ||
|
||
# process_before_response must be True when running on FaaS | ||
app = App(process_before_response=True) | ||
|
||
|
||
@app.middleware # or app.use(log_request) | ||
def log_request(logger, payload, next): | ||
logger.debug(payload) | ||
return next() | ||
|
||
|
||
command = "/hello-bolt-python-lambda" | ||
|
||
|
||
def respond_to_slack_within_3_seconds(payload, ack): | ||
if payload.get("text", None) is None: | ||
ack(f":x: Usage: {command} (description here)") | ||
else: | ||
title = payload["text"] | ||
ack(f"Accepted! (task: {title})") | ||
|
||
|
||
def process_request(respond, payload): | ||
time.sleep(5) | ||
title = payload["text"] | ||
respond(f"Completed! (task: {title})") | ||
|
||
|
||
app.command(command)(ack=respond_to_slack_within_3_seconds, lazy=[process_request]) | ||
|
||
SlackRequestHandler.clear_all_log_handlers() | ||
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG) | ||
|
||
|
||
def handler(event, context): | ||
slack_handler = SlackRequestHandler(app=app) | ||
return slack_handler.handle(event, context) | ||
|
||
|
||
# export SLACK_SIGNING_SECRET=*** | ||
# export SLACK_BOT_TOKEN=xoxb-*** | ||
|
||
# rm -rf vendor && cp -pr ../../src/* vendor/ | ||
# pip install python-lambda | ||
# lambda deploy --config-file aws_lambda_config.yaml --requirements requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
region: us-east-1 | ||
|
||
function_name: bolt_py_function | ||
handler: lazy_aws_lambda.handler | ||
description: My first lambda function | ||
runtime: python3.8 | ||
# role: lambda_basic_execution | ||
role: bolt_python_lambda_invocation # AWSLambdaFullAccess | ||
|
||
# S3 upload requires appropriate role with s3:PutObject permission | ||
# (ex. basic_s3_upload), a destination bucket, and the key prefix | ||
# bucket_name: 'example-bucket' | ||
# s3_key_prefix: 'path/to/file/' | ||
|
||
# if access key and secret are left blank, boto will use the credentials | ||
# defined in the [default] section of ~/.aws/credentials. | ||
aws_access_key_id: | ||
aws_secret_access_key: | ||
|
||
# dist_directory: dist | ||
# timeout: 15 | ||
# memory_size: 512 | ||
# concurrency: 500 | ||
# | ||
|
||
# Experimental Environment variables | ||
environment_variables: | ||
SLACK_BOT_TOKEN: ${SLACK_BOT_TOKEN} | ||
SLACK_SIGNING_SECRET: ${SLACK_SIGNING_SECRET} | ||
|
||
# If `tags` is uncommented then tags will be set at creation or update | ||
# time. During an update all other tags will be removed except the tags | ||
# listed here. | ||
#tags: | ||
# tag_1: foo | ||
# tag_2: bar | ||
|
||
# Build options | ||
build: | ||
source_directories: vendor # a comma delimited list of directories in your project root that contains source to package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.