@kodelyth/line 2026.5.42 → 2026.6.2

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