File tree Expand file tree Collapse file tree 4 files changed +57
-14
lines changed
slack_bolt/context/get_thread_context Expand file tree Collapse file tree 4 files changed +57
-14
lines changed Original file line number Diff line number Diff line change @@ -31,14 +31,10 @@ async def __call__(self) -> Optional[AssistantThreadContext]:
3131 if self .thread_context_loaded is True :
3232 return self ._thread_context
3333
34- if self .payload .get ("assistant_thread" ) is not None :
34+ thread = self .payload .get ("assistant_thread" )
35+ if isinstance (thread , dict ) and thread .get ("context" , {}).get ("channel_id" ) is not None :
3536 # assistant_thread_started
36- thread = self .payload ["assistant_thread" ]
37- self ._thread_context = (
38- AssistantThreadContext (thread ["context" ])
39- if thread .get ("context" , {}).get ("channel_id" ) is not None
40- else None
41- )
37+ self ._thread_context = AssistantThreadContext (thread ["context" ])
4238 # for this event, the context will never be changed
4339 self .thread_context_loaded = True
4440 elif self .payload .get ("channel" ) is not None and self .payload .get ("thread_ts" ) is not None :
Original file line number Diff line number Diff line change @@ -31,14 +31,10 @@ def __call__(self) -> Optional[AssistantThreadContext]:
3131 if self .thread_context_loaded is True :
3232 return self ._thread_context
3333
34- if self .payload .get ("assistant_thread" ) is not None :
34+ thread = self .payload .get ("assistant_thread" )
35+ if isinstance (thread , dict ) and thread .get ("context" , {}).get ("channel_id" ) is not None :
3536 # assistant_thread_started
36- thread = self .payload ["assistant_thread" ]
37- self ._thread_context = (
38- AssistantThreadContext (thread ["context" ])
39- if thread .get ("context" , {}).get ("channel_id" ) is not None
40- else None
41- )
37+ self ._thread_context = AssistantThreadContext (thread ["context" ])
4238 # for this event, the context will never be changed
4339 self .thread_context_loaded = True
4440 elif self .payload .get ("channel" ) is not None and self .payload .get ("thread_ts" ) is not None :
Original file line number Diff line number Diff line change @@ -133,6 +133,12 @@ def handle_bot_message():
133133
134134 app .assistant (assistant )
135135
136+ request = BoltRequest (body = user_message_event_body_with_action_token , mode = "socket_mode" )
137+ response = app .dispatch (request )
138+ assert response .status == 200
139+ assert listener_called .wait (timeout = 0.1 ) is True
140+ listener_called .clear ()
141+
136142 request = BoltRequest (body = message_changed_event_body , mode = "socket_mode" )
137143 response = app .dispatch (request )
138144 assert response .status == 200
@@ -332,6 +338,25 @@ def build_payload(event: dict) -> dict:
332338 }
333339)
334340
341+ user_message_event_body_with_action_token = build_payload (
342+ {
343+ "user" : "W222" ,
344+ "type" : "message" ,
345+ "ts" : "1726133700.887259" ,
346+ "text" : "When Slack was released?" ,
347+ "team" : "T111" ,
348+ "user_team" : "T111" ,
349+ "source_team" : "T222" ,
350+ "user_profile" : {},
351+ "thread_ts" : "1726133698.626339" ,
352+ "parent_user_id" : "W222" ,
353+ "channel" : "D111" ,
354+ "event_ts" : "1726133700.887259" ,
355+ "channel_type" : "im" ,
356+ "assistant_thread" : {"action_token" : "10647138185092.960436384805.afce3599" },
357+ }
358+ )
359+
335360message_changed_event_body = build_payload (
336361 {
337362 "type" : "message" ,
Original file line number Diff line number Diff line change @@ -157,6 +157,13 @@ async def handle_bot_message():
157157
158158 app .assistant (assistant )
159159
160+ request = AsyncBoltRequest (body = user_message_event_body_with_action_token , mode = "socket_mode" )
161+ response = await app .async_dispatch (request )
162+ assert response .status == 200
163+ await asyncio .sleep (0.1 )
164+ assert listener_called .is_set ()
165+ listener_called .clear ()
166+
160167 request = AsyncBoltRequest (body = message_changed_event_body , mode = "socket_mode" )
161168 response = await app .async_dispatch (request )
162169 assert response .status == 200
@@ -405,6 +412,25 @@ def build_payload(event: dict) -> dict:
405412)
406413
407414
415+ user_message_event_body_with_action_token = build_payload (
416+ {
417+ "user" : "W222" ,
418+ "type" : "message" ,
419+ "ts" : "1726133700.887259" ,
420+ "text" : "When Slack was released?" ,
421+ "team" : "T111" ,
422+ "user_team" : "T111" ,
423+ "source_team" : "T222" ,
424+ "user_profile" : {},
425+ "thread_ts" : "1726133698.626339" ,
426+ "parent_user_id" : "W222" ,
427+ "channel" : "D111" ,
428+ "event_ts" : "1726133700.887259" ,
429+ "channel_type" : "im" ,
430+ "assistant_thread" : {"action_token" : "10647138185092.960436384805.afce3599" },
431+ }
432+ )
433+
408434message_changed_event_body = build_payload (
409435 {
410436 "type" : "message" ,
You can’t perform that action at this time.
0 commit comments