@@ -27,14 +27,18 @@ import {
2727import { SLACK_TEXT_LIMIT } from "./limits.js" ;
2828import { escapeSlackMrkdwn } from "./monitor/mrkdwn.js" ;
2929import { SLACK_PRESENTATION_CAPABILITIES } from "./presentation.js" ;
30+ import {
31+ resolveSlackQuestionActionIds ,
32+ SLACK_QUESTION_FINALIZATION_BLOCKS ,
33+ } from "./reply-action-ids.js" ;
3034import {
3135 parseSlackReplyBlockSegments ,
3236 resolveSlackReplyBlockResolution ,
3337 resolveSlackReplyDeliveryMessages ,
3438 type SlackReplyBlockResolution ,
3539 type SlackReplyBlockSegment ,
3640} from "./reply-blocks.js" ;
37- import type { SlackSendIdentity } from "./send.js" ;
41+ import type { SlackSendIdentity , SlackSendResult } from "./send.js" ;
3842import { resolveSlackThreadTsValue } from "./thread-ts.js" ;
3943
4044type SlackSendFn = typeof import ( "./send.runtime.js" ) . sendMessageSlack ;
@@ -358,35 +362,49 @@ export const slackOutbound: ChannelOutboundAdapter = {
358362 segments : resolution . segments ,
359363 text : payload . text ,
360364 } ) ;
361- const blockMessageIndex = deliveryMessages . findIndex ( ( message ) =>
362- message . blocks ?. some ( ( block ) => block . type === "actions" ) ,
365+ const deliveryMessage = deliveryMessages . find (
366+ ( message ) => resolveSlackQuestionActionIds ( message . blocks ) . length > 0 ,
367+ ) ;
368+ const questionActionIds = resolveSlackQuestionActionIds ( deliveryMessage ?. blocks ) ;
369+ const result = results . find (
370+ ( { channel, meta } ) =>
371+ channel === "slack" &&
372+ Array . isArray ( meta ?. slackQuestionActionIds ) &&
373+ meta . slackQuestionActionIds . some (
374+ ( actionId ) => typeof actionId === "string" && questionActionIds . includes ( actionId ) ,
375+ ) ,
363376 ) ;
364- const deliveryMessage = deliveryMessages [ blockMessageIndex ] ;
365- const result =
366- results [ blockMessageIndex ] ?? results . find ( ( candidate ) => candidate . channel === "slack" ) ;
367- const deliveryBlocks = deliveryMessage ?. blocks ;
368- if ( ! deliveryMessage || ! deliveryBlocks || ! result ?. messageId ) {
377+ const deliveredDisplayBlocks = ( result ?. meta as SlackSendResult [ "meta" ] | undefined ) ?. [
378+ SLACK_QUESTION_FINALIZATION_BLOCKS
379+ ] ;
380+ if ( ! deliveryMessage || ! deliveredDisplayBlocks || ! result ?. messageId ) {
369381 return ;
370382 }
371383 const channelId = result . channelId ;
372384 if ( ! channelId ) {
373385 return ;
374386 }
387+ // Aggregate fallback receipts retain their last platform id separately
388+ // from the actual card whose question controls need finalization.
389+ const questionMessageId =
390+ typeof result . meta ?. slackQuestionMessageId === "string"
391+ ? result . meta . slackQuestionMessageId
392+ : result . messageId ;
375393 questionGatewayRuntime . registerChannelDelivery ( {
376394 questionId,
377- deliveryId : `slack:${ target . accountId ?? "default" } :${ channelId } :${ result . messageId } ` ,
395+ deliveryId : `slack:${ target . accountId ?? "default" } :${ channelId } :${ questionMessageId } ` ,
378396 finalize : async ( statusLine ) => {
379397 const { updateMessageSlack } = await loadSlackSendRuntime ( ) ;
380398 const escapedStatusLine = escapeSlackMrkdwn ( statusLine ) ;
381399 const blocks = [
382- ...deliveryBlocks . filter ( ( block ) => block . type !== "actions" ) ,
400+ ...deliveredDisplayBlocks ,
383401 { type : "context" , elements : [ { type : "mrkdwn" , text : escapedStatusLine } ] } ,
384402 ] ;
385403 await updateMessageSlack ( {
386404 cfg,
387405 accountId : target . accountId ?? undefined ,
388406 channelId,
389- messageTs : result . messageId ,
407+ messageTs : questionMessageId ,
390408 text : `${ deliveryMessage . text } \n\n${ escapedStatusLine } ` ,
391409 blocks,
392410 } ) ;
0 commit comments