Skip to content

Commit 7b90327

Browse files
committed
Make samples up-to-date
* Fix some OAuth issues * Change app.event("message")'s behavior to receive all subtype events too
1 parent e035154 commit 7b90327

8 files changed

Lines changed: 42 additions & 11 deletions

File tree

samples/falcon/oauth_app.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ def handle_app_mentions(body, say, logger):
8787
say("What's up?")
8888

8989

90+
@app.message("What")
91+
def handle_matched_messages(event, logger):
92+
logger.info(f"message matched: {event['text']}")
93+
94+
95+
@app.event("message")
96+
def handle_messages(event, logger):
97+
logger.info(f"subtype: {event.get('subytype')}")
98+
99+
90100
api = falcon.API()
91101
resource = SlackAppResource(app)
92102
api.add_route("/slack/events", resource)

samples/fastapi/async_oauth_app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
sys.path.insert(1, "../..")
66
# ------------------------------------------------
77

8+
import logging
9+
logging.basicConfig(level=logging.DEBUG)
10+
811
from slack_bolt.async_app import AsyncApp
912
from slack_bolt.adapter.fastapi.async_handler import AsyncSlackRequestHandler
1013

samples/fastapi/oauth_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def handle_app_mentions(body, say, logger):
1919

2020

2121
@app.event("message")
22-
async def handle_message():
22+
def handle_message():
2323
pass
2424

2525

slack_bolt/app/app.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ def __init__(
141141
)
142142

143143
self._oauth_flow: Optional[OAuthFlow] = None
144+
145+
if (
146+
oauth_settings is None
147+
and os.environ.get("SLACK_CLIENT_ID") is not None
148+
and os.environ.get("SLACK_CLIENT_SECRET") is not None
149+
):
150+
# initialize with the default settings
151+
oauth_settings = OAuthSettings()
152+
144153
if oauth_flow:
145154
self._oauth_flow = oauth_flow
146155
if self._installation_store is None:
@@ -389,7 +398,9 @@ def message(
389398

390399
def __call__(*args, **kwargs):
391400
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
392-
primary_matcher = builtin_matchers.event("message")
401+
primary_matcher = builtin_matchers.event(
402+
{"type": "message", "subtype": None}
403+
)
393404
middleware.append(MessageListenerMatches(keyword))
394405
return self._register_listener(
395406
list(functions), primary_matcher, matchers, middleware, True

slack_bolt/app/async_app.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ def __init__(
149149
)
150150

151151
self._async_oauth_flow: Optional[AsyncOAuthFlow] = None
152+
153+
if (
154+
oauth_settings is None
155+
and os.environ.get("SLACK_CLIENT_ID") is not None
156+
and os.environ.get("SLACK_CLIENT_SECRET") is not None
157+
):
158+
# initialize with the default settings
159+
oauth_settings = AsyncOAuthSettings()
160+
152161
if oauth_flow:
153162
self._async_oauth_flow = oauth_flow
154163
if self._async_installation_store is None:
@@ -398,7 +407,9 @@ def message(
398407

399408
def __call__(*args, **kwargs):
400409
functions = self._to_listener_functions(kwargs) if kwargs else list(args)
401-
primary_matcher = builtin_matchers.event("message", True)
410+
primary_matcher = builtin_matchers.event(
411+
{"type": "message", "subtype": None}, True
412+
)
402413
middleware.append(AsyncMessageListenerMatches(keyword))
403414
return self._register_listener(
404415
list(functions), primary_matcher, matchers, middleware, True

slack_bolt/listener_matcher/builtins.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ async def async_fun(body: Dict[str, Any]) -> bool:
7575
def event(
7676
constraints: Union[str, Pattern, Dict[str, str]], asyncio: bool = False,
7777
) -> Union[ListenerMatcher, "AsyncListenerMatcher"]:
78-
if constraints == "message":
79-
# matches message events that don't have subtype in body
80-
constraints = {"type": "message", "subtype": None}
81-
8278
if isinstance(constraints, (str, Pattern)):
8379
event_type: Union[str, Pattern] = constraints
8480

slack_bolt/oauth/async_oauth_settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def __init__(
5555
self,
5656
*,
5757
# OAuth flow parameters/credentials
58-
client_id: str,
59-
client_secret: str,
58+
client_id: Optional[str] = None, # required
59+
client_secret: Optional[str] = None, # required
6060
scopes: Optional[List[str]] = None,
6161
user_scopes: Optional[List[str]] = None,
6262
redirect_uri: Optional[str] = None,

slack_bolt/oauth/oauth_settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def __init__(
5050
self,
5151
*,
5252
# OAuth flow parameters/credentials
53-
client_id: str,
54-
client_secret: str,
53+
client_id: Optional[str] = None, # required
54+
client_secret: Optional[str] = None, # required
5555
scopes: Optional[List[str]] = None,
5656
user_scopes: Optional[List[str]] = None,
5757
redirect_uri: Optional[str] = None,

0 commit comments

Comments
 (0)