@openclaw/line 2026.5.2-beta.2 → 2026.5.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/accounts-UXAvdBo_.js +105 -0
  2. package/dist/api.js +11 -0
  3. package/dist/basic-cards-7DTG6E-A.js +307 -0
  4. package/dist/card-command-UlPc6Vuc.js +240 -0
  5. package/dist/channel-Rls9s60K.js +601 -0
  6. package/dist/channel-plugin-api.js +2 -0
  7. package/dist/channel.runtime-bXoj8_Sl.js +4 -0
  8. package/dist/contract-api.js +2 -0
  9. package/dist/index.js +45 -0
  10. package/dist/markdown-to-line-CCWK6PJh.js +789 -0
  11. package/dist/monitor-B4_RxHc0.js +1523 -0
  12. package/dist/monitor.runtime-DyxYlrM9.js +2 -0
  13. package/dist/outbound-media-BfhBmWq5.js +55 -0
  14. package/dist/outbound.runtime-B-luYwEB.js +2 -0
  15. package/dist/probe-D9BPzb2n.js +30 -0
  16. package/dist/probe.runtime-N91OWW1J.js +2 -0
  17. package/dist/quick-reply-fallback-HskUUWsn.js +55 -0
  18. package/dist/reply-payload-transform-CFGTs9ln.js +713 -0
  19. package/dist/runtime-api.js +277 -0
  20. package/dist/schedule-cards-BwQChTdM.js +359 -0
  21. package/dist/secret-contract-api.js +5 -0
  22. package/dist/setup-api.js +2 -0
  23. package/dist/setup-entry.js +11 -0
  24. package/dist/setup-surface-DCH7CE-y.js +281 -0
  25. package/package.json +14 -6
  26. package/api.ts +0 -11
  27. package/channel-plugin-api.ts +0 -1
  28. package/contract-api.ts +0 -5
  29. package/index.ts +0 -54
  30. package/runtime-api.ts +0 -187
  31. package/secret-contract-api.ts +0 -4
  32. package/setup-api.ts +0 -2
  33. package/setup-entry.ts +0 -9
  34. package/src/account-helpers.ts +0 -16
  35. package/src/accounts.test.ts +0 -290
  36. package/src/accounts.ts +0 -187
  37. package/src/actions.ts +0 -61
  38. package/src/auto-reply-delivery.test.ts +0 -248
  39. package/src/auto-reply-delivery.ts +0 -200
  40. package/src/bindings.ts +0 -65
  41. package/src/bot-access.ts +0 -48
  42. package/src/bot-handlers.test.ts +0 -1089
  43. package/src/bot-handlers.ts +0 -642
  44. package/src/bot-message-context.test.ts +0 -405
  45. package/src/bot-message-context.ts +0 -581
  46. package/src/bot.ts +0 -70
  47. package/src/card-command.ts +0 -347
  48. package/src/channel-access-token.ts +0 -14
  49. package/src/channel-api.ts +0 -17
  50. package/src/channel-setup-status.contract.test.ts +0 -70
  51. package/src/channel-shared.ts +0 -48
  52. package/src/channel.logout.test.ts +0 -145
  53. package/src/channel.runtime.ts +0 -3
  54. package/src/channel.sendPayload.test.ts +0 -514
  55. package/src/channel.setup.ts +0 -11
  56. package/src/channel.status.test.ts +0 -63
  57. package/src/channel.ts +0 -154
  58. package/src/config-adapter.ts +0 -29
  59. package/src/config-schema.ts +0 -57
  60. package/src/download.test.ts +0 -133
  61. package/src/download.ts +0 -87
  62. package/src/flex-templates/basic-cards.ts +0 -395
  63. package/src/flex-templates/common.ts +0 -20
  64. package/src/flex-templates/media-control-cards.ts +0 -555
  65. package/src/flex-templates/message.ts +0 -13
  66. package/src/flex-templates/schedule-cards.ts +0 -467
  67. package/src/flex-templates/types.ts +0 -22
  68. package/src/flex-templates.ts +0 -32
  69. package/src/gateway.ts +0 -129
  70. package/src/group-keys.test.ts +0 -123
  71. package/src/group-keys.ts +0 -65
  72. package/src/group-policy.ts +0 -22
  73. package/src/markdown-to-line.test.ts +0 -348
  74. package/src/markdown-to-line.ts +0 -416
  75. package/src/message-cards.test.ts +0 -204
  76. package/src/monitor.lifecycle.test.ts +0 -421
  77. package/src/monitor.runtime.ts +0 -1
  78. package/src/monitor.ts +0 -506
  79. package/src/outbound-media.test.ts +0 -189
  80. package/src/outbound-media.ts +0 -120
  81. package/src/outbound.runtime.ts +0 -12
  82. package/src/outbound.ts +0 -356
  83. package/src/probe.contract.test.ts +0 -9
  84. package/src/probe.runtime.ts +0 -1
  85. package/src/probe.ts +0 -34
  86. package/src/quick-reply-fallback.ts +0 -10
  87. package/src/reply-chunks.test.ts +0 -179
  88. package/src/reply-chunks.ts +0 -110
  89. package/src/reply-payload-transform.test.ts +0 -387
  90. package/src/reply-payload-transform.ts +0 -317
  91. package/src/rich-menu.test.ts +0 -310
  92. package/src/rich-menu.ts +0 -326
  93. package/src/runtime.ts +0 -32
  94. package/src/send.test.ts +0 -346
  95. package/src/send.ts +0 -489
  96. package/src/setup-core.ts +0 -149
  97. package/src/setup-runtime-api.ts +0 -9
  98. package/src/setup-surface.test.ts +0 -474
  99. package/src/setup-surface.ts +0 -227
  100. package/src/signature.test.ts +0 -34
  101. package/src/signature.ts +0 -24
  102. package/src/status.ts +0 -37
  103. package/src/template-messages.ts +0 -333
  104. package/src/types.ts +0 -128
  105. package/src/webhook-node.test.ts +0 -513
  106. package/src/webhook-node.ts +0 -131
  107. package/src/webhook-utils.ts +0 -10
  108. package/src/webhook.ts +0 -111
  109. package/tsconfig.json +0 -16
