Skip to content

Commit f2f084e

Browse files
committed
refactor: avoid adding to context in this changeset
1 parent 38d0c42 commit f2f084e

File tree

5 files changed

+4
-37
lines changed

5 files changed

+4
-37
lines changed

slack_bolt/context/base_context.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class BaseContext(dict):
1818
"actor_team_id",
1919
"actor_user_id",
2020
"channel_id",
21-
"ts",
2221
"thread_ts",
2322
"response_url",
2423
"matches",
@@ -111,11 +110,6 @@ def channel_id(self) -> Optional[str]:
111110
"""The conversation ID associated with this request."""
112111
return self.get("channel_id")
113112

114-
@property
115-
def ts(self) -> Optional[str]:
116-
"""The message timestamp associated with this request."""
117-
return self.get("ts")
118-
119113
@property
120114
def thread_ts(self) -> Optional[str]:
121115
"""The conversation thread's ID associated with this request."""

slack_bolt/kwargs_injection/async_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,9 @@ def build_async_required_kwargs(
8989
if "agent" in required_arg_names:
9090
from slack_bolt.agent.async_agent import AsyncBoltAgent
9191

92-
# For thread_ts, we check multiple sources:
93-
# 1. context.thread_ts - populated for assistant events
94-
# 2. event.thread_ts - for non-assistant events in a thread (e.g., app_mention in thread)
95-
# 3. context.ts - fallback to the message timestamp
96-
# We read from event directly to avoid changing context.thread_ts which would affect say() behavior
92+
# Resolve thread_ts: assistant events set context.thread_ts, otherwise read from event
9793
event = request.body.get("event", {})
98-
thread_ts = request.context.thread_ts or event.get("thread_ts") or request.context.ts
94+
thread_ts = request.context.thread_ts or event.get("thread_ts") or event.get("ts")
9995

10096
all_available_args["agent"] = AsyncBoltAgent(
10197
client=request.context.client,

slack_bolt/kwargs_injection/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,9 @@ def build_required_kwargs(
8888
if "agent" in required_arg_names:
8989
from slack_bolt.agent.agent import BoltAgent
9090

91-
# For thread_ts, we check multiple sources:
92-
# 1. context.thread_ts - populated for assistant events
93-
# 2. event.thread_ts - for non-assistant events in a thread (e.g., app_mention in thread)
94-
# 3. context.ts - fallback to the message timestamp
95-
# We read from event directly to avoid changing context.thread_ts which would affect say() behavior
91+
# Resolve thread_ts: assistant events set context.thread_ts, otherwise read from event
9692
event = request.body.get("event", {})
97-
thread_ts = request.context.thread_ts or event.get("thread_ts") or request.context.ts
93+
thread_ts = request.context.thread_ts or event.get("thread_ts") or event.get("ts")
9894

9995
all_available_args["agent"] = BoltAgent(
10096
client=request.context.client,

slack_bolt/request/async_internals.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
extract_actor_team_id,
1616
extract_actor_user_id,
1717
extract_thread_ts,
18-
extract_ts,
1918
)
2019

2120

@@ -46,9 +45,6 @@ def build_async_context(
4645
channel_id = extract_channel_id(body)
4746
if channel_id:
4847
context["channel_id"] = channel_id
49-
ts = extract_ts(body)
50-
if ts:
51-
context["ts"] = ts
5248
thread_ts = extract_thread_ts(body)
5349
if thread_ts:
5450
context["thread_ts"] = thread_ts

slack_bolt/request/internals.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,6 @@ def extract_thread_ts(payload: Dict[str, Any]) -> Optional[str]:
245245
return None
246246

247247

248-
def extract_ts(payload: Dict[str, Any]) -> Optional[str]:
249-
"""Extract the message timestamp from an event payload."""
250-
event = payload.get("event", {})
251-
# Direct ts on the event (e.g., app_mention, message)
252-
if event.get("ts") is not None:
253-
return event["ts"]
254-
# message_changed events have ts in the message
255-
if event.get("message", {}).get("ts") is not None:
256-
return event["message"]["ts"]
257-
return None
258-
259-
260248
def extract_function_execution_id(payload: Dict[str, Any]) -> Optional[str]:
261249
if payload.get("function_execution_id") is not None:
262250
return payload.get("function_execution_id")
@@ -307,9 +295,6 @@ def build_context(context: BoltContext, body: Dict[str, Any]) -> BoltContext:
307295
channel_id = extract_channel_id(body)
308296
if channel_id:
309297
context["channel_id"] = channel_id
310-
ts = extract_ts(body)
311-
if ts:
312-
context["ts"] = ts
313298
thread_ts = extract_thread_ts(body)
314299
if thread_ts:
315300
context["thread_ts"] = thread_ts

0 commit comments

Comments
 (0)