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
4 changes: 2 additions & 2 deletions .github/workflows/pytype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 20
strategy:
matrix:
python-version: ['3.8']
python-version: ['3.9']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ log_date_format = %Y-%m-%d %H:%M:%S
filterwarnings =
ignore:"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead:DeprecationWarning
ignore:The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.:DeprecationWarning
asyncio_mode = auto
2 changes: 1 addition & 1 deletion scripts/run_pytype.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ script_dir=$(dirname $0)
cd ${script_dir}/.. && \
pip install -e ".[async]" && \
pip install -e ".[adapter]" && \
pip install "pytype==2022.2.23" && \
pip install "pytype==2022.3.8" && \
pytype slack_bolt/
4 changes: 3 additions & 1 deletion slack_bolt/adapter/aws_lambda/chalice_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class ChaliceSlackRequestHandler:
def __init__(self, app: App, chalice: Chalice, lambda_client: Optional[BaseClient] = None): # type: ignore
self.app = app
self.chalice = chalice
self.logger = get_bolt_app_logger(app.name, ChaliceSlackRequestHandler)
self.logger = get_bolt_app_logger(
app.name, ChaliceSlackRequestHandler, app.logger
)

if getenv("AWS_CHALICE_CLI_MODE") == "true" and lambda_client is None:
try:
Expand Down
2 changes: 1 addition & 1 deletion slack_bolt/adapter/aws_lambda/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class SlackRequestHandler:
def __init__(self, app: App): # type: ignore
self.app = app
self.logger = get_bolt_app_logger(app.name, SlackRequestHandler)
self.logger = get_bolt_app_logger(app.name, SlackRequestHandler, app.logger)
self.app.listener_runner.lazy_listener_runner = LambdaLazyListenerRunner(
self.logger
)
Expand Down
124 changes: 95 additions & 29 deletions slack_bolt/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ def message_hello(message, say):
self._verification_token: Optional[str] = verification_token or os.environ.get(
"SLACK_VERIFICATION_TOKEN", None
)
# If a logger is explicitly passed when initializing, the logger works as the base logger.
# The base logger's logging settings will be propagated to all the loggers created by bolt-python.
self._base_logger = logger
# The framework logger is supposed to be used for the internal logging.
# Also, it's accessible via `app.logger` as the app's singleton logger.
self._framework_logger = logger or get_bolt_logger(App)
self._raise_error_for_unhandled_request = raise_error_for_unhandled_request

