Skip to content

Commit 820cd7c

Browse files
authored
fix(slack): finalize the actual delivered question card (#118450)
* fix(slack): finalize the actual delivered question card * test(slack): type question delivery response mocks correctly * fix(slack): retain delivered question identity through reconciliation * fix(slack): finalize through the registered channel adapter * fix(slack): share question runtime and finalize accepted cards * test(slack): assert private card metadata with direct JSON serialization
1 parent 7c35cbc commit 820cd7c

10 files changed

Lines changed: 703 additions & 42 deletions

‎extensions/slack/src/channel.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ const slackChannelOutbound: ChannelOutboundAdapter = {
484484
accountId,
485485
payload,
486486
}),
487+
// Core sees this facade, not its lazy owner; forward finalization or question cards stay live.
488+
afterDeliverPayload: async (ctx) => {
489+
const { slackOutbound } = await loadSlackOutboundAdapterModule();
490+
await slackOutbound.afterDeliverPayload!(ctx);
491+
},
487492
presentationCapabilities: SLACK_PRESENTATION_CAPABILITIES,
488493
...createRuntimeOutboundDelegates({
489494
getRuntime: loadSlackOutboundAdapterModule,

‎extensions/slack/src/outbound-adapter.ts‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ import {
2727
import { SLACK_TEXT_LIMIT } from "./limits.js";
2828
import { escapeSlackMrkdwn } from "./monitor/mrkdwn.js";
2929
import { SLACK_PRESENTATION_CAPABILITIES } from "./presentation.js";
30+
import {
31+
resolveSlackQuestionActionIds,
32+
SLACK_QUESTION_FINALIZATION_BLOCKS,
33+
} from "./reply-action-ids.js";
3034
import {
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";
3842
import { resolveSlackThreadTsValue } from "./thread-ts.js";
3943

4044
type 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

Comments
 (0)