@kodelyth/line 2026.5.39 → 2026.5.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.ts +11 -0
- package/channel-plugin-api.ts +1 -0
- package/contract-api.ts +5 -0
- package/dist/accounts-CD4A1FE7.js +105 -0
- package/dist/api.js +11 -0
- package/dist/basic-cards-BISytiSa.js +307 -0
- package/dist/card-command-dQBX3fVN.js +240 -0
- package/dist/channel-DV5h44-j.js +649 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-Cc-v3szZ.js +4 -0
- package/dist/contract-api.js +2 -0
- package/dist/index.js +45 -0
- package/dist/markdown-to-line-CC3BU6CC.js +810 -0
- package/dist/monitor-Ci8Hg8ay.js +1485 -0
- package/dist/monitor.runtime-t6-QvlDB.js +2 -0
- package/dist/outbound.runtime-D1CxEvcL.js +2 -0
- package/dist/probe-BPSs_A_8.js +30 -0
- package/dist/probe.runtime-7u2o9QN5.js +2 -0
- package/dist/reply-payload-transform-CDuBzoT4.js +855 -0
- package/dist/runtime-api.js +291 -0
- package/dist/schedule-cards-D-yZMHDE.js +359 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/setup-api.js +2 -0
- package/dist/setup-entry.js +11 -0
- package/dist/setup-surface-CHfQ6Z4i.js +282 -0
- package/index.ts +53 -0
- package/klaw.plugin.json +2 -329
- package/package.json +4 -4
- package/runtime-api.ts +179 -0
- package/secret-contract-api.ts +4 -0
- package/setup-api.ts +2 -0
- package/setup-entry.ts +9 -0
- package/src/account-helpers.ts +16 -0
- package/src/accounts.test.ts +288 -0
- package/src/accounts.ts +187 -0
- package/src/actions.ts +61 -0
- package/src/auto-reply-delivery.test.ts +253 -0
- package/src/auto-reply-delivery.ts +200 -0
- package/src/bindings.ts +65 -0
- package/src/bot-access.ts +30 -0
- package/src/bot-handlers.test.ts +1094 -0
- package/src/bot-handlers.ts +620 -0
- package/src/bot-message-context.test.ts +420 -0
- package/src/bot-message-context.ts +586 -0
- package/src/bot.ts +66 -0
- package/src/card-command.ts +347 -0
- package/src/channel-access-token.ts +14 -0
- package/src/channel-api.ts +17 -0
- package/src/channel-setup-status.contract.test.ts +70 -0
- package/src/channel-shared.ts +48 -0
- package/src/channel.logout.test.ts +145 -0
- package/src/channel.runtime.ts +3 -0
- package/src/channel.sendPayload.test.ts +659 -0
- package/src/channel.setup.ts +11 -0
- package/src/channel.status.test.ts +63 -0
- package/src/channel.ts +155 -0
- package/src/config-adapter.ts +29 -0
- package/src/config-schema.test.ts +53 -0
- package/src/config-schema.ts +81 -0
- package/src/download.test.ts +164 -0
- package/src/download.ts +34 -0
- package/src/flex-templates/basic-cards.ts +395 -0
- package/src/flex-templates/common.ts +20 -0
- package/src/flex-templates/media-control-cards.ts +555 -0
- package/src/flex-templates/message.ts +13 -0
- package/src/flex-templates/schedule-cards.ts +467 -0
- package/src/flex-templates/types.ts +22 -0
- package/src/flex-templates.ts +32 -0
- package/src/gateway.ts +129 -0
- package/src/group-keys.test.ts +123 -0
- package/src/group-keys.ts +65 -0
- package/src/group-policy.ts +22 -0
- package/src/markdown-to-line.test.ts +348 -0
- package/src/markdown-to-line.ts +416 -0
- package/src/message-cards.test.ts +204 -0
- package/src/monitor-durable.test.ts +57 -0
- package/src/monitor-durable.ts +37 -0
- package/src/monitor.lifecycle.test.ts +499 -0
- package/src/monitor.runtime.ts +1 -0
- package/src/monitor.ts +507 -0
- package/src/outbound-media.test.ts +194 -0
- package/src/outbound-media.ts +120 -0
- package/src/outbound.runtime.ts +12 -0
- package/src/outbound.ts +427 -0
- package/src/probe.contract.test.ts +9 -0
- package/src/probe.runtime.ts +1 -0
- package/src/probe.ts +34 -0
- package/src/quick-reply-fallback.ts +10 -0
- package/src/reply-chunks.test.ts +180 -0
- package/src/reply-chunks.ts +110 -0
- package/src/reply-payload-transform.test.ts +392 -0
- package/src/reply-payload-transform.ts +317 -0
- package/src/rich-menu.test.ts +315 -0
- package/src/rich-menu.ts +326 -0
- package/src/runtime.ts +32 -0
- package/src/send-receipt.ts +32 -0
- package/src/send.test.ts +453 -0
- package/src/send.ts +531 -0
- package/src/setup-core.ts +149 -0
- package/src/setup-runtime-api.ts +9 -0
- package/src/setup-surface.test.ts +481 -0
- package/src/setup-surface.ts +229 -0
- package/src/signature.test.ts +34 -0
- package/src/signature.ts +24 -0
- package/src/status.ts +37 -0
- package/src/template-messages.ts +333 -0
- package/src/types.ts +130 -0
- package/src/webhook-node.test.ts +598 -0
- package/src/webhook-node.ts +155 -0
- package/src/webhook-utils.ts +10 -0
- package/src/webhook.ts +135 -0
- package/tsconfig.json +16 -0
- package/api.js +0 -7
- package/channel-plugin-api.js +0 -7
- package/contract-api.js +0 -7
- package/index.js +0 -7
- package/runtime-api.js +0 -7
- package/secret-contract-api.js +0 -7
- package/setup-api.js +0 -7
- package/setup-entry.js +0 -7
package/api.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
ChannelAccountSnapshot,
|
|
3
|
+
ChannelPlugin,
|
|
4
|
+
KlawConfig,
|
|
5
|
+
KlawPluginApi,
|
|
6
|
+
PluginRuntime,
|
|
7
|
+
} from "klaw/plugin-sdk/core";
|
|
8
|
+
export type { ReplyPayload } from "klaw/plugin-sdk/reply-runtime";
|
|
9
|
+
export type { ResolvedLineAccount } from "./runtime-api.js";
|
|
10
|
+
export { linePlugin } from "./src/channel.js";
|
|
11
|
+
export { lineSetupPlugin } from "./src/channel.setup.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { linePlugin } from "./src/channel.js";
|
package/contract-api.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId, normalizeOptionalAccountId } from "klaw/plugin-sdk/account-id";
|
|
2
|
+
import { resolveAccountEntry } from "klaw/plugin-sdk/account-resolution";
|
|
3
|
+
import { tryReadSecretFileSync } from "klaw/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-DV5h44-j.js";
|
|
2
|
+
import { n as lineSetupAdapter, t as lineSetupWizard } from "./setup-surface-CHfQ6Z4i.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-D-yZMHDE.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-D-yZMHDE.js";
|
|
2
|
+
import { a as createListCard, i as createInfoCard, r as createImageCard, t as createActionCard } from "./basic-cards-BISytiSa.js";
|
|
3
|
+
import { normalizeLowercaseStringOrEmpty } from "klaw/plugin-sdk/string-coerce-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 };
|