@@ -1,179 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { sendLineReplyChunks } from "./reply-chunks.js";
3
-
4
- const LINE_TEST_CFG = { channels: { line: { channelAccessToken: "line-token" } } };
5
-
6
- function createReplyChunksHarness() {
7
- const replyMessageLine = vi.fn(async () => ({}));
8
- const pushMessageLine = vi.fn(async () => ({}));
9
- const pushTextMessageWithQuickReplies = vi.fn(async () => ({}));
10
- const createTextMessageWithQuickReplies = vi.fn((text: string, _quickReplies: string[]) => ({
11
- type: "text" as const,
12
- text,
13
- }));
14
-
15
- return {
16
- replyMessageLine,
17
- pushMessageLine,
18
- pushTextMessageWithQuickReplies,
19
- createTextMessageWithQuickReplies,
20
- };
21
- }
22
-
23
- describe("sendLineReplyChunks", () => {
24
- it("uses reply token for all chunks when possible", async () => {
25
- const {
26
- replyMessageLine,
27
- pushMessageLine,
28
- pushTextMessageWithQuickReplies,
29
- createTextMessageWithQuickReplies,
30
- } = createReplyChunksHarness();
31
-
32
- const result = await sendLineReplyChunks({
33
- to: "line:group:1",
34
- chunks: ["one", "two", "three"],
35
- quickReplies: ["A", "B"],
36
- replyToken: "token",
37
- replyTokenUsed: false,
38
- cfg: LINE_TEST_CFG,
39
- accountId: "default",
40
- replyMessageLine,
41
- pushMessageLine,
42
- pushTextMessageWithQuickReplies,
43
- createTextMessageWithQuickReplies,
44
- });
45
-
46
- expect(result.replyTokenUsed).toBe(true);
47
- expect(replyMessageLine).toHaveBeenCalledTimes(1);
48
- expect(createTextMessageWithQuickReplies).toHaveBeenCalledWith("three", ["A", "B"]);
49
- expect(replyMessageLine).toHaveBeenCalledWith(
50
- "token",
51
- [
52
- { type: "text", text: "one" },
53
- { type: "text", text: "two" },
54
- { type: "text", text: "three" },
55
- ],
56
- { cfg: LINE_TEST_CFG, accountId: "default" },
57
- );
58
- expect(pushMessageLine).not.toHaveBeenCalled();
59
- expect(pushTextMessageWithQuickReplies).not.toHaveBeenCalled();
60
- });
61
-
62
- it("attaches quick replies to a single reply chunk", async () => {
63
- const { replyMessageLine, pushMessageLine, pushTextMessageWithQuickReplies } =
64
- createReplyChunksHarness();
65
- const createTextMessageWithQuickReplies = vi.fn((text: string, _quickReplies: string[]) => ({
66
- type: "text" as const,
67
- text,
68
- quickReply: { items: [] },
69
- }));
70
-
71
- const result = await sendLineReplyChunks({
72
- to: "line:user:1",
73
- chunks: ["only"],
74
- quickReplies: ["A"],
75
- replyToken: "token",
76
- replyTokenUsed: false,
77
- cfg: LINE_TEST_CFG,
78
- replyMessageLine,
79
- pushMessageLine,
80
- pushTextMessageWithQuickReplies,
81
- createTextMessageWithQuickReplies,
82
- });
83
-
84
- expect(result.replyTokenUsed).toBe(true);
85
- expect(createTextMessageWithQuickReplies).toHaveBeenCalledWith("only", ["A"]);
86
- expect(replyMessageLine).toHaveBeenCalledTimes(1);
87
- expect(pushMessageLine).not.toHaveBeenCalled();
88
- expect(pushTextMessageWithQuickReplies).not.toHaveBeenCalled();
89
- });
90
-
91
- it("replies with up to five chunks before pushing the rest", async () => {
92
- const {
93
- replyMessageLine,
94
- pushMessageLine,
95
- pushTextMessageWithQuickReplies,
96
- createTextMessageWithQuickReplies,
97
- } = createReplyChunksHarness();
98
-
99
- const chunks = ["1", "2", "3", "4", "5", "6", "7"];
100
- const result = await sendLineReplyChunks({
101
- to: "line:group:1",
102
- chunks,
103
- quickReplies: ["A"],
104
- replyToken: "token",
105
- replyTokenUsed: false,
106
- cfg: LINE_TEST_CFG,
107
- replyMessageLine,
108
- pushMessageLine,
109
- pushTextMessageWithQuickReplies,
110
- createTextMessageWithQuickReplies,
111
- });
112
-
113
- expect(result.replyTokenUsed).toBe(true);
114
- expect(replyMessageLine).toHaveBeenCalledTimes(1);
115
- expect(replyMessageLine).toHaveBeenCalledWith(
116
- "token",
117
- [
118
- { type: "text", text: "1" },
119
- { type: "text", text: "2" },
120
- { type: "text", text: "3" },
121
- { type: "text", text: "4" },
122
- { type: "text", text: "5" },
123
- ],
124
- { cfg: LINE_TEST_CFG, accountId: undefined },
125
- );
126
- expect(pushMessageLine).toHaveBeenCalledTimes(1);
127
- expect(pushMessageLine).toHaveBeenCalledWith("line:group:1", "6", {
128
- cfg: LINE_TEST_CFG,
129
- accountId: undefined,
130
- });
131
- expect(pushTextMessageWithQuickReplies).toHaveBeenCalledTimes(1);
132
- expect(pushTextMessageWithQuickReplies).toHaveBeenCalledWith("line:group:1", "7", ["A"], {
133
- cfg: LINE_TEST_CFG,
134
- accountId: undefined,
135
- });
136
- expect(createTextMessageWithQuickReplies).not.toHaveBeenCalled();
137
- });
138
-
139
- it("falls back to push flow when replying fails", async () => {
140
- const {
141
- replyMessageLine,
142
- pushMessageLine,
143
- pushTextMessageWithQuickReplies,
144
- createTextMessageWithQuickReplies,
145
- } = createReplyChunksHarness();
146
- const onReplyError = vi.fn();
147
- replyMessageLine.mockRejectedValueOnce(new Error("reply failed"));
148
-
149
- const result = await sendLineReplyChunks({
150
- to: "line:group:1",
151
- chunks: ["1", "2", "3"],
152
- quickReplies: ["A"],
153
- replyToken: "token",
154
- replyTokenUsed: false,
155
- cfg: LINE_TEST_CFG,
156
- accountId: "default",
157
- replyMessageLine,
158
- pushMessageLine,
159
- pushTextMessageWithQuickReplies,
160
- createTextMessageWithQuickReplies,
161
- onReplyError,
162
- });
163
-
164
- expect(result.replyTokenUsed).toBe(true);
165
- expect(onReplyError).toHaveBeenCalledWith(expect.any(Error));
166
- expect(pushMessageLine).toHaveBeenNthCalledWith(1, "line:group:1", "1", {
167
- cfg: LINE_TEST_CFG,
168
- accountId: "default",
169
- });
170
- expect(pushMessageLine).toHaveBeenNthCalledWith(2, "line:group:1", "2", {
171
- cfg: LINE_TEST_CFG,
172
- accountId: "default",
173
- });
174
- expect(pushTextMessageWithQuickReplies).toHaveBeenCalledWith("line:group:1", "3", ["A"], {
175
- cfg: LINE_TEST_CFG,
176
- accountId: "default",
177
- });
178
- });
179
- });
@@ -1,110 +0,0 @@
1
- import type { messagingApi } from "@line/bot-sdk";
2
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
3
-
4
- type LineReplyMessage = messagingApi.TextMessage;
5
-
6
- export type SendLineReplyChunksParams = {
7
- to: string;
8
- chunks: string[];
9
- quickReplies?: string[];
10
- replyToken?: string | null;
11
- replyTokenUsed?: boolean;
12
- cfg: OpenClawConfig;
13
- accountId?: string;
14
- replyMessageLine: (
15
- replyToken: string,
16
- messages: messagingApi.Message[],
17
- opts: { cfg: OpenClawConfig; accountId?: string },
18
- ) => Promise<unknown>;
19
- pushMessageLine: (
20
- to: string,
21
- text: string,
22
- opts: { cfg: OpenClawConfig; accountId?: string },
23
- ) => Promise<unknown>;
24
- pushTextMessageWithQuickReplies: (
25
- to: string,
26
- text: string,
27
- quickReplies: string[],
28
- opts: { cfg: OpenClawConfig; accountId?: string },
29
- ) => Promise<unknown>;
30
- createTextMessageWithQuickReplies: (text: string, quickReplies: string[]) => LineReplyMessage;
31
- onReplyError?: (err: unknown) => void;
32
- };
33
-
34
- export async function sendLineReplyChunks(
35
- params: SendLineReplyChunksParams,
36
- ): Promise<{ replyTokenUsed: boolean }> {
37
- const hasQuickReplies = Boolean(params.quickReplies?.length);
38
- let replyTokenUsed = Boolean(params.replyTokenUsed);
39
-
40
- if (params.chunks.length === 0) {
41
- return { replyTokenUsed };
42
- }
43
-
44
- if (params.replyToken && !replyTokenUsed) {
45
- try {
46
- const replyBatch = params.chunks.slice(0, 5);
47
- const remaining = params.chunks.slice(replyBatch.length);
48
-
49
- const replyMessages: LineReplyMessage[] = replyBatch.map((chunk) => ({
50
- type: "text",
51
- text: chunk,
52
- }));
53
-
54
- if (hasQuickReplies && remaining.length === 0 && replyMessages.length > 0) {
55
- const lastIndex = replyMessages.length - 1;
56
- replyMessages[lastIndex] = params.createTextMessageWithQuickReplies(
57
- replyBatch[lastIndex],
58
- params.quickReplies!,
59
- );
60
- }
61
-
62
- await params.replyMessageLine(params.replyToken, replyMessages, {
63
- cfg: params.cfg,
64
- accountId: params.accountId,
65
- });
66
- replyTokenUsed = true;
67
-
68
- for (let i = 0; i < remaining.length; i += 1) {
69
- const isLastChunk = i === remaining.length - 1;
70
- if (isLastChunk && hasQuickReplies) {
71
- await params.pushTextMessageWithQuickReplies(
72
- params.to,
73
- remaining[i],
74
- params.quickReplies!,
75
- { cfg: params.cfg, accountId: params.accountId },
76
- );
77
- } else {
78
- await params.pushMessageLine(params.to, remaining[i], {
79
- cfg: params.cfg,
80
- accountId: params.accountId,
81
- });
82
- }
83
- }
84
-
85
- return { replyTokenUsed };
86
- } catch (err) {
87
- params.onReplyError?.(err);
88
- replyTokenUsed = true;
89
- }
90
- }
91
-
92
- for (let i = 0; i < params.chunks.length; i += 1) {
93
- const isLastChunk = i === params.chunks.length - 1;
94
- if (isLastChunk && hasQuickReplies) {
95
- await params.pushTextMessageWithQuickReplies(
96
- params.to,
97
- params.chunks[i],
98
- params.quickReplies!,
99
- { cfg: params.cfg, accountId: params.accountId },
100
- );
101
- } else {
102
- await params.pushMessageLine(params.to, params.chunks[i], {
103
- cfg: params.cfg,
104
- accountId: params.accountId,
105
- });
106
- }
107
- }
108
-
109
- return { replyTokenUsed };
110
- }
@@ -1,387 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { hasLineDirectives, parseLineDirectives } from "./reply-payload-transform.js";
3
-
4
- const getLineData = (result: ReturnType<typeof parseLineDirectives>) =>
5
- (result.channelData?.line as Record<string, unknown> | undefined) ?? {};
6
-
7
- describe("hasLineDirectives", () => {
8
- it("matches expected detection across directive patterns", () => {
9
- const cases: Array<{ text: string; expected: boolean }> = [
10
- { text: "Here are options [[quick_replies: A, B, C]]", expected: true },
11
- { text: "[[location: Place | Address | 35.6 | 139.7]]", expected: true },
12
- { text: "[[confirm: Continue? | Yes | No]]", expected: true },
13
- { text: "[[buttons: Menu | Choose | Opt1:data1, Opt2:data2]]", expected: true },
14
- { text: "Just regular text", expected: false },
15
- { text: "[[not_a_directive: something]]", expected: false },
16
- { text: "[[media_player: Song | Artist | Speaker]]", expected: true },
17
- { text: "[[event: Meeting | Jan 24 | 2pm]]", expected: true },
18
- { text: "[[agenda: Today | Meeting:9am, Lunch:12pm]]", expected: true },
19
- { text: "[[device: TV | Room]]", expected: true },
20
- { text: "[[appletv_remote: Apple TV | Playing]]", expected: true },
21
- ];
22
-
23
- for (const testCase of cases) {
24
- expect(hasLineDirectives(testCase.text)).toBe(testCase.expected);
25
- }
26
- });
27
- });
28
-
29
- describe("parseLineDirectives", () => {
30
- describe("quick_replies", () => {
31
- it("parses quick replies variants", () => {
32
- const cases: Array<{
33
- text: string;
34
- channelData?: { line: { quickReplies: string[] } };
35
- quickReplies: string[];
36
- outputText?: string;
37
- }> = [
38
- {
39
- text: "Choose one:\n[[quick_replies: Option A, Option B, Option C]]",
40
- quickReplies: ["Option A", "Option B", "Option C"],
41
- outputText: "Choose one:",
42
- },
43
- {
44
- text: "Before [[quick_replies: A, B]] After",
45
- quickReplies: ["A", "B"],
46
- outputText: "Before After",
47
- },
48
- {
49
- text: "Text [[quick_replies: C, D]]",
50
- channelData: { line: { quickReplies: ["A", "B"] } },
51
- quickReplies: ["A", "B", "C", "D"],
52
- outputText: "Text",
53
- },
54
- ];
55
-
56
- for (const testCase of cases) {
57
- const result = parseLineDirectives({
58
- text: testCase.text,
59
- channelData: testCase.channelData,
60
- });
61
- expect(getLineData(result).quickReplies).toEqual(testCase.quickReplies);
62
- if (testCase.outputText !== undefined) {
63
- expect(result.text).toBe(testCase.outputText);
64
- }
65
- }
66
- });
67
- });
68
-
69
- describe("location", () => {
70
- it("parses location variants", () => {
71
- const existing = { title: "Existing", address: "Addr", latitude: 1, longitude: 2 };
72
- const cases: Array<{
73
- text: string;
74
- channelData?: { line: { location: typeof existing } };
75
- location?: typeof existing;
76
- outputText?: string;
77
- }> = [
78
- {
79
- text: "Here's the location:\n[[location: Tokyo Station | Tokyo, Japan | 35.6812 | 139.7671]]",
80
- location: {
81
- title: "Tokyo Station",
82
- address: "Tokyo, Japan",
83
- latitude: 35.6812,
84
- longitude: 139.7671,
85
- },
86
- outputText: "Here's the location:",
87
- },
88
- {
89
- text: "[[location: Place | Address | invalid | 139.7]]",
90
- location: undefined,
91
- },
92
- {
93
- text: "[[location: New | New Addr | 35.6 | 139.7]]",
94
- channelData: { line: { location: existing } },
95
- location: existing,
96
- },
97
- ];
98
-
99
- for (const testCase of cases) {
100
- const result = parseLineDirectives({
101
- text: testCase.text,
102
- channelData: testCase.channelData,
103
- });
104
- expect(getLineData(result).location).toEqual(testCase.location);
105
- if (testCase.outputText !== undefined) {
106
- expect(result.text).toBe(testCase.outputText);
107
- }
108
- }
109
- });
110
- });
111
-
112
- describe("confirm", () => {
113
- it("parses confirm directives with default and custom action payloads", () => {
114
- const cases = [
115
- {
116
- name: "default yes/no data",
117
- text: "[[confirm: Delete this item? | Yes | No]]",
118
- expectedTemplate: {
119
- type: "confirm",
120
- text: "Delete this item?",
121
- confirmLabel: "Yes",
122
- confirmData: "yes",
123
- cancelLabel: "No",
124
- cancelData: "no",
125
- altText: "Delete this item?",
126
- },
127
- expectedText: undefined,
128
- },
129
- {
130
- name: "custom action data",
131
- text: "[[confirm: Proceed? | OK:action=confirm | Cancel:action=cancel]]",
132
- expectedTemplate: {
133
- type: "confirm",
134
- text: "Proceed?",
135
- confirmLabel: "OK",
136
- confirmData: "action=confirm",
137
- cancelLabel: "Cancel",
138
- cancelData: "action=cancel",
139
- altText: "Proceed?",
140
- },
141
- expectedText: undefined,
142
- },
143
- ] as const;
144
-
145
- for (const testCase of cases) {
146
- const result = parseLineDirectives({ text: testCase.text });
147
- expect(getLineData(result).templateMessage, testCase.name).toEqual(
148
- testCase.expectedTemplate,
149
- );
150
- expect(result.text, testCase.name).toBe(testCase.expectedText);
151
- }
152
- });
153
- });
154
-
155
- describe("buttons", () => {
156
- it("parses message/uri/postback button actions and enforces action caps", () => {
157
- const cases = [
158
- {
159
- name: "message actions",
160
- text: "[[buttons: Menu | Select an option | Help:/help, Status:/status]]",
161
- expectedTemplate: {
162
- type: "buttons",
163
- title: "Menu",
164
- text: "Select an option",
165
- actions: [
166
- { type: "message", label: "Help", data: "/help" },
167
- { type: "message", label: "Status", data: "/status" },
168
- ],
169
- altText: "Menu: Select an option",
170
- },
171
- },
172
- {
173
- name: "uri action",
174
- text: "[[buttons: Links | Visit us | Site:https://example.com]]",
175
- expectedFirstAction: {
176
- type: "uri",
177
- label: "Site",
178
- uri: "https://example.com",
179
- },
180
- },
181
- {
182
- name: "postback action",
183
- text: "[[buttons: Actions | Choose | Select:action=select&id=1]]",
184
- expectedFirstAction: {
185
- type: "postback",
186
- label: "Select",
187
- data: "action=select&id=1",
188
- },
189
- },
190
- {
191
- name: "action cap",
192
- text: "[[buttons: Menu | Text | A:a, B:b, C:c, D:d, E:e, F:f]]",
193
- expectedActionCount: 4,
194
- },
195
- ] as const;
196
-
197
- for (const testCase of cases) {
198
- const result = parseLineDirectives({ text: testCase.text });
199
- const templateMessage = getLineData(result).templateMessage as {
200
- type?: string;
201
- actions?: Array<Record<string, unknown>>;
202
- };
203
- expect(templateMessage?.type, testCase.name).toBe("buttons");
204
- if ("expectedTemplate" in testCase) {
205
- expect(templateMessage, testCase.name).toEqual(testCase.expectedTemplate);
206
- }
207
- if ("expectedFirstAction" in testCase) {
208
- expect(templateMessage?.actions?.[0], testCase.name).toEqual(
209
- testCase.expectedFirstAction,
210
- );
211
- }
212
- if ("expectedActionCount" in testCase) {
213
- expect(templateMessage?.actions?.length, testCase.name).toBe(
214
- testCase.expectedActionCount,
215
- );
216
- }
217
- }
218
- });
219
- });
220
-
221
- describe("media_player", () => {
222
- it("parses media_player directives across full/minimal/paused variants", () => {
223
- const cases = [
224
- {
225
- name: "all fields",
226
- text: "Now playing:\n[[media_player: Bohemian Rhapsody | Queen | Speaker | https://example.com/album.jpg | playing]]",
227
- expectedAltText: "🎵 Bohemian Rhapsody - Queen",
228
- expectedText: "Now playing:",
229
- expectFooter: true,
230
- expectBodyContents: false,
231
- },
232
- {
233
- name: "minimal",
234
- text: "[[media_player: Unknown Track]]",
235
- expectedAltText: "🎵 Unknown Track",
236
- expectedText: undefined,
237
- expectFooter: false,
238
- expectBodyContents: false,
239
- },
240
- {
241
- name: "paused status",
242
- text: "[[media_player: Song | Artist | Player | | paused]]",
243
- expectedAltText: undefined,
244
- expectedText: undefined,
245
- expectFooter: false,
246
- expectBodyContents: true,
247
- },
248
- ] as const;
249
-
250
- for (const testCase of cases) {
251
- const result = parseLineDirectives({ text: testCase.text });
252
- const flexMessage = getLineData(result).flexMessage as {
253
- altText?: string;
254
- contents?: { footer?: { contents?: unknown[] }; body?: { contents?: unknown[] } };
255
- };
256
- expect(flexMessage, testCase.name).toBeDefined();
257
- if (testCase.expectedAltText !== undefined) {
258
- expect(flexMessage?.altText, testCase.name).toBe(testCase.expectedAltText);
259
- }
260
- if (testCase.expectedText !== undefined) {
261
- expect(result.text, testCase.name).toBe(testCase.expectedText);
262
- }
263
- if (testCase.expectFooter) {
264
- expect(flexMessage?.contents?.footer?.contents?.length, testCase.name).toBeGreaterThan(0);
265
- }
266
- if ("expectBodyContents" in testCase && testCase.expectBodyContents) {
267
- expect(flexMessage?.contents?.body?.contents, testCase.name).toBeDefined();
268
- }
269
- }
270
- });
271
- });
272
-
273
- describe("event", () => {
274
- it("parses event variants", () => {
275
- const cases = [
276
- {
277
- text: "[[event: Team Meeting | January 24, 2026 | 2:00 PM - 3:00 PM | Conference Room A | Discuss Q1 roadmap]]",
278
- altText: "📅 Team Meeting - January 24, 2026 2:00 PM - 3:00 PM",
279
- },
280
- {
281
- text: "[[event: Birthday Party | March 15]]",
282
- altText: "📅 Birthday Party - March 15",
283
- },
284
- ];
285
-
286
- for (const testCase of cases) {
287
- const result = parseLineDirectives({ text: testCase.text });
288
- const flexMessage = getLineData(result).flexMessage as { altText?: string };
289
- expect(flexMessage).toBeDefined();
290
- expect(flexMessage?.altText).toBe(testCase.altText);
291
- }
292
- });
293
- });
294
-
295
- describe("agenda", () => {
296
- it("parses agenda variants", () => {
297
- const cases = [
298
- {
299
- text: "[[agenda: Today's Schedule | Team Meeting:9:00 AM, Lunch:12:00 PM, Review:3:00 PM]]",
300
- altText: "📋 Today's Schedule (3 events)",
301
- },
302
- {
303
- text: "[[agenda: Tasks | Buy groceries, Call mom, Workout]]",
304
- altText: "📋 Tasks (3 events)",
305
- },
306
- ];
307
-
308
- for (const testCase of cases) {
309
- const result = parseLineDirectives({ text: testCase.text });
310
- const flexMessage = getLineData(result).flexMessage as { altText?: string };
311
- expect(flexMessage).toBeDefined();
312
- expect(flexMessage?.altText).toBe(testCase.altText);
313
- }
314
- });
315
- });
316
-
317
- describe("device", () => {
318
- it("parses device variants", () => {
319
- const cases = [
320
- {
321
- text: "[[device: TV | Streaming Box | Playing | Play/Pause:toggle, Menu:menu]]",
322
- altText: "📱 TV: Playing",
323
- },
324
- {
325
- text: "[[device: Speaker]]",
326
- altText: "📱 Speaker",
327
- },
328
- ];
329
-
330
- for (const testCase of cases) {
331
- const result = parseLineDirectives({ text: testCase.text });
332
- const flexMessage = getLineData(result).flexMessage as { altText?: string };
333
- expect(flexMessage).toBeDefined();
334
- expect(flexMessage?.altText).toBe(testCase.altText);
335
- }
336
- });
337
- });
338
-
339
- describe("appletv_remote", () => {
340
- it("parses appletv remote variants", () => {
341
- const cases = [
342
- {
343
- text: "[[appletv_remote: Apple TV | Playing]]",
344
- contains: "Apple TV",
345
- },
346
- {
347
- text: "[[appletv_remote: Apple TV]]",
348
- contains: undefined,
349
- },
350
- ];
351
-
352
- for (const testCase of cases) {
353
- const result = parseLineDirectives({ text: testCase.text });
354
- const flexMessage = getLineData(result).flexMessage as { altText?: string };
355
- expect(flexMessage).toBeDefined();
356
- if (testCase.contains) {
357
- expect(flexMessage?.altText).toContain(testCase.contains);
358
- }
359
- }
360
- });
361
- });
362
-
363
- describe("combined directives", () => {
364
- it("handles text with no directives", () => {
365
- const result = parseLineDirectives({
366
- text: "Just plain text here",
367
- });
368
-
369
- expect(result.text).toBe("Just plain text here");
370
- expect(getLineData(result).quickReplies).toBeUndefined();
371
- expect(getLineData(result).location).toBeUndefined();
372
- expect(getLineData(result).templateMessage).toBeUndefined();
373
- });
374
-
375
- it("preserves other payload fields", () => {
376
- const result = parseLineDirectives({
377
- text: "Hello [[quick_replies: A, B]]",
378
- mediaUrl: "https://example.com/image.jpg",
379
- replyToId: "msg123",
380
- });
381
-
382
- expect(result.mediaUrl).toBe("https://example.com/image.jpg");
383
- expect(result.replyToId).toBe("msg123");
384
- expect(getLineData(result).quickReplies).toEqual(["A", "B"]);
385
- });
386
- });
387
- });