Skip to content

Commit 3704b8f

Browse files
committed
chore: use context.user_token instead of manual query
1 parent 1d4aa94 commit 3704b8f

3 files changed

Lines changed: 3 additions & 34 deletions

File tree

pydantic-ai/listeners/events/app_home_opened.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ def handle_app_home_opened(client: WebClient, context: BoltContext, logger: Logg
1616
is_connected = False
1717

1818
if os.environ.get("SLACK_CLIENT_ID"):
19-
from oauth import installation_store
20-
21-
installation = installation_store.find_installation(
22-
enterprise_id=context.enterprise_id or "",
23-
team_id=context.team_id or "",
24-
user_id=user_id,
25-
)
26-
if installation and installation.user_token:
19+
if context.user_token:
2720
is_connected = True
2821
else:
2922
redirect_uri = os.environ.get("SLACK_REDIRECT_URI", "")

pydantic-ai/listeners/events/app_mentioned.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from agent import CaseyDeps, run_casey
88
from thread_context import conversation_store
99
from listeners.views.feedback_builder import build_feedback_blocks
10-
from oauth import installation_store
1110

1211

1312
def handle_app_mentioned(
@@ -59,25 +58,14 @@ def handle_app_mentioned(
5958
# Get conversation history
6059
history = conversation_store.get_history(channel_id, thread_ts)
6160

62-
# Look up the user token directly from the installation store rather
63-
# than context.user_token. Bolt's InstallationStoreAuthorize may fail
64-
# to resolve the user token when installer-latest is missing or the
65-
# requesting user differs from the original installer.
66-
installation = installation_store.find_installation(
67-
enterprise_id=context.enterprise_id,
68-
team_id=context.team_id,
69-
user_id=user_id,
70-
)
71-
user_token = installation.user_token if installation else None
72-
7361
# Run the agent
7462
deps = CaseyDeps(
7563
client=client,
7664
user_id=user_id,
7765
channel_id=channel_id,
7866
thread_ts=thread_ts,
7967
message_ts=event["ts"],
80-
user_token=user_token,
68+
user_token=context.user_token,
8169
)
8270
result = run_casey(cleaned_text, deps, message_history=history)
8371

pydantic-ai/listeners/events/message.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from agent import CaseyDeps, run_casey
77
from thread_context import conversation_store
88
from listeners.views.feedback_builder import build_feedback_blocks
9-
from oauth import installation_store
109

1110

1211
def handle_message(
@@ -82,25 +81,14 @@ def handle_message(
8281
],
8382
)
8483

85-
# Look up the user token directly from the installation store rather
86-
# than context.user_token. Bolt's InstallationStoreAuthorize may fail
87-
# to resolve the user token when installer-latest is missing or the
88-
# requesting user differs from the original installer.
89-
installation = installation_store.find_installation(
90-
enterprise_id=context.enterprise_id,
91-
team_id=context.team_id,
92-
user_id=user_id,
93-
)
94-
user_token = installation.user_token if installation else None
95-
9684
# Run the agent
9785
deps = CaseyDeps(
9886
client=client,
9987
user_id=user_id,
10088
channel_id=channel_id,
10189
thread_ts=thread_ts,
10290
message_ts=event["ts"],
103-
user_token=user_token,
91+
user_token=context.user_token,
10492
)
10593
result = run_casey(text, deps, message_history=history)
10694

0 commit comments

Comments
 (0)