@@ -502,6 +502,8 @@ async function runArgMenuAction(
502502 userName ?: string ;
503503 channelId ?: string ;
504504 channelName ?: string ;
505+ message ?: { ts : string ; thread_ts ?: string } ;
506+ container ?: { message_ts : string ; thread_ts ?: string } ;
505507 respond ?: ReturnType < typeof vi . fn > ;
506508 includeRespond ?: boolean ;
507509 } ,
@@ -515,6 +517,8 @@ async function runArgMenuAction(
515517 user : { id : params . userId ?? "U1" , name : params . userName ?? "Ada" } ,
516518 channel : { id : params . channelId ?? "C1" , name : params . channelName ?? "directmessage" } ,
517519 trigger_id : "t1" ,
520+ ...( params . message ? { message : params . message } : { } ) ,
521+ ...( params . container ? { container : params . container } : { } ) ,
518522 } ,
519523 } ;
520524 if ( includeRespond ) {
@@ -1223,17 +1227,28 @@ describe("Slack native command argument menus", () => {
12231227 expect ( firstDispatchArg ( ) . ctx ?. OriginatingTo ) . toBe ( "team:TGRID1:user:U1" ) ;
12241228 } ) ;
12251229
1226- it ( "does not apply the response_url call cap to Web API action replies" , async ( ) => {
1230+ it . each ( [
1231+ { name : "top-level" , message : undefined , threadTs : undefined } ,
1232+ {
1233+ name : "threaded" ,
1234+ message : { ts : "171.222" , thread_ts : "170.111" } ,
1235+ threadTs : "170.111" ,
1236+ } ,
1237+ ] ) ( "does not cap $name Web API action replies" , async ( { message, threadTs } ) => {
12271238 mockSixDispatchedReplies ( ) ;
12281239
12291240 await runArgMenuAction ( argMenuHandler , {
12301241 action : {
12311242 value : encodeValue ( { command : "usage" , arg : "mode" , value : "tokens" , userId : "U1" } ) ,
12321243 } ,
1244+ message,
12331245 includeRespond : false ,
12341246 } ) ;
12351247
12361248 expect ( harness . postEphemeral ) . toHaveBeenCalledTimes ( 6 ) ;
1249+ for ( const [ payload ] of harness . postEphemeral . mock . calls ) {
1250+ expect ( payload . thread_ts ) . toBe ( threadTs ) ;
1251+ }
12371252 } ) ;
12381253
12391254 it ( "keeps table fallback tokens literal in Web API action replies" , async ( ) => {
@@ -1280,6 +1295,7 @@ describe("Slack native command argument menus", () => {
12801295 action : {
12811296 value : encodeValue ( { command : "usage" , arg : "mode" , value : "tokens" , userId : "U1" } ) ,
12821297 } ,
1298+ message : { ts : "171.222" , thread_ts : "170.111" } ,
12831299 } ) ;
12841300
12851301 expect ( respond ) . toHaveBeenCalledTimes ( 5 ) ;
@@ -1488,17 +1504,37 @@ describe("Slack native command argument menus", () => {
14881504 expect ( trackEvent ) . toHaveBeenCalledTimes ( 1 ) ;
14891505 } ) ;
14901506
1491- it ( "falls back to postEphemeral with token when respond is unavailable" , async ( ) => {
1492- await runArgMenuAction ( argMenuHandler , {
1493- action : { value : "garbage" } ,
1494- includeRespond : false ,
1495- } ) ;
1507+ it . each ( [
1508+ { name : "a top-level action" , message : undefined , container : undefined , threadTs : undefined } ,
1509+ {
1510+ name : "the action container's parent thread" ,
1511+ message : { ts : "171.222" , thread_ts : "169.999" } ,
1512+ container : { message_ts : "171.222" , thread_ts : "170.111" } ,
1513+ threadTs : "170.111" ,
1514+ } ,
1515+ {
1516+ name : "the action message's parent thread" ,
1517+ message : { ts : "171.222" , thread_ts : "170.111" } ,
1518+ container : { message_ts : "171.222" } ,
1519+ threadTs : "170.111" ,
1520+ } ,
1521+ ] ) (
1522+ "keeps $name when respond falls back to postEphemeral" ,
1523+ async ( { message, container, threadTs } ) => {
1524+ await runArgMenuAction ( argMenuHandler , {
1525+ action : { value : "garbage" } ,
1526+ message,
1527+ container,
1528+ includeRespond : false ,
1529+ } ) ;
14961530
1497- const payload = firstCallPayload ( harness . postEphemeral , "postEphemeral" ) ;
1498- expect ( payload . token ) . toBe ( "bot-token" ) ;
1499- expect ( payload . channel ) . toBe ( "C1" ) ;
1500- expect ( payload . user ) . toBe ( "U1" ) ;
1501- } ) ;
1531+ const payload = firstCallPayload ( harness . postEphemeral , "postEphemeral" ) ;
1532+ expect ( payload . token ) . toBe ( "bot-token" ) ;
1533+ expect ( payload . channel ) . toBe ( "C1" ) ;
1534+ expect ( payload . user ) . toBe ( "U1" ) ;
1535+ expect ( payload . thread_ts ) . toBe ( threadTs ) ;
1536+ } ,
1537+ ) ;
15021538
15031539 it ( "treats malformed percent-encoding as an invalid button" , async ( ) => {
15041540 await runArgMenuAction ( argMenuHandler , {
0 commit comments