X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ python:
install:
- python setup.py install
script:
- python setup.py test
- pip install "pytest>=5,<6"
- pytest tests/scenario_tests/
- pip install "pytest-asyncio<1"
- pip install "aiohttp>=3,<4"
- pytest tests/scenario_tests_async/
- python setup.py test
20 changes: 6 additions & 14 deletions samples/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
logging.basicConfig(level=logging.DEBUG)

from slack_bolt import App
from slack_bolt.kwargs_injection import Args
from slack_sdk import WebClient

app = App(process_before_response=True)

Expand All @@ -23,10 +21,11 @@ def log_request(logger, payload, next):
return next()


@app.command("/bolt-py-proto-111") # or app.command(re.compile(r"/bolt-.+"))(test_command)
def test_command(args: Args):
args.logger.info(args.payload)
respond, ack = args.respond, args.ack
@app.command("/hello-bolt-python")
# or app.command(re.compile(r"/hello-.+"))(test_command)
def test_command(payload, respond, client, ack, logger):
logger.info(payload)
ack("Thanks!")

respond(blocks=[
{
Expand All @@ -47,13 +46,7 @@ def test_command(args: Args):
}
}
])
ack("thanks!")


@app.shortcut("test-shortcut")
def test_shortcut(ack, client: WebClient, logger, payload):
logger.info(payload)
ack()
res = client.views_open(
trigger_id=payload["trigger_id"],
view={
Expand Down Expand Up @@ -102,10 +95,9 @@ def button_click(logger, payload, ack, respond):


@app.event("app_mention")
def event_test(ack, payload, say, logger):
def event_test(payload, say, logger):
logger.info(payload)
say("What's up?")
return ack()


@app.message("test")
Expand Down
8 changes: 7 additions & 1 deletion samples/async_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

logging.basicConfig(level=logging.DEBUG)

from slack_bolt import AsyncApp
from slack_bolt.async_app import AsyncApp

app = AsyncApp()

Expand All @@ -26,6 +26,12 @@ async def event_test(payload, say, logger):
await say("What's up?")


@app.command("/hello-bolt-python")
# or app.command(re.compile(r"/hello-.+"))(test_command)
async def command(ack):
await ack("Thanks!")


if __name__ == "__main__":
app.start(3000)

Expand Down
45 changes: 34 additions & 11 deletions samples/aws_chalice/app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# ------------------------------------------------
# instead of slack_bolt in requirements.txt
import sys

sys.path.insert(1, "latest_slack_bolt")
# ------------------------------------------------

import logging
import time

from chalice import Chalice, Response

from slack_bolt import App
from slack_bolt.adapter.aws_lambda.chalice_handler import ChaliceSlackRequestHandler
from slack_bolt.adapter.aws_lambda.lambda_s3_oauth_flow import LambdaS3OAuthFlow

# process_before_response must be True when running on FaaS
bolt_app = App(process_before_response=True)
bolt_app = App(
process_before_response=True,
authorization_test_enabled=False,
oauth_flow=LambdaS3OAuthFlow(
install_path="/api/slack/install",
redirect_uri_path="/api/slack/oauth_redirect",
),
)


@bolt_app.event("app_mention")
Expand All @@ -20,22 +24,41 @@ def handle_app_mentions(payload, say, logger):
say("What's up? I'm a Chalice app :wave:")


@bolt_app.command("/hello-bolt-python-chalice")
def respond_to_slack_within_3_seconds(ack):
ack("Thanks!")


ChaliceSlackRequestHandler.clear_all_log_handlers()
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)

# Don't change this variable name "app"
app = Chalice(app_name="bolt-python-chalice")
slack_handler = ChaliceSlackRequestHandler(app=bolt_app)
slack_handler = ChaliceSlackRequestHandler(app=bolt_app, chalice=app)


@app.route("/slack/events", methods=["POST"])
@app.route(
"/slack/events",
methods=["POST"],
content_types=["application/x-www-form-urlencoded", "application/json"],
)
def events() -> Response:
return slack_handler.handle(app.current_request)


@app.route("/slack/install", methods=["GET"])
def install() -> Response:
return slack_handler.handle(app.current_request)


@app.route("/slack/oauth_redirect", methods=["GET"])
def oauth_redirect() -> Response:
return slack_handler.handle(app.current_request)

# configure aws credentials properly
# pip install -r requirements.txt
# edit .chalice/config.json
# rm -rf vendor/latest_slack_bolt && cp -pr ../../src vendor/latest_slack_bolt
# rm -rf vendor/slack_* && cp -pr ../../src/* vendor/
# chalice deploy

# for local dev
Expand Down
3 changes: 2 additions & 1 deletion samples/aws_chalice/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

# configure aws credentials properly
pip install -U chalice click boto3
pip install -r requirements.txt
# edit .chalice/config.json
rm -rf vendor/latest_slack_bolt && cp -pr ../../src vendor/latest_slack_bolt
rm -rf vendor/slack_* && cp -pr ../../src vendor
chalice deploy
23 changes: 14 additions & 9 deletions samples/aws_chalice/oauth_app.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# ------------------------------------------------
# instead of slack_bolt in requirements.txt
import sys

sys.path.insert(1, "latest_slack_bolt")
# ------------------------------------------------

import logging

from chalice import Chalice, Response

from slack_bolt import App
from slack_bolt.adapter.aws_lambda.chalice_handler import ChaliceSlackRequestHandler
from slack_bolt.adapter.aws_lambda.lambda_s3_oauth_flow import LambdaS3OAuthFlow

# process_before_response must be True when running on FaaS
bolt_app = App(
process_before_response=True,
authorization_test_enabled=False,
oauth_flow=LambdaS3OAuthFlow(
install_path="/api/slack/install",
redirect_uri_path="/api/slack/oauth_redirect",
Expand All @@ -27,15 +23,24 @@ def handle_app_mentions(payload, say, logger):
say("What's up? I'm a Chalice app :wave:")


@bolt_app.command("/hello-bolt-python-chalice")
def respond_to_slack_within_3_seconds(ack):
ack("Thanks!")


ChaliceSlackRequestHandler.clear_all_log_handlers()
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)

# Don't change this variable name "app"
app = Chalice(app_name="bolt-python-chalice")
slack_handler = ChaliceSlackRequestHandler(app=bolt_app)
slack_handler = ChaliceSlackRequestHandler(app=bolt_app, chalice=app)


@app.route("/slack/events", methods=["POST"])
@app.route(
"/slack/events",
methods=["POST"],
content_types=["application/x-www-form-urlencoded", "application/json"],
)
def events() -> Response:
return slack_handler.handle(app.current_request)

Expand Down
5 changes: 1 addition & 4 deletions samples/aws_chalice/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
chalice>=1,<2
click>=7,<8
slackclient>=2,<3
boto3==1.4.4
#slackclient>=2,<3
35 changes: 26 additions & 9 deletions samples/aws_chalice/simple_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# ------------------------------------------------
# instead of slack_bolt in requirements.txt
import sys

sys.path.insert(1, "latest_slack_bolt")
# ------------------------------------------------

import logging
import time

from chalice import Chalice, Response
from slack_bolt import App
from slack_bolt.adapter.aws_lambda.chalice_handler import ChaliceSlackRequestHandler
Expand All @@ -25,10 +20,32 @@ def handle_app_mentions(payload, say, logger):

# Don't change this variable name "app"
app = Chalice(app_name="bolt-python-chalice")
slack_handler = ChaliceSlackRequestHandler(app=bolt_app)
slack_handler = ChaliceSlackRequestHandler(app=bolt_app, chalice=app)


def respond_to_slack_within_3_seconds(ack):
# This method is for synchronous communication with the Slack API server
ack("Thanks!")


def can_be_long(say):
# This can be executed in a thread, asyncio's Future, a new AWS lambda function
# ack() is not allowed here
time.sleep(5)
say("I'm done!")


bolt_app.command("/hello-bolt-python-chalice")(
ack=respond_to_slack_within_3_seconds,
subsequent=[can_be_long],
)


@app.route("/slack/events", methods=["POST"])
@app.route(
"/slack/events",
methods=["POST"],
content_types=["application/x-www-form-urlencoded", "application/json"],
)
def events() -> Response:
return slack_handler.handle(app.current_request)

Expand Down
2 changes: 1 addition & 1 deletion samples/aws_lambda/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
latest_slack_bolt/
vendor/
10 changes: 8 additions & 2 deletions samples/aws_lambda/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# instead of slack_bolt in requirements.txt
import sys

sys.path.insert(1, "latest_slack_bolt")
sys.path.insert(1, "vendor")
# ------------------------------------------------

import logging

from slack_bolt import App
from slack_bolt.adapter.aws_lambda import SlackRequestHandler

Expand All @@ -19,6 +20,11 @@ def handle_app_mentions(payload, say, logger):
say("What's up?")


@app.command("/hello-bolt-python-lambda")
def respond_to_slack_within_3_seconds(ack):
ack("Thanks!")


SlackRequestHandler.clear_all_log_handlers()
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)

Expand All @@ -30,6 +36,6 @@ def handler(event, context):
# export SLACK_SIGNING_SECRET=***
# export SLACK_BOT_TOKEN=xoxb-***

# rm -rf latest_slack_bolt && cp -pr ../../src latest_slack_bolt
# rm -rf vendor && cp -pr ../../src/* vendor/
# pip install python-lambda
# lambda deploy --config-file aws_lambda_config.yaml --requirements requirements.txt
2 changes: 1 addition & 1 deletion samples/aws_lambda/aws_lambda_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ environment_variables:

# Build options
build:
source_directories: latest_slack_bolt # a comma delimited list of directories in your project root that contains source to package.
source_directories: vendor # a comma delimited list of directories in your project root that contains source to package.
9 changes: 8 additions & 1 deletion samples/aws_lambda/aws_lambda_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# instead of slack_bolt in requirements.txt
import sys

sys.path.insert(1, "latest_slack_bolt")
sys.path.insert(1, "vendor")
# ------------------------------------------------

import logging

from slack_bolt import App
from slack_bolt.adapter.aws_lambda import SlackRequestHandler
from slack_bolt.adapter.aws_lambda.lambda_s3_oauth_flow import LambdaS3OAuthFlow
Expand All @@ -23,6 +24,12 @@ def handle_app_mentions(payload, say, logger):
say("What's up?")


@app.command("/hello-bolt-python-lambda")
def respond_to_slack_within_3_seconds(ack):
# This method is for synchronous communication with the Slack API server
ack("Thanks!")


SlackRequestHandler.clear_all_log_handlers()
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)

Expand Down
2 changes: 1 addition & 1 deletion samples/aws_lambda/aws_lambda_oauth_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ environment_variables:

# Build options
build:
source_directories: latest_slack_bolt # a comma delimited list of directories in your project root that contains source to package.
source_directories: vendor # a comma delimited list of directories in your project root that contains source to package.
2 changes: 1 addition & 1 deletion samples/aws_lambda/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
rm -rf latest_slack_bolt && cp -pr ../../src latest_slack_bolt
rm -rf vendor && cp -pr ../../src vendor
pip install python-lambda -U
lambda deploy \
--config-file aws_lambda_config.yaml \
Expand Down
2 changes: 1 addition & 1 deletion samples/aws_lambda/deploy_oauth.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
rm -rf latest_slack_bolt && cp -pr ../../src latest_slack_bolt
rm -rf vendor && cp -pr ../../src vendor
pip install python-lambda -U
lambda deploy \
--config-file aws_lambda_oauth_config.yaml \
Expand Down
1 change: 0 additions & 1 deletion samples/aws_lambda/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
slackclient>=2,<3
2 changes: 0 additions & 2 deletions samples/aws_lambda/requirements_oauth.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
slackclient>=2,<3
boto3==1.4.4
Loading
X Tutup