@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
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { i as resolveLineAccount, n as normalizeAccountId, r as resolveDefaultLineAccountId, t as listLineAccountIds } from "./accounts-CD4A1FE7.js";
|
|
2
|
+
import { _ as resolveLineGroupsConfig, a as createMediaPlayerCard, d as setLineRuntime, f as LineChannelConfigSchema, g as resolveLineGroupLookupIds, h as resolveLineGroupConfigEntry, i as createDeviceControlCard, m as resolveExactLineGroupConfigKey, n as parseLineDirectives, p as LineConfigSchema, r as createAppleTvRemoteCard, t as hasLineDirectives } from "./reply-payload-transform-CDuBzoT4.js";
|
|
3
|
+
import { n as createEventCard, r as createReceiptCard, t as createAgendaCard } from "./schedule-cards-D-yZMHDE.js";
|
|
4
|
+
import { a as createListCard, i as createInfoCard, n as createCarousel, o as createNotificationBubble, r as createImageCard, t as createActionCard } from "./basic-cards-BISytiSa.js";
|
|
5
|
+
import { A as buildTemplateMessageFromPayload, B as createYesNoConfirm, C as pushMessagesLine, D as sendMessageLine, E as replyMessageLine, F as createImageCarousel, G as toFlexMessage, H as messageAction, I as createImageCarouselColumn, L as createLinkMenu, M as createButtonTemplate, N as createCarouselColumn, O as showLoadingAnimation, P as createConfirmTemplate, R as createProductCarousel, S as pushMessageLine, T as pushTextMessageWithQuickReplies, U as postbackAction, V as datetimePickerAction, W as uriAction, _ as getUserDisplayName, a as extractLinks, b as pushImageMessage, c as processLineMessage, d as createFlexMessage, f as createImageMessage, g as createVideoMessage, h as createTextMessageWithQuickReplies, i as extractCodeBlocks, j as createButtonMenu, k as resolveLineChannelAccessToken, l as stripMarkdown, m as createQuickReplyItems, n as convertLinksToFlexBubble, o as extractMarkdownTables, p as createLocationMessage, r as convertTableToFlexBubble, s as hasMarkdownToConvert, t as convertCodeBlockToFlexBubble, u as createAudioMessage, v as getUserProfile, w as pushTemplateMessage, x as pushLocationMessage, y as pushFlexMessage, z as createTemplateCarousel } from "./markdown-to-line-CC3BU6CC.js";
|
|
6
|
+
import { a as validateLineSignature, c as normalizeAllowFrom, i as parseLineWebhookBody, n as createLineNodeWebhookHandler, o as downloadLineMedia, r as readLineWebhookRequestBody, s as firstDefined, t as monitorLineProvider } from "./monitor-Ci8Hg8ay.js";
|
|
7
|
+
import { t as probeLineBot } from "./probe-BPSs_A_8.js";
|
|
8
|
+
import { clearAccountEntryFields } from "klaw/plugin-sdk/core";
|
|
9
|
+
import { buildChannelConfigSchema } from "klaw/plugin-sdk/channel-config-schema";
|
|
10
|
+
import { createMessageReceiveContext } from "klaw/plugin-sdk/channel-message";
|
|
11
|
+
import { DEFAULT_ACCOUNT_ID, formatDocsLink, setSetupChannelEnabled, splitSetupEntries } from "klaw/plugin-sdk/setup";
|
|
12
|
+
import { buildComputedAccountStatusSnapshot, buildTokenChannelStatusSummary } from "klaw/plugin-sdk/status-helpers";
|
|
13
|
+
import { messagingApi } from "@line/bot-sdk";
|
|
14
|
+
import { danger, logVerbose } from "klaw/plugin-sdk/runtime-env";
|
|
15
|
+
import { getAgentScopedMediaLocalRoots } from "klaw/plugin-sdk/agent-media-payload";
|
|
16
|
+
import { mimeTypeFromFilePath } from "klaw/plugin-sdk/media-mime";
|
|
17
|
+
import { loadWebMediaRaw } from "klaw/plugin-sdk/web-media";
|
|
18
|
+
//#region extensions/line/src/webhook.ts
|
|
19
|
+
const LINE_WEBHOOK_MAX_RAW_BODY_BYTES = 64 * 1024;
|
|
20
|
+
function readRawBody(req) {
|
|
21
|
+
const rawBody = req.rawBody ?? (typeof req.body === "string" || Buffer.isBuffer(req.body) ? req.body : null);
|
|
22
|
+
if (!rawBody) return null;
|
|
23
|
+
return Buffer.isBuffer(rawBody) ? rawBody.toString("utf-8") : rawBody;
|
|
24
|
+
}
|
|
25
|
+
function parseWebhookBody(rawBody) {
|
|
26
|
+
if (!rawBody) return null;
|
|
27
|
+
return parseLineWebhookBody(rawBody);
|
|
28
|
+
}
|
|
29
|
+
function logLineWebhookDispatchError(runtime, err) {
|
|
30
|
+
runtime?.error?.(danger(`line webhook dispatch failed: ${String(err)}`));
|
|
31
|
+
}
|
|
32
|
+
function createLineWebhookMiddleware(options) {
|
|
33
|
+
const { channelSecret, onEvents, runtime } = options;
|
|
34
|
+
return async (req, res, _next) => {
|
|
35
|
+
let receiveContext;
|
|
36
|
+
try {
|
|
37
|
+
const signature = req.headers["x-line-signature"];
|
|
38
|
+
if (!signature || typeof signature !== "string") {
|
|
39
|
+
res.status(400).json({ error: "Missing X-Line-Signature header" });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const rawBody = readRawBody(req);
|
|
43
|
+
if (!rawBody) {
|
|
44
|
+
res.status(400).json({ error: "Missing raw request body for signature verification" });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (Buffer.byteLength(rawBody, "utf-8") > LINE_WEBHOOK_MAX_RAW_BODY_BYTES) {
|
|
48
|
+
res.status(413).json({ error: "Payload too large" });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!validateLineSignature(rawBody, signature, channelSecret)) {
|
|
52
|
+
logVerbose("line: webhook signature validation failed");
|
|
53
|
+
res.status(401).json({ error: "Invalid signature" });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const body = parseWebhookBody(rawBody);
|
|
57
|
+
if (!body) {
|
|
58
|
+
res.status(400).json({ error: "Invalid webhook payload" });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
receiveContext = createMessageReceiveContext({
|
|
62
|
+
id: `${Date.now()}:line:webhook`,
|
|
63
|
+
channel: "line",
|
|
64
|
+
message: body,
|
|
65
|
+
ackPolicy: "after_receive_record",
|
|
66
|
+
onAck: () => {
|
|
67
|
+
res.status(200).json({ status: "ok" });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (receiveContext.shouldAckAfter("receive_record")) await receiveContext.ack();
|
|
71
|
+
if (body.events && body.events.length > 0) {
|
|
72
|
+
logVerbose(`line: received ${body.events.length} webhook events`);
|
|
73
|
+
Promise.resolve().then(() => onEvents(body)).catch((err) => logLineWebhookDispatchError(runtime, err));
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
await receiveContext?.nack(err);
|
|
77
|
+
runtime?.error?.(danger(`line webhook error: ${String(err)}`));
|
|
78
|
+
if (!res.headersSent) res.status(500).json({ error: "Internal server error" });
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function startLineWebhook(options) {
|
|
83
|
+
const channelSecret = typeof options.channelSecret === "string" ? options.channelSecret.trim() : "";
|
|
84
|
+
if (!channelSecret) throw new Error("LINE webhook mode requires a non-empty channel secret. Set channels.line.channelSecret in your config.");
|
|
85
|
+
return {
|
|
86
|
+
path: options.path ?? "/line/webhook",
|
|
87
|
+
handler: createLineWebhookMiddleware({
|
|
88
|
+
channelSecret,
|
|
89
|
+
onEvents: options.onEvents,
|
|
90
|
+
runtime: options.runtime
|
|
91
|
+
})
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region extensions/line/src/rich-menu.ts
|
|
96
|
+
const USER_BATCH_SIZE = 500;
|
|
97
|
+
function getClient(opts) {
|
|
98
|
+
const account = resolveLineAccount({
|
|
99
|
+
cfg: opts.cfg,
|
|
100
|
+
accountId: opts.accountId
|
|
101
|
+
});
|
|
102
|
+
const token = resolveLineChannelAccessToken(opts.channelAccessToken, account);
|
|
103
|
+
return new messagingApi.MessagingApiClient({ channelAccessToken: token });
|
|
104
|
+
}
|
|
105
|
+
function getBlobClient(opts) {
|
|
106
|
+
const account = resolveLineAccount({
|
|
107
|
+
cfg: opts.cfg,
|
|
108
|
+
accountId: opts.accountId
|
|
109
|
+
});
|
|
110
|
+
const token = resolveLineChannelAccessToken(opts.channelAccessToken, account);
|
|
111
|
+
return new messagingApi.MessagingApiBlobClient({ channelAccessToken: token });
|
|
112
|
+
}
|
|
113
|
+
function chunkUserIds(userIds) {
|
|
114
|
+
const batches = [];
|
|
115
|
+
for (let i = 0; i < userIds.length; i += USER_BATCH_SIZE) batches.push(userIds.slice(i, i + USER_BATCH_SIZE));
|
|
116
|
+
return batches;
|
|
117
|
+
}
|
|
118
|
+
async function createRichMenu(menu, opts) {
|
|
119
|
+
const client = getClient(opts);
|
|
120
|
+
const richMenuRequest = {
|
|
121
|
+
size: menu.size,
|
|
122
|
+
selected: menu.selected ?? false,
|
|
123
|
+
name: menu.name.slice(0, 300),
|
|
124
|
+
chatBarText: menu.chatBarText.slice(0, 14),
|
|
125
|
+
areas: menu.areas
|
|
126
|
+
};
|
|
127
|
+
const response = await client.createRichMenu(richMenuRequest);
|
|
128
|
+
if (opts.verbose) logVerbose(`line: created rich menu ${response.richMenuId}`);
|
|
129
|
+
return response.richMenuId;
|
|
130
|
+
}
|
|
131
|
+
async function uploadRichMenuImage(richMenuId, imagePath, opts) {
|
|
132
|
+
const blobClient = getBlobClient(opts);
|
|
133
|
+
const media = await loadWebMediaRaw(imagePath, { localRoots: opts.mediaLocalRoots ?? getAgentScopedMediaLocalRoots(opts.cfg) });
|
|
134
|
+
const contentType = media.contentType === "image/png" || media.contentType === "image/jpeg" ? media.contentType : mimeTypeFromFilePath(imagePath) === "image/png" ? "image/png" : "image/jpeg";
|
|
135
|
+
const imageBytes = new ArrayBuffer(media.buffer.byteLength);
|
|
136
|
+
new Uint8Array(imageBytes).set(media.buffer);
|
|
137
|
+
await blobClient.setRichMenuImage(richMenuId, new Blob([imageBytes], { type: contentType }));
|
|
138
|
+
if (opts.verbose) logVerbose(`line: uploaded image to rich menu ${richMenuId}`);
|
|
139
|
+
}
|
|
140
|
+
async function setDefaultRichMenu(richMenuId, opts) {
|
|
141
|
+
await getClient(opts).setDefaultRichMenu(richMenuId);
|
|
142
|
+
if (opts.verbose) logVerbose(`line: set default rich menu to ${richMenuId}`);
|
|
143
|
+
}
|
|
144
|
+
async function cancelDefaultRichMenu(opts) {
|
|
145
|
+
await getClient(opts).cancelDefaultRichMenu();
|
|
146
|
+
if (opts.verbose) logVerbose("line: cancelled default rich menu");
|
|
147
|
+
}
|
|
148
|
+
async function getDefaultRichMenuId(opts) {
|
|
149
|
+
const client = getClient(opts);
|
|
150
|
+
try {
|
|
151
|
+
return (await client.getDefaultRichMenuId()).richMenuId ?? null;
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function linkRichMenuToUser(userId, richMenuId, opts) {
|
|
157
|
+
await getClient(opts).linkRichMenuIdToUser(userId, richMenuId);
|
|
158
|
+
if (opts.verbose) logVerbose(`line: linked rich menu ${richMenuId} to user ${userId}`);
|
|
159
|
+
}
|
|
160
|
+
async function linkRichMenuToUsers(userIds, richMenuId, opts) {
|
|
161
|
+
const client = getClient(opts);
|
|
162
|
+
for (const batch of chunkUserIds(userIds)) await client.linkRichMenuIdToUsers({
|
|
163
|
+
richMenuId,
|
|
164
|
+
userIds: batch
|
|
165
|
+
});
|
|
166
|
+
if (opts.verbose) logVerbose(`line: linked rich menu ${richMenuId} to ${userIds.length} users`);
|
|
167
|
+
}
|
|
168
|
+
async function unlinkRichMenuFromUser(userId, opts) {
|
|
169
|
+
await getClient(opts).unlinkRichMenuIdFromUser(userId);
|
|
170
|
+
if (opts.verbose) logVerbose(`line: unlinked rich menu from user ${userId}`);
|
|
171
|
+
}
|
|
172
|
+
async function unlinkRichMenuFromUsers(userIds, opts) {
|
|
173
|
+
const client = getClient(opts);
|
|
174
|
+
for (const batch of chunkUserIds(userIds)) await client.unlinkRichMenuIdFromUsers({ userIds: batch });
|
|
175
|
+
if (opts.verbose) logVerbose(`line: unlinked rich menu from ${userIds.length} users`);
|
|
176
|
+
}
|
|
177
|
+
async function getRichMenuIdOfUser(userId, opts) {
|
|
178
|
+
const client = getClient(opts);
|
|
179
|
+
try {
|
|
180
|
+
return (await client.getRichMenuIdOfUser(userId)).richMenuId ?? null;
|
|
181
|
+
} catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function getRichMenuList(opts) {
|
|
186
|
+
return (await getClient(opts).getRichMenuList()).richmenus ?? [];
|
|
187
|
+
}
|
|
188
|
+
async function getRichMenu(richMenuId, opts) {
|
|
189
|
+
const client = getClient(opts);
|
|
190
|
+
try {
|
|
191
|
+
return await client.getRichMenu(richMenuId);
|
|
192
|
+
} catch {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async function deleteRichMenu(richMenuId, opts) {
|
|
197
|
+
await getClient(opts).deleteRichMenu(richMenuId);
|
|
198
|
+
if (opts.verbose) logVerbose(`line: deleted rich menu ${richMenuId}`);
|
|
199
|
+
}
|
|
200
|
+
async function createRichMenuAlias(richMenuId, aliasId, opts) {
|
|
201
|
+
await getClient(opts).createRichMenuAlias({
|
|
202
|
+
richMenuId,
|
|
203
|
+
richMenuAliasId: aliasId
|
|
204
|
+
});
|
|
205
|
+
if (opts.verbose) logVerbose(`line: created alias ${aliasId} for rich menu ${richMenuId}`);
|
|
206
|
+
}
|
|
207
|
+
async function deleteRichMenuAlias(aliasId, opts) {
|
|
208
|
+
await getClient(opts).deleteRichMenuAlias(aliasId);
|
|
209
|
+
if (opts.verbose) logVerbose(`line: deleted alias ${aliasId}`);
|
|
210
|
+
}
|
|
211
|
+
function createGridLayout(height, actions) {
|
|
212
|
+
const colWidth = Math.floor(2500 / 3);
|
|
213
|
+
const rowHeight = Math.floor(height / 2);
|
|
214
|
+
return [
|
|
215
|
+
{
|
|
216
|
+
bounds: {
|
|
217
|
+
x: 0,
|
|
218
|
+
y: 0,
|
|
219
|
+
width: colWidth,
|
|
220
|
+
height: rowHeight
|
|
221
|
+
},
|
|
222
|
+
action: actions[0]
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
bounds: {
|
|
226
|
+
x: colWidth,
|
|
227
|
+
y: 0,
|
|
228
|
+
width: colWidth,
|
|
229
|
+
height: rowHeight
|
|
230
|
+
},
|
|
231
|
+
action: actions[1]
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
bounds: {
|
|
235
|
+
x: colWidth * 2,
|
|
236
|
+
y: 0,
|
|
237
|
+
width: colWidth,
|
|
238
|
+
height: rowHeight
|
|
239
|
+
},
|
|
240
|
+
action: actions[2]
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
bounds: {
|
|
244
|
+
x: 0,
|
|
245
|
+
y: rowHeight,
|
|
246
|
+
width: colWidth,
|
|
247
|
+
height: rowHeight
|
|
248
|
+
},
|
|
249
|
+
action: actions[3]
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
bounds: {
|
|
253
|
+
x: colWidth,
|
|
254
|
+
y: rowHeight,
|
|
255
|
+
width: colWidth,
|
|
256
|
+
height: rowHeight
|
|
257
|
+
},
|
|
258
|
+
action: actions[4]
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
bounds: {
|
|
262
|
+
x: colWidth * 2,
|
|
263
|
+
y: rowHeight,
|
|
264
|
+
width: colWidth,
|
|
265
|
+
height: rowHeight
|
|
266
|
+
},
|
|
267
|
+
action: actions[5]
|
|
268
|
+
}
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
function createDefaultMenuConfig() {
|
|
272
|
+
return {
|
|
273
|
+
size: {
|
|
274
|
+
width: 2500,
|
|
275
|
+
height: 843
|
|
276
|
+
},
|
|
277
|
+
selected: false,
|
|
278
|
+
name: "Default Menu",
|
|
279
|
+
chatBarText: "Menu",
|
|
280
|
+
areas: createGridLayout(843, [
|
|
281
|
+
messageAction("Help", "/help"),
|
|
282
|
+
messageAction("Status", "/status"),
|
|
283
|
+
messageAction("Settings", "/settings"),
|
|
284
|
+
messageAction("About", "/about"),
|
|
285
|
+
messageAction("Feedback", "/feedback"),
|
|
286
|
+
messageAction("Contact", "/contact")
|
|
287
|
+
])
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
291
|
+
export { DEFAULT_ACCOUNT_ID, LineChannelConfigSchema, LineConfigSchema, buildChannelConfigSchema, buildComputedAccountStatusSnapshot, buildTemplateMessageFromPayload, buildTokenChannelStatusSummary, cancelDefaultRichMenu, clearAccountEntryFields, convertCodeBlockToFlexBubble, convertLinksToFlexBubble, convertTableToFlexBubble, createActionCard, createAgendaCard, createAppleTvRemoteCard, createAudioMessage, createButtonMenu, createButtonTemplate, createCarousel, createCarouselColumn, createConfirmTemplate, createDefaultMenuConfig, createDeviceControlCard, createEventCard, createFlexMessage, createGridLayout, createImageCard, createImageCarousel, createImageCarouselColumn, createImageMessage, createInfoCard, createLineNodeWebhookHandler, createLineWebhookMiddleware, createLinkMenu, createListCard, createLocationMessage, createMediaPlayerCard, createNotificationBubble, createProductCarousel, createQuickReplyItems, createReceiptCard, createRichMenu, createRichMenuAlias, createTemplateCarousel, createTextMessageWithQuickReplies, createVideoMessage, createYesNoConfirm, datetimePickerAction, deleteRichMenu, deleteRichMenuAlias, downloadLineMedia, extractCodeBlocks, extractLinks, extractMarkdownTables, firstDefined, formatDocsLink, getDefaultRichMenuId, getRichMenu, getRichMenuIdOfUser, getRichMenuList, getUserDisplayName, getUserProfile, hasLineDirectives, hasMarkdownToConvert, linkRichMenuToUser, linkRichMenuToUsers, listLineAccountIds, messageAction, monitorLineProvider, normalizeAccountId, normalizeAllowFrom, parseLineDirectives, parseLineWebhookBody, postbackAction, probeLineBot, processLineMessage, pushFlexMessage, pushImageMessage, pushLocationMessage, pushMessageLine, pushMessagesLine, pushTemplateMessage, pushTextMessageWithQuickReplies, readLineWebhookRequestBody, replyMessageLine, resolveDefaultLineAccountId, resolveExactLineGroupConfigKey, resolveLineAccount, resolveLineChannelAccessToken, resolveLineGroupConfigEntry, resolveLineGroupLookupIds, resolveLineGroupsConfig, sendMessageLine, setDefaultRichMenu, setLineRuntime, setSetupChannelEnabled, showLoadingAnimation, splitSetupEntries, startLineWebhook, stripMarkdown, toFlexMessage, unlinkRichMenuFromUser, unlinkRichMenuFromUsers, uploadRichMenuImage, uriAction, validateLineSignature };
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
//#region extensions/line/src/flex-templates/common.ts
|
|
2
|
+
function attachFooterText(bubble, footer) {
|
|
3
|
+
bubble.footer = {
|
|
4
|
+
type: "box",
|
|
5
|
+
layout: "vertical",
|
|
6
|
+
contents: [{
|
|
7
|
+
type: "text",
|
|
8
|
+
text: footer,
|
|
9
|
+
size: "xs",
|
|
10
|
+
color: "#AAAAAA",
|
|
11
|
+
wrap: true,
|
|
12
|
+
align: "center"
|
|
13
|
+
}],
|
|
14
|
+
paddingAll: "lg",
|
|
15
|
+
backgroundColor: "#FAFAFA"
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region extensions/line/src/flex-templates/schedule-cards.ts
|
|
20
|
+
function buildTitleSubtitleHeader(params) {
|
|
21
|
+
const { title, subtitle } = params;
|
|
22
|
+
const headerContents = [{
|
|
23
|
+
type: "text",
|
|
24
|
+
text: title,
|
|
25
|
+
weight: "bold",
|
|
26
|
+
size: "xl",
|
|
27
|
+
color: "#111111",
|
|
28
|
+
wrap: true
|
|
29
|
+
}];
|
|
30
|
+
if (subtitle) headerContents.push({
|
|
31
|
+
type: "text",
|
|
32
|
+
text: subtitle,
|
|
33
|
+
size: "sm",
|
|
34
|
+
color: "#888888",
|
|
35
|
+
margin: "sm",
|
|
36
|
+
wrap: true
|
|
37
|
+
});
|
|
38
|
+
return headerContents;
|
|
39
|
+
}
|
|
40
|
+
function buildCardHeaderSections(headerContents) {
|
|
41
|
+
return [{
|
|
42
|
+
type: "box",
|
|
43
|
+
layout: "vertical",
|
|
44
|
+
contents: headerContents,
|
|
45
|
+
paddingBottom: "lg"
|
|
46
|
+
}, {
|
|
47
|
+
type: "separator",
|
|
48
|
+
color: "#EEEEEE"
|
|
49
|
+
}];
|
|
50
|
+
}
|
|
51
|
+
function createMegaBubbleWithFooter(params) {
|
|
52
|
+
const bubble = {
|
|
53
|
+
type: "bubble",
|
|
54
|
+
size: "mega",
|
|
55
|
+
body: {
|
|
56
|
+
type: "box",
|
|
57
|
+
layout: "vertical",
|
|
58
|
+
contents: params.bodyContents,
|
|
59
|
+
paddingAll: "xl",
|
|
60
|
+
backgroundColor: "#FFFFFF"
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
if (params.footer) attachFooterText(bubble, params.footer);
|
|
64
|
+
return bubble;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a receipt/summary card (for orders, transactions, data tables)
|
|
68
|
+
*
|
|
69
|
+
* Editorial design: Clean table layout with alternating row backgrounds,
|
|
70
|
+
* prominent total section, and clear visual hierarchy.
|
|
71
|
+
*/
|
|
72
|
+
function createReceiptCard(params) {
|
|
73
|
+
const { title, subtitle, items, total, footer } = params;
|
|
74
|
+
const itemRows = items.slice(0, 12).map((item, index) => ({
|
|
75
|
+
type: "box",
|
|
76
|
+
layout: "horizontal",
|
|
77
|
+
contents: [{
|
|
78
|
+
type: "text",
|
|
79
|
+
text: item.name,
|
|
80
|
+
size: "sm",
|
|
81
|
+
color: item.highlight ? "#111111" : "#666666",
|
|
82
|
+
weight: item.highlight ? "bold" : "regular",
|
|
83
|
+
flex: 3,
|
|
84
|
+
wrap: true
|
|
85
|
+
}, {
|
|
86
|
+
type: "text",
|
|
87
|
+
text: item.value,
|
|
88
|
+
size: "sm",
|
|
89
|
+
color: item.highlight ? "#06C755" : "#333333",
|
|
90
|
+
weight: item.highlight ? "bold" : "regular",
|
|
91
|
+
flex: 2,
|
|
92
|
+
align: "end",
|
|
93
|
+
wrap: true
|
|
94
|
+
}],
|
|
95
|
+
paddingAll: "md",
|
|
96
|
+
backgroundColor: index % 2 === 0 ? "#FFFFFF" : "#FAFAFA"
|
|
97
|
+
}));
|
|
98
|
+
const bodyContents = [...buildCardHeaderSections(buildTitleSubtitleHeader({
|
|
99
|
+
title,
|
|
100
|
+
subtitle
|
|
101
|
+
})), {
|
|
102
|
+
type: "box",
|
|
103
|
+
layout: "vertical",
|
|
104
|
+
contents: itemRows,
|
|
105
|
+
margin: "md",
|
|
106
|
+
cornerRadius: "md",
|
|
107
|
+
borderWidth: "light",
|
|
108
|
+
borderColor: "#EEEEEE"
|
|
109
|
+
}];
|
|
110
|
+
if (total) bodyContents.push({
|
|
111
|
+
type: "box",
|
|
112
|
+
layout: "horizontal",
|
|
113
|
+
contents: [{
|
|
114
|
+
type: "text",
|
|
115
|
+
text: total.label,
|
|
116
|
+
size: "lg",
|
|
117
|
+
weight: "bold",
|
|
118
|
+
color: "#111111",
|
|
119
|
+
flex: 2
|
|
120
|
+
}, {
|
|
121
|
+
type: "text",
|
|
122
|
+
text: total.value,
|
|
123
|
+
size: "xl",
|
|
124
|
+
weight: "bold",
|
|
125
|
+
color: "#06C755",
|
|
126
|
+
flex: 2,
|
|
127
|
+
align: "end"
|
|
128
|
+
}],
|
|
129
|
+
margin: "xl",
|
|
130
|
+
paddingAll: "lg",
|
|
131
|
+
backgroundColor: "#F0FDF4",
|
|
132
|
+
cornerRadius: "lg"
|
|
133
|
+
});
|
|
134
|
+
return createMegaBubbleWithFooter({
|
|
135
|
+
bodyContents,
|
|
136
|
+
footer
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create a calendar event card (for meetings, appointments, reminders)
|
|
141
|
+
*
|
|
142
|
+
* Editorial design: Date as hero, strong typographic hierarchy,
|
|
143
|
+
* color-blocked zones, full text wrapping for readability.
|
|
144
|
+
*/
|
|
145
|
+
function createEventCard(params) {
|
|
146
|
+
const { title, date, time, location, description, calendar, isAllDay, action } = params;
|
|
147
|
+
const dateBlock = {
|
|
148
|
+
type: "box",
|
|
149
|
+
layout: "vertical",
|
|
150
|
+
contents: [{
|
|
151
|
+
type: "text",
|
|
152
|
+
text: date.toUpperCase(),
|
|
153
|
+
size: "sm",
|
|
154
|
+
weight: "bold",
|
|
155
|
+
color: "#06C755",
|
|
156
|
+
wrap: true
|
|
157
|
+
}, {
|
|
158
|
+
type: "text",
|
|
159
|
+
text: isAllDay ? "ALL DAY" : time ?? "",
|
|
160
|
+
size: "xxl",
|
|
161
|
+
weight: "bold",
|
|
162
|
+
color: "#111111",
|
|
163
|
+
wrap: true,
|
|
164
|
+
margin: "xs"
|
|
165
|
+
}],
|
|
166
|
+
paddingBottom: "lg",
|
|
167
|
+
borderWidth: "none"
|
|
168
|
+
};
|
|
169
|
+
if (!time && !isAllDay) dateBlock.contents = [{
|
|
170
|
+
type: "text",
|
|
171
|
+
text: date,
|
|
172
|
+
size: "xl",
|
|
173
|
+
weight: "bold",
|
|
174
|
+
color: "#111111",
|
|
175
|
+
wrap: true
|
|
176
|
+
}];
|
|
177
|
+
const bodyContents = [dateBlock, {
|
|
178
|
+
type: "box",
|
|
179
|
+
layout: "horizontal",
|
|
180
|
+
contents: [{
|
|
181
|
+
type: "box",
|
|
182
|
+
layout: "vertical",
|
|
183
|
+
contents: [],
|
|
184
|
+
width: "4px",
|
|
185
|
+
backgroundColor: "#06C755",
|
|
186
|
+
cornerRadius: "2px"
|
|
187
|
+
}, {
|
|
188
|
+
type: "box",
|
|
189
|
+
layout: "vertical",
|
|
190
|
+
contents: [{
|
|
191
|
+
type: "text",
|
|
192
|
+
text: title,
|
|
193
|
+
size: "lg",
|
|
194
|
+
weight: "bold",
|
|
195
|
+
color: "#1a1a1a",
|
|
196
|
+
wrap: true
|
|
197
|
+
}, ...calendar ? [{
|
|
198
|
+
type: "text",
|
|
199
|
+
text: calendar,
|
|
200
|
+
size: "xs",
|
|
201
|
+
color: "#888888",
|
|
202
|
+
margin: "sm",
|
|
203
|
+
wrap: true
|
|
204
|
+
}] : []],
|
|
205
|
+
flex: 1,
|
|
206
|
+
paddingStart: "lg"
|
|
207
|
+
}],
|
|
208
|
+
paddingTop: "lg",
|
|
209
|
+
paddingBottom: "lg",
|
|
210
|
+
borderWidth: "light",
|
|
211
|
+
borderColor: "#EEEEEE"
|
|
212
|
+
}];
|
|
213
|
+
if (location || description) {
|
|
214
|
+
const detailItems = [];
|
|
215
|
+
if (location) detailItems.push({
|
|
216
|
+
type: "box",
|
|
217
|
+
layout: "horizontal",
|
|
218
|
+
contents: [{
|
|
219
|
+
type: "text",
|
|
220
|
+
text: "📍",
|
|
221
|
+
size: "sm",
|
|
222
|
+
flex: 0
|
|
223
|
+
}, {
|
|
224
|
+
type: "text",
|
|
225
|
+
text: location,
|
|
226
|
+
size: "sm",
|
|
227
|
+
color: "#444444",
|
|
228
|
+
margin: "md",
|
|
229
|
+
flex: 1,
|
|
230
|
+
wrap: true
|
|
231
|
+
}],
|
|
232
|
+
alignItems: "flex-start"
|
|
233
|
+
});
|
|
234
|
+
if (description) detailItems.push({
|
|
235
|
+
type: "text",
|
|
236
|
+
text: description,
|
|
237
|
+
size: "sm",
|
|
238
|
+
color: "#666666",
|
|
239
|
+
wrap: true,
|
|
240
|
+
margin: location ? "lg" : "none"
|
|
241
|
+
});
|
|
242
|
+
bodyContents.push({
|
|
243
|
+
type: "box",
|
|
244
|
+
layout: "vertical",
|
|
245
|
+
contents: detailItems,
|
|
246
|
+
margin: "lg",
|
|
247
|
+
paddingAll: "lg",
|
|
248
|
+
backgroundColor: "#F8F9FA",
|
|
249
|
+
cornerRadius: "lg"
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
type: "bubble",
|
|
254
|
+
size: "mega",
|
|
255
|
+
body: {
|
|
256
|
+
type: "box",
|
|
257
|
+
layout: "vertical",
|
|
258
|
+
contents: bodyContents,
|
|
259
|
+
paddingAll: "xl",
|
|
260
|
+
backgroundColor: "#FFFFFF",
|
|
261
|
+
action
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Create a calendar agenda card showing multiple events
|
|
267
|
+
*
|
|
268
|
+
* Editorial timeline design: Time-focused left column with event details
|
|
269
|
+
* on the right. Visual accent bars indicate event priority/recency.
|
|
270
|
+
*/
|
|
271
|
+
function createAgendaCard(params) {
|
|
272
|
+
const { title, subtitle, events, footer } = params;
|
|
273
|
+
const headerContents = buildTitleSubtitleHeader({
|
|
274
|
+
title,
|
|
275
|
+
subtitle
|
|
276
|
+
});
|
|
277
|
+
const eventItems = events.slice(0, 6).map((event, index) => {
|
|
278
|
+
const isActive = event.isNow || index === 0;
|
|
279
|
+
const accentColor = isActive ? "#06C755" : "#E5E5E5";
|
|
280
|
+
const timeColumn = {
|
|
281
|
+
type: "box",
|
|
282
|
+
layout: "vertical",
|
|
283
|
+
contents: [{
|
|
284
|
+
type: "text",
|
|
285
|
+
text: event.time ?? "—",
|
|
286
|
+
size: "sm",
|
|
287
|
+
weight: isActive ? "bold" : "regular",
|
|
288
|
+
color: isActive ? "#06C755" : "#666666",
|
|
289
|
+
align: "end",
|
|
290
|
+
wrap: true
|
|
291
|
+
}],
|
|
292
|
+
width: "65px",
|
|
293
|
+
justifyContent: "flex-start"
|
|
294
|
+
};
|
|
295
|
+
const dotColumn = {
|
|
296
|
+
type: "box",
|
|
297
|
+
layout: "vertical",
|
|
298
|
+
contents: [{
|
|
299
|
+
type: "box",
|
|
300
|
+
layout: "vertical",
|
|
301
|
+
contents: [],
|
|
302
|
+
width: "10px",
|
|
303
|
+
height: "10px",
|
|
304
|
+
backgroundColor: accentColor,
|
|
305
|
+
cornerRadius: "5px"
|
|
306
|
+
}],
|
|
307
|
+
width: "24px",
|
|
308
|
+
alignItems: "center",
|
|
309
|
+
justifyContent: "flex-start",
|
|
310
|
+
paddingTop: "xs"
|
|
311
|
+
};
|
|
312
|
+
const detailContents = [{
|
|
313
|
+
type: "text",
|
|
314
|
+
text: event.title,
|
|
315
|
+
size: "md",
|
|
316
|
+
weight: "bold",
|
|
317
|
+
color: "#1a1a1a",
|
|
318
|
+
wrap: true
|
|
319
|
+
}];
|
|
320
|
+
const secondaryParts = [];
|
|
321
|
+
if (event.location) secondaryParts.push(event.location);
|
|
322
|
+
if (event.calendar) secondaryParts.push(event.calendar);
|
|
323
|
+
if (secondaryParts.length > 0) detailContents.push({
|
|
324
|
+
type: "text",
|
|
325
|
+
text: secondaryParts.join(" · "),
|
|
326
|
+
size: "xs",
|
|
327
|
+
color: "#888888",
|
|
328
|
+
wrap: true,
|
|
329
|
+
margin: "xs"
|
|
330
|
+
});
|
|
331
|
+
return {
|
|
332
|
+
type: "box",
|
|
333
|
+
layout: "horizontal",
|
|
334
|
+
contents: [
|
|
335
|
+
timeColumn,
|
|
336
|
+
dotColumn,
|
|
337
|
+
{
|
|
338
|
+
type: "box",
|
|
339
|
+
layout: "vertical",
|
|
340
|
+
contents: detailContents,
|
|
341
|
+
flex: 1
|
|
342
|
+
}
|
|
343
|
+
],
|
|
344
|
+
margin: index > 0 ? "xl" : void 0,
|
|
345
|
+
alignItems: "flex-start"
|
|
346
|
+
};
|
|
347
|
+
});
|
|
348
|
+
return createMegaBubbleWithFooter({
|
|
349
|
+
bodyContents: [...buildCardHeaderSections(headerContents), {
|
|
350
|
+
type: "box",
|
|
351
|
+
layout: "vertical",
|
|
352
|
+
contents: eventItems,
|
|
353
|
+
paddingTop: "xl"
|
|
354
|
+
}],
|
|
355
|
+
footer
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
//#endregion
|
|
359
|
+
export { attachFooterText as i, createEventCard as n, createReceiptCard as r, createAgendaCard as t };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineBundledChannelSetupEntry } from "klaw/plugin-sdk/channel-entry-contract";
|
|
2
|
+
//#region extensions/line/setup-entry.ts
|
|
3
|
+
var setup_entry_default = defineBundledChannelSetupEntry({
|
|
4
|
+
importMetaUrl: import.meta.url,
|
|
5
|
+
plugin: {
|
|
6
|
+
specifier: "./api.js",
|
|
7
|
+
exportName: "lineSetupPlugin"
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
//#endregion
|
|
11
|
+
export { setup_entry_default as default };
|