@@ -215,9 +215,14 @@ def extract_channel_id(payload: Dict[str, Any]) -> Optional[str]:
215215
216216
217217def extract_thread_ts (payload : Dict [str , Any ]) -> Optional [str ]:
218- # This utility initially supports only the use cases for AI assistants, but it may be fine to add more patterns.
219- # That said, note that thread_ts is always required for assistant threads, but it's not for channels.
220- # Thus, blindly setting this thread_ts to say utility can break existing apps' behaviors.
218+ # This utility only extracts thread_ts for assistant events to avoid breaking existing say() behavior.
219+ # For non-assistant events, thread_ts is intentionally NOT extracted into context because:
220+ # - say() uses context.thread_ts to decide where to post messages
221+ # - Existing apps may expect say() to post to the channel, not the thread
222+ # - Changing this would be a breaking change for existing apps
223+ #
224+ # The BoltAgent class handles non-assistant thread_ts separately by reading from the event directly,
225+ # allowing it to work correctly without affecting say() behavior.
221226 if is_assistant_event (payload ):
222227 event = payload ["event" ]
223228 if (
@@ -242,6 +247,18 @@ def extract_thread_ts(payload: Dict[str, Any]) -> Optional[str]:
242247 return None
243248
244249
250+ def extract_ts (payload : Dict [str , Any ]) -> Optional [str ]:
251+ """Extract the message timestamp from an event payload."""
252+ event = payload .get ("event" , {})
253+ # Direct ts on the event (e.g., app_mention, message)
254+ if event .get ("ts" ) is not None :
255+ return event ["ts" ]
256+ # message_changed events have ts in the message
257+ if event .get ("message" , {}).get ("ts" ) is not None :
258+ return event ["message" ]["ts" ]
259+ return None
260+
261+
245262def extract_function_execution_id (payload : Dict [str , Any ]) -> Optional [str ]:
246263 if payload .get ("function_execution_id" ) is not None :
247264 return payload .get ("function_execution_id" )
@@ -292,6 +309,9 @@ def build_context(context: BoltContext, body: Dict[str, Any]) -> BoltContext:
292309 channel_id = extract_channel_id (body )
293310 if channel_id :
294311 context ["channel_id" ] = channel_id
312+ ts = extract_ts (body )
313+ if ts :
314+ context ["ts" ] = ts
295315 thread_ts = extract_thread_ts (body )
296316 if thread_ts :
297317 context ["thread_ts" ] = thread_ts
0 commit comments