Skip to content

Commit 06568d8

Browse files
committed
feishu: parse interactive i18n elements across locales
1 parent 362e2bb commit 06568d8

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

extensions/feishu/src/interactive-card.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ describe("parseInteractiveCardPayload", () => {
4040
expect(parsed.text).toBe("Title\nBody");
4141
});
4242

43+
it("extracts i18n element text from non-zh locales", () => {
44+
const payload = JSON.stringify({
45+
header: { title: { content: "Weekly Report" } },
46+
i18n_elements: {
47+
en_us: [{ tag: "markdown", content: "Delivered in English locale" }],
48+
},
49+
});
50+
51+
const parsed = parseInteractiveCardPayload(payload);
52+
expect(parsed.text).toBe("Weekly Report\nDelivered in English locale");
53+
});
54+
4355
it("caps recursive parsing depth to avoid stack overflow on deeply nested cards", () => {
4456
let nested: Record<string, unknown> = { tag: "div", text: { content: "leaf" } };
4557
for (let i = 0; i < 100; i++) {
@@ -51,4 +63,3 @@ describe("parseInteractiveCardPayload", () => {
5163
expect(parsed.text).toBe("[Interactive Card]");
5264
});
5365
});
54-

extensions/feishu/src/interactive-card.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ function collectCardText(card: InteractiveCardObject): string[] {
151151
isRecord(card.body) && Array.isArray((card.body as Record<string, unknown>).elements)
152152
? ((card.body as Record<string, unknown>).elements as unknown[])
153153
: [];
154-
const i18nElements =
155-
isRecord(card.i18n_elements) &&
156-
Array.isArray((card.i18n_elements as Record<string, unknown>).zh_cn)
157-
? ((card.i18n_elements as Record<string, unknown>).zh_cn as unknown[])
158-
: [];
154+
const i18nElements: unknown[] = [];
155+
if (isRecord(card.i18n_elements)) {
156+
const i18n = card.i18n_elements as Record<string, unknown>;
157+
for (const localeElements of Object.values(i18n)) {
158+
if (Array.isArray(localeElements)) {
159+
i18nElements.push(...localeElements);
160+
}
161+
}
162+
}
159163

160164
for (const element of [...topLevelElements, ...bodyElements, ...i18nElements]) {
161165
collectElementText(element, lines);

0 commit comments

Comments
 (0)