Skip to content

Commit 6c41f37

Browse files
authored
fix(feishu): avoid 400s on topic reaction hydration (#117685)
* fix(feishu): hydrate reaction topics with real ids Fixes #34528 * fix(feishu): scope topic hydration id for errors
1 parent 5c2f935 commit 6c41f37

2 files changed

Lines changed: 73 additions & 3 deletions

File tree

‎extensions/feishu/src/bot.test.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,73 @@ describe("handleFeishuMessage command authorization", () => {
28372837
expectResolvedRouteCall(1, { kind: "group", id: "oc-group:topic:omt_native_topic" });
28382838
});
28392839

2840+
it.each([
2841+
{
2842+
action: "created",
2843+
scope: "group_topic",
2844+
expectedPeerId: "oc-group:topic:omt_native_reaction",
2845+
},
2846+
{
2847+
action: "deleted",
2848+
scope: "group_topic",
2849+
expectedPeerId: "oc-group:topic:omt_native_reaction",
2850+
},
2851+
{
2852+
action: "created",
2853+
scope: "group_topic_sender",
2854+
expectedPeerId: "oc-group:topic:omt_native_reaction:sender:ou-reaction-actor",
2855+
},
2856+
{
2857+
action: "deleted",
2858+
scope: "group_topic_sender",
2859+
expectedPeerId: "oc-group:topic:omt_native_reaction:sender:ou-reaction-actor",
2860+
},
2861+
] as const)(
2862+
"hydrates topic threads from the real message ID for synthetic $action reactions in $scope sessions",
2863+
async ({ action, scope, expectedPeerId }) => {
2864+
mockShouldComputeCommandAuthorized.mockReturnValue(false);
2865+
const reactedMessageId = `om_reacted_${action}_${scope}`;
2866+
mockGetMessageFeishu.mockResolvedValueOnce({
2867+
messageId: reactedMessageId,
2868+
chatId: "oc-group",
2869+
chatType: "topic_group",
2870+
content: "reacted message",
2871+
contentType: "text",
2872+
threadId: "omt_native_reaction",
2873+
});
2874+
2875+
await dispatchMessage({
2876+
cfg: createFeishuTestConfig({
2877+
groups: {
2878+
"oc-group": {
2879+
requireMention: false,
2880+
groupSessionScope: scope,
2881+
replyInThread: "enabled",
2882+
},
2883+
},
2884+
}),
2885+
event: createFeishuTestEvent({
2886+
messageId: `${reactedMessageId}:reaction:THUMBSUP:synthetic`,
2887+
senderOpenId: "ou-reaction-actor",
2888+
chatId: "oc-group",
2889+
chatType: "topic_group",
2890+
text:
2891+
action === "deleted"
2892+
? `[removed reaction THUMBSUP from message ${reactedMessageId}]`
2893+
: `[reacted with THUMBSUP to message ${reactedMessageId}]`,
2894+
message: {
2895+
reply_target_message_id: reactedMessageId,
2896+
typing_target_message_id: reactedMessageId,
2897+
},
2898+
}),
2899+
});
2900+
2901+
const getMessageRequest = mockCallArg<{ messageId?: string }>(mockGetMessageFeishu, 0, 0);
2902+
expect(getMessageRequest.messageId).toBe(reactedMessageId);
2903+
expectResolvedRouteCall(0, { kind: "group", id: expectedPeerId });
2904+
},
2905+
);
2906+
28402907
it.each([
28412908
{
28422909
name: "replies to the topic root when handling a message inside an existing topic",

‎extensions/feishu/src/bot.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,23 +517,26 @@ export async function handleFeishuMessage(params: {
517517
!effectiveThreadId &&
518518
isFeishuTopicSessionScope(groupSessionScope ?? "group")
519519
) {
520+
// Synthetic turns keep a local dedupe ID in messageId; their explicit reply target is
521+
// the real Feishu message ID that topic hydration can send back to the provider.
522+
const topicHydrationMessageId = ctx.replyTargetMessageId ?? ctx.messageId;
520523
try {
521524
const messageInfo = await getMessageFeishu({
522525
cfg,
523526
accountId: account.accountId,
524-
messageId: ctx.messageId,
527+
messageId: topicHydrationMessageId,
525528
});
526529
const hydratedThreadId = messageInfo?.threadId?.trim();
527530
if (hydratedThreadId) {
528531
ctx = { ...ctx, threadId: hydratedThreadId };
529532
effectiveThreadId = hydratedThreadId;
530533
log(
531-
`feishu[${account.accountId}]: hydrated topic thread_id=${hydratedThreadId} for message=${ctx.messageId}`,
534+
`feishu[${account.accountId}]: hydrated topic thread_id=${hydratedThreadId} for message=${topicHydrationMessageId}`,
532535
);
533536
}
534537
} catch (err) {
535538
log(
536-
`feishu[${account.accountId}]: failed to hydrate topic thread_id for message=${ctx.messageId}: ${String(err)}`,
539+
`feishu[${account.accountId}]: failed to hydrate topic thread_id for message=${topicHydrationMessageId}: ${String(err)}`,
537540
);
538541
}
539542
}

0 commit comments

Comments
 (0)