@openclaw/line 2026.5.2-beta.2 → 2026.5.3-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/accounts-UXAvdBo_.js +105 -0
  2. package/dist/api.js +11 -0
  3. package/dist/basic-cards-7DTG6E-A.js +307 -0
  4. package/dist/card-command-UlPc6Vuc.js +240 -0
  5. package/dist/channel-Rls9s60K.js +601 -0
  6. package/dist/channel-plugin-api.js +2 -0
  7. package/dist/channel.runtime-bXoj8_Sl.js +4 -0
  8. package/dist/contract-api.js +2 -0
  9. package/dist/index.js +45 -0
  10. package/dist/markdown-to-line-CCWK6PJh.js +789 -0
  11. package/dist/monitor-B4_RxHc0.js +1523 -0
  12. package/dist/monitor.runtime-DyxYlrM9.js +2 -0
  13. package/dist/outbound-media-BfhBmWq5.js +55 -0
  14. package/dist/outbound.runtime-B-luYwEB.js +2 -0
  15. package/dist/probe-D9BPzb2n.js +30 -0
  16. package/dist/probe.runtime-N91OWW1J.js +2 -0
  17. package/dist/quick-reply-fallback-HskUUWsn.js +55 -0
  18. package/dist/reply-payload-transform-CFGTs9ln.js +713 -0
  19. package/dist/runtime-api.js +277 -0
  20. package/dist/schedule-cards-BwQChTdM.js +359 -0
  21. package/dist/secret-contract-api.js +5 -0
  22. package/dist/setup-api.js +2 -0
  23. package/dist/setup-entry.js +11 -0
  24. package/dist/setup-surface-DCH7CE-y.js +281 -0
  25. package/package.json +14 -6
  26. package/api.ts +0 -11
  27. package/channel-plugin-api.ts +0 -1
  28. package/contract-api.ts +0 -5
  29. package/index.ts +0 -54
  30. package/runtime-api.ts +0 -187
  31. package/secret-contract-api.ts +0 -4
  32. package/setup-api.ts +0 -2
  33. package/setup-entry.ts +0 -9
  34. package/src/account-helpers.ts +0 -16
  35. package/src/accounts.test.ts +0 -290
  36. package/src/accounts.ts +0 -187
  37. package/src/actions.ts +0 -61
  38. package/src/auto-reply-delivery.test.ts +0 -248
  39. package/src/auto-reply-delivery.ts +0 -200
  40. package/src/bindings.ts +0 -65
  41. package/src/bot-access.ts +0 -48
  42. package/src/bot-handlers.test.ts +0 -1089
  43. package/src/bot-handlers.ts +0 -642
  44. package/src/bot-message-context.test.ts +0 -405
  45. package/src/bot-message-context.ts +0 -581
  46. package/src/bot.ts +0 -70
  47. package/src/card-command.ts +0 -347
  48. package/src/channel-access-token.ts +0 -14
  49. package/src/channel-api.ts +0 -17
  50. package/src/channel-setup-status.contract.test.ts +0 -70
  51. package/src/channel-shared.ts +0 -48
  52. package/src/channel.logout.test.ts +0 -145
  53. package/src/channel.runtime.ts +0 -3
  54. package/src/channel.sendPayload.test.ts +0 -514
  55. package/src/channel.setup.ts +0 -11
  56. package/src/channel.status.test.ts +0 -63
  57. package/src/channel.ts +0 -154
  58. package/src/config-adapter.ts +0 -29
  59. package/src/config-schema.ts +0 -57
  60. package/src/download.test.ts +0 -133
  61. package/src/download.ts +0 -87
  62. package/src/flex-templates/basic-cards.ts +0 -395
  63. package/src/flex-templates/common.ts +0 -20
  64. package/src/flex-templates/media-control-cards.ts +0 -555
  65. package/src/flex-templates/message.ts +0 -13
  66. package/src/flex-templates/schedule-cards.ts +0 -467
  67. package/src/flex-templates/types.ts +0 -22
  68. package/src/flex-templates.ts +0 -32
  69. package/src/gateway.ts +0 -129
  70. package/src/group-keys.test.ts +0 -123
  71. package/src/group-keys.ts +0 -65
  72. package/src/group-policy.ts +0 -22
  73. package/src/markdown-to-line.test.ts +0 -348
  74. package/src/markdown-to-line.ts +0 -416
  75. package/src/message-cards.test.ts +0 -204
  76. package/src/monitor.lifecycle.test.ts +0 -421
  77. package/src/monitor.runtime.ts +0 -1
  78. package/src/monitor.ts +0 -506
  79. package/src/outbound-media.test.ts +0 -189
  80. package/src/outbound-media.ts +0 -120
  81. package/src/outbound.runtime.ts +0 -12
  82. package/src/outbound.ts +0 -356
  83. package/src/probe.contract.test.ts +0 -9
  84. package/src/probe.runtime.ts +0 -1
  85. package/src/probe.ts +0 -34
  86. package/src/quick-reply-fallback.ts +0 -10
  87. package/src/reply-chunks.test.ts +0 -179
  88. package/src/reply-chunks.ts +0 -110
  89. package/src/reply-payload-transform.test.ts +0 -387
  90. package/src/reply-payload-transform.ts +0 -317
  91. package/src/rich-menu.test.ts +0 -310
  92. package/src/rich-menu.ts +0 -326
  93. package/src/runtime.ts +0 -32
  94. package/src/send.test.ts +0 -346
  95. package/src/send.ts +0 -489
  96. package/src/setup-core.ts +0 -149
  97. package/src/setup-runtime-api.ts +0 -9
  98. package/src/setup-surface.test.ts +0 -474
  99. package/src/setup-surface.ts +0 -227
  100. package/src/signature.test.ts +0 -34
  101. package/src/signature.ts +0 -24
  102. package/src/status.ts +0 -37
  103. package/src/template-messages.ts +0 -333
  104. package/src/types.ts +0 -128
  105. package/src/webhook-node.test.ts +0 -513
  106. package/src/webhook-node.ts +0 -131
  107. package/src/webhook-utils.ts +0 -10
  108. package/src/webhook.ts +0 -111
  109. package/tsconfig.json +0 -16