Expand Down Expand Up @@ -356,10 +361,15 @@ def _init_middleware_list(
return
if ssl_check_enabled is True:
self._middleware_list.append(
SslCheck(verification_token=self._verification_token)
SslCheck(
verification_token=self._verification_token,
base_logger=self._base_logger,
)
)
if request_verification_enabled is True:
self._middleware_list.append(RequestVerification(self._signing_secret))
self._middleware_list.append(
RequestVerification(self._signing_secret, base_logger=self._base_logger)
)

# As authorize is required for making a Bolt app function, we don't offer the flag to disable this
if self._oauth_flow is None:
Expand All @@ -370,24 +380,33 @@ def _init_middleware_list(
# This API call is for eagerly validating the token
auth_test_result = self._client.auth_test(token=self._token)
self._middleware_list.append(
SingleTeamAuthorization(auth_test_result=auth_test_result)
SingleTeamAuthorization(
auth_test_result=auth_test_result,
base_logger=self._base_logger,
)
)
except SlackApiError as err:
raise BoltError(error_auth_test_failure(err.response))
elif self._authorize is not None:
self._middleware_list.append(
MultiTeamsAuthorization(authorize=self._authorize)
MultiTeamsAuthorization(
authorize=self._authorize, base_logger=self._base_logger
)
)
else:
raise BoltError(error_token_required())
else:
self._middleware_list.append(
MultiTeamsAuthorization(authorize=self._authorize)
MultiTeamsAuthorization(
authorize=self._authorize, base_logger=self._base_logger
)
)
if ignoring_self_events_enabled is True:
self._middleware_list.append(IgnoringSelfEvents())
self._middleware_list.append(
IgnoringSelfEvents(base_logger=self._base_logger)
)
if url_verification_enabled is True:
self._middleware_list.append(UrlVerification())
self._middleware_list.append(UrlVerification(base_logger=self._base_logger))
self._init_middleware_list_done = True

# -------------------------
Expand Down Expand Up @@ -616,7 +635,11 @@ def middleware_func(logger, body, next):
self._middleware_list.append(middleware)
elif isinstance(middleware_or_callable, Callable):
self._middleware_list.append(
CustomMiddleware(app_name=self.name, func=middleware_or_callable)
CustomMiddleware(
app_name=self.name,
func=middleware_or_callable,
base_logger=self._base_logger,
)
)
return middleware_or_callable
else:
Expand Down Expand Up @@ -677,9 +700,10 @@ def step(
edit=edit,
save=save,
execute=execute,
base_logger=self._base_logger,
)
elif isinstance(step, WorkflowStepBuilder):
step = step.build()
step = step.build(base_logger=self._base_logger)
elif not isinstance(step, WorkflowStep):
raise BoltError(f"Invalid step object ({type(step)})")

Expand Down Expand Up @@ -759,7 +783,9 @@ def ask_for_introduction(event, say):

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.event(event)
primary_matcher = builtin_matchers.event(
event, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware, True
)
Expand Down Expand Up @@ -814,7 +840,7 @@ def __call__(*args, **kwargs):
),
}
primary_matcher = builtin_matchers.message_event(
keyword=keyword, constraints=constraints
keyword=keyword, constraints=constraints, base_logger=self._base_logger
)
middleware.insert(0, MessageListenerMatches(keyword))
return self._register_listener(
Expand Down Expand Up @@ -859,7 +885,9 @@ def repeat_text(ack, say, command):

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.command(command)
primary_matcher = builtin_matchers.command(
command, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand Down Expand Up @@ -908,7 +936,9 @@ def open_modal(ack, body, client):

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.shortcut(constraints)
primary_matcher = builtin_matchers.shortcut(
constraints, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -925,7 +955,9 @@ def global_shortcut(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.global_shortcut(callback_id)
primary_matcher = builtin_matchers.global_shortcut(
callback_id, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -942,7 +974,9 @@ def message_shortcut(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.message_shortcut(callback_id)
primary_matcher = builtin_matchers.message_shortcut(
callback_id, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand Down Expand Up @@ -984,7 +1018,9 @@ def update_message(ack):

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.action(constraints)
primary_matcher = builtin_matchers.action(
constraints, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -1003,7 +1039,9 @@ def block_action(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.block_action(constraints)
primary_matcher = builtin_matchers.block_action(
constraints, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -1021,7 +1059,9 @@ def attachment_action(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.attachment_action(callback_id)
primary_matcher = builtin_matchers.attachment_action(
callback_id, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -1039,7 +1079,9 @@ def dialog_submission(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.dialog_submission(callback_id)
primary_matcher = builtin_matchers.dialog_submission(
callback_id, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -1057,7 +1099,9 @@ def dialog_cancellation(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.dialog_cancellation(callback_id)
primary_matcher = builtin_matchers.dialog_cancellation(
callback_id, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand Down Expand Up @@ -1110,7 +1154,9 @@ def handle_submission(ack, body, client, view):

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.view(constraints)
primary_matcher = builtin_matchers.view(
constraints, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -1128,7 +1174,9 @@ def view_submission(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.view_submission(constraints)
primary_matcher = builtin_matchers.view_submission(
constraints, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -1146,7 +1194,9 @@ def view_closed(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.view_closed(constraints)
primary_matcher = builtin_matchers.view_closed(
constraints, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand Down Expand Up @@ -1199,7 +1249,9 @@ def show_menu_options(ack):

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.options(constraints)
primary_matcher = builtin_matchers.options(
constraints, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -1216,7 +1268,9 @@ def block_suggestion(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.block_suggestion(action_id)
primary_matcher = builtin_matchers.block_suggestion(
action_id, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand All @@ -1234,7 +1288,9 @@ def dialog_suggestion(

def __call__(*args, **kwargs):
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
primary_matcher = builtin_matchers.dialog_suggestion(callback_id)
primary_matcher = builtin_matchers.dialog_suggestion(
callback_id, base_logger=self._base_logger
)
return self._register_listener(
list(functions), primary_matcher, matchers, middleware
)
Expand Down Expand Up @@ -1265,7 +1321,9 @@ def enable_token_revocation_listeners(self) -> None:
# -------------------------

def _init_context(self, req: BoltRequest):
req.context["logger"] = get_bolt_app_logger(self.name)
req.context["logger"] = get_bolt_app_logger(
app_name=self.name, base_logger=self._base_logger
)
req.context["token"] = self._token
if self._token is not None:
# This WebClient instance can be safely singleton
Expand Down Expand Up @@ -1311,15 +1369,22 @@ def _register_listener(
value_to_return = functions[0]

listener_matchers = [
CustomListenerMatcher(app_name=self.name, func=f) for f in (matchers or [])
CustomListenerMatcher(
app_name=self.name, func=f, base_logger=self._base_logger
)
for f in (matchers or [])
]
listener_matchers.insert(0, primary_matcher)
listener_middleware = []
for m in middleware or []:
if isinstance(m, Middleware):
listener_middleware.append(m)
elif isinstance(m, Callable):
listener_middleware.append(CustomMiddleware(app_name=self.name, func=m))
listener_middleware.append(
CustomMiddleware(
app_name=self.name, func=m, base_logger=self._base_logger
)
)
else:
raise ValueError(error_unexpected_listener_middleware(type(m)))

Expand All @@ -1331,6 +1396,7 @@ def _register_listener(
matchers=listener_matchers,
middleware=listener_middleware,
auto_acknowledgement=auto_acknowledgement,
base_logger=self._base_logger,
)
)
return value_to_return
Expand Down
Loading