@openclaw/line 2026.5.2-beta.2 → 2026.5.3-beta.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 (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
@@ -0,0 +1,105 @@
1
+ import { DEFAULT_ACCOUNT_ID, normalizeAccountId, normalizeOptionalAccountId } from "openclaw/plugin-sdk/account-id";
2
+ import { resolveAccountEntry } from "openclaw/plugin-sdk/account-resolution";
3
+ import { tryReadSecretFileSync } from "openclaw/plugin-sdk/core";
4
+ //#region extensions/line/src/accounts.ts
5
+ function readFileIfExists(filePath) {
6
+ return tryReadSecretFileSync(filePath, "LINE credential file", { rejectSymlink: true });
7
+ }
8
+ function resolveToken(params) {
9
+ const { accountId, baseConfig, accountConfig } = params;
10
+ if (accountConfig?.channelAccessToken?.trim()) return {
11
+ token: accountConfig.channelAccessToken.trim(),
12
+ tokenSource: "config"
13
+ };
14
+ const accountFileToken = readFileIfExists(accountConfig?.tokenFile);
15
+ if (accountFileToken) return {
16
+ token: accountFileToken,
17
+ tokenSource: "file"
18
+ };
19
+ if (accountId === DEFAULT_ACCOUNT_ID) {
20
+ if (baseConfig?.channelAccessToken?.trim()) return {
21
+ token: baseConfig.channelAccessToken.trim(),
22
+ tokenSource: "config"
23
+ };
24
+ const baseFileToken = readFileIfExists(baseConfig?.tokenFile);
25
+ if (baseFileToken) return {
26
+ token: baseFileToken,
27
+ tokenSource: "file"
28
+ };
29
+ const envToken = process.env.LINE_CHANNEL_ACCESS_TOKEN?.trim();
30
+ if (envToken) return {
31
+ token: envToken,
32
+ tokenSource: "env"
33
+ };
34
+ }
35
+ return {
36
+ token: "",
37
+ tokenSource: "none"
38
+ };
39
+ }
40
+ function resolveSecret(params) {
41
+ const { accountId, baseConfig, accountConfig } = params;
42
+ if (accountConfig?.channelSecret?.trim()) return accountConfig.channelSecret.trim();
43
+ const accountFileSecret = readFileIfExists(accountConfig?.secretFile);
44
+ if (accountFileSecret) return accountFileSecret;
45
+ if (accountId === DEFAULT_ACCOUNT_ID) {
46
+ if (baseConfig?.channelSecret?.trim()) return baseConfig.channelSecret.trim();
47
+ const baseFileSecret = readFileIfExists(baseConfig?.secretFile);
48
+ if (baseFileSecret) return baseFileSecret;
49
+ const envSecret = process.env.LINE_CHANNEL_SECRET?.trim();
50
+ if (envSecret) return envSecret;
51
+ }
52
+ return "";
53
+ }
54
+ function resolveLineAccount(params) {
55
+ const cfg = params.cfg;
56
+ const accountId = normalizeAccountId(params.accountId ?? resolveDefaultLineAccountId(cfg));
57
+ const lineConfig = cfg.channels?.line;
58
+ const accounts = lineConfig?.accounts;
59
+ const accountConfig = accountId !== DEFAULT_ACCOUNT_ID ? resolveAccountEntry(accounts, accountId) : void 0;
60
+ const { token, tokenSource } = resolveToken({
61
+ accountId,
62
+ baseConfig: lineConfig,
63
+ accountConfig
64
+ });
65
+ const secret = resolveSecret({
66
+ accountId,
67
+ baseConfig: lineConfig,
68
+ accountConfig
69
+ });
70
+ const { accounts: _ignoredAccounts, defaultAccount: _ignoredDefaultAccount, ...lineBase } = lineConfig ?? {};
71
+ const mergedConfig = {
72
+ ...lineBase,
73
+ ...accountConfig
74
+ };
75
+ const enabled = accountConfig?.enabled ?? (accountId === DEFAULT_ACCOUNT_ID ? lineConfig?.enabled ?? true : false);
76
+ return {
77
+ accountId,
78
+ name: accountConfig?.name ?? (accountId === DEFAULT_ACCOUNT_ID ? lineConfig?.name : void 0),
79
+ enabled,
80
+ channelAccessToken: token,
81
+ channelSecret: secret,
82
+ tokenSource,
83
+ config: mergedConfig
84
+ };
85
+ }
86
+ function listLineAccountIds(cfg) {
87
+ const lineConfig = cfg.channels?.line;
88
+ const accounts = lineConfig?.accounts;
89
+ const ids = /* @__PURE__ */ new Set();
90
+ if (lineConfig?.channelAccessToken?.trim() || lineConfig?.tokenFile || process.env.LINE_CHANNEL_ACCESS_TOKEN?.trim()) ids.add(DEFAULT_ACCOUNT_ID);
91
+ if (accounts) for (const id of Object.keys(accounts)) ids.add(id);
92
+ return Array.from(ids);
93
+ }
94
+ function resolveDefaultLineAccountId(cfg) {
95
+ const preferred = normalizeOptionalAccountId((cfg.channels?.line)?.defaultAccount);
96
+ if (preferred && listLineAccountIds(cfg).some((accountId) => normalizeAccountId(accountId) === preferred)) return preferred;
97
+ const ids = listLineAccountIds(cfg);
98
+ if (ids.includes(DEFAULT_ACCOUNT_ID)) return DEFAULT_ACCOUNT_ID;
99
+ return ids[0] ?? DEFAULT_ACCOUNT_ID;
100
+ }
101
+ function normalizeAccountId$1(accountId) {
102
+ return normalizeAccountId(accountId);
103
+ }
104
+ //#endregion
105
+ export { resolveLineAccount as i, normalizeAccountId$1 as n, resolveDefaultLineAccountId as r, listLineAccountIds as t };
package/dist/api.js ADDED
@@ -0,0 +1,11 @@
1
+ import { n as lineChannelPluginCommon, t as linePlugin } from "./channel-Rls9s60K.js";
2
+ import { n as lineSetupAdapter, t as lineSetupWizard } from "./setup-surface-DCH7CE-y.js";
3
+ //#region extensions/line/src/channel.setup.ts
4
+ const lineSetupPlugin = {
5
+ id: "line",
6
+ ...lineChannelPluginCommon,
7
+ setupWizard: lineSetupWizard,
8
+ setup: lineSetupAdapter
9
+ };
10
+ //#endregion
11
+ export { linePlugin, lineSetupPlugin };
@@ -0,0 +1,307 @@
1
+ import { i as attachFooterText } from "./schedule-cards-BwQChTdM.js";
2
+ //#region extensions/line/src/flex-templates/basic-cards.ts
3
+ /**
4
+ * Create an info card with title, body, and optional footer
5
+ *
6
+ * Editorial design: Clean hierarchy with accent bar, generous spacing,
7
+ * and subtle background zones for visual separation.
8
+ */
9
+ function createInfoCard(title, body, footer) {
10
+ const bubble = {
11
+ type: "bubble",
12
+ size: "mega",
13
+ body: {
14
+ type: "box",
15
+ layout: "vertical",
16
+ contents: [{
17
+ type: "box",
18
+ layout: "horizontal",
19
+ contents: [{
20
+ type: "box",
21
+ layout: "vertical",
22
+ contents: [],
23
+ width: "4px",
24
+ backgroundColor: "#06C755",
25
+ cornerRadius: "2px"
26
+ }, {
27
+ type: "text",
28
+ text: title,
29
+ weight: "bold",
30
+ size: "xl",
31
+ color: "#111111",
32
+ wrap: true,
33
+ flex: 1,
34
+ margin: "lg"
35
+ }]
36
+ }, {
37
+ type: "box",
38
+ layout: "vertical",
39
+ contents: [{
40
+ type: "text",
41
+ text: body,
42
+ size: "md",
43
+ color: "#444444",
44
+ wrap: true,
45
+ lineSpacing: "6px"
46
+ }],
47
+ margin: "xl",
48
+ paddingAll: "lg",
49
+ backgroundColor: "#F8F9FA",
50
+ cornerRadius: "lg"
51
+ }],
52
+ paddingAll: "xl",
53
+ backgroundColor: "#FFFFFF"
54
+ }
55
+ };
56
+ if (footer) attachFooterText(bubble, footer);
57
+ return bubble;
58
+ }
59
+ /**
60
+ * Create a list card with title and multiple items
61
+ *
62
+ * Editorial design: Numbered/bulleted list with clear visual hierarchy,
63
+ * accent dots for each item, and generous spacing.
64
+ */
65
+ function createListCard(title, items) {
66
+ const itemContents = items.slice(0, 8).map((item, index) => {
67
+ const itemContents = [{
68
+ type: "text",
69
+ text: item.title,
70
+ size: "md",
71
+ weight: "bold",
72
+ color: "#1a1a1a",
73
+ wrap: true
74
+ }];
75
+ if (item.subtitle) itemContents.push({
76
+ type: "text",
77
+ text: item.subtitle,
78
+ size: "sm",
79
+ color: "#888888",
80
+ wrap: true,
81
+ margin: "xs"
82
+ });
83
+ const itemBox = {
84
+ type: "box",
85
+ layout: "horizontal",
86
+ contents: [{
87
+ type: "box",
88
+ layout: "vertical",
89
+ contents: [{
90
+ type: "box",
91
+ layout: "vertical",
92
+ contents: [],
93
+ width: "8px",
94
+ height: "8px",
95
+ backgroundColor: index === 0 ? "#06C755" : "#DDDDDD",
96
+ cornerRadius: "4px"
97
+ }],
98
+ width: "20px",
99
+ alignItems: "center",
100
+ paddingTop: "sm"
101
+ }, {
102
+ type: "box",
103
+ layout: "vertical",
104
+ contents: itemContents,
105
+ flex: 1
106
+ }],
107
+ margin: index > 0 ? "lg" : void 0
108
+ };
109
+ if (item.action) itemBox.action = item.action;
110
+ return itemBox;
111
+ });
112
+ return {
113
+ type: "bubble",
114
+ size: "mega",
115
+ body: {
116
+ type: "box",
117
+ layout: "vertical",
118
+ contents: [
119
+ {
120
+ type: "text",
121
+ text: title,
122
+ weight: "bold",
123
+ size: "xl",
124
+ color: "#111111",
125
+ wrap: true
126
+ },
127
+ {
128
+ type: "separator",
129
+ margin: "lg",
130
+ color: "#EEEEEE"
131
+ },
132
+ {
133
+ type: "box",
134
+ layout: "vertical",
135
+ contents: itemContents,
136
+ margin: "lg"
137
+ }
138
+ ],
139
+ paddingAll: "xl",
140
+ backgroundColor: "#FFFFFF"
141
+ }
142
+ };
143
+ }
144
+ /**
145
+ * Create an image card with image, title, and optional body text
146
+ */
147
+ function createImageCard(imageUrl, title, body, options) {
148
+ const bubble = {
149
+ type: "bubble",
150
+ hero: {
151
+ type: "image",
152
+ url: imageUrl,
153
+ size: "full",
154
+ aspectRatio: options?.aspectRatio ?? "20:13",
155
+ aspectMode: options?.aspectMode ?? "cover",
156
+ action: options?.action
157
+ },
158
+ body: {
159
+ type: "box",
160
+ layout: "vertical",
161
+ contents: [{
162
+ type: "text",
163
+ text: title,
164
+ weight: "bold",
165
+ size: "xl",
166
+ wrap: true
167
+ }],
168
+ paddingAll: "lg"
169
+ }
170
+ };
171
+ if (body && bubble.body) bubble.body.contents.push({
172
+ type: "text",
173
+ text: body,
174
+ size: "md",
175
+ wrap: true,
176
+ margin: "md",
177
+ color: "#666666"
178
+ });
179
+ return bubble;
180
+ }
181
+ /**
182
+ * Create an action card with title, body, and action buttons
183
+ */
184
+ function createActionCard(title, body, actions, options) {
185
+ const bubble = {
186
+ type: "bubble",
187
+ body: {
188
+ type: "box",
189
+ layout: "vertical",
190
+ contents: [{
191
+ type: "text",
192
+ text: title,
193
+ weight: "bold",
194
+ size: "xl",
195
+ wrap: true
196
+ }, {
197
+ type: "text",
198
+ text: body,
199
+ size: "md",
200
+ wrap: true,
201
+ margin: "md",
202
+ color: "#666666"
203
+ }],
204
+ paddingAll: "lg"
205
+ },
206
+ footer: {
207
+ type: "box",
208
+ layout: "vertical",
209
+ contents: actions.slice(0, 4).map((action, index) => ({
210
+ type: "button",
211
+ action: action.action,
212
+ style: index === 0 ? "primary" : "secondary",
213
+ margin: index > 0 ? "sm" : void 0
214
+ })),
215
+ paddingAll: "md"
216
+ }
217
+ };
218
+ if (options?.imageUrl) bubble.hero = {
219
+ type: "image",
220
+ url: options.imageUrl,
221
+ size: "full",
222
+ aspectRatio: options.aspectRatio ?? "20:13",
223
+ aspectMode: "cover"
224
+ };
225
+ return bubble;
226
+ }
227
+ /**
228
+ * Create a carousel container from multiple bubbles
229
+ * LINE allows max 12 bubbles in a carousel
230
+ */
231
+ function createCarousel(bubbles) {
232
+ return {
233
+ type: "carousel",
234
+ contents: bubbles.slice(0, 12)
235
+ };
236
+ }
237
+ /**
238
+ * Create a notification bubble (for alerts, status updates)
239
+ *
240
+ * Editorial design: Bold status indicator with accent color,
241
+ * clear typography, optional icon for context.
242
+ */
243
+ function createNotificationBubble(text, options) {
244
+ const typeColors = {
245
+ info: {
246
+ accent: "#3B82F6",
247
+ bg: "#EFF6FF"
248
+ },
249
+ success: {
250
+ accent: "#06C755",
251
+ bg: "#F0FDF4"
252
+ },
253
+ warning: {
254
+ accent: "#F59E0B",
255
+ bg: "#FFFBEB"
256
+ },
257
+ error: {
258
+ accent: "#EF4444",
259
+ bg: "#FEF2F2"
260
+ }
261
+ }[options?.type ?? "info"];
262
+ const contents = [];
263
+ contents.push({
264
+ type: "box",
265
+ layout: "vertical",
266
+ contents: [],
267
+ width: "4px",
268
+ backgroundColor: typeColors.accent,
269
+ cornerRadius: "2px"
270
+ });
271
+ const textContents = [];
272
+ if (options?.title) textContents.push({
273
+ type: "text",
274
+ text: options.title,
275
+ size: "md",
276
+ weight: "bold",
277
+ color: "#111111",
278
+ wrap: true
279
+ });
280
+ textContents.push({
281
+ type: "text",
282
+ text,
283
+ size: options?.title ? "sm" : "md",
284
+ color: options?.title ? "#666666" : "#333333",
285
+ wrap: true,
286
+ margin: options?.title ? "sm" : void 0
287
+ });
288
+ contents.push({
289
+ type: "box",
290
+ layout: "vertical",
291
+ contents: textContents,
292
+ flex: 1,
293
+ paddingStart: "lg"
294
+ });
295
+ return {
296
+ type: "bubble",
297
+ body: {
298
+ type: "box",
299
+ layout: "horizontal",
300
+ contents,
301
+ paddingAll: "xl",
302
+ backgroundColor: typeColors.bg
303
+ }
304
+ };
305
+ }
306
+ //#endregion
307
+ export { createListCard as a, createInfoCard as i, createCarousel as n, createNotificationBubble as o, createImageCard as r, createActionCard as t };
@@ -0,0 +1,240 @@
1
+ import { r as createReceiptCard } from "./schedule-cards-BwQChTdM.js";
2
+ import { a as createListCard, i as createInfoCard, r as createImageCard, t as createActionCard } from "./basic-cards-7DTG6E-A.js";
3
+ import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
4
+ //#region extensions/line/src/card-command.ts
5
+ const CARD_USAGE = `Usage: /card <type> "title" "body" [options]
6
+
7
+ Types:
8
+ info "Title" "Body" ["Footer"]
9
+ image "Title" "Caption" --url <image-url>
10
+ action "Title" "Body" --actions "Btn1|url1,Btn2|text2"
11
+ list "Title" "Item1|Desc1,Item2|Desc2"
12
+ receipt "Title" "Item1:$10,Item2:$20" --total "$30"
13
+ confirm "Question?" --yes "Yes|data" --no "No|data"
14
+ buttons "Title" "Text" --actions "Btn1|url1,Btn2|data2"
15
+
16
+ Examples:
17
+ /card info "Welcome" "Thanks for joining!"
18
+ /card image "Product" "Check it out" --url https://example.com/img.jpg
19
+ /card action "Menu" "Choose an option" --actions "Order|/order,Help|/help"`;
20
+ function buildLineReply(lineData) {
21
+ return { channelData: { line: lineData } };
22
+ }
23
+ /**
24
+ * Parse action string format: "Label|data,Label2|data2"
25
+ * Data can be a URL (uri action) or plain text (message action) or key=value (postback)
26
+ */
27
+ function parseActions(actionsStr) {
28
+ if (!actionsStr) return [];
29
+ const results = [];
30
+ for (const part of actionsStr.split(",")) {
31
+ const [label, data] = part.trim().split("|").map((s) => s.trim());
32
+ if (!label) continue;
33
+ const actionData = data || label;
34
+ if (actionData.startsWith("http://") || actionData.startsWith("https://")) results.push({
35
+ label,
36
+ action: {
37
+ type: "uri",
38
+ label: label.slice(0, 20),
39
+ uri: actionData
40
+ }
41
+ });
42
+ else if (actionData.includes("=")) results.push({
43
+ label,
44
+ action: {
45
+ type: "postback",
46
+ label: label.slice(0, 20),
47
+ data: actionData.slice(0, 300),
48
+ displayText: label
49
+ }
50
+ });
51
+ else results.push({
52
+ label,
53
+ action: {
54
+ type: "message",
55
+ label: label.slice(0, 20),
56
+ text: actionData
57
+ }
58
+ });
59
+ }
60
+ return results;
61
+ }
62
+ /**
63
+ * Parse list items format: "Item1|Subtitle1,Item2|Subtitle2"
64
+ */
65
+ function parseListItems(itemsStr) {
66
+ return itemsStr.split(",").map((part) => {
67
+ const [title, subtitle] = part.trim().split("|").map((s) => s.trim());
68
+ return {
69
+ title: title || "",
70
+ subtitle
71
+ };
72
+ }).filter((item) => item.title);
73
+ }
74
+ /**
75
+ * Parse receipt items format: "Item1:$10,Item2:$20"
76
+ */
77
+ function parseReceiptItems(itemsStr) {
78
+ return itemsStr.split(",").map((part) => {
79
+ const colonIndex = part.lastIndexOf(":");
80
+ if (colonIndex === -1) return {
81
+ name: part.trim(),
82
+ value: ""
83
+ };
84
+ return {
85
+ name: part.slice(0, colonIndex).trim(),
86
+ value: part.slice(colonIndex + 1).trim()
87
+ };
88
+ }).filter((item) => item.name);
89
+ }
90
+ /**
91
+ * Parse quoted arguments from command string
92
+ * Supports: /card type "arg1" "arg2" "arg3" --flag value
93
+ */
94
+ function parseCardArgs(argsStr) {
95
+ const result = {
96
+ type: "",
97
+ args: [],
98
+ flags: {}
99
+ };
100
+ const typeMatch = argsStr.match(/^(\w+)/);
101
+ if (typeMatch) {
102
+ result.type = normalizeLowercaseStringOrEmpty(typeMatch[1]);
103
+ argsStr = argsStr.slice(typeMatch[0].length).trim();
104
+ }
105
+ const quotedRegex = /"([^"]*?)"/g;
106
+ let match;
107
+ while ((match = quotedRegex.exec(argsStr)) !== null) result.args.push(match[1]);
108
+ const flagRegex = /--(\w+)\s+(?:"([^"]*?)"|(\S+))/g;
109
+ while ((match = flagRegex.exec(argsStr)) !== null) result.flags[match[1]] = match[2] ?? match[3];
110
+ return result;
111
+ }
112
+ function registerLineCardCommand(api) {
113
+ api.registerCommand({
114
+ name: "card",
115
+ description: "Send a rich card message (LINE).",
116
+ acceptsArgs: true,
117
+ requireAuth: false,
118
+ handler: async (ctx) => {
119
+ const argsStr = ctx.args?.trim() ?? "";
120
+ if (!argsStr) return { text: CARD_USAGE };
121
+ const { type, args, flags } = parseCardArgs(argsStr);
122
+ if (!type) return { text: CARD_USAGE };
123
+ if (ctx.channel !== "line") return { text: `[${type} card] ${args.join(" - ")}`.trim() };
124
+ try {
125
+ switch (type) {
126
+ case "info": {
127
+ const [title = "Info", body = "", footer] = args;
128
+ const bubble = createInfoCard(title, body, footer);
129
+ return buildLineReply({ flexMessage: {
130
+ altText: `${title}: ${body}`.slice(0, 400),
131
+ contents: bubble
132
+ } });
133
+ }
134
+ case "image": {
135
+ const [title = "Image", caption = ""] = args;
136
+ const imageUrl = flags.url || flags.image;
137
+ if (!imageUrl) return { text: "Error: Image card requires --url <image-url>" };
138
+ const bubble = createImageCard(imageUrl, title, caption);
139
+ return buildLineReply({ flexMessage: {
140
+ altText: `${title}: ${caption}`.slice(0, 400),
141
+ contents: bubble
142
+ } });
143
+ }
144
+ case "action": {
145
+ const [title = "Actions", body = ""] = args;
146
+ const actions = parseActions(flags.actions);
147
+ if (actions.length === 0) return { text: "Error: Action card requires --actions \"Label1|data1,Label2|data2\"" };
148
+ const bubble = createActionCard(title, body, actions, { imageUrl: flags.url || flags.image });
149
+ return buildLineReply({ flexMessage: {
150
+ altText: `${title}: ${body}`.slice(0, 400),
151
+ contents: bubble
152
+ } });
153
+ }
154
+ case "list": {
155
+ const [title = "List", itemsStr = ""] = args;
156
+ const items = parseListItems(itemsStr || flags.items || "");
157
+ if (items.length === 0) return { text: "Error: List card requires items. Usage: /card list \"Title\" \"Item1|Desc1,Item2|Desc2\"" };
158
+ const bubble = createListCard(title, items);
159
+ return buildLineReply({ flexMessage: {
160
+ altText: `${title}: ${items.map((i) => i.title).join(", ")}`.slice(0, 400),
161
+ contents: bubble
162
+ } });
163
+ }
164
+ case "receipt": {
165
+ const [title = "Receipt", itemsStr = ""] = args;
166
+ const items = parseReceiptItems(itemsStr || flags.items || "");
167
+ const total = flags.total ? {
168
+ label: "Total",
169
+ value: flags.total
170
+ } : void 0;
171
+ const footer = flags.footer;
172
+ if (items.length === 0) return { text: "Error: Receipt card requires items. Usage: /card receipt \"Title\" \"Item1:$10,Item2:$20\" --total \"$30\"" };
173
+ const bubble = createReceiptCard({
174
+ title,
175
+ items,
176
+ total,
177
+ footer
178
+ });
179
+ return buildLineReply({ flexMessage: {
180
+ altText: `${title}: ${items.map((i) => `${i.name} ${i.value}`).join(", ")}`.slice(0, 400),
181
+ contents: bubble
182
+ } });
183
+ }
184
+ case "confirm": {
185
+ const [question = "Confirm?"] = args;
186
+ const yesStr = flags.yes || "Yes|yes";
187
+ const noStr = flags.no || "No|no";
188
+ const [yesLabel, yesData] = yesStr.split("|").map((s) => s.trim());
189
+ const [noLabel, noData] = noStr.split("|").map((s) => s.trim());
190
+ return buildLineReply({ templateMessage: {
191
+ type: "confirm",
192
+ text: question,
193
+ confirmLabel: yesLabel || "Yes",
194
+ confirmData: yesData || "yes",
195
+ cancelLabel: noLabel || "No",
196
+ cancelData: noData || "no",
197
+ altText: question
198
+ } });
199
+ }
200
+ case "buttons": {
201
+ const [title = "Menu", text = "Choose an option"] = args;
202
+ const actionParts = parseActions(flags.actions || "");
203
+ if (actionParts.length === 0) return { text: "Error: Buttons card requires --actions \"Label1|data1,Label2|data2\"" };
204
+ const templateActions = actionParts.map((a) => {
205
+ const action = a.action;
206
+ const label = action.label ?? a.label;
207
+ if (action.type === "uri") return {
208
+ type: "uri",
209
+ label,
210
+ uri: action.uri
211
+ };
212
+ if (action.type === "postback") return {
213
+ type: "postback",
214
+ label,
215
+ data: action.data
216
+ };
217
+ return {
218
+ type: "message",
219
+ label,
220
+ data: action.text
221
+ };
222
+ });
223
+ return buildLineReply({ templateMessage: {
224
+ type: "buttons",
225
+ title,
226
+ text,
227
+ thumbnailImageUrl: flags.url || flags.image,
228
+ actions: templateActions
229
+ } });
230
+ }
231
+ default: return { text: `Unknown card type: "${type}". Available types: info, image, action, list, receipt, confirm, buttons` };
232
+ }
233
+ } catch (err) {
234
+ return { text: `Error creating card: ${String(err)}` };
235
+ }
236
+ }
237
+ });
238
+ }
239
+ //#endregion
240
+ export { registerLineCardCommand };