@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,253 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import type { LineAutoReplyDeps } from "./auto-reply-delivery.js";
3
- import { deliverLineAutoReply } from "./auto-reply-delivery.js";
4
- import { sendLineReplyChunks } from "./reply-chunks.js";
5
- import { createLineSendReceipt } from "./send-receipt.js";
6
-
7
- const createFlexMessage = (altText: string, contents: unknown) => ({
8
- type: "flex" as const,
9
- altText,
10
- contents,
11
- });
12
-
13
- const createImageMessage = (url: string) => ({
14
- type: "image" as const,
15
- originalContentUrl: url,
16
- previewImageUrl: url,
17
- });
18
-
19
- const createLocationMessage = (location: {
20
- title: string;
21
- address: string;
22
- latitude: number;
23
- longitude: number;
24
- }) => ({
25
- type: "location" as const,
26
- ...location,
27
- });
28
-
29
- describe("deliverLineAutoReply", () => {
30
- const LINE_TEST_CFG = { channels: { line: { accounts: { acc: {} } } } };
31
- const baseDeliveryParams = {
32
- cfg: LINE_TEST_CFG,
33
- to: "line:user:1",
34
- replyToken: "token",
35
- replyTokenUsed: false,
36
- accountId: "acc",
37
- textLimit: 5000,
38
- };
39
-
40
- function createDeps(overrides?: Partial<LineAutoReplyDeps>) {
41
- const replyMessageLine = vi.fn(async () => ({}));
42
- const pushMessageLine = vi.fn(async () => ({}));
43
- const pushTextMessageWithQuickReplies = vi.fn(async () => ({}));
44
- const createTextMessageWithQuickReplies = vi.fn((text: string) => ({
45
- type: "text" as const,
46
- text,
47
- }));
48
- const createQuickReplyItems = vi.fn((labels: string[]) => ({ items: labels }));
49
- const pushMessagesLine = vi.fn(async () => ({
50
- messageId: "push",
51
- chatId: "u1",
52
- receipt: createLineSendReceipt({ messageId: "push", chatId: "u1", kind: "text" }),
53
- }));
54
-
55
- const deps: LineAutoReplyDeps = {
56
- buildTemplateMessageFromPayload: () => null,
57
- processLineMessage: (text) => ({ text, flexMessages: [] }),
58
- chunkMarkdownText: (text) => [text],
59
- sendLineReplyChunks,
60
- replyMessageLine,
61
- pushMessageLine,
62
- pushTextMessageWithQuickReplies,
63
- createTextMessageWithQuickReplies,
64
- createQuickReplyItems: createQuickReplyItems as LineAutoReplyDeps["createQuickReplyItems"],
65
- pushMessagesLine,
66
- createFlexMessage: createFlexMessage as LineAutoReplyDeps["createFlexMessage"],
67
- createImageMessage,
68
- createLocationMessage,
69
- ...overrides,
70
- };
71
-
72
- return {
73
- deps,
74
- replyMessageLine,
75
- pushMessageLine,
76
- pushTextMessageWithQuickReplies,
77
- createTextMessageWithQuickReplies,
78
- createQuickReplyItems,
79
- pushMessagesLine,
80
- };
81
- }
82
-
83
- it("uses reply token for text before sending rich messages", async () => {
84
- const lineData = {
85
- flexMessage: { altText: "Card", contents: { type: "bubble" } },
86
- };
87
- const { deps, replyMessageLine, pushMessagesLine, createQuickReplyItems } = createDeps();
88
-
89
- const result = await deliverLineAutoReply({
90
- ...baseDeliveryParams,
91
- payload: { text: "hello", channelData: { line: lineData } },
92
- lineData,
93
- deps,
94
- });
95
-
96
- expect(result.replyTokenUsed).toBe(true);
97
- expect(replyMessageLine).toHaveBeenCalledTimes(1);
98
- expect(replyMessageLine).toHaveBeenCalledWith("token", [{ type: "text", text: "hello" }], {
99
- cfg: LINE_TEST_CFG,
100
- accountId: "acc",
101
- });
102
- expect(pushMessagesLine).toHaveBeenCalledTimes(1);
103
- expect(pushMessagesLine).toHaveBeenCalledWith(
104
- "line:user:1",
105
- [createFlexMessage("Card", { type: "bubble" })],
106
- { cfg: LINE_TEST_CFG, accountId: "acc" },
107
- );
108
- expect(createQuickReplyItems).not.toHaveBeenCalled();
109
- });
110
-
111
- it("uses reply token for rich-only payloads", async () => {
112
- const lineData = {
113
- flexMessage: { altText: "Card", contents: { type: "bubble" } },
114
- quickReplies: ["A"],
115
- };
116
- const { deps, replyMessageLine, pushMessagesLine, createQuickReplyItems } = createDeps({
117
- processLineMessage: () => ({ text: "", flexMessages: [] }),
118
- chunkMarkdownText: () => [],
119
- sendLineReplyChunks: vi.fn(async () => ({ replyTokenUsed: false })),
120
- });
121
-
122
- const result = await deliverLineAutoReply({
123
- ...baseDeliveryParams,
124
- payload: { channelData: { line: lineData } },
125
- lineData,
126
- deps,
127
- });
128
-
129
- expect(result.replyTokenUsed).toBe(true);
130
- expect(replyMessageLine).toHaveBeenCalledTimes(1);
131
- expect(replyMessageLine).toHaveBeenCalledWith(
132
- "token",
133
- [
134
- {
135
- ...createFlexMessage("Card", { type: "bubble" }),
136
- quickReply: { items: ["A"] },
137
- },
138
- ],
139
- { cfg: LINE_TEST_CFG, accountId: "acc" },
140
- );
141
- expect(pushMessagesLine).not.toHaveBeenCalled();
142
- expect(createQuickReplyItems).toHaveBeenCalledWith(["A"]);
143
- });
144
-
145
- it("uses fallback text for quick-reply-only payloads", async () => {
146
- const createTextMessageWithQuickReplies = vi.fn((text: string, _quickReplies: string[]) => ({
147
- type: "text" as const,
148
- text,
149
- quickReply: { items: ["A", "B"] },
150
- }));
151
- const lineData = {
152
- quickReplies: ["A", "B"],
153
- };
154
- const { deps, replyMessageLine, pushMessagesLine } = createDeps({
155
- createTextMessageWithQuickReplies:
156
- createTextMessageWithQuickReplies as LineAutoReplyDeps["createTextMessageWithQuickReplies"],
157
- });
158
-
159
- const result = await deliverLineAutoReply({
160
- ...baseDeliveryParams,
161
- payload: { text: "", channelData: { line: lineData } },
162
- lineData,
163
- deps,
164
- });
165
-
166
- expect(result.replyTokenUsed).toBe(true);
167
- expect(replyMessageLine).toHaveBeenCalledWith(
168
- "token",
169
- [
170
- {
171
- type: "text",
172
- text: "Options:\n- A\n- B",
173
- quickReply: { items: ["A", "B"] },
174
- },
175
- ],
176
- { cfg: LINE_TEST_CFG, accountId: "acc" },
177
- );
178
- expect(pushMessagesLine).not.toHaveBeenCalled();
179
- });
180
-
181
- it("sends rich messages before quick-reply text so quick replies remain visible", async () => {
182
- const createTextMessageWithQuickReplies = vi.fn((text: string, _quickReplies: string[]) => ({
183
- type: "text" as const,
184
- text,
185
- quickReply: { items: ["A"] },
186
- }));
187
-
188
- const lineData = {
189
- flexMessage: { altText: "Card", contents: { type: "bubble" } },
190
- quickReplies: ["A"],
191
- };
192
- const { deps, pushMessagesLine, replyMessageLine } = createDeps({
193
- createTextMessageWithQuickReplies:
194
- createTextMessageWithQuickReplies as LineAutoReplyDeps["createTextMessageWithQuickReplies"],
195
- });
196
-
197
- await deliverLineAutoReply({
198
- ...baseDeliveryParams,
199
- payload: { text: "hello", channelData: { line: lineData } },
200
- lineData,
201
- deps,
202
- });
203
-
204
- expect(pushMessagesLine).toHaveBeenCalledWith(
205
- "line:user:1",
206
- [createFlexMessage("Card", { type: "bubble" })],
207
- { cfg: LINE_TEST_CFG, accountId: "acc" },
208
- );
209
- expect(replyMessageLine).toHaveBeenCalledWith(
210
- "token",
211
- [
212
- {
213
- type: "text",
214
- text: "hello",
215
- quickReply: { items: ["A"] },
216
- },
217
- ],
218
- { cfg: LINE_TEST_CFG, accountId: "acc" },
219
- );
220
- const pushOrder = pushMessagesLine.mock.invocationCallOrder[0];
221
- const replyOrder = replyMessageLine.mock.invocationCallOrder[0];
222
- expect(pushOrder).toBeLessThan(replyOrder);
223
- });
224
-
225
- it("falls back to push when reply token delivery fails", async () => {
226
- const lineData = {
227
- flexMessage: { altText: "Card", contents: { type: "bubble" } },
228
- };
229
- const failingReplyMessageLine = vi.fn(async () => {
230
- throw new Error("reply failed");
231
- });
232
- const { deps, pushMessagesLine } = createDeps({
233
- processLineMessage: () => ({ text: "", flexMessages: [] }),
234
- chunkMarkdownText: () => [],
235
- replyMessageLine: failingReplyMessageLine as LineAutoReplyDeps["replyMessageLine"],
236
- });
237
-
238
- const result = await deliverLineAutoReply({
239
- ...baseDeliveryParams,
240
- payload: { channelData: { line: lineData } },
241
- lineData,
242
- deps,
243
- });
244
-
245
- expect(result.replyTokenUsed).toBe(true);
246
- expect(failingReplyMessageLine).toHaveBeenCalledTimes(1);
247
- expect(pushMessagesLine).toHaveBeenCalledWith(
248
- "line:user:1",
249
- [createFlexMessage("Card", { type: "bubble" })],
250
- { cfg: LINE_TEST_CFG, accountId: "acc" },
251
- );
252
- });
253
- });
@@ -1,200 +0,0 @@
1
- import type { messagingApi } from "@line/bot-sdk";
2
- import type { KlawConfig } from "klaw/plugin-sdk/config-contracts";
3
- import { resolveSendableOutboundReplyParts } from "klaw/plugin-sdk/reply-payload";
4
- import type { ReplyPayload } from "klaw/plugin-sdk/reply-runtime";
5
- import type { FlexContainer } from "./flex-templates.js";
6
- import type { ProcessedLineMessage } from "./markdown-to-line.js";
7
- import { buildLineQuickReplyFallbackText } from "./quick-reply-fallback.js";
8
- import type { SendLineReplyChunksParams } from "./reply-chunks.js";
9
- import type { LineChannelData, LineTemplateMessagePayload } from "./types.js";
10
-
11
- export type LineAutoReplyDeps = {
12
- buildTemplateMessageFromPayload: (
13
- payload: LineTemplateMessagePayload,
14
- ) => messagingApi.TemplateMessage | null;
15
- processLineMessage: (text: string) => ProcessedLineMessage;
16
- chunkMarkdownText: (text: string, limit: number) => string[];
17
- sendLineReplyChunks: (params: SendLineReplyChunksParams) => Promise<{ replyTokenUsed: boolean }>;
18
- createQuickReplyItems: (labels: string[]) => messagingApi.QuickReply;
19
- pushMessagesLine: (
20
- to: string,
21
- messages: messagingApi.Message[],
22
- opts: { cfg: KlawConfig; accountId?: string },
23
- ) => Promise<unknown>;
24
- createFlexMessage: (altText: string, contents: FlexContainer) => messagingApi.FlexMessage;
25
- createImageMessage: (
26
- originalContentUrl: string,
27
- previewImageUrl?: string,
28
- ) => messagingApi.ImageMessage;
29
- createLocationMessage: (location: {
30
- title: string;
31
- address: string;
32
- latitude: number;
33
- longitude: number;
34
- }) => messagingApi.LocationMessage;
35
- } & Pick<
36
- SendLineReplyChunksParams,
37
- | "replyMessageLine"
38
- | "pushMessageLine"
39
- | "pushTextMessageWithQuickReplies"
40
- | "createTextMessageWithQuickReplies"
41
- | "onReplyError"
42
- >;
43
-
44
- export async function deliverLineAutoReply(params: {
45
- payload: ReplyPayload;
46
- lineData: LineChannelData;
47
- to: string;
48
- replyToken?: string | null;
49
- replyTokenUsed: boolean;
50
- accountId?: string;
51
- cfg: KlawConfig;
52
- textLimit: number;
53
- deps: LineAutoReplyDeps;
54
- }): Promise<{ replyTokenUsed: boolean }> {
55
- const { payload, lineData, replyToken, accountId, to, textLimit, deps } = params;
56
- let replyTokenUsed = params.replyTokenUsed;
57
-
58
- const pushLineMessages = async (messages: messagingApi.Message[]): Promise<void> => {
59
- if (messages.length === 0) {
60
- return;
61
- }
62
- for (let i = 0; i < messages.length; i += 5) {
63
- await deps.pushMessagesLine(to, messages.slice(i, i + 5), {
64
- cfg: params.cfg,
65
- accountId,
66
- });
67
- }
68
- };
69
-
70
- const sendLineMessages = async (
71
- messages: messagingApi.Message[],
72
- allowReplyToken: boolean,
73
- ): Promise<void> => {
74
- if (messages.length === 0) {
75
- return;
76
- }
77
-
78
- let remaining = messages;
79
- if (allowReplyToken && replyToken && !replyTokenUsed) {
80
- const replyBatch = remaining.slice(0, 5);
81
- try {
82
- await deps.replyMessageLine(replyToken, replyBatch, {
83
- cfg: params.cfg,
84
- accountId,
85
- });
86
- } catch (err) {
87
- deps.onReplyError?.(err);
88
- await pushLineMessages(replyBatch);
89
- }
90
- replyTokenUsed = true;
91
- remaining = remaining.slice(replyBatch.length);
92
- }
93
-
94
- if (remaining.length > 0) {
95
- await pushLineMessages(remaining);
96
- }
97
- };
98
-
99
- const richMessages: messagingApi.Message[] = [];
100
- const hasQuickReplies = Boolean(lineData.quickReplies?.length);
101
-
102
- if (lineData.flexMessage) {
103
- richMessages.push(
104
- deps.createFlexMessage(
105
- lineData.flexMessage.altText.slice(0, 400),
106
- lineData.flexMessage.contents as FlexContainer,
107
- ),
108
- );
109
- }
110
-
111
- if (lineData.templateMessage) {
112
- const templateMsg = deps.buildTemplateMessageFromPayload(lineData.templateMessage);
113
- if (templateMsg) {
114
- richMessages.push(templateMsg);
115
- }
116
- }
117
-
118
- if (lineData.location) {
119
- richMessages.push(deps.createLocationMessage(lineData.location));
120
- }
121
-
122
- const processed = payload.text
123
- ? deps.processLineMessage(payload.text)
124
- : { text: "", flexMessages: [] };
125
-
126
- for (const flexMsg of processed.flexMessages) {
127
- richMessages.push(deps.createFlexMessage(flexMsg.altText.slice(0, 400), flexMsg.contents));
128
- }
129
-
130
- const chunks = processed.text ? deps.chunkMarkdownText(processed.text, textLimit) : [];
131
-
132
- const mediaUrls = resolveSendableOutboundReplyParts(payload).mediaUrls;
133
- const mediaMessages = mediaUrls
134
- .map((url) => url?.trim())
135
- .filter((url): url is string => Boolean(url))
136
- .map((url) => deps.createImageMessage(url));
137
-
138
- if (chunks.length > 0) {
139
- const hasRichOrMedia = richMessages.length > 0 || mediaMessages.length > 0;
140
- if (hasQuickReplies && hasRichOrMedia) {
141
- try {
142
- await sendLineMessages([...richMessages, ...mediaMessages], false);
143
- } catch (err) {
144
- deps.onReplyError?.(err);
145
- }
146
- }
147
- const { replyTokenUsed: nextReplyTokenUsed } = await deps.sendLineReplyChunks({
148
- to,
149
- chunks,
150
- quickReplies: lineData.quickReplies,
151
- replyToken,
152
- replyTokenUsed,
153
- cfg: params.cfg,
154
- accountId,
155
- replyMessageLine: deps.replyMessageLine,
156
- pushMessageLine: deps.pushMessageLine,
157
- pushTextMessageWithQuickReplies: deps.pushTextMessageWithQuickReplies,
158
- createTextMessageWithQuickReplies: deps.createTextMessageWithQuickReplies,
159
- });
160
- replyTokenUsed = nextReplyTokenUsed;
161
- if (!hasQuickReplies || !hasRichOrMedia) {
162
- await sendLineMessages(richMessages, false);
163
- if (mediaMessages.length > 0) {
164
- await sendLineMessages(mediaMessages, false);
165
- }
166
- }
167
- } else {
168
- const combined = [...richMessages, ...mediaMessages];
169
- if (hasQuickReplies && combined.length === 0) {
170
- const { replyTokenUsed: nextReplyTokenUsed } = await deps.sendLineReplyChunks({
171
- to,
172
- chunks: [buildLineQuickReplyFallbackText(lineData.quickReplies)],
173
- quickReplies: lineData.quickReplies,
174
- replyToken,
175
- replyTokenUsed,
176
- cfg: params.cfg,
177
- accountId,
178
- replyMessageLine: deps.replyMessageLine,
179
- pushMessageLine: deps.pushMessageLine,
180
- pushTextMessageWithQuickReplies: deps.pushTextMessageWithQuickReplies,
181
- createTextMessageWithQuickReplies: deps.createTextMessageWithQuickReplies,
182
- onReplyError: deps.onReplyError,
183
- });
184
- replyTokenUsed = nextReplyTokenUsed;
185
- } else {
186
- if (hasQuickReplies && combined.length > 0) {
187
- const quickReply = deps.createQuickReplyItems(lineData.quickReplies!);
188
- const targetIndex =
189
- replyToken && !replyTokenUsed ? Math.min(4, combined.length - 1) : combined.length - 1;
190
- const target = combined[targetIndex] as messagingApi.Message & {
191
- quickReply?: messagingApi.QuickReply;
192
- };
193
- combined[targetIndex] = { ...target, quickReply };
194
- }
195
- await sendLineMessages(combined, true);
196
- }
197
- }
198
-
199
- return { replyTokenUsed };
200
- }
package/src/bindings.ts DELETED
@@ -1,65 +0,0 @@
1
- function normalizeLineConversationId(raw?: string | null): string | null {
2
- const trimmed = raw?.trim() ?? "";
3
- if (!trimmed) {
4
- return null;
5
- }
6
- const prefixed = trimmed.match(/^line:(?:(?:user|group|room):)?(.+)$/i)?.[1];
7
- return (prefixed ?? trimmed).trim() || null;
8
- }
9
-
10
- function resolveLineCommandConversation(params: {
11
- originatingTo?: string;
12
- commandTo?: string;
13
- fallbackTo?: string;
14
- }) {
15
- const conversationId =
16
- normalizeLineConversationId(params.originatingTo) ??
17
- normalizeLineConversationId(params.commandTo) ??
18
- normalizeLineConversationId(params.fallbackTo);
19
- return conversationId ? { conversationId } : null;
20
- }
21
-
22
- function resolveLineInboundConversation(params: { to?: string; conversationId?: string }) {
23
- const conversationId =
24
- normalizeLineConversationId(params.conversationId) ?? normalizeLineConversationId(params.to);
25
- return conversationId ? { conversationId } : null;
26
- }
27
-
28
- export const lineBindingsAdapter = {
29
- compileConfiguredBinding: ({ conversationId }: { conversationId?: string }) => {
30
- const normalized = normalizeLineConversationId(conversationId);
31
- return normalized ? { conversationId: normalized } : null;
32
- },
33
- matchInboundConversation: ({
34
- compiledBinding,
35
- conversationId,
36
- }: {
37
- compiledBinding: { conversationId: string };
38
- conversationId?: string;
39
- }) => {
40
- const normalizedIncoming = normalizeLineConversationId(conversationId);
41
- if (!normalizedIncoming || compiledBinding.conversationId !== normalizedIncoming) {
42
- return null;
43
- }
44
- return {
45
- conversationId: normalizedIncoming,
46
- matchPriority: 2,
47
- };
48
- },
49
- resolveCommandConversation: ({
50
- originatingTo,
51
- commandTo,
52
- fallbackTo,
53
- }: {
54
- originatingTo?: string;
55
- commandTo?: string;
56
- fallbackTo?: string;
57
- }) =>
58
- resolveLineCommandConversation({
59
- originatingTo,
60
- commandTo,
61
- fallbackTo,
62
- }),
63
- resolveInboundConversation: ({ to, conversationId }: { to?: string; conversationId?: string }) =>
64
- resolveLineInboundConversation({ to, conversationId }),
65
- };
package/src/bot-access.ts DELETED
@@ -1,30 +0,0 @@
1
- import { firstDefined } from "klaw/plugin-sdk/allow-from";
2
-
3
- export type NormalizedAllowFrom = {
4
- entries: string[];
5
- hasWildcard: boolean;
6
- hasEntries: boolean;
7
- };
8
-
9
- export function normalizeLineAllowEntry(value: string | number): string {
10
- const trimmed = String(value).trim();
11
- if (!trimmed) {
12
- return "";
13
- }
14
- if (trimmed === "*") {
15
- return "*";
16
- }
17
- return trimmed.replace(/^line:(?:user:)?/i, "");
18
- }
19
-
20
- export const normalizeAllowFrom = (list?: Array<string | number>): NormalizedAllowFrom => {
21
- const entries = (list ?? []).map((value) => normalizeLineAllowEntry(value)).filter(Boolean);
22
- const hasWildcard = entries.includes("*");
23
- return {
24
- entries,
25
- hasWildcard,
26
- hasEntries: entries.length > 0,
27
- };
28
- };
29
-
30
- export { firstDefined };