@kodelyth/line 2026.5.42 → 2026.6.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.
- package/klaw.plugin.json +329 -2
- package/package.json +16 -4
- package/api.ts +0 -11
- package/channel-plugin-api.ts +0 -1
- package/contract-api.ts +0 -5
- package/index.ts +0 -53
- package/runtime-api.ts +0 -179
- package/secret-contract-api.ts +0 -4
- package/setup-api.ts +0 -2
- package/setup-entry.ts +0 -9
- package/src/account-helpers.ts +0 -16
- package/src/accounts.test.ts +0 -288
- package/src/accounts.ts +0 -187
- package/src/actions.ts +0 -61
- package/src/auto-reply-delivery.test.ts +0 -253
- package/src/auto-reply-delivery.ts +0 -200
- package/src/bindings.ts +0 -65
- package/src/bot-access.ts +0 -30
- package/src/bot-handlers.test.ts +0 -1094
- package/src/bot-handlers.ts +0 -620
- package/src/bot-message-context.test.ts +0 -420
- package/src/bot-message-context.ts +0 -586
- package/src/bot.ts +0 -66
- package/src/card-command.ts +0 -347
- package/src/channel-access-token.ts +0 -14
- package/src/channel-api.ts +0 -17
- package/src/channel-setup-status.contract.test.ts +0 -70
- package/src/channel-shared.ts +0 -48
- package/src/channel.logout.test.ts +0 -145
- package/src/channel.runtime.ts +0 -3
- package/src/channel.sendPayload.test.ts +0 -659
- package/src/channel.setup.ts +0 -11
- package/src/channel.status.test.ts +0 -63
- package/src/channel.ts +0 -155
- package/src/config-adapter.ts +0 -29
- package/src/config-schema.test.ts +0 -53
- package/src/config-schema.ts +0 -81
- package/src/download.test.ts +0 -164
- package/src/download.ts +0 -34
- package/src/flex-templates/basic-cards.ts +0 -395
- package/src/flex-templates/common.ts +0 -20
- package/src/flex-templates/media-control-cards.ts +0 -555
- package/src/flex-templates/message.ts +0 -13
- package/src/flex-templates/schedule-cards.ts +0 -467
- package/src/flex-templates/types.ts +0 -22
- package/src/flex-templates.ts +0 -32
- package/src/gateway.ts +0 -129
- package/src/group-keys.test.ts +0 -123
- package/src/group-keys.ts +0 -65
- package/src/group-policy.ts +0 -22
- package/src/markdown-to-line.test.ts +0 -348
- package/src/markdown-to-line.ts +0 -416
- package/src/message-cards.test.ts +0 -204
- package/src/monitor-durable.test.ts +0 -57
- package/src/monitor-durable.ts +0 -37
- package/src/monitor.lifecycle.test.ts +0 -499
- package/src/monitor.runtime.ts +0 -1
- package/src/monitor.ts +0 -507
- package/src/outbound-media.test.ts +0 -194
- package/src/outbound-media.ts +0 -120
- package/src/outbound.runtime.ts +0 -12
- package/src/outbound.ts +0 -427
- package/src/probe.contract.test.ts +0 -9
- package/src/probe.runtime.ts +0 -1
- package/src/probe.ts +0 -34
- package/src/quick-reply-fallback.ts +0 -10
- package/src/reply-chunks.test.ts +0 -180
- package/src/reply-chunks.ts +0 -110
- package/src/reply-payload-transform.test.ts +0 -392
- package/src/reply-payload-transform.ts +0 -317
- package/src/rich-menu.test.ts +0 -315
- package/src/rich-menu.ts +0 -326
- package/src/runtime.ts +0 -32
- package/src/send-receipt.ts +0 -32
- package/src/send.test.ts +0 -453
- package/src/send.ts +0 -531
- package/src/setup-core.ts +0 -149
- package/src/setup-runtime-api.ts +0 -9
- package/src/setup-surface.test.ts +0 -481
- package/src/setup-surface.ts +0 -229
- package/src/signature.test.ts +0 -34
- package/src/signature.ts +0 -24
- package/src/status.ts +0 -37
- package/src/template-messages.ts +0 -333
- package/src/types.ts +0 -130
- package/src/webhook-node.test.ts +0 -598
- package/src/webhook-node.ts +0 -155
- package/src/webhook-utils.ts +0 -10
- package/src/webhook.ts +0 -135
- package/tsconfig.json +0 -16
|
@@ -1,659 +0,0 @@
|
|
|
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
|
-
});
|
package/src/channel.setup.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
};
|