@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.
Files changed (90) hide show
  1. package/klaw.plugin.json +329 -2
  2. package/package.json +16 -4
  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,120 +0,0 @@
1
- import { resolvePinnedHostnameWithPolicy, type SsrFPolicy } from "klaw/plugin-sdk/ssrf-runtime";
2
- import { normalizeLowercaseStringOrEmpty } from "klaw/plugin-sdk/string-coerce-runtime";
3
-
4
- type LineOutboundMediaKind = "image" | "video" | "audio";
5
-
6
- export type LineOutboundMediaResolved = {
7
- mediaUrl: string;
8
- mediaKind: LineOutboundMediaKind;
9
- previewImageUrl?: string;
10
- durationMs?: number;
11
- trackingId?: string;
12
- };
13
-
14
- type ResolveLineOutboundMediaOpts = {
15
- mediaKind?: LineOutboundMediaKind;
16
- previewImageUrl?: string;
17
- durationMs?: number;
18
- trackingId?: string;
19
- };
20
-
21
- const LINE_OUTBOUND_MEDIA_SSRF_POLICY: SsrFPolicy = {
22
- allowPrivateNetwork: false,
23
- };
24
-
25
- export async function validateLineMediaUrl(url: string): Promise<void> {
26
- let parsed: URL;
27
- try {
28
- parsed = new URL(url);
29
- } catch {
30
- throw new Error(`LINE outbound media URL must be a valid URL: ${url}`);
31
- }
32
- if (parsed.protocol !== "https:") {
33
- throw new Error(`LINE outbound media URL must use HTTPS: ${url}`);
34
- }
35
- if (url.length > 2000) {
36
- throw new Error(`LINE outbound media URL must be 2000 chars or less (got ${url.length})`);
37
- }
38
- await resolvePinnedHostnameWithPolicy(parsed.hostname, {
39
- policy: LINE_OUTBOUND_MEDIA_SSRF_POLICY,
40
- });
41
- }
42
-
43
- export function detectLineMediaKind(mimeType: string): LineOutboundMediaKind {
44
- const normalized = normalizeLowercaseStringOrEmpty(mimeType);
45
- if (normalized.startsWith("image/")) {
46
- return "image";
47
- }
48
- if (normalized.startsWith("video/")) {
49
- return "video";
50
- }
51
- if (normalized.startsWith("audio/")) {
52
- return "audio";
53
- }
54
- return "image";
55
- }
56
-
57
- function isHttpsUrl(url: string): boolean {
58
- try {
59
- return new URL(url).protocol === "https:";
60
- } catch {
61
- return false;
62
- }
63
- }
64
-
65
- function detectLineMediaKindFromUrl(url: string): LineOutboundMediaKind | undefined {
66
- try {
67
- const pathname = normalizeLowercaseStringOrEmpty(new URL(url).pathname);
68
- if (/\.(png|jpe?g|gif|webp|bmp|heic|heif|avif)$/i.test(pathname)) {
69
- return "image";
70
- }
71
- if (/\.(mp4|mov|m4v|webm)$/i.test(pathname)) {
72
- return "video";
73
- }
74
- if (/\.(mp3|m4a|aac|wav|ogg|oga)$/i.test(pathname)) {
75
- return "audio";
76
- }
77
- } catch {
78
- return undefined;
79
- }
80
- return undefined;
81
- }
82
-
83
- export async function resolveLineOutboundMedia(
84
- mediaUrl: string,
85
- opts: ResolveLineOutboundMediaOpts = {},
86
- ): Promise<LineOutboundMediaResolved> {
87
- const trimmedUrl = mediaUrl.trim();
88
- if (isHttpsUrl(trimmedUrl)) {
89
- await validateLineMediaUrl(trimmedUrl);
90
- const previewImageUrl = opts.previewImageUrl?.trim();
91
- if (previewImageUrl) {
92
- await validateLineMediaUrl(previewImageUrl);
93
- }
94
- const mediaKind =
95
- opts.mediaKind ??
96
- (typeof opts.durationMs === "number" ? "audio" : undefined) ??
97
- (opts.trackingId?.trim() ? "video" : undefined) ??
98
- detectLineMediaKindFromUrl(trimmedUrl) ??
99
- "image";
100
- return {
101
- mediaUrl: trimmedUrl,
102
- mediaKind,
103
- ...(previewImageUrl ? { previewImageUrl } : {}),
104
- ...(typeof opts.durationMs === "number" ? { durationMs: opts.durationMs } : {}),
105
- ...(opts.trackingId ? { trackingId: opts.trackingId } : {}),
106
- };
107
- }
108
-
109
- try {
110
- const parsed = new URL(trimmedUrl);
111
- if (parsed.protocol !== "https:") {
112
- throw new Error(`LINE outbound media URL must use HTTPS: ${trimmedUrl}`);
113
- }
114
- } catch (e) {
115
- if (e instanceof Error && e.message.startsWith("LINE outbound")) {
116
- throw e;
117
- }
118
- }
119
- throw new Error("LINE outbound media currently requires a public HTTPS URL");
120
- }
@@ -1,12 +0,0 @@
1
- export { processLineMessage } from "./markdown-to-line.js";
2
- export {
3
- createQuickReplyItems,
4
- pushFlexMessage,
5
- pushLocationMessage,
6
- pushMessageLine,
7
- pushMessagesLine,
8
- pushTemplateMessage,
9
- pushTextMessageWithQuickReplies,
10
- sendMessageLine,
11
- } from "./send.js";
12
- export { buildTemplateMessageFromPayload } from "./template-messages.js";
package/src/outbound.ts DELETED
@@ -1,427 +0,0 @@
1
- import {
2
- defineChannelMessageAdapter,
3
- type ChannelMessageSendResult,
4
- type MessageReceiptPartKind,
5
- } from "klaw/plugin-sdk/channel-message";
6
- import {
7
- createAttachedChannelResultAdapter,
8
- createEmptyChannelResult,
9
- } from "klaw/plugin-sdk/channel-send-result";
10
- import { createLazyRuntimeModule } from "klaw/plugin-sdk/lazy-runtime";
11
- import { resolveOutboundMediaUrls } from "klaw/plugin-sdk/reply-payload";
12
- import { type ChannelPlugin, type ResolvedLineAccount } from "./channel-api.js";
13
- import { resolveLineOutboundMedia, type LineOutboundMediaResolved } from "./outbound-media.js";
14
- import { buildLineQuickReplyFallbackText } from "./quick-reply-fallback.js";
15
- import { getLineRuntime } from "./runtime.js";
16
- import { createLineSendReceipt } from "./send-receipt.js";
17
- import type { LineChannelData, LineSendResult } from "./types.js";
18
-
19
- const loadLineOutboundRuntime = createLazyRuntimeModule(() => import("./outbound.runtime.js"));
20
-
21
- type LineChannelDataWithMedia = LineChannelData & {
22
- mediaKind?: "image" | "video" | "audio";
23
- previewImageUrl?: string;
24
- durationMs?: number;
25
- trackingId?: string;
26
- };
27
-
28
- function isLineUserTarget(target: string): boolean {
29
- const normalized = target
30
- .trim()
31
- .replace(/^line:(group|room|user):/i, "")
32
- .replace(/^line:/i, "");
33
- return /^U/i.test(normalized);
34
- }
35
-
36
- function hasLineSpecificMediaOptions(lineData: LineChannelDataWithMedia): boolean {
37
- return Boolean(
38
- lineData.mediaKind ??
39
- lineData.previewImageUrl?.trim() ??
40
- (typeof lineData.durationMs === "number" ? lineData.durationMs : undefined) ??
41
- lineData.trackingId?.trim(),
42
- );
43
- }
44
-
45
- function buildLineMediaMessageObject(
46
- resolved: LineOutboundMediaResolved,
47
- opts?: { allowTrackingId?: boolean },
48
- ): Record<string, unknown> {
49
- switch (resolved.mediaKind) {
50
- case "video": {
51
- const previewImageUrl = resolved.previewImageUrl?.trim();
52
- if (!previewImageUrl) {
53
- throw new Error("LINE video messages require previewImageUrl to reference an image URL");
54
- }
55
- return {
56
- type: "video",
57
- originalContentUrl: resolved.mediaUrl,
58
- previewImageUrl,
59
- ...(opts?.allowTrackingId && resolved.trackingId
60
- ? { trackingId: resolved.trackingId }
61
- : {}),
62
- };
63
- }
64
- case "audio":
65
- return {
66
- type: "audio",
67
- originalContentUrl: resolved.mediaUrl,
68
- duration: resolved.durationMs ?? 60000,
69
- };
70
- default:
71
- return {
72
- type: "image",
73
- originalContentUrl: resolved.mediaUrl,
74
- previewImageUrl: resolved.previewImageUrl ?? resolved.mediaUrl,
75
- };
76
- }
77
- }
78
-
79
- export const lineOutboundAdapter: NonNullable<ChannelPlugin<ResolvedLineAccount>["outbound"]> = {
80
- deliveryMode: "direct",
81
- chunker: (text, limit) => getLineRuntime().channel.text.chunkMarkdownText(text, limit),
82
- textChunkLimit: 5000,
83
- sendPayload: async ({ to, payload, accountId, cfg }) => {
84
- const runtime = getLineRuntime();
85
- const outboundRuntime = await loadLineOutboundRuntime();
86
- const lineData = (payload.channelData?.line as LineChannelDataWithMedia | undefined) ?? {};
87
- const lineRuntime = runtime.channel.line;
88
- const sendText = lineRuntime?.pushMessageLine ?? outboundRuntime.pushMessageLine;
89
- const sendBatch = lineRuntime?.pushMessagesLine ?? outboundRuntime.pushMessagesLine;
90
- const sendFlex = lineRuntime?.pushFlexMessage ?? outboundRuntime.pushFlexMessage;
91
- const sendTemplate = lineRuntime?.pushTemplateMessage ?? outboundRuntime.pushTemplateMessage;
92
- const sendLocation = lineRuntime?.pushLocationMessage ?? outboundRuntime.pushLocationMessage;
93
- const sendQuickReplies =
94
- lineRuntime?.pushTextMessageWithQuickReplies ??
95
- outboundRuntime.pushTextMessageWithQuickReplies;
96
- const buildTemplate =
97
- lineRuntime?.buildTemplateMessageFromPayload ??
98
- outboundRuntime.buildTemplateMessageFromPayload;
99
-
100
- let lastResult: LineSendResult | null = null;
101
- const quickReplies = lineData.quickReplies ?? [];
102
- const hasQuickReplies = quickReplies.length > 0;
103
- const quickReply = hasQuickReplies
104
- ? (lineRuntime?.createQuickReplyItems ?? outboundRuntime.createQuickReplyItems)(quickReplies)
105
- : undefined;
106
-
107
- // LINE SDK expects Message[] but we build dynamically.
108
- const sendMessageBatch = async (messages: Array<Record<string, unknown>>) => {
109
- if (messages.length === 0) {
110
- return;
111
- }
112
- for (let i = 0; i < messages.length; i += 5) {
113
- const batch = messages.slice(i, i + 5) as unknown as Parameters<typeof sendBatch>[1];
114
- const result = await sendBatch(to, batch, {
115
- verbose: false,
116
- cfg,
117
- accountId: accountId ?? undefined,
118
- });
119
- lastResult = result;
120
- }
121
- };
122
-
123
- const processed = payload.text
124
- ? outboundRuntime.processLineMessage(payload.text)
125
- : { text: "", flexMessages: [] };
126
-
127
- const chunkLimit =
128
- runtime.channel.text.resolveTextChunkLimit?.(cfg, "line", accountId ?? undefined, {
129
- fallbackLimit: 5000,
130
- }) ?? 5000;
131
-
132
- const chunks = processed.text
133
- ? runtime.channel.text.chunkMarkdownText(processed.text, chunkLimit)
134
- : [];
135
- const mediaUrls = resolveOutboundMediaUrls(payload);
136
- const useLineSpecificMedia = hasLineSpecificMediaOptions(lineData);
137
- const shouldSendQuickRepliesInline = chunks.length === 0 && hasQuickReplies;
138
- const sendMediaMessages = async () => {
139
- for (const url of mediaUrls) {
140
- const trimmed = url?.trim();
141
- if (!trimmed) {
142
- continue;
143
- }
144
- if (!useLineSpecificMedia) {
145
- lastResult = await (lineRuntime?.sendMessageLine ?? outboundRuntime.sendMessageLine)(
146
- to,
147
- "",
148
- {
149
- verbose: false,
150
- mediaUrl: trimmed,
151
- cfg,
152
- accountId: accountId ?? undefined,
153
- },
154
- );
155
- continue;
156
- }
157
- const resolved = await resolveLineOutboundMedia(trimmed, {
158
- mediaKind: lineData.mediaKind,
159
- previewImageUrl: lineData.previewImageUrl,
160
- durationMs: lineData.durationMs,
161
- trackingId: lineData.trackingId,
162
- });
163
- lastResult = await (lineRuntime?.sendMessageLine ?? outboundRuntime.sendMessageLine)(
164
- to,
165
- "",
166
- {
167
- verbose: false,
168
- mediaUrl: resolved.mediaUrl,
169
- mediaKind: resolved.mediaKind,
170
- previewImageUrl: resolved.previewImageUrl,
171
- durationMs: resolved.durationMs,
172
- trackingId: resolved.trackingId,
173
- cfg,
174
- accountId: accountId ?? undefined,
175
- },
176
- );
177
- }
178
- };
179
-
180
- if (!shouldSendQuickRepliesInline) {
181
- if (lineData.flexMessage) {
182
- const flexContents = lineData.flexMessage.contents as Parameters<typeof sendFlex>[2];
183
- lastResult = await sendFlex(to, lineData.flexMessage.altText, flexContents, {
184
- verbose: false,
185
- cfg,
186
- accountId: accountId ?? undefined,
187
- });
188
- }
189
-
190
- if (lineData.templateMessage) {
191
- const template = buildTemplate(lineData.templateMessage);
192
- if (template) {
193
- lastResult = await sendTemplate(to, template, {
194
- verbose: false,
195
- cfg,
196
- accountId: accountId ?? undefined,
197
- });
198
- }
199
- }
200
-
201
- if (lineData.location) {
202
- lastResult = await sendLocation(to, lineData.location, {
203
- verbose: false,
204
- cfg,
205
- accountId: accountId ?? undefined,
206
- });
207
- }
208
-
209
- for (const flexMsg of processed.flexMessages) {
210
- const flexContents = flexMsg.contents;
211
- lastResult = await sendFlex(to, flexMsg.altText, flexContents, {
212
- verbose: false,
213
- cfg,
214
- accountId: accountId ?? undefined,
215
- });
216
- }
217
- }
218
-
219
- const sendMediaAfterText = !(hasQuickReplies && chunks.length > 0);
220
- if (mediaUrls.length > 0 && !shouldSendQuickRepliesInline && !sendMediaAfterText) {
221
- await sendMediaMessages();
222
- }
223
-
224
- if (chunks.length > 0) {
225
- for (let i = 0; i < chunks.length; i += 1) {
226
- const isLast = i === chunks.length - 1;
227
- if (isLast && hasQuickReplies) {
228
- lastResult = await sendQuickReplies(to, chunks[i], quickReplies, {
229
- verbose: false,
230
- cfg,
231
- accountId: accountId ?? undefined,
232
- });
233
- } else {
234
- lastResult = await sendText(to, chunks[i], {
235
- verbose: false,
236
- cfg,
237
- accountId: accountId ?? undefined,
238
- });
239
- }
240
- }
241
- } else if (shouldSendQuickRepliesInline) {
242
- const quickReplyMessages: Array<Record<string, unknown>> = [];
243
- if (lineData.flexMessage) {
244
- quickReplyMessages.push({
245
- type: "flex",
246
- altText: lineData.flexMessage.altText.slice(0, 400),
247
- contents: lineData.flexMessage.contents,
248
- });
249
- }
250
- if (lineData.templateMessage) {
251
- const template = buildTemplate(lineData.templateMessage);
252
- if (template) {
253
- quickReplyMessages.push(template);
254
- }
255
- }
256
- if (lineData.location) {
257
- quickReplyMessages.push({
258
- type: "location",
259
- title: lineData.location.title.slice(0, 100),
260
- address: lineData.location.address.slice(0, 100),
261
- latitude: lineData.location.latitude,
262
- longitude: lineData.location.longitude,
263
- });
264
- }
265
- for (const flexMsg of processed.flexMessages) {
266
- quickReplyMessages.push({
267
- type: "flex",
268
- altText: flexMsg.altText.slice(0, 400),
269
- contents: flexMsg.contents,
270
- });
271
- }
272
- for (const url of mediaUrls) {
273
- const trimmed = url?.trim();
274
- if (!trimmed) {
275
- continue;
276
- }
277
- if (!useLineSpecificMedia) {
278
- quickReplyMessages.push({
279
- type: "image",
280
- originalContentUrl: trimmed,
281
- previewImageUrl: trimmed,
282
- });
283
- continue;
284
- }
285
- const resolved = await resolveLineOutboundMedia(trimmed, {
286
- mediaKind: lineData.mediaKind,
287
- previewImageUrl: lineData.previewImageUrl,
288
- durationMs: lineData.durationMs,
289
- trackingId: lineData.trackingId,
290
- });
291
- quickReplyMessages.push(
292
- buildLineMediaMessageObject(resolved, { allowTrackingId: isLineUserTarget(to) }),
293
- );
294
- }
295
- if (quickReplyMessages.length > 0 && quickReply) {
296
- const lastIndex = quickReplyMessages.length - 1;
297
- quickReplyMessages[lastIndex] = {
298
- ...quickReplyMessages[lastIndex],
299
- quickReply,
300
- };
301
- await sendMessageBatch(quickReplyMessages);
302
- } else if (quickReply) {
303
- lastResult = await sendQuickReplies(
304
- to,
305
- buildLineQuickReplyFallbackText(quickReplies),
306
- quickReplies,
307
- {
308
- verbose: false,
309
- cfg,
310
- accountId: accountId ?? undefined,
311
- },
312
- );
313
- }
314
- }
315
-
316
- if (mediaUrls.length > 0 && !shouldSendQuickRepliesInline && sendMediaAfterText) {
317
- await sendMediaMessages();
318
- }
319
-
320
- if (lastResult) {
321
- return createEmptyChannelResult("line", { ...lastResult });
322
- }
323
- return createEmptyChannelResult("line", { messageId: "empty", chatId: to });
324
- },
325
- ...createAttachedChannelResultAdapter({
326
- channel: "line",
327
- sendText: async ({ cfg, to, text, accountId }) => {
328
- const outboundRuntime = await loadLineOutboundRuntime();
329
- const sendText = outboundRuntime.pushMessageLine;
330
- const sendFlex = outboundRuntime.pushFlexMessage;
331
- const processed = outboundRuntime.processLineMessage(text);
332
- let result: LineSendResult;
333
- if (processed.text.trim()) {
334
- result = await sendText(to, processed.text, {
335
- verbose: false,
336
- cfg,
337
- accountId: accountId ?? undefined,
338
- });
339
- } else {
340
- result = {
341
- messageId: "processed",
342
- chatId: to,
343
- receipt: createLineSendReceipt({ messageId: "processed", chatId: to, kind: "card" }),
344
- };
345
- }
346
- for (const flexMsg of processed.flexMessages) {
347
- const flexContents = flexMsg.contents;
348
- await sendFlex(to, flexMsg.altText, flexContents, {
349
- verbose: false,
350
- cfg,
351
- accountId: accountId ?? undefined,
352
- });
353
- }
354
- return result;
355
- },
356
- sendMedia: async ({ cfg, to, text, mediaUrl, accountId }) =>
357
- await (
358
- await loadLineOutboundRuntime()
359
- ).sendMessageLine(to, text, {
360
- verbose: false,
361
- mediaUrl,
362
- cfg,
363
- accountId: accountId ?? undefined,
364
- }),
365
- }),
366
- };
367
-
368
- function toLineMessageSendResult(
369
- result: Awaited<ReturnType<NonNullable<typeof lineOutboundAdapter.sendPayload>>>,
370
- kind: MessageReceiptPartKind,
371
- ): ChannelMessageSendResult {
372
- const source = result as typeof result & { chatId?: string };
373
- const receipt =
374
- result.receipt ??
375
- (result.messageId
376
- ? createLineSendReceipt({
377
- messageId: result.messageId,
378
- chatId: source.chatId ?? "",
379
- kind,
380
- })
381
- : undefined);
382
- if (!receipt) {
383
- throw new Error("LINE message adapter send did not return a receipt");
384
- }
385
- return {
386
- messageId: result.messageId || receipt.primaryPlatformMessageId,
387
- receipt,
388
- };
389
- }
390
-
391
- export const lineMessageAdapter = defineChannelMessageAdapter({
392
- id: "line",
393
- durableFinal: {
394
- capabilities: {
395
- text: true,
396
- media: true,
397
- messageSendingHooks: true,
398
- },
399
- },
400
- send: {
401
- text: async ({ cfg, to, text, accountId }) => {
402
- const result = await lineOutboundAdapter.sendPayload!({
403
- cfg,
404
- to,
405
- text,
406
- accountId,
407
- payload: { text },
408
- });
409
- return toLineMessageSendResult(result, "text");
410
- },
411
- media: async ({ cfg, to, text, mediaUrl, accountId }) => {
412
- const result = await lineOutboundAdapter.sendPayload!({
413
- cfg,
414
- to,
415
- text,
416
- mediaUrl,
417
- accountId,
418
- payload: { text, mediaUrl },
419
- });
420
- return toLineMessageSendResult(result, "media");
421
- },
422
- },
423
- receive: {
424
- defaultAckPolicy: "after_receive_record",
425
- supportedAckPolicies: ["after_receive_record"],
426
- },
427
- });
@@ -1,9 +0,0 @@
1
- import type { BaseProbeResult } from "klaw/plugin-sdk/channel-contract";
2
- import { describe, expectTypeOf, it } from "vitest";
3
- import type { LineProbeResult } from "./types.js";
4
-
5
- describe("LINE probe contract", () => {
6
- it("keeps public probe aligned with base contract", () => {
7
- expectTypeOf<LineProbeResult>().toMatchTypeOf<BaseProbeResult>();
8
- });
9
- });
@@ -1 +0,0 @@
1
- export { probeLineBot } from "./probe.js";
package/src/probe.ts DELETED
@@ -1,34 +0,0 @@
1
- import { messagingApi } from "@line/bot-sdk";
2
- import { formatErrorMessage } from "klaw/plugin-sdk/error-runtime";
3
- import { withTimeout } from "klaw/plugin-sdk/text-utility-runtime";
4
- import type { LineProbeResult } from "./types.js";
5
-
6
- export async function probeLineBot(
7
- channelAccessToken: string,
8
- timeoutMs = 5000,
9
- ): Promise<LineProbeResult> {
10
- if (!channelAccessToken?.trim()) {
11
- return { ok: false, error: "Channel access token not configured" };
12
- }
13
-
14
- const client = new messagingApi.MessagingApiClient({
15
- channelAccessToken: channelAccessToken.trim(),
16
- });
17
-
18
- try {
19
- const profile = await withTimeout(client.getBotInfo(), timeoutMs);
20
-
21
- return {
22
- ok: true,
23
- bot: {
24
- displayName: profile.displayName,
25
- userId: profile.userId,
26
- basicId: profile.basicId,
27
- pictureUrl: profile.pictureUrl,
28
- },
29
- };
30
- } catch (err) {
31
- const message = formatErrorMessage(err);
32
- return { ok: false, error: message };
33
- }
34
- }
@@ -1,10 +0,0 @@
1
- export function buildLineQuickReplyFallbackText(labels: readonly string[] | undefined): string {
2
- const normalized = (labels ?? [])
3
- .map((label) => label.trim())
4
- .filter(Boolean)
5
- .slice(0, 13);
6
- if (normalized.length === 0) {
7
- return "Choose an option.";
8
- }
9
- return `Options:\n${normalized.map((label) => `- ${label}`).join("\n")}`;
10
- }