@@ -1,248 +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
-
6
- const createFlexMessage = (altText: string, contents: unknown) => ({
7
- type: "flex" as const,
8
- altText,
9
- contents,
10
- });
11
-
12
- const createImageMessage = (url: string) => ({
13
- type: "image" as const,
14
- originalContentUrl: url,
15
- previewImageUrl: url,
16
- });
17
-
18
- const createLocationMessage = (location: {
19
- title: string;
20
- address: string;
21
- latitude: number;
22
- longitude: number;
23
- }) => ({
24
- type: "location" as const,
25
- ...location,
26
- });
27
-
28
- describe("deliverLineAutoReply", () => {
29
- const LINE_TEST_CFG = { channels: { line: { accounts: { acc: {} } } } };
30
- const baseDeliveryParams = {
31
- cfg: LINE_TEST_CFG,
32
- to: "line:user:1",
33
- replyToken: "token",
34
- replyTokenUsed: false,
35
- accountId: "acc",
36
- textLimit: 5000,
37
- };
38
-
39
- function createDeps(overrides?: Partial<LineAutoReplyDeps>) {
40
- const replyMessageLine = vi.fn(async () => ({}));
41
- const pushMessageLine = vi.fn(async () => ({}));
42
- const pushTextMessageWithQuickReplies = vi.fn(async () => ({}));
43
- const createTextMessageWithQuickReplies = vi.fn((text: string) => ({
44
- type: "text" as const,
45
- text,
46
- }));
47
- const createQuickReplyItems = vi.fn((labels: string[]) => ({ items: labels }));
48
- const pushMessagesLine = vi.fn(async () => ({ messageId: "push", chatId: "u1" }));
49
-
50
- const deps: LineAutoReplyDeps = {
51
- buildTemplateMessageFromPayload: () => null,
52
- processLineMessage: (text) => ({ text, flexMessages: [] }),
53
- chunkMarkdownText: (text) => [text],
54
- sendLineReplyChunks,
55
- replyMessageLine,
56
- pushMessageLine,
57
- pushTextMessageWithQuickReplies,
58
- createTextMessageWithQuickReplies,
59
- createQuickReplyItems: createQuickReplyItems as LineAutoReplyDeps["createQuickReplyItems"],
60
- pushMessagesLine,
61
- createFlexMessage: createFlexMessage as LineAutoReplyDeps["createFlexMessage"],
62
- createImageMessage,
63
- createLocationMessage,
64
- ...overrides,
65
- };
66
-
67
- return {
68
- deps,
69
- replyMessageLine,
70
- pushMessageLine,
71
- pushTextMessageWithQuickReplies,
72
- createTextMessageWithQuickReplies,
73
- createQuickReplyItems,
74
- pushMessagesLine,
75
- };
76
- }
77
-
78
- it("uses reply token for text before sending rich messages", async () => {
79
- const lineData = {
80
- flexMessage: { altText: "Card", contents: { type: "bubble" } },
81
- };
82
- const { deps, replyMessageLine, pushMessagesLine, createQuickReplyItems } = createDeps();
83
-
84
- const result = await deliverLineAutoReply({
85
- ...baseDeliveryParams,
86
- payload: { text: "hello", channelData: { line: lineData } },
87
- lineData,
88
- deps,
89
- });
90
-
91
- expect(result.replyTokenUsed).toBe(true);
92
- expect(replyMessageLine).toHaveBeenCalledTimes(1);
93
- expect(replyMessageLine).toHaveBeenCalledWith("token", [{ type: "text", text: "hello" }], {
94
- cfg: LINE_TEST_CFG,
95
- accountId: "acc",
96
- });
97
- expect(pushMessagesLine).toHaveBeenCalledTimes(1);
98
- expect(pushMessagesLine).toHaveBeenCalledWith(
99
- "line:user:1",
100
- [createFlexMessage("Card", { type: "bubble" })],
101
- { cfg: LINE_TEST_CFG, accountId: "acc" },
102
- );
103
- expect(createQuickReplyItems).not.toHaveBeenCalled();
104
- });
105
-
106
- it("uses reply token for rich-only payloads", async () => {
107
- const lineData = {
108
- flexMessage: { altText: "Card", contents: { type: "bubble" } },
109
- quickReplies: ["A"],
110
- };
111
- const { deps, replyMessageLine, pushMessagesLine, createQuickReplyItems } = createDeps({
112
- processLineMessage: () => ({ text: "", flexMessages: [] }),
113
- chunkMarkdownText: () => [],
114
- sendLineReplyChunks: vi.fn(async () => ({ replyTokenUsed: false })),
115
- });
116
-
117
- const result = await deliverLineAutoReply({
118
- ...baseDeliveryParams,
119
- payload: { channelData: { line: lineData } },
120
- lineData,
121
- deps,
122
- });
123
-
124
- expect(result.replyTokenUsed).toBe(true);
125
- expect(replyMessageLine).toHaveBeenCalledTimes(1);
126
- expect(replyMessageLine).toHaveBeenCalledWith(
127
- "token",
128
- [
129
- {
130
- ...createFlexMessage("Card", { type: "bubble" }),
131
- quickReply: { items: ["A"] },
132
- },
133
- ],
134
- { cfg: LINE_TEST_CFG, accountId: "acc" },
135
- );
136
- expect(pushMessagesLine).not.toHaveBeenCalled();
137
- expect(createQuickReplyItems).toHaveBeenCalledWith(["A"]);
138
- });
139
-
140
- it("uses fallback text for quick-reply-only payloads", async () => {
141
- const createTextMessageWithQuickReplies = vi.fn((text: string, _quickReplies: string[]) => ({
142
- type: "text" as const,
143
- text,
144
- quickReply: { items: ["A", "B"] },
145
- }));
146
- const lineData = {
147
- quickReplies: ["A", "B"],
148
- };
149
- const { deps, replyMessageLine, pushMessagesLine } = createDeps({
150
- createTextMessageWithQuickReplies:
151
- createTextMessageWithQuickReplies as LineAutoReplyDeps["createTextMessageWithQuickReplies"],
152
- });
153
-
154
- const result = await deliverLineAutoReply({
155
- ...baseDeliveryParams,
156
- payload: { text: "", channelData: { line: lineData } },
157
- lineData,
158
- deps,
159
- });
160
-
161
- expect(result.replyTokenUsed).toBe(true);
162
- expect(replyMessageLine).toHaveBeenCalledWith(
163
- "token",
164
- [
165
- {
166
- type: "text",
167
- text: "Options:\n- A\n- B",
168
- quickReply: { items: ["A", "B"] },
169
- },
170
- ],
171
- { cfg: LINE_TEST_CFG, accountId: "acc" },
172
- );
173
- expect(pushMessagesLine).not.toHaveBeenCalled();
174
- });
175
-
176
- it("sends rich messages before quick-reply text so quick replies remain visible", async () => {
177
- const createTextMessageWithQuickReplies = vi.fn((text: string, _quickReplies: string[]) => ({
178
- type: "text" as const,
179
- text,
180
- quickReply: { items: ["A"] },
181
- }));
182
-
183
- const lineData = {
184
- flexMessage: { altText: "Card", contents: { type: "bubble" } },
185
- quickReplies: ["A"],
186
- };
187
- const { deps, pushMessagesLine, replyMessageLine } = createDeps({
188
- createTextMessageWithQuickReplies:
189
- createTextMessageWithQuickReplies as LineAutoReplyDeps["createTextMessageWithQuickReplies"],
190
- });
191
-
192
- await deliverLineAutoReply({
193
- ...baseDeliveryParams,
194
- payload: { text: "hello", channelData: { line: lineData } },
195
- lineData,
196
- deps,
197
- });
198
-
199
- expect(pushMessagesLine).toHaveBeenCalledWith(
200
- "line:user:1",
201
- [createFlexMessage("Card", { type: "bubble" })],
202
- { cfg: LINE_TEST_CFG, accountId: "acc" },
203
- );
204
- expect(replyMessageLine).toHaveBeenCalledWith(
205
- "token",
206
- [
207
- {
208
- type: "text",
209
- text: "hello",
210
- quickReply: { items: ["A"] },
211
- },
212
- ],
213
- { cfg: LINE_TEST_CFG, accountId: "acc" },
214
- );
215
- const pushOrder = pushMessagesLine.mock.invocationCallOrder[0];
216
- const replyOrder = replyMessageLine.mock.invocationCallOrder[0];
217
- expect(pushOrder).toBeLessThan(replyOrder);
218
- });
219
-
220
- it("falls back to push when reply token delivery fails", async () => {
221
- const lineData = {
222
- flexMessage: { altText: "Card", contents: { type: "bubble" } },
223
- };
224
- const failingReplyMessageLine = vi.fn(async () => {
225
- throw new Error("reply failed");
226
- });
227
- const { deps, pushMessagesLine } = createDeps({
228
- processLineMessage: () => ({ text: "", flexMessages: [] }),
229
- chunkMarkdownText: () => [],
230
- replyMessageLine: failingReplyMessageLine as LineAutoReplyDeps["replyMessageLine"],
231
- });
232
-
233
- const result = await deliverLineAutoReply({
234
- ...baseDeliveryParams,
235
- payload: { channelData: { line: lineData } },
236
- lineData,
237
- deps,
238
- });
239
-
240
- expect(result.replyTokenUsed).toBe(true);
241
- expect(failingReplyMessageLine).toHaveBeenCalledTimes(1);
242
- expect(pushMessagesLine).toHaveBeenCalledWith(
243
- "line:user:1",
244
- [createFlexMessage("Card", { type: "bubble" })],
245
- { cfg: LINE_TEST_CFG, accountId: "acc" },
246
- );
247
- });
248
- });
@@ -1,200 +0,0 @@
1
- import type { messagingApi } from "@line/bot-sdk";
2
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
3
- import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
4
- import type { ReplyPayload } from "openclaw/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: OpenClawConfig; 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: OpenClawConfig;
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,48 +0,0 @@
1
- import {
2
- firstDefined,
3
- isSenderIdAllowed,
4
- mergeDmAllowFromSources,
5
- } from "openclaw/plugin-sdk/allow-from";
6
-
7
- export type NormalizedAllowFrom = {
8
- entries: string[];
9
- hasWildcard: boolean;
10
- hasEntries: boolean;
11
- };
12
-
13
- function normalizeAllowEntry(value: string | number): string {
14
- const trimmed = String(value).trim();
15
- if (!trimmed) {
16
- return "";
17
- }
18
- if (trimmed === "*") {
19
- return "*";
20
- }
21
- return trimmed.replace(/^line:(?:user:)?/i, "");
22
- }
23
-
24
- export const normalizeAllowFrom = (list?: Array<string | number>): NormalizedAllowFrom => {
25
- const entries = (list ?? []).map((value) => normalizeAllowEntry(value)).filter(Boolean);
26
- const hasWildcard = entries.includes("*");
27
- return {
28
- entries,
29
- hasWildcard,
30
- hasEntries: entries.length > 0,
31
- };
32
- };
33
-
34
- export const normalizeDmAllowFromWithStore = (params: {
35
- allowFrom?: Array<string | number>;
36
- storeAllowFrom?: string[];
37
- dmPolicy?: string;
38
- }): NormalizedAllowFrom => normalizeAllowFrom(mergeDmAllowFromSources(params));
39
-
40
- export const isSenderAllowed = (params: {
41
- allow: NormalizedAllowFrom;
42
- senderId?: string;
43
- }): boolean => {
44
- const { allow, senderId } = params;
45
- return isSenderIdAllowed(allow, senderId, false);
46
- };
47
-
48
- export { firstDefined };