@kodelyth/line 2026.5.39 → 2026.5.42
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.
- package/api.ts +11 -0
- package/channel-plugin-api.ts +1 -0
- package/contract-api.ts +5 -0
- package/dist/accounts-CD4A1FE7.js +105 -0
- package/dist/api.js +11 -0
- package/dist/basic-cards-BISytiSa.js +307 -0
- package/dist/card-command-dQBX3fVN.js +240 -0
- package/dist/channel-DV5h44-j.js +649 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-Cc-v3szZ.js +4 -0
- package/dist/contract-api.js +2 -0
- package/dist/index.js +45 -0
- package/dist/markdown-to-line-CC3BU6CC.js +810 -0
- package/dist/monitor-Ci8Hg8ay.js +1485 -0
- package/dist/monitor.runtime-t6-QvlDB.js +2 -0
- package/dist/outbound.runtime-D1CxEvcL.js +2 -0
- package/dist/probe-BPSs_A_8.js +30 -0
- package/dist/probe.runtime-7u2o9QN5.js +2 -0
- package/dist/reply-payload-transform-CDuBzoT4.js +855 -0
- package/dist/runtime-api.js +291 -0
- package/dist/schedule-cards-D-yZMHDE.js +359 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/setup-api.js +2 -0
- package/dist/setup-entry.js +11 -0
- package/dist/setup-surface-CHfQ6Z4i.js +282 -0
- package/index.ts +53 -0
- package/klaw.plugin.json +2 -329
- package/package.json +4 -4
- package/runtime-api.ts +179 -0
- package/secret-contract-api.ts +4 -0
- package/setup-api.ts +2 -0
- package/setup-entry.ts +9 -0
- package/src/account-helpers.ts +16 -0
- package/src/accounts.test.ts +288 -0
- package/src/accounts.ts +187 -0
- package/src/actions.ts +61 -0
- package/src/auto-reply-delivery.test.ts +253 -0
- package/src/auto-reply-delivery.ts +200 -0
- package/src/bindings.ts +65 -0
- package/src/bot-access.ts +30 -0
- package/src/bot-handlers.test.ts +1094 -0
- package/src/bot-handlers.ts +620 -0
- package/src/bot-message-context.test.ts +420 -0
- package/src/bot-message-context.ts +586 -0
- package/src/bot.ts +66 -0
- package/src/card-command.ts +347 -0
- package/src/channel-access-token.ts +14 -0
- package/src/channel-api.ts +17 -0
- package/src/channel-setup-status.contract.test.ts +70 -0
- package/src/channel-shared.ts +48 -0
- package/src/channel.logout.test.ts +145 -0
- package/src/channel.runtime.ts +3 -0
- package/src/channel.sendPayload.test.ts +659 -0
- package/src/channel.setup.ts +11 -0
- package/src/channel.status.test.ts +63 -0
- package/src/channel.ts +155 -0
- package/src/config-adapter.ts +29 -0
- package/src/config-schema.test.ts +53 -0
- package/src/config-schema.ts +81 -0
- package/src/download.test.ts +164 -0
- package/src/download.ts +34 -0
- package/src/flex-templates/basic-cards.ts +395 -0
- package/src/flex-templates/common.ts +20 -0
- package/src/flex-templates/media-control-cards.ts +555 -0
- package/src/flex-templates/message.ts +13 -0
- package/src/flex-templates/schedule-cards.ts +467 -0
- package/src/flex-templates/types.ts +22 -0
- package/src/flex-templates.ts +32 -0
- package/src/gateway.ts +129 -0
- package/src/group-keys.test.ts +123 -0
- package/src/group-keys.ts +65 -0
- package/src/group-policy.ts +22 -0
- package/src/markdown-to-line.test.ts +348 -0
- package/src/markdown-to-line.ts +416 -0
- package/src/message-cards.test.ts +204 -0
- package/src/monitor-durable.test.ts +57 -0
- package/src/monitor-durable.ts +37 -0
- package/src/monitor.lifecycle.test.ts +499 -0
- package/src/monitor.runtime.ts +1 -0
- package/src/monitor.ts +507 -0
- package/src/outbound-media.test.ts +194 -0
- package/src/outbound-media.ts +120 -0
- package/src/outbound.runtime.ts +12 -0
- package/src/outbound.ts +427 -0
- package/src/probe.contract.test.ts +9 -0
- package/src/probe.runtime.ts +1 -0
- package/src/probe.ts +34 -0
- package/src/quick-reply-fallback.ts +10 -0
- package/src/reply-chunks.test.ts +180 -0
- package/src/reply-chunks.ts +110 -0
- package/src/reply-payload-transform.test.ts +392 -0
- package/src/reply-payload-transform.ts +317 -0
- package/src/rich-menu.test.ts +315 -0
- package/src/rich-menu.ts +326 -0
- package/src/runtime.ts +32 -0
- package/src/send-receipt.ts +32 -0
- package/src/send.test.ts +453 -0
- package/src/send.ts +531 -0
- package/src/setup-core.ts +149 -0
- package/src/setup-runtime-api.ts +9 -0
- package/src/setup-surface.test.ts +481 -0
- package/src/setup-surface.ts +229 -0
- package/src/signature.test.ts +34 -0
- package/src/signature.ts +24 -0
- package/src/status.ts +37 -0
- package/src/template-messages.ts +333 -0
- package/src/types.ts +130 -0
- package/src/webhook-node.test.ts +598 -0
- package/src/webhook-node.ts +155 -0
- package/src/webhook-utils.ts +10 -0
- package/src/webhook.ts +135 -0
- package/tsconfig.json +16 -0
- package/api.js +0 -7
- package/channel-plugin-api.js +0 -7
- package/contract-api.js +0 -7
- package/index.js +0 -7
- package/runtime-api.js +0 -7
- package/secret-contract-api.js +0 -7
- package/setup-api.js +0 -7
- package/setup-entry.js +0 -7
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import {
|
|
2
|
+
verifyChannelMessageAdapterCapabilityProofs,
|
|
3
|
+
verifyChannelMessageReceiveAckPolicyAdapterProofs,
|
|
4
|
+
} from "klaw/plugin-sdk/channel-message";
|
|
5
|
+
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import type { KlawConfig, PluginRuntime } from "../api.js";
|
|
7
|
+
import { linePlugin } from "./channel.js";
|
|
8
|
+
import { lineConfigAdapter } from "./config-adapter.js";
|
|
9
|
+
import { resolveLineGroupRequireMention } from "./group-policy.js";
|
|
10
|
+
import { lineOutboundAdapter } from "./outbound.js";
|
|
11
|
+
import { setLineRuntime } from "./runtime.js";
|
|
12
|
+
import { createLineSendReceipt } from "./send-receipt.js";
|
|
13
|
+
|
|
14
|
+
const ssrfMocks = vi.hoisted(() => ({
|
|
15
|
+
resolvePinnedHostnameWithPolicy: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
vi.mock("klaw/plugin-sdk/ssrf-runtime", () => ({
|
|
19
|
+
resolvePinnedHostnameWithPolicy: ssrfMocks.resolvePinnedHostnameWithPolicy,
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
afterAll(() => {
|
|
23
|
+
vi.doUnmock("klaw/plugin-sdk/ssrf-runtime");
|
|
24
|
+
vi.resetModules();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
type LineRuntimeMocks = {
|
|
28
|
+
pushMessageLine: ReturnType<typeof vi.fn>;
|
|
29
|
+
pushMessagesLine: ReturnType<typeof vi.fn>;
|
|
30
|
+
pushFlexMessage: ReturnType<typeof vi.fn>;
|
|
31
|
+
pushTemplateMessage: ReturnType<typeof vi.fn>;
|
|
32
|
+
pushLocationMessage: ReturnType<typeof vi.fn>;
|
|
33
|
+
pushTextMessageWithQuickReplies: ReturnType<typeof vi.fn>;
|
|
34
|
+
createQuickReplyItems: ReturnType<typeof vi.fn>;
|
|
35
|
+
buildTemplateMessageFromPayload: ReturnType<typeof vi.fn>;
|
|
36
|
+
sendMessageLine: ReturnType<typeof vi.fn>;
|
|
37
|
+
chunkMarkdownText: ReturnType<typeof vi.fn>;
|
|
38
|
+
resolveLineAccount: ReturnType<typeof vi.fn>;
|
|
39
|
+
resolveTextChunkLimit: ReturnType<typeof vi.fn>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
vi.setSystemTime(1_800_000_000_000);
|
|
44
|
+
ssrfMocks.resolvePinnedHostnameWithPolicy.mockReset();
|
|
45
|
+
ssrfMocks.resolvePinnedHostnameWithPolicy.mockResolvedValue({
|
|
46
|
+
hostname: "example.com",
|
|
47
|
+
addresses: ["93.184.216.34"],
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
vi.useRealTimers();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function lineResult(messageId: string, chatId = "c1") {
|
|
56
|
+
return {
|
|
57
|
+
messageId,
|
|
58
|
+
chatId,
|
|
59
|
+
receipt: createLineSendReceipt({ messageId, chatId, kind: "text" }),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function createRuntime(): { runtime: PluginRuntime; mocks: LineRuntimeMocks } {
|
|
64
|
+
const pushMessageLine = vi.fn(async () => lineResult("m-text"));
|
|
65
|
+
const pushMessagesLine = vi.fn(async () => lineResult("m-batch"));
|
|
66
|
+
const pushFlexMessage = vi.fn(async () => lineResult("m-flex"));
|
|
67
|
+
const pushTemplateMessage = vi.fn(async () => lineResult("m-template"));
|
|
68
|
+
const pushLocationMessage = vi.fn(async () => lineResult("m-loc"));
|
|
69
|
+
const pushTextMessageWithQuickReplies = vi.fn(async () => lineResult("m-quick"));
|
|
70
|
+
const createQuickReplyItems = vi.fn((labels: string[]) => ({ items: labels }));
|
|
71
|
+
const buildTemplateMessageFromPayload = vi.fn(() => ({ type: "buttons" }));
|
|
72
|
+
const sendMessageLine = vi.fn(async () => lineResult("m-media"));
|
|
73
|
+
const chunkMarkdownText = vi.fn((text: string) => [text]);
|
|
74
|
+
const resolveTextChunkLimit = vi.fn(() => 123);
|
|
75
|
+
const resolveLineAccount = vi.fn(
|
|
76
|
+
({ cfg, accountId }: { cfg: KlawConfig; accountId?: string }) => {
|
|
77
|
+
const resolved = accountId ?? "default";
|
|
78
|
+
const lineConfig = (cfg.channels?.line ?? {}) as {
|
|
79
|
+
accounts?: Record<string, Record<string, unknown>>;
|
|
80
|
+
};
|
|
81
|
+
const accountConfig = resolved !== "default" ? (lineConfig.accounts?.[resolved] ?? {}) : {};
|
|
82
|
+
return {
|
|
83
|
+
accountId: resolved,
|
|
84
|
+
config: { ...lineConfig, ...accountConfig },
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const runtime = {
|
|
90
|
+
channel: {
|
|
91
|
+
line: {
|
|
92
|
+
pushMessageLine,
|
|
93
|
+
pushMessagesLine,
|
|
94
|
+
pushFlexMessage,
|
|
95
|
+
pushTemplateMessage,
|
|
96
|
+
pushLocationMessage,
|
|
97
|
+
pushTextMessageWithQuickReplies,
|
|
98
|
+
createQuickReplyItems,
|
|
99
|
+
buildTemplateMessageFromPayload,
|
|
100
|
+
sendMessageLine,
|
|
101
|
+
resolveLineAccount,
|
|
102
|
+
},
|
|
103
|
+
text: {
|
|
104
|
+
chunkMarkdownText,
|
|
105
|
+
resolveTextChunkLimit,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
} as unknown as PluginRuntime;
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
runtime,
|
|
112
|
+
mocks: {
|
|
113
|
+
pushMessageLine,
|
|
114
|
+
pushMessagesLine,
|
|
115
|
+
pushFlexMessage,
|
|
116
|
+
pushTemplateMessage,
|
|
117
|
+
pushLocationMessage,
|
|
118
|
+
pushTextMessageWithQuickReplies,
|
|
119
|
+
createQuickReplyItems,
|
|
120
|
+
buildTemplateMessageFromPayload,
|
|
121
|
+
sendMessageLine,
|
|
122
|
+
chunkMarkdownText,
|
|
123
|
+
resolveLineAccount,
|
|
124
|
+
resolveTextChunkLimit,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
describe("line outbound sendPayload", () => {
|
|
130
|
+
it("sends flex message without dropping text", async () => {
|
|
131
|
+
const { runtime, mocks } = createRuntime();
|
|
132
|
+
setLineRuntime(runtime);
|
|
133
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
134
|
+
|
|
135
|
+
const payload = {
|
|
136
|
+
text: "Now playing:",
|
|
137
|
+
channelData: {
|
|
138
|
+
line: {
|
|
139
|
+
flexMessage: {
|
|
140
|
+
altText: "Now playing",
|
|
141
|
+
contents: { type: "bubble" },
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
await lineOutboundAdapter.sendPayload!({
|
|
148
|
+
to: "line:group:1",
|
|
149
|
+
text: payload.text,
|
|
150
|
+
payload,
|
|
151
|
+
accountId: "default",
|
|
152
|
+
cfg,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(mocks.pushFlexMessage).toHaveBeenCalledTimes(1);
|
|
156
|
+
expect(mocks.pushMessageLine).toHaveBeenCalledWith("line:group:1", "Now playing:", {
|
|
157
|
+
verbose: false,
|
|
158
|
+
accountId: "default",
|
|
159
|
+
cfg,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("sends template message without dropping text", async () => {
|
|
164
|
+
const { runtime, mocks } = createRuntime();
|
|
165
|
+
setLineRuntime(runtime);
|
|
166
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
167
|
+
|
|
168
|
+
const payload = {
|
|
169
|
+
text: "Choose one:",
|
|
170
|
+
channelData: {
|
|
171
|
+
line: {
|
|
172
|
+
templateMessage: {
|
|
173
|
+
type: "confirm",
|
|
174
|
+
text: "Continue?",
|
|
175
|
+
confirmLabel: "Yes",
|
|
176
|
+
confirmData: "yes",
|
|
177
|
+
cancelLabel: "No",
|
|
178
|
+
cancelData: "no",
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
await lineOutboundAdapter.sendPayload!({
|
|
185
|
+
to: "line:user:1",
|
|
186
|
+
text: payload.text,
|
|
187
|
+
payload,
|
|
188
|
+
accountId: "default",
|
|
189
|
+
cfg,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(mocks.buildTemplateMessageFromPayload).toHaveBeenCalledTimes(1);
|
|
193
|
+
expect(mocks.pushTemplateMessage).toHaveBeenCalledTimes(1);
|
|
194
|
+
expect(mocks.pushMessageLine).toHaveBeenCalledWith("line:user:1", "Choose one:", {
|
|
195
|
+
verbose: false,
|
|
196
|
+
accountId: "default",
|
|
197
|
+
cfg,
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("attaches quick replies when no text chunks are present", async () => {
|
|
202
|
+
const { runtime, mocks } = createRuntime();
|
|
203
|
+
setLineRuntime(runtime);
|
|
204
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
205
|
+
|
|
206
|
+
const payload = {
|
|
207
|
+
channelData: {
|
|
208
|
+
line: {
|
|
209
|
+
quickReplies: ["One", "Two"],
|
|
210
|
+
flexMessage: {
|
|
211
|
+
altText: "Card",
|
|
212
|
+
contents: { type: "bubble" },
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
await lineOutboundAdapter.sendPayload!({
|
|
219
|
+
to: "line:user:2",
|
|
220
|
+
text: "",
|
|
221
|
+
payload,
|
|
222
|
+
accountId: "default",
|
|
223
|
+
cfg,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(mocks.pushFlexMessage).not.toHaveBeenCalled();
|
|
227
|
+
expect(mocks.pushMessagesLine).toHaveBeenCalledWith(
|
|
228
|
+
"line:user:2",
|
|
229
|
+
[
|
|
230
|
+
{
|
|
231
|
+
type: "flex",
|
|
232
|
+
altText: "Card",
|
|
233
|
+
contents: { type: "bubble" },
|
|
234
|
+
quickReply: { items: ["One", "Two"] },
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
{ verbose: false, accountId: "default", cfg },
|
|
238
|
+
);
|
|
239
|
+
expect(mocks.createQuickReplyItems).toHaveBeenCalledWith(["One", "Two"]);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("sends quick-reply-only payloads with fallback text", async () => {
|
|
243
|
+
const { runtime, mocks } = createRuntime();
|
|
244
|
+
setLineRuntime(runtime);
|
|
245
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
246
|
+
|
|
247
|
+
const result = await lineOutboundAdapter.sendPayload!({
|
|
248
|
+
to: "line:user:quick",
|
|
249
|
+
text: "",
|
|
250
|
+
payload: {
|
|
251
|
+
channelData: {
|
|
252
|
+
line: {
|
|
253
|
+
quickReplies: ["One", "Two"],
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
accountId: "default",
|
|
258
|
+
cfg,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(mocks.pushTextMessageWithQuickReplies).toHaveBeenCalledWith(
|
|
262
|
+
"line:user:quick",
|
|
263
|
+
"Options:\n- One\n- Two",
|
|
264
|
+
["One", "Two"],
|
|
265
|
+
{ verbose: false, accountId: "default", cfg },
|
|
266
|
+
);
|
|
267
|
+
expect(result).toEqual({
|
|
268
|
+
channel: "line",
|
|
269
|
+
chatId: "c1",
|
|
270
|
+
messageId: "m-quick",
|
|
271
|
+
receipt: {
|
|
272
|
+
parts: [
|
|
273
|
+
{
|
|
274
|
+
index: 0,
|
|
275
|
+
kind: "text",
|
|
276
|
+
platformMessageId: "m-quick",
|
|
277
|
+
raw: {
|
|
278
|
+
channel: "line",
|
|
279
|
+
chatId: "c1",
|
|
280
|
+
conversationId: "c1",
|
|
281
|
+
messageId: "m-quick",
|
|
282
|
+
meta: { messageCount: 1 },
|
|
283
|
+
},
|
|
284
|
+
threadId: "c1",
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
platformMessageIds: ["m-quick"],
|
|
288
|
+
primaryPlatformMessageId: "m-quick",
|
|
289
|
+
raw: [
|
|
290
|
+
{
|
|
291
|
+
channel: "line",
|
|
292
|
+
chatId: "c1",
|
|
293
|
+
conversationId: "c1",
|
|
294
|
+
messageId: "m-quick",
|
|
295
|
+
meta: { messageCount: 1 },
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
sentAt: 1_800_000_000_000,
|
|
299
|
+
threadId: "c1",
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("sends media before quick-reply text so buttons stay visible", async () => {
|
|
305
|
+
const { runtime, mocks } = createRuntime();
|
|
306
|
+
setLineRuntime(runtime);
|
|
307
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
308
|
+
|
|
309
|
+
const payload = {
|
|
310
|
+
text: "Hello",
|
|
311
|
+
mediaUrl: "https://example.com/img.jpg",
|
|
312
|
+
channelData: {
|
|
313
|
+
line: {
|
|
314
|
+
quickReplies: ["One", "Two"],
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
await lineOutboundAdapter.sendPayload!({
|
|
320
|
+
to: "line:user:3",
|
|
321
|
+
text: payload.text,
|
|
322
|
+
payload,
|
|
323
|
+
accountId: "default",
|
|
324
|
+
cfg,
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
expect(mocks.sendMessageLine).toHaveBeenCalledWith("line:user:3", "", {
|
|
328
|
+
verbose: false,
|
|
329
|
+
mediaUrl: "https://example.com/img.jpg",
|
|
330
|
+
mediaKind: undefined,
|
|
331
|
+
previewImageUrl: undefined,
|
|
332
|
+
durationMs: undefined,
|
|
333
|
+
trackingId: undefined,
|
|
334
|
+
accountId: "default",
|
|
335
|
+
cfg,
|
|
336
|
+
});
|
|
337
|
+
expect(mocks.pushTextMessageWithQuickReplies).toHaveBeenCalledWith(
|
|
338
|
+
"line:user:3",
|
|
339
|
+
"Hello",
|
|
340
|
+
["One", "Two"],
|
|
341
|
+
{ verbose: false, accountId: "default", cfg },
|
|
342
|
+
);
|
|
343
|
+
const mediaOrder = mocks.sendMessageLine.mock.invocationCallOrder[0];
|
|
344
|
+
const quickReplyOrder = mocks.pushTextMessageWithQuickReplies.mock.invocationCallOrder[0];
|
|
345
|
+
expect(mediaOrder).toBeLessThan(quickReplyOrder);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("keeps generic media payloads on the image-only send path", async () => {
|
|
349
|
+
const { runtime, mocks } = createRuntime();
|
|
350
|
+
setLineRuntime(runtime);
|
|
351
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
352
|
+
|
|
353
|
+
await lineOutboundAdapter.sendPayload!({
|
|
354
|
+
to: "line:user:4",
|
|
355
|
+
text: "",
|
|
356
|
+
payload: {
|
|
357
|
+
mediaUrl: "https://example.com/video.mp4",
|
|
358
|
+
},
|
|
359
|
+
accountId: "default",
|
|
360
|
+
cfg,
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
expect(mocks.sendMessageLine).toHaveBeenCalledWith("line:user:4", "", {
|
|
364
|
+
verbose: false,
|
|
365
|
+
mediaUrl: "https://example.com/video.mp4",
|
|
366
|
+
accountId: "default",
|
|
367
|
+
cfg,
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("uses LINE-specific media options for rich media payloads", async () => {
|
|
372
|
+
const { runtime, mocks } = createRuntime();
|
|
373
|
+
setLineRuntime(runtime);
|
|
374
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
375
|
+
|
|
376
|
+
await lineOutboundAdapter.sendPayload!({
|
|
377
|
+
to: "line:user:5",
|
|
378
|
+
text: "",
|
|
379
|
+
payload: {
|
|
380
|
+
mediaUrl: "https://example.com/video.mp4",
|
|
381
|
+
channelData: {
|
|
382
|
+
line: {
|
|
383
|
+
mediaKind: "video",
|
|
384
|
+
previewImageUrl: "https://example.com/preview.jpg",
|
|
385
|
+
trackingId: "track-123",
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
accountId: "default",
|
|
390
|
+
cfg,
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
expect(mocks.sendMessageLine).toHaveBeenCalledWith("line:user:5", "", {
|
|
394
|
+
verbose: false,
|
|
395
|
+
mediaUrl: "https://example.com/video.mp4",
|
|
396
|
+
mediaKind: "video",
|
|
397
|
+
previewImageUrl: "https://example.com/preview.jpg",
|
|
398
|
+
durationMs: undefined,
|
|
399
|
+
trackingId: "track-123",
|
|
400
|
+
accountId: "default",
|
|
401
|
+
cfg,
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it("uses configured text chunk limit for payloads", async () => {
|
|
406
|
+
const { runtime, mocks } = createRuntime();
|
|
407
|
+
setLineRuntime(runtime);
|
|
408
|
+
const cfg = { channels: { line: { textChunkLimit: 123 } } } as KlawConfig;
|
|
409
|
+
|
|
410
|
+
const payload = {
|
|
411
|
+
text: "Hello world",
|
|
412
|
+
channelData: {
|
|
413
|
+
line: {
|
|
414
|
+
flexMessage: {
|
|
415
|
+
altText: "Card",
|
|
416
|
+
contents: { type: "bubble" },
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
await lineOutboundAdapter.sendPayload!({
|
|
423
|
+
to: "line:user:3",
|
|
424
|
+
text: payload.text,
|
|
425
|
+
payload,
|
|
426
|
+
accountId: "primary",
|
|
427
|
+
cfg,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
expect(mocks.resolveTextChunkLimit).toHaveBeenCalledWith(cfg, "line", "primary", {
|
|
431
|
+
fallbackLimit: 5000,
|
|
432
|
+
});
|
|
433
|
+
expect(mocks.chunkMarkdownText).toHaveBeenCalledWith("Hello world", 123);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it("omits trackingId for non-user quick-reply inline video media", async () => {
|
|
437
|
+
const { runtime, mocks } = createRuntime();
|
|
438
|
+
setLineRuntime(runtime);
|
|
439
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
440
|
+
|
|
441
|
+
const payload = {
|
|
442
|
+
text: "",
|
|
443
|
+
mediaUrl: "https://example.com/video.mp4",
|
|
444
|
+
channelData: {
|
|
445
|
+
line: {
|
|
446
|
+
quickReplies: ["One"],
|
|
447
|
+
mediaKind: "video" as const,
|
|
448
|
+
previewImageUrl: "https://example.com/preview.jpg",
|
|
449
|
+
trackingId: "track-group",
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
await lineOutboundAdapter.sendPayload!({
|
|
455
|
+
to: "line:group:C123",
|
|
456
|
+
text: payload.text,
|
|
457
|
+
payload,
|
|
458
|
+
accountId: "default",
|
|
459
|
+
cfg,
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
expect(mocks.pushMessagesLine).toHaveBeenCalledWith(
|
|
463
|
+
"line:group:C123",
|
|
464
|
+
[
|
|
465
|
+
{
|
|
466
|
+
type: "video",
|
|
467
|
+
originalContentUrl: "https://example.com/video.mp4",
|
|
468
|
+
previewImageUrl: "https://example.com/preview.jpg",
|
|
469
|
+
quickReply: { items: ["One"] },
|
|
470
|
+
},
|
|
471
|
+
],
|
|
472
|
+
{ verbose: false, accountId: "default", cfg },
|
|
473
|
+
);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it("keeps trackingId for user quick-reply inline video media", async () => {
|
|
477
|
+
const { runtime, mocks } = createRuntime();
|
|
478
|
+
setLineRuntime(runtime);
|
|
479
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
480
|
+
|
|
481
|
+
const payload = {
|
|
482
|
+
text: "",
|
|
483
|
+
mediaUrl: "https://example.com/video.mp4",
|
|
484
|
+
channelData: {
|
|
485
|
+
line: {
|
|
486
|
+
quickReplies: ["One"],
|
|
487
|
+
mediaKind: "video" as const,
|
|
488
|
+
previewImageUrl: "https://example.com/preview.jpg",
|
|
489
|
+
trackingId: "track-user",
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
await lineOutboundAdapter.sendPayload!({
|
|
495
|
+
to: "line:user:U123",
|
|
496
|
+
text: payload.text,
|
|
497
|
+
payload,
|
|
498
|
+
accountId: "default",
|
|
499
|
+
cfg,
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
expect(mocks.pushMessagesLine).toHaveBeenCalledWith(
|
|
503
|
+
"line:user:U123",
|
|
504
|
+
[
|
|
505
|
+
{
|
|
506
|
+
type: "video",
|
|
507
|
+
originalContentUrl: "https://example.com/video.mp4",
|
|
508
|
+
previewImageUrl: "https://example.com/preview.jpg",
|
|
509
|
+
trackingId: "track-user",
|
|
510
|
+
quickReply: { items: ["One"] },
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
{ verbose: false, accountId: "default", cfg },
|
|
514
|
+
);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it("rejects quick-reply inline video media without previewImageUrl", async () => {
|
|
518
|
+
const { runtime } = createRuntime();
|
|
519
|
+
setLineRuntime(runtime);
|
|
520
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
521
|
+
|
|
522
|
+
const payload = {
|
|
523
|
+
text: "",
|
|
524
|
+
mediaUrl: "https://example.com/video.mp4",
|
|
525
|
+
channelData: {
|
|
526
|
+
line: {
|
|
527
|
+
quickReplies: ["One"],
|
|
528
|
+
mediaKind: "video" as const,
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
await expect(
|
|
534
|
+
lineOutboundAdapter.sendPayload!({
|
|
535
|
+
to: "line:user:U123",
|
|
536
|
+
text: payload.text,
|
|
537
|
+
payload,
|
|
538
|
+
accountId: "default",
|
|
539
|
+
cfg,
|
|
540
|
+
}),
|
|
541
|
+
).rejects.toThrow(/require previewimageurl/i);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("declares message adapter durable text and media with receipt proofs", async () => {
|
|
545
|
+
const { runtime, mocks } = createRuntime();
|
|
546
|
+
setLineRuntime(runtime);
|
|
547
|
+
const cfg = { channels: { line: {} } } as KlawConfig;
|
|
548
|
+
|
|
549
|
+
const proofResults = await verifyChannelMessageAdapterCapabilityProofs({
|
|
550
|
+
adapterName: "line",
|
|
551
|
+
adapter: linePlugin.message!,
|
|
552
|
+
proofs: {
|
|
553
|
+
text: async () => {
|
|
554
|
+
const result = await linePlugin.message?.send?.text?.({
|
|
555
|
+
cfg,
|
|
556
|
+
to: "line:user:U123",
|
|
557
|
+
text: "hello",
|
|
558
|
+
accountId: "primary",
|
|
559
|
+
});
|
|
560
|
+
expect(mocks.pushMessageLine).toHaveBeenCalledWith("line:user:U123", "hello", {
|
|
561
|
+
verbose: false,
|
|
562
|
+
accountId: "primary",
|
|
563
|
+
cfg,
|
|
564
|
+
});
|
|
565
|
+
expect(result?.receipt.platformMessageIds).toEqual(["m-text"]);
|
|
566
|
+
},
|
|
567
|
+
media: async () => {
|
|
568
|
+
const result = await linePlugin.message?.send?.media?.({
|
|
569
|
+
cfg,
|
|
570
|
+
to: "line:user:U123",
|
|
571
|
+
text: "image",
|
|
572
|
+
mediaUrl: "https://example.com/image.jpg",
|
|
573
|
+
accountId: "primary",
|
|
574
|
+
});
|
|
575
|
+
expect(mocks.sendMessageLine).toHaveBeenCalledWith("line:user:U123", "", {
|
|
576
|
+
verbose: false,
|
|
577
|
+
mediaUrl: "https://example.com/image.jpg",
|
|
578
|
+
accountId: "primary",
|
|
579
|
+
cfg,
|
|
580
|
+
});
|
|
581
|
+
expect(result?.receipt.platformMessageIds).toEqual(["m-media"]);
|
|
582
|
+
},
|
|
583
|
+
messageSendingHooks: () => {
|
|
584
|
+
expect(linePlugin.message?.send?.text).toBeTypeOf("function");
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
expect(proofResults.find((result) => result.capability === "text")?.status).toBe("verified");
|
|
590
|
+
expect(proofResults.find((result) => result.capability === "media")?.status).toBe("verified");
|
|
591
|
+
expect(proofResults.find((result) => result.capability === "messageSendingHooks")?.status).toBe(
|
|
592
|
+
"verified",
|
|
593
|
+
);
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
it("declares receive ack policies for immediate LINE webhook acknowledgement", async () => {
|
|
597
|
+
const proofResults = await verifyChannelMessageReceiveAckPolicyAdapterProofs({
|
|
598
|
+
adapterName: "line",
|
|
599
|
+
adapter: linePlugin.message!,
|
|
600
|
+
proofs: {
|
|
601
|
+
after_receive_record: () => {
|
|
602
|
+
expect(linePlugin.message?.receive?.defaultAckPolicy).toBe("after_receive_record");
|
|
603
|
+
expect(linePlugin.message?.receive?.supportedAckPolicies).toContain(
|
|
604
|
+
"after_receive_record",
|
|
605
|
+
);
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
expect(proofResults.find((result) => result.policy === "after_receive_record")?.status).toBe(
|
|
611
|
+
"verified",
|
|
612
|
+
);
|
|
613
|
+
expect(proofResults.find((result) => result.policy === "after_agent_dispatch")?.status).toBe(
|
|
614
|
+
"not_declared",
|
|
615
|
+
);
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
describe("linePlugin config.formatAllowFrom", () => {
|
|
620
|
+
it("strips line:user: prefixes without lowercasing", () => {
|
|
621
|
+
const formatted = lineConfigAdapter.formatAllowFrom!({
|
|
622
|
+
cfg: {} as KlawConfig,
|
|
623
|
+
allowFrom: ["line:user:UABC", "line:UDEF"],
|
|
624
|
+
});
|
|
625
|
+
expect(formatted).toEqual(["UABC", "UDEF"]);
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
describe("linePlugin groups.resolveRequireMention", () => {
|
|
630
|
+
it("uses account-level group settings when provided", () => {
|
|
631
|
+
const { runtime } = createRuntime();
|
|
632
|
+
setLineRuntime(runtime);
|
|
633
|
+
|
|
634
|
+
const cfg = {
|
|
635
|
+
channels: {
|
|
636
|
+
line: {
|
|
637
|
+
groups: {
|
|
638
|
+
"*": { requireMention: false },
|
|
639
|
+
},
|
|
640
|
+
accounts: {
|
|
641
|
+
primary: {
|
|
642
|
+
groups: {
|
|
643
|
+
"group-1": { requireMention: true },
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
} as KlawConfig;
|
|
650
|
+
|
|
651
|
+
const requireMention = resolveLineGroupRequireMention({
|
|
652
|
+
cfg,
|
|
653
|
+
accountId: "primary",
|
|
654
|
+
groupId: "group-1",
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
expect(requireMention).toBe(true);
|
|
658
|
+
});
|
|
659
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ChannelPlugin, type ResolvedLineAccount } from "./channel-api.js";
|
|
2
|
+
import { lineChannelPluginCommon } from "./channel-shared.js";
|
|
3
|
+
import { lineSetupAdapter } from "./setup-core.js";
|
|
4
|
+
import { lineSetupWizard } from "./setup-surface.js";
|
|
5
|
+
|
|
6
|
+
export const lineSetupPlugin: ChannelPlugin<ResolvedLineAccount> = {
|
|
7
|
+
id: "line",
|
|
8
|
+
...lineChannelPluginCommon,
|
|
9
|
+
setupWizard: lineSetupWizard,
|
|
10
|
+
setup: lineSetupAdapter,
|
|
11
|
+
};
|