Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ async def __call__(self) -> Optional[AssistantThreadContext]:
if self.thread_context_loaded is True:
return self._thread_context

if self.payload.get("assistant_thread") is not None:
thread = self.payload.get("assistant_thread")
if thread is not None and thread.get("context", {}).get("channel_id") is not None:
# assistant_thread_started
thread = self.payload["assistant_thread"]
self._thread_context = (
AssistantThreadContext(thread["context"])
if thread.get("context", {}).get("channel_id") is not None
else None
)
self._thread_context = AssistantThreadContext(thread["context"])
# for this event, the context will never be changed
self.thread_context_loaded = True
elif self.payload.get("channel") is not None and self.payload.get("thread_ts") is not None:
Expand Down
10 changes: 3 additions & 7 deletions slack_bolt/context/get_thread_context/get_thread_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ def __call__(self) -> Optional[AssistantThreadContext]:
if self.thread_context_loaded is True:
return self._thread_context

if self.payload.get("assistant_thread") is not None:
thread = self.payload.get("assistant_thread")
if thread is not None and thread.get("context", {}).get("channel_id") is not None:
# assistant_thread_started
thread = self.payload["assistant_thread"]
self._thread_context = (
AssistantThreadContext(thread["context"])
if thread.get("context", {}).get("channel_id") is not None
else None
)
self._thread_context = AssistantThreadContext(thread["context"])
# for this event, the context will never be changed
self.thread_context_loaded = True
elif self.payload.get("channel") is not None and self.payload.get("thread_ts") is not None:
Expand Down
24 changes: 24 additions & 0 deletions tests/scenario_tests/test_events_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def handle_user_message(say: Say, set_status: SetStatus, context: BoltContext):
assert response.status == 200
assert_target_called()

request = BoltRequest(body=user_message_event_body_with_action_token, mode="socket_mode")
response = app.dispatch(request)
assert response.status == 200
assert_target_called()

request = BoltRequest(body=message_changed_event_body, mode="socket_mode")
response = app.dispatch(request)
assert response.status == 200
Expand Down Expand Up @@ -190,6 +195,25 @@ def build_payload(event: dict) -> dict:
}
)

user_message_event_body_with_action_token = build_payload(
{
"user": "W222",
"type": "message",
"ts": "1726133700.887259",
"text": "When Slack was released?",
"team": "T111",
"user_team": "T111",
"source_team": "T222",
"user_profile": {},
"thread_ts": "1726133698.626339",
"parent_user_id": "W222",
"channel": "D111",
"event_ts": "1726133700.887259",
"channel_type": "im",
"assistant_thread": {"action_token": "10647138185092.960436384805.afce3599"},
}
)

message_changed_event_body = build_payload(
{
"type": "message",
Expand Down
24 changes: 24 additions & 0 deletions tests/scenario_tests_async/test_events_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ async def handle_user_message(say: AsyncSay, set_status: AsyncSetStatus, context
assert response.status == 200
await assert_target_called()

request = AsyncBoltRequest(body=user_message_event_body_with_action_token, mode="socket_mode")
response = await app.async_dispatch(request)
assert response.status == 200
await assert_target_called()

request = AsyncBoltRequest(body=message_changed_event_body, mode="socket_mode")
response = await app.async_dispatch(request)
assert response.status == 200
Expand Down Expand Up @@ -205,6 +210,25 @@ def build_payload(event: dict) -> dict:
)


user_message_event_body_with_action_token = build_payload(
{
"user": "W222",
"type": "message",
"ts": "1726133700.887259",
"text": "When Slack was released?",
"team": "T111",
"user_team": "T111",
"source_team": "T222",
"user_profile": {},
"thread_ts": "1726133698.626339",
"parent_user_id": "W222",
"channel": "D111",
"event_ts": "1726133700.887259",
"channel_type": "im",
"assistant_thread": {"action_token": "10647138185092.960436384805.afce3599"},
}
)

message_changed_event_body = build_payload(
{
"type": "message",
Expand Down
Loading