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
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
if [ ${python_version:7:3} == "3.8" ]; then
pip install -e ".[async]"
pip install -e ".[adapter]"
pip install "pytype==2021.4.15" && pytype slack_bolt/
pip install "pytype" && pytype slack_bolt/
fi
- name: Run all tests for codecov (3.9 only)
run: |
Expand Down
6 changes: 4 additions & 2 deletions slack_bolt/oauth/async_callback_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def __init__(
state_utils=state_utils,
redirect_uri_page_renderer=redirect_uri_page_renderer,
)
self.success = self._success_handler
self.failure = self._failure_handler
# Note that pytype 2021.4.26 misunderstands these assignments.
# Thus, we put "type: ignore" for the following two lines
self.success = self._success_handler # type: ignore
self.failure = self._failure_handler # type: ignore

# --------------------------
# Internal methods
Expand Down
10 changes: 6 additions & 4 deletions slack_bolt/oauth/async_oauth_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ def __init__(
logger: The logger that will be used internally
"""
# OAuth flow parameters/credentials
self.client_id = client_id or os.environ.get("SLACK_CLIENT_ID")
self.client_secret = client_secret or os.environ.get(
"SLACK_CLIENT_SECRET", None
client_id: Optional[str] = client_id or os.environ.get("SLACK_CLIENT_ID")
client_secret: Optional[str] = client_secret or os.environ.get(
"SLACK_CLIENT_SECRET"
)
if self.client_id is None or self.client_secret is None:
if client_id is None or client_secret is None:
raise BoltError("Both client_id and client_secret are required")
self.client_id = client_id
self.client_secret = client_secret

self.scopes = scopes or os.environ.get("SLACK_SCOPES", "").split(",")
if isinstance(self.scopes, str):
Expand Down
10 changes: 6 additions & 4 deletions slack_bolt/oauth/oauth_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ def __init__(
state_expiration_seconds: The seconds that the state value is alive (Default: 600 seconds)
logger: The logger that will be used internally
"""
self.client_id = client_id or os.environ.get("SLACK_CLIENT_ID")
self.client_secret = client_secret or os.environ.get(
"SLACK_CLIENT_SECRET", None
client_id: Optional[str] = client_id or os.environ.get("SLACK_CLIENT_ID")
client_secret: Optional[str] = client_secret or os.environ.get(
"SLACK_CLIENT_SECRET"
)
if self.client_id is None or self.client_secret is None:
if client_id is None or client_secret is None:
raise BoltError("Both client_id and client_secret are required")
self.client_id = client_id
self.client_secret = client_secret

self.scopes = scopes or os.environ.get("SLACK_SCOPES", "").split(",")
if isinstance(self.scopes, str):
Expand Down
20 changes: 16 additions & 4 deletions slack_bolt/request/async_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,21 @@ def __init__(
context: The context in this request.
mode: The mode used for this request. (either "http" or "socket_mode")
"""
if mode == "http" and not isinstance(body, str):
raise BoltError(error_message_raw_body_required_in_http_mode())
self.raw_body = body if mode == "http" else ""

if mode == "http":
# HTTP Mode
if not isinstance(body, str):
raise BoltError(error_message_raw_body_required_in_http_mode())
self.raw_body = body if body is not None else ""
else:
# Socket Mode
if body is not None and isinstance(body, str):
self.raw_body = body
else:
# We don't convert the dict value to str
# as doing so does not guarantee to keep the original structure/format.
self.raw_body = ""

self.query = parse_query(query)
self.headers = build_normalized_headers(headers)
self.content_type = extract_content_type(self.headers)
Expand All @@ -57,7 +69,7 @@ def __init__(
self.context = build_async_context(
AsyncBoltContext(context if context else {}), self.body
)
self.lazy_only = self.headers.get("x-slack-bolt-lazy-only", [False])[0]
self.lazy_only = bool(self.headers.get("x-slack-bolt-lazy-only", [False])[0])
self.lazy_function_name = self.headers.get(
"x-slack-bolt-lazy-function-name", [None]
)[0]
Expand Down
19 changes: 15 additions & 4 deletions slack_bolt/request/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,20 @@ def __init__(
context: The context in this request.
mode: The mode used for this request. (either "http" or "socket_mode")
"""
if mode == "http" and not isinstance(body, str):
raise BoltError(error_message_raw_body_required_in_http_mode())
self.raw_body = body if mode == "http" else ""
if mode == "http":
# HTTP Mode
if not isinstance(body, str):
raise BoltError(error_message_raw_body_required_in_http_mode())
self.raw_body = body if body is not None else ""
else:
# Socket Mode
if body is not None and isinstance(body, str):
self.raw_body = body
else:
# We don't convert the dict value to str
# as doing so does not guarantee to keep the original structure/format.
self.raw_body = ""

self.query = parse_query(query)
self.headers = build_normalized_headers(headers)
self.content_type = extract_content_type(self.headers)
Expand All @@ -56,7 +67,7 @@ def __init__(
raise BoltError(error_message_unknown_request_body_type())

self.context = build_context(BoltContext(context if context else {}), self.body)
self.lazy_only = self.headers.get("x-slack-bolt-lazy-only", [False])[0]
self.lazy_only = bool(self.headers.get("x-slack-bolt-lazy-only", [False])[0])
self.lazy_function_name = self.headers.get(
"x-slack-bolt-lazy-function-name", [None]
)[0]
Expand Down