@openclaw/line 2026.11.12 → 2026.12.1-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.
- package/dist/.setup/api-BFKOcDBj.mjs +3 -0
- package/dist/.setup/{api-CMPtJvIX.mjs → api-BHi0Jdse.mjs} +1 -1
- package/dist/.setup/{card-command-utjlRvb-.mjs → card-command-3YJcF1Sg.mjs} +2 -2
- package/dist/.setup/{channel-p6vbK7z1.mjs → channel-D8h0qJMW.mjs} +381 -18
- package/dist/.setup/channel.runtime-BBSUSMgH.mjs +4 -0
- package/dist/.setup/{monitor-D_RfCX20.mjs → monitor-B4Vqphj5.mjs} +7 -8
- package/dist/.setup/outbound.runtime-C41lKCRl.mjs +3 -0
- package/dist/.setup/{send-retry-D6J7bThI.mjs → schedule-cards-D2zI0jRv.mjs} +3 -352
- package/dist/.setup/send-Btj5Sv6v.mjs +664 -0
- package/dist/.setup/template-messages-5ZlXYNrb.mjs +198 -0
- package/dist/.source-module-urls/2c97352967966b7ab9f67f528eb25c098b6fe10ea0e4616ffae3851ed839d81e.json +1 -1
- package/dist/api.js +2 -2
- package/dist/channel-plugin-api.js +1 -1
- package/dist/index.js +1 -1
- package/dist/setup-entry.js +1 -1
- package/package.json +4 -4
- package/dist/.setup/api-B7qoCDpM.mjs +0 -3
- package/dist/.setup/channel.runtime-DlTsOqaQ.mjs +0 -4
- package/dist/.setup/outbound.runtime-BGlJ18sK.mjs +0 -3
- package/dist/.setup/send-H86JOXWw.mjs +0 -335
- package/dist/.setup/template-messages-B8c6X5DV.mjs +0 -464
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { f as messageAction, g as uriAction, m as postbackAction } from "./schedule-cards-D2zI0jRv.mjs";
|
|
2
|
+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
3
|
+
// packages/normalization-core/src/utf16-slice.ts
|
|
4
|
+
function isHighSurrogate(codeUnit) {
|
|
5
|
+
return codeUnit >= 55296 && codeUnit <= 56319;
|
|
6
|
+
}
|
|
7
|
+
function isLowSurrogate(codeUnit) {
|
|
8
|
+
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
9
|
+
}
|
|
10
|
+
/** Moves a chunk boundary away from the middle of a UTF-16 surrogate pair. */
|
|
11
|
+
function avoidTrailingHighSurrogateBreak(text, start, end) {
|
|
12
|
+
if (end <= start || end >= text.length || !isHighSurrogate(text.charCodeAt(end - 1)) || !isLowSurrogate(text.charCodeAt(end))) return end;
|
|
13
|
+
const adjusted = end - 1;
|
|
14
|
+
return adjusted > start ? adjusted : end + 1;
|
|
15
|
+
}
|
|
16
|
+
// packages/normalization-core/src/grapheme.ts
|
|
17
|
+
let graphemeSegmenter;
|
|
18
|
+
function getGraphemeSegmenter() {
|
|
19
|
+
graphemeSegmenter ??= new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
20
|
+
return graphemeSegmenter;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Chooses a whole-grapheme cut within the hard budget, honoring a usable preference.
|
|
24
|
+
* If no whole grapheme fits, allowPartial permits a surrogate-safe progress cut;
|
|
25
|
+
* a leading surrogate pair can exceed maxEnd by one code unit.
|
|
26
|
+
*/
|
|
27
|
+
function findGraphemeChunkEnd(text, start, maxEnd, preferredEnd = maxEnd, allowPartial = true) {
|
|
28
|
+
return graphemeChunkEndFinder(text, false)(start, maxEnd, preferredEnd, allowPartial);
|
|
29
|
+
}
|
|
30
|
+
function indexGraphemeBoundaries(text) {
|
|
31
|
+
const starts = new Uint32Array(Math.ceil(text.length / 32));
|
|
32
|
+
for (const { index } of getGraphemeSegmenter().segment(text)) {
|
|
33
|
+
const word = Math.floor(index / 32);
|
|
34
|
+
starts[word] = (starts[word] ?? 0) | 1 << index % 32;
|
|
35
|
+
}
|
|
36
|
+
const preceding = new Uint32Array(starts.length);
|
|
37
|
+
let last = 0;
|
|
38
|
+
for (const [word, bits] of starts.entries()) {
|
|
39
|
+
preceding[word] = last;
|
|
40
|
+
if (bits !== 0) last = word * 32 + 31 - Math.clz32(bits);
|
|
41
|
+
}
|
|
42
|
+
return (offset) => {
|
|
43
|
+
const word = Math.floor(offset / 32);
|
|
44
|
+
const throughOffset = 4294967295 >>> 31 - (offset & 31);
|
|
45
|
+
const bits = (starts[word] ?? 0) & throughOffset;
|
|
46
|
+
return bits === 0 ? preceding[word] ?? 0 : word * 32 + 31 - Math.clz32(bits);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function graphemeChunkEndFinder(text, reuse) {
|
|
50
|
+
let lastBoundary = 0;
|
|
51
|
+
let indexed;
|
|
52
|
+
return (start, maxEnd, preferredEnd = maxEnd, allowPartial = true) => {
|
|
53
|
+
const hardEnd = Math.min(maxEnd, text.length);
|
|
54
|
+
if (hardEnd <= start) return start;
|
|
55
|
+
const preferred = Number.isInteger(preferredEnd) && preferredEnd > start && preferredEnd <= hardEnd ? preferredEnd : hardEnd;
|
|
56
|
+
if (preferred === text.length) return preferred;
|
|
57
|
+
const before = text.charCodeAt(preferred - 1);
|
|
58
|
+
const after = text.charCodeAt(preferred);
|
|
59
|
+
if (Number.isInteger(preferred) && before <= 127 && after <= 127 && !(before === 13 && after === 10)) {
|
|
60
|
+
lastBoundary = preferred;
|
|
61
|
+
return preferred;
|
|
62
|
+
}
|
|
63
|
+
const from = start === 0 ? 0 : lastBoundary ?? 0;
|
|
64
|
+
if (reuse && start !== 0 && (lastBoundary === void 0 || from > start || start - from > hardEnd - start)) indexed ??= indexGraphemeBoundaries(text);
|
|
65
|
+
const segments = indexed ? void 0 : getGraphemeSegmenter().segment(text.slice(from, hardEnd + 2));
|
|
66
|
+
const boundaryAt = indexed ?? ((position) => from + (segments?.containing(position - from)?.index ?? position - from));
|
|
67
|
+
let end = boundaryAt(preferred);
|
|
68
|
+
if (end <= start && preferred < hardEnd) end = hardEnd === text.length ? hardEnd : boundaryAt(hardEnd);
|
|
69
|
+
if (end > start) {
|
|
70
|
+
lastBoundary = end;
|
|
71
|
+
return end;
|
|
72
|
+
}
|
|
73
|
+
if (allowPartial) {
|
|
74
|
+
lastBoundary = void 0;
|
|
75
|
+
return avoidTrailingHighSurrogateBreak(text, start, hardEnd);
|
|
76
|
+
}
|
|
77
|
+
return start;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// extensions/line/src/template-messages.ts
|
|
81
|
+
const COMPACT_TEMPLATE_TEXT_LIMIT = 60;
|
|
82
|
+
const TEMPLATE_ALT_TEXT_LIMIT = 1500;
|
|
83
|
+
const LINE_FLEX_ALT_TEXT_LIMIT = 1500;
|
|
84
|
+
const LINE_LOCATION_LABEL_LIMIT = 100;
|
|
85
|
+
function buildTemplatePayloadAction(action) {
|
|
86
|
+
if (action.type === "uri" && action.uri) return uriAction(action.label, action.uri);
|
|
87
|
+
if (action.type === "postback" && action.data) return postbackAction(action.label, action.data, action.label);
|
|
88
|
+
return messageAction(action.label, action.data ?? action.label);
|
|
89
|
+
}
|
|
90
|
+
function buildInferredTemplateAction(label, data) {
|
|
91
|
+
return data.startsWith("http") ? uriAction(label, data) : data.includes("=") ? postbackAction(label, data, label) : messageAction(label, data);
|
|
92
|
+
}
|
|
93
|
+
function resolveTemplateTextLimit(title, thumbnailImageUrl, textOnlyLimit) {
|
|
94
|
+
return title !== void 0 || thumbnailImageUrl !== void 0 ? COMPACT_TEMPLATE_TEXT_LIMIT : textOnlyLimit;
|
|
95
|
+
}
|
|
96
|
+
function truncateTemplateText(text, limit) {
|
|
97
|
+
const end = findGraphemeChunkEnd(text, 0, limit, limit, false);
|
|
98
|
+
return end > 0 ? text.slice(0, end) : truncateUtf16Safe(text, limit);
|
|
99
|
+
}
|
|
100
|
+
function resolveTemplateAltText(value, fallback) {
|
|
101
|
+
return truncateTemplateText(value ?? fallback, TEMPLATE_ALT_TEXT_LIMIT);
|
|
102
|
+
}
|
|
103
|
+
function createLocationMessage(location) {
|
|
104
|
+
if (!location.title.trim() || !location.address.trim()) return {
|
|
105
|
+
type: "text",
|
|
106
|
+
text: [...[location.title, location.address].map((label) => truncateUtf16Safe(label.trim(), LINE_LOCATION_LABEL_LIMIT)).filter(Boolean), `${location.latitude}, ${location.longitude}`].join("\n")
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
type: "location",
|
|
110
|
+
title: truncateUtf16Safe(location.title, LINE_LOCATION_LABEL_LIMIT),
|
|
111
|
+
address: truncateUtf16Safe(location.address, LINE_LOCATION_LABEL_LIMIT),
|
|
112
|
+
latitude: location.latitude,
|
|
113
|
+
longitude: location.longitude
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function createFlexMessage(altText, contents) {
|
|
117
|
+
return {
|
|
118
|
+
type: "flex",
|
|
119
|
+
altText: truncateUtf16Safe(altText, LINE_FLEX_ALT_TEXT_LIMIT),
|
|
120
|
+
contents
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function createQuickReplyItems(labels) {
|
|
124
|
+
return { items: labels.map((label) => label.trim()).filter(Boolean).slice(0, 13).map((label) => ({
|
|
125
|
+
type: "action",
|
|
126
|
+
action: messageAction(label, label)
|
|
127
|
+
})) };
|
|
128
|
+
}
|
|
129
|
+
function buildTemplateMessageFromPayload(payload) {
|
|
130
|
+
switch (payload.type) {
|
|
131
|
+
case "confirm": return {
|
|
132
|
+
type: "template",
|
|
133
|
+
altText: resolveTemplateAltText(payload.altText, payload.text),
|
|
134
|
+
template: {
|
|
135
|
+
type: "confirm",
|
|
136
|
+
text: truncateTemplateText(payload.text, 240),
|
|
137
|
+
actions: [buildInferredTemplateAction(payload.confirmLabel, payload.confirmData), buildInferredTemplateAction(payload.cancelLabel, payload.cancelData)]
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
case "buttons": {
|
|
141
|
+
const title = payload.title || void 0;
|
|
142
|
+
const textLimit = resolveTemplateTextLimit(title, payload.thumbnailImageUrl, 160);
|
|
143
|
+
return {
|
|
144
|
+
type: "template",
|
|
145
|
+
altText: resolveTemplateAltText(payload.altText, title ? `${title}: ${payload.text}` : payload.text),
|
|
146
|
+
template: {
|
|
147
|
+
type: "buttons",
|
|
148
|
+
...title ? { title: truncateTemplateText(title, 40) } : {},
|
|
149
|
+
text: truncateTemplateText(payload.text, textLimit),
|
|
150
|
+
actions: payload.actions.slice(0, 4).map(buildTemplatePayloadAction),
|
|
151
|
+
thumbnailImageUrl: payload.thumbnailImageUrl,
|
|
152
|
+
imageAspectRatio: "rectangle",
|
|
153
|
+
imageSize: "cover",
|
|
154
|
+
imageBackgroundColor: void 0,
|
|
155
|
+
defaultAction: void 0
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
case "carousel": {
|
|
160
|
+
const visibleColumns = payload.columns.map((column) => {
|
|
161
|
+
const title = column.title || void 0;
|
|
162
|
+
const textLimit = resolveTemplateTextLimit(title, column.thumbnailImageUrl, 120);
|
|
163
|
+
return {
|
|
164
|
+
title: title === void 0 ? void 0 : truncateTemplateText(title, 40),
|
|
165
|
+
text: truncateTemplateText(column.text, textLimit),
|
|
166
|
+
actions: column.actions.map(buildTemplatePayloadAction).filter((action) => action.label !== void 0 && action.label !== "").slice(0, 3),
|
|
167
|
+
thumbnailImageUrl: column.thumbnailImageUrl,
|
|
168
|
+
imageBackgroundColor: void 0,
|
|
169
|
+
defaultAction: void 0
|
|
170
|
+
};
|
|
171
|
+
}).slice(0, 10);
|
|
172
|
+
const first = visibleColumns[0];
|
|
173
|
+
if (!first || visibleColumns.some((column) => column.text === "" || column.actions.length === 0 || column.title === void 0 !== (first.title === void 0) || column.actions.length !== first.actions.length)) {
|
|
174
|
+
const text = [...payload.altText ? [truncateTemplateText(payload.altText, TEMPLATE_ALT_TEXT_LIMIT)] : [], ...visibleColumns.map((column) => {
|
|
175
|
+
const body = column.title ? `${column.title}: ${column.text}` : column.text;
|
|
176
|
+
const labels = column.actions.map((action) => action.label).filter((label) => label !== void 0 && label !== "");
|
|
177
|
+
return labels.length > 0 ? `${body} (${labels.join(" / ")})` : body;
|
|
178
|
+
}).filter((line) => line !== "")].join("\n");
|
|
179
|
+
return text ? {
|
|
180
|
+
type: "text",
|
|
181
|
+
text
|
|
182
|
+
} : null;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
type: "template",
|
|
186
|
+
altText: resolveTemplateAltText(payload.altText, "View carousel"),
|
|
187
|
+
template: {
|
|
188
|
+
type: "carousel",
|
|
189
|
+
columns: visibleColumns,
|
|
190
|
+
imageAspectRatio: "rectangle",
|
|
191
|
+
imageSize: "cover"
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
default: return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export { createQuickReplyItems as i, createFlexMessage as n, createLocationMessage as r, buildTemplateMessageFromPayload as t };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"entries":[{"output":"api.js","source":"extensions/line/api.ts"},{"output":"channel-plugin-api.js","source":"extensions/line/channel-plugin-api.ts"},{"output":"contract-api.js","source":"extensions/line/contract-api.ts"},{"output":"doctor-contract-api.js","source":"extensions/line/doctor-contract-api.ts"},{"output":"index.js","source":"extensions/line/index.ts"},{"output":"runtime-api.js","source":"extensions/line/runtime-api.ts"},{"output":"secret-contract-api.js","source":"extensions/line/secret-contract-api.ts"},{"output":"setup-api.js","source":"extensions/line/setup-api.ts"},{"output":"setup-entry.js","source":"extensions/line/setup-entry.ts"}],"chunks":[{"output":".setup/accounts-Dm_NoU7R.mjs","sha256":"fbb3c981ee38eddff00d1f154e26a072649d43bb8648fad0e9318725f3c28b97","facadeSource":null,"sources":["extensions/line/src/accounts.ts"]},{"output":".setup/api-
|
|
1
|
+
{"version":3,"entries":[{"output":"api.js","source":"extensions/line/api.ts"},{"output":"channel-plugin-api.js","source":"extensions/line/channel-plugin-api.ts"},{"output":"contract-api.js","source":"extensions/line/contract-api.ts"},{"output":"doctor-contract-api.js","source":"extensions/line/doctor-contract-api.ts"},{"output":"index.js","source":"extensions/line/index.ts"},{"output":"runtime-api.js","source":"extensions/line/runtime-api.ts"},{"output":"secret-contract-api.js","source":"extensions/line/secret-contract-api.ts"},{"output":"setup-api.js","source":"extensions/line/setup-api.ts"},{"output":"setup-entry.js","source":"extensions/line/setup-entry.ts"}],"chunks":[{"output":".setup/accounts-Dm_NoU7R.mjs","sha256":"fbb3c981ee38eddff00d1f154e26a072649d43bb8648fad0e9318725f3c28b97","facadeSource":null,"sources":["extensions/line/src/accounts.ts"]},{"output":".setup/api-BFKOcDBj.mjs","sha256":"ef7650988c2f177e9f598f44403379ddaa465c4c9e39c5b6f0a1e8acab512ef9","facadeSource":"extensions/line/api.ts","sources":[]},{"output":".setup/api-BHi0Jdse.mjs","sha256":"5967c7c106b4271b513271db9ab02a8d69516dcc5368bb098a8423532185017f","facadeSource":null,"sources":["extensions/line/src/channel.setup.ts"]},{"output":".setup/card-command-3YJcF1Sg.mjs","sha256":"dd26a515c2f6f2b85fc639a229e3ecf90cf2ca398d188b58ce9fd8d1a8068cf4","facadeSource":"extensions/line/src/card-command.ts","sources":["extensions/line/src/card-command.ts"]},{"output":".setup/channel-D8h0qJMW.mjs","sha256":"f9e97b2ae4333aed8b025c38697a3d88d7a9b3bd6161654dbadf56f77c7e489e","facadeSource":null,"sources":["extensions/line/src/channel-access-token.ts","extensions/line/src/channel-shared.ts","extensions/line/src/channel.ts","extensions/line/src/config-adapter.ts","extensions/line/src/config-schema.ts","extensions/line/src/doctor.ts","extensions/line/src/gateway.ts","extensions/line/src/group-keys.ts","extensions/line/src/messaging-target.ts","extensions/line/src/outbound-media.ts","extensions/line/src/outbound.ts","extensions/line/src/probe.ts","extensions/line/src/question-postback.ts","extensions/line/src/quick-reply-fallback.ts","extensions/line/src/quote-tokens.ts","extensions/line/src/rich-message-schema.ts","extensions/line/src/rich-messages.ts","extensions/line/src/send-retry.ts","extensions/line/src/status.ts"]},{"output":".setup/channel.runtime-BBSUSMgH.mjs","sha256":"f0f2cb49fe54919310d99fa8ddac9a55ddecd25abb1890270af1b4ba3f70c346","facadeSource":"extensions/line/src/channel.runtime.ts","sources":[]},{"output":".setup/monitor-B4Vqphj5.mjs","sha256":"5eb4f583aad361f684f3b0358524670351c9f409701385f63a862ffd4a2f5a06","facadeSource":"extensions/line/src/monitor.ts","sources":["extensions/line/src/auto-reply-delivery.ts","extensions/line/src/bot-handlers.ts","extensions/line/src/bot-message-context.ts","extensions/line/src/bot.ts","extensions/line/src/download.ts","extensions/line/src/group-history.ts","extensions/line/src/inbound-image-set.ts","extensions/line/src/mentions.ts","extensions/line/src/monitor.ts","extensions/line/src/signature.ts","extensions/line/src/webhook-node.ts","extensions/line/src/webhook-spool.ts"]},{"output":".setup/outbound.runtime-C41lKCRl.mjs","sha256":"abb408cf2eccd8081907a013f5160749b0e28ee463c33487404629449ce911d4","facadeSource":"extensions/line/src/outbound.runtime.ts","sources":[]},{"output":".setup/runtime-C9ldw-V4.mjs","sha256":"ac1144683eff8dc37f71e7b26f00dd5f692e4c35b6ac4a14d11ba81603dc0414","facadeSource":null,"sources":["extensions/line/src/runtime.ts"]},{"output":".setup/schedule-cards-D2zI0jRv.mjs","sha256":"0d015e0923b7eb479ede357ac1497a415c646f480a89bca9a4ff4012f53a2436","facadeSource":null,"sources":["extensions/line/src/actions.ts","extensions/line/src/flex-templates/basic-cards.ts","extensions/line/src/flex-templates/common.ts","extensions/line/src/flex-templates/message.ts","extensions/line/src/flex-templates/schedule-cards.ts","extensions/line/src/media-url.ts"]},{"output":".setup/send-Btj5Sv6v.mjs","sha256":"09757980b856feadfbef4617597c6112f4249d44b3547609189d1359e5106e04","facadeSource":null,"sources":["extensions/line/src/markdown-to-line.ts","extensions/line/src/outbound-message-log.ts","extensions/line/src/send.ts"]},{"output":".setup/setup-surface-DvbBjHFi.mjs","sha256":"9d8e2bdd72c9e37a53b10784ca83e0257e8ce7da2f40f8fb279132babf872430","facadeSource":null,"sources":["extensions/line/src/account-helpers.ts","extensions/line/src/bot-access.ts","extensions/line/src/setup-core.ts","extensions/line/src/setup-surface.ts"]},{"output":".setup/template-messages-5ZlXYNrb.mjs","sha256":"c45ea3e83fda48337869f85901d62a088d1f9a435f6f3c2b51d82fdc9db12b1c","facadeSource":null,"sources":["extensions/line/src/template-messages.ts","packages/normalization-core/src/grapheme.ts","packages/normalization-core/src/utf16-slice.ts"]},{"output":".setup/webhook-spool-contract-COhQK5XQ.mjs","sha256":"c5980d6b5431bd7ffab5f3c3351ac3aa3c7d477f1aec4244e1f3d8b01d704743","facadeSource":null,"sources":["extensions/line/src/webhook-spool-contract.ts"]},{"output":"api.js","sha256":"5e9f58c90690d4285e993be486cdfdb389c60a2461ffb43b27cec20421b49e44","facadeSource":"extensions/line/api.ts","sources":[]},{"output":"channel-plugin-api.js","sha256":"24d7f13d277266f1abd237a3e977b7730b37348fe26417b8a42d6ef12ff7ec79","facadeSource":"extensions/line/channel-plugin-api.ts","sources":[]},{"output":"contract-api.js","sha256":"88215026ff1655afd96c12893f7d2efdbcfacd9b21c5029e1653de305c208773","facadeSource":"extensions/line/contract-api.ts","sources":[]},{"output":"doctor-contract-api.js","sha256":"a516c654e8d5273dd36fd75728a10b044021efb68815296dd0400b1958a49dbe","facadeSource":"extensions/line/doctor-contract-api.ts","sources":["extensions/line/doctor-contract-api.ts","extensions/line/src/webhook-spool-migration.ts"]},{"output":"index.js","sha256":"f1704905a543e6b32361a8b5231ceddfd4bf9ea2bf324730d296d9f462fbeebd","facadeSource":"extensions/line/index.ts","sources":["extensions/line/index.ts"]},{"output":"runtime-api.js","sha256":"e37fbce0148c490628ce5edc25492212c1a2d3a7c3f084353a5ee49972159886","facadeSource":"extensions/line/runtime-api.ts","sources":[]},{"output":"secret-contract-api.js","sha256":"4824eb0315431709e20d35bb056c00eae3498212e57bda4dd9cdbb24f3db07c4","facadeSource":"extensions/line/secret-contract-api.ts","sources":["extensions/line/secret-contract-api.ts"]},{"output":"setup-api.js","sha256":"730732424bb98bbceaca6d6e982a03e799f30200b1413fc0bd82aef62865b256","facadeSource":"extensions/line/setup-api.ts","sources":[]},{"output":"setup-entry.js","sha256":"ab5c1144dfdd792f279b3be7f1916fbfe48bdf7196e05a6b2f21483d78d8adf7","facadeSource":"extensions/line/setup-entry.ts","sources":["extensions/line/setup-entry.ts"]}],"unrenderedSources":["extensions/line/api.ts","extensions/line/channel-plugin-api.ts","extensions/line/contract-api.ts","extensions/line/runtime-api.ts","extensions/line/setup-api.ts","extensions/line/src/channel.runtime.ts","extensions/line/src/outbound.runtime.ts","src/plugin-sdk/text-grapheme.ts"]}
|
package/dist/api.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as linePlugin } from "./.setup/channel-
|
|
2
|
-
import { t as lineSetupPlugin } from "./.setup/api-
|
|
1
|
+
import { t as linePlugin } from "./.setup/channel-D8h0qJMW.mjs";
|
|
2
|
+
import { t as lineSetupPlugin } from "./.setup/api-BHi0Jdse.mjs";
|
|
3
3
|
export { linePlugin, lineSetupPlugin };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as linePlugin } from "./.setup/channel-
|
|
1
|
+
export { t as linePlugin } from "./.setup/channel-D8h0qJMW.mjs";
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ var line_default = defineBundledChannelEntry({
|
|
|
21
21
|
acceptsArgs: true,
|
|
22
22
|
requireAuth: false,
|
|
23
23
|
async handler(ctx) {
|
|
24
|
-
const { handleLineCardCommand } = await import("./.setup/card-command-
|
|
24
|
+
const { handleLineCardCommand } = await import("./.setup/card-command-3YJcF1Sg.mjs");
|
|
25
25
|
return await handleLineCardCommand(ctx.args);
|
|
26
26
|
}
|
|
27
27
|
});
|
package/dist/setup-entry.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
var setup_entry_default = defineBundledChannelSetupEntry({
|
|
5
5
|
importMetaUrl: import.meta.url,
|
|
6
6
|
plugin: {
|
|
7
|
-
specifier: fileURLToPath(new URL(".setup/api-
|
|
7
|
+
specifier: fileURLToPath(new URL(".setup/api-BFKOcDBj.mjs", import.meta.url).href),
|
|
8
8
|
exportName: "lineSetupPlugin"
|
|
9
9
|
}
|
|
10
10
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/line",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.12.1-beta.2",
|
|
4
4
|
"description": "OpenClaw LINE channel plugin for LINE Bot API chats.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"zod": "4.6.7"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"openclaw": ">=2026.
|
|
16
|
+
"openclaw": ">=2026.12.1-beta.2"
|
|
17
17
|
},
|
|
18
18
|
"peerDependenciesMeta": {
|
|
19
19
|
"openclaw": {
|
|
@@ -122,10 +122,10 @@
|
|
|
122
122
|
"minHostVersion": ">=2026.4.10"
|
|
123
123
|
},
|
|
124
124
|
"compat": {
|
|
125
|
-
"pluginApi": ">=2026.
|
|
125
|
+
"pluginApi": ">=2026.12.1-beta.2"
|
|
126
126
|
},
|
|
127
127
|
"build": {
|
|
128
|
-
"openclawVersion": "2026.
|
|
128
|
+
"openclawVersion": "2026.12.1-beta.2"
|
|
129
129
|
},
|
|
130
130
|
"release": {
|
|
131
131
|
"publishToClawHub": true,
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { a as probeLineBot } from "./send-retry-D6J7bThI.mjs";
|
|
2
|
-
import { l as pushMessageLine, m as showLoadingAnimation } from "./send-H86JOXWw.mjs";
|
|
3
|
-
import { monitorLineProvider } from "./monitor-D_RfCX20.mjs";
|
|
4
|
-
export { monitorLineProvider, probeLineBot, pushMessageLine, showLoadingAnimation };
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { c as pushLocationMessage, d as pushTemplateMessage, f as pushTextMessageWithQuickReplies, l as pushMessageLine, n as createLocationMessage, r as createQuickReplyItems, s as pushFlexMessage, t as createFlexMessage, u as pushMessagesLine } from "./send-H86JOXWw.mjs";
|
|
2
|
-
import { n as processLineMessage, t as buildTemplateMessageFromPayload } from "./template-messages-B8c6X5DV.mjs";
|
|
3
|
-
export { buildTemplateMessageFromPayload, createFlexMessage, createLocationMessage, createQuickReplyItems, processLineMessage, pushFlexMessage, pushLocationMessage, pushMessageLine, pushMessagesLine, pushTemplateMessage, pushTextMessageWithQuickReplies };
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import { E as applyLineQuoteToken, F as normalizeLineMessagingTarget, M as withoutLineQuoteTokens, N as buildLineMediaMessage, b as normalizeLineMessage, i as runLinePushWithRetries, n as findLineHttpError, s as resolveLineChannelAccessToken, y as messageAction } from "./send-retry-D6J7bThI.mjs";
|
|
2
|
-
import { r as resolveLineAccount } from "./accounts-Dm_NoU7R.mjs";
|
|
3
|
-
import { createMessageReceiptFromOutboundResults } from "openclaw/plugin-sdk/channel-outbound";
|
|
4
|
-
import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
|
|
5
|
-
import { createStaleWhileRevalidateCache } from "openclaw/plugin-sdk/collection-runtime";
|
|
6
|
-
import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
|
|
7
|
-
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
8
|
-
import { HTTPFetchError, messagingApi } from "@line/bot-sdk";
|
|
9
|
-
import { readProviderJsonResponse, readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
|
|
10
|
-
import { fetchWithRuntimeDispatcherOrMockedGlobal } from "openclaw/plugin-sdk/runtime-fetch";
|
|
11
|
-
import { randomUUID } from "node:crypto";
|
|
12
|
-
import lineBotSdkPackage from "@line/bot-sdk/package.json" with { type: "json" };
|
|
13
|
-
import { recordChannelActivity } from "openclaw/plugin-sdk/channel-activity-runtime";
|
|
14
|
-
import { captureEffectAuthority } from "openclaw/plugin-sdk/fetch-runtime";
|
|
15
|
-
import { redactToolPayloadText } from "openclaw/plugin-sdk/logging-core";
|
|
16
|
-
import { requireRuntimeConfig } from "openclaw/plugin-sdk/plugin-config-runtime";
|
|
17
|
-
import { createDedupeCache } from "openclaw/plugin-sdk/dedupe-runtime";
|
|
18
|
-
// extensions/line/src/outbound-message-log.ts
|
|
19
|
-
const RECENT_SENT_LIMIT = 500;
|
|
20
|
-
const recentSentByAccount = /* @__PURE__ */ new Map();
|
|
21
|
-
function recentSentFor(accountId) {
|
|
22
|
-
const existing = recentSentByAccount.get(accountId);
|
|
23
|
-
if (existing) return existing;
|
|
24
|
-
const created = createDedupeCache({
|
|
25
|
-
ttlMs: 0,
|
|
26
|
-
maxSize: RECENT_SENT_LIMIT
|
|
27
|
-
});
|
|
28
|
-
recentSentByAccount.set(accountId, created);
|
|
29
|
-
return created;
|
|
30
|
-
}
|
|
31
|
-
function recordLineSentMessages(accountId, messageIds) {
|
|
32
|
-
if (messageIds.length === 0) return;
|
|
33
|
-
const recentSent = recentSentFor(accountId);
|
|
34
|
-
for (const messageId of messageIds) recentSent.check(messageId);
|
|
35
|
-
}
|
|
36
|
-
function quotesLineBotMessage(accountId, quotedMessageId) {
|
|
37
|
-
return recentSentByAccount.get(accountId)?.peek(quotedMessageId) ?? false;
|
|
38
|
-
}
|
|
39
|
-
// extensions/line/src/send.ts
|
|
40
|
-
const PROFILE_CACHE_TTL_MS = 3e5;
|
|
41
|
-
const PROFILE_CACHE_MAX_ENTRIES = 1e3;
|
|
42
|
-
const profileCache = createStaleWhileRevalidateCache({
|
|
43
|
-
maxEntries: PROFILE_CACHE_MAX_ENTRIES,
|
|
44
|
-
ttlMs: PROFILE_CACHE_TTL_MS
|
|
45
|
-
});
|
|
46
|
-
const groupNameCache = createStaleWhileRevalidateCache({
|
|
47
|
-
maxEntries: PROFILE_CACHE_MAX_ENTRIES,
|
|
48
|
-
ttlMs: PROFILE_CACHE_TTL_MS
|
|
49
|
-
});
|
|
50
|
-
const LINE_FLEX_ALT_TEXT_LIMIT = 1500;
|
|
51
|
-
const LINE_LOCATION_LABEL_LIMIT = 100;
|
|
52
|
-
const LINE_PROVIDER_RESPONSE_MAX_BYTES = 16384;
|
|
53
|
-
function resolveLineProviderMessageIds(response, operation) {
|
|
54
|
-
const sentMessages = Array.isArray(response?.sentMessages) ? response.sentMessages : [];
|
|
55
|
-
const messageIds = sentMessages.flatMap((entry) => {
|
|
56
|
-
const id = entry && typeof entry === "object" ? entry.id : void 0;
|
|
57
|
-
const messageId = typeof id === "string" ? id.trim() : "";
|
|
58
|
-
return messageId ? [messageId] : [];
|
|
59
|
-
});
|
|
60
|
-
const messageId = messageIds[0];
|
|
61
|
-
if (!messageId || messageIds.length !== sentMessages.length) throw createChannelPartialDeliveryError(/* @__PURE__ */ new Error(`LINE ${operation} response did not include a sent message id`), {
|
|
62
|
-
messageIds,
|
|
63
|
-
visibleReplySent: true
|
|
64
|
-
});
|
|
65
|
-
return {
|
|
66
|
-
messageId,
|
|
67
|
-
messageIds
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function normalizeTarget(to) {
|
|
71
|
-
const normalized = normalizeLineMessagingTarget(to);
|
|
72
|
-
if (!normalized) throw new Error("Recipient is required for LINE sends");
|
|
73
|
-
if (normalized.length >= 33 && !/^[CUR]/.test(normalized)) throw new Error(`Recipient is not a valid LINE id (case-sensitive; expected leading capital C/U/R): ${truncateUtf16Safe(normalized, 4)}…`);
|
|
74
|
-
return normalized;
|
|
75
|
-
}
|
|
76
|
-
function resolveLineMessagingAccount(opts) {
|
|
77
|
-
const cfg = requireRuntimeConfig(opts.cfg, "LINE send");
|
|
78
|
-
const account = resolveLineAccount({
|
|
79
|
-
cfg,
|
|
80
|
-
accountId: opts.accountId
|
|
81
|
-
});
|
|
82
|
-
return {
|
|
83
|
-
account,
|
|
84
|
-
token: resolveLineChannelAccessToken(opts.channelAccessToken, account)
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
async function sendLineProviderMessages(operation, token, request, retryKey, authorize, assertDirectAdapterHandoff) {
|
|
88
|
-
try {
|
|
89
|
-
return await postLineProviderMessages(operation, token, request, retryKey, authorize, assertDirectAdapterHandoff);
|
|
90
|
-
} catch (error) {
|
|
91
|
-
const unquoted = findLineHttpError(error)?.status === 400 ? withoutLineQuoteTokens(request.messages) : void 0;
|
|
92
|
-
if (!unquoted) throw error;
|
|
93
|
-
return await postLineProviderMessages(operation, token, {
|
|
94
|
-
...request,
|
|
95
|
-
messages: unquoted
|
|
96
|
-
}, retryKey, authorize, assertDirectAdapterHandoff);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async function postLineProviderMessages(operation, token, request, retryKey, authorize, assertDirectAdapterHandoff) {
|
|
100
|
-
const effect = captureEffectAuthority();
|
|
101
|
-
const requestBody = JSON.stringify(request);
|
|
102
|
-
if (authorize) {
|
|
103
|
-
const authorized = authorize();
|
|
104
|
-
if (!(typeof authorized === "boolean" ? authorized : await authorized)) throw new Error("LINE send authorization denied");
|
|
105
|
-
}
|
|
106
|
-
const response = await effect.initiate(() => {
|
|
107
|
-
assertDirectAdapterHandoff?.();
|
|
108
|
-
return fetchWithRuntimeDispatcherOrMockedGlobal(`https://api.line.me/v2/bot/message/${operation}`, {
|
|
109
|
-
method: "POST",
|
|
110
|
-
headers: {
|
|
111
|
-
"Content-Type": "application/json",
|
|
112
|
-
Authorization: `Bearer ${token}`,
|
|
113
|
-
"User-Agent": `@line/bot-sdk/${lineBotSdkPackage.version}`,
|
|
114
|
-
...retryKey ? { "X-Line-Retry-Key": retryKey } : {}
|
|
115
|
-
},
|
|
116
|
-
body: requestBody
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
const acceptedRetryConflict = retryKey !== void 0 && response.status === 409;
|
|
120
|
-
if (!response.ok && !acceptedRetryConflict) {
|
|
121
|
-
const body = await readResponseTextLimited(response, LINE_PROVIDER_RESPONSE_MAX_BYTES).catch(() => "");
|
|
122
|
-
const redactedBody = redactToolPayloadText(body);
|
|
123
|
-
throw new HTTPFetchError(`${response.status} - ${response.statusText}`, {
|
|
124
|
-
status: response.status,
|
|
125
|
-
statusText: response.statusText,
|
|
126
|
-
headers: response.headers,
|
|
127
|
-
body: redactedBody
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
return await readProviderJsonResponse(response, `LINE ${operation} response`, { maxBytes: LINE_PROVIDER_RESPONSE_MAX_BYTES });
|
|
132
|
-
} catch (error) {
|
|
133
|
-
throw createChannelPartialDeliveryError(error, {
|
|
134
|
-
messageIds: [],
|
|
135
|
-
visibleReplySent: true
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function createLocationMessage(location) {
|
|
140
|
-
if (!location.title.trim() || !location.address.trim()) return {
|
|
141
|
-
type: "text",
|
|
142
|
-
text: [...[location.title, location.address].map((label) => truncateUtf16Safe(label.trim(), LINE_LOCATION_LABEL_LIMIT)).filter(Boolean), `${location.latitude}, ${location.longitude}`].join("\n")
|
|
143
|
-
};
|
|
144
|
-
return {
|
|
145
|
-
type: "location",
|
|
146
|
-
title: truncateUtf16Safe(location.title, LINE_LOCATION_LABEL_LIMIT),
|
|
147
|
-
address: truncateUtf16Safe(location.address, LINE_LOCATION_LABEL_LIMIT),
|
|
148
|
-
latitude: location.latitude,
|
|
149
|
-
longitude: location.longitude
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function recordLineOutboundActivity(accountId, delivery) {
|
|
153
|
-
recordLineSentMessages(accountId, delivery.messageIds);
|
|
154
|
-
try {
|
|
155
|
-
recordChannelActivity({
|
|
156
|
-
channel: "line",
|
|
157
|
-
accountId,
|
|
158
|
-
direction: "outbound"
|
|
159
|
-
});
|
|
160
|
-
} catch (error) {
|
|
161
|
-
throw createChannelPartialDeliveryError(error, {
|
|
162
|
-
messageIds: delivery.messageIds,
|
|
163
|
-
...delivery.receipt ? { receipt: delivery.receipt } : {},
|
|
164
|
-
visibleReplySent: true
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function resolveLineReceiptKind(messages) {
|
|
169
|
-
const types = new Set(messages.map((message) => message.type));
|
|
170
|
-
if (types.has("audio")) return "voice";
|
|
171
|
-
if (types.has("image") || types.has("video")) return "media";
|
|
172
|
-
if (types.has("flex") || types.has("template") || types.has("location")) return "card";
|
|
173
|
-
if (types.has("text")) return "text";
|
|
174
|
-
return "unknown";
|
|
175
|
-
}
|
|
176
|
-
async function pushLineMessages(to, messages, opts) {
|
|
177
|
-
if (messages.length === 0) throw new Error("Message must be non-empty for LINE sends");
|
|
178
|
-
const { account, token } = resolveLineMessagingAccount(opts);
|
|
179
|
-
const chatId = normalizeTarget(to);
|
|
180
|
-
const normalizedMessages = applyLineQuoteToken(messages, opts.quoteToken).map(normalizeLineMessage);
|
|
181
|
-
const retryKey = randomUUID();
|
|
182
|
-
const { messageId, messageIds } = resolveLineProviderMessageIds(await runLinePushWithRetries(() => sendLineProviderMessages("push", token, {
|
|
183
|
-
to: chatId,
|
|
184
|
-
messages: normalizedMessages
|
|
185
|
-
}, retryKey, opts.authorize, opts.assertDirectAdapterHandoff), "line:push"), "push");
|
|
186
|
-
const result = {
|
|
187
|
-
messageId,
|
|
188
|
-
chatId,
|
|
189
|
-
receipt: createMessageReceiptFromOutboundResults({
|
|
190
|
-
results: messageIds.map((providerMessageId) => ({
|
|
191
|
-
channel: "line",
|
|
192
|
-
messageId: providerMessageId,
|
|
193
|
-
chatId,
|
|
194
|
-
conversationId: chatId,
|
|
195
|
-
meta: { messageCount: messages.length }
|
|
196
|
-
})),
|
|
197
|
-
...chatId ? { threadId: chatId } : {},
|
|
198
|
-
kind: resolveLineReceiptKind(messages)
|
|
199
|
-
})
|
|
200
|
-
};
|
|
201
|
-
recordLineOutboundActivity(account.accountId, {
|
|
202
|
-
messageIds,
|
|
203
|
-
receipt: result.receipt
|
|
204
|
-
});
|
|
205
|
-
return result;
|
|
206
|
-
}
|
|
207
|
-
async function pushMessageLine(to, text, opts) {
|
|
208
|
-
const chatId = normalizeTarget(to);
|
|
209
|
-
const messages = [];
|
|
210
|
-
const mediaUrl = opts.mediaUrl?.trim();
|
|
211
|
-
if (mediaUrl) messages.push(await buildLineMediaMessage(mediaUrl, {
|
|
212
|
-
mediaKind: opts.mediaKind,
|
|
213
|
-
previewImageUrl: opts.previewImageUrl,
|
|
214
|
-
durationMs: opts.durationMs,
|
|
215
|
-
trackingId: opts.trackingId
|
|
216
|
-
}, chatId));
|
|
217
|
-
if (text?.trim()) messages.push({
|
|
218
|
-
type: "text",
|
|
219
|
-
text: text.trim()
|
|
220
|
-
});
|
|
221
|
-
return pushLineMessages(chatId, messages, opts);
|
|
222
|
-
}
|
|
223
|
-
async function replyMessageLine(replyToken, messages, opts) {
|
|
224
|
-
const { account, token } = resolveLineMessagingAccount(opts);
|
|
225
|
-
const { messageIds } = resolveLineProviderMessageIds(await sendLineProviderMessages("reply", token, {
|
|
226
|
-
replyToken,
|
|
227
|
-
messages: applyLineQuoteToken(messages, opts.quoteToken).map(normalizeLineMessage)
|
|
228
|
-
}, void 0, opts.authorize, opts.assertDirectAdapterHandoff), "reply");
|
|
229
|
-
recordLineOutboundActivity(account.accountId, { messageIds });
|
|
230
|
-
}
|
|
231
|
-
async function pushMessagesLine(to, messages, opts) {
|
|
232
|
-
return pushLineMessages(to, messages, opts);
|
|
233
|
-
}
|
|
234
|
-
function createFlexMessage(altText, contents) {
|
|
235
|
-
return {
|
|
236
|
-
type: "flex",
|
|
237
|
-
altText: truncateUtf16Safe(altText, LINE_FLEX_ALT_TEXT_LIMIT),
|
|
238
|
-
contents
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
async function pushLocationMessage(to, location, opts) {
|
|
242
|
-
return pushLineMessages(to, [createLocationMessage(location)], opts);
|
|
243
|
-
}
|
|
244
|
-
async function pushFlexMessage(to, altText, contents, opts) {
|
|
245
|
-
return pushLineMessages(to, [createFlexMessage(altText, contents)], opts);
|
|
246
|
-
}
|
|
247
|
-
async function pushTemplateMessage(to, template, opts) {
|
|
248
|
-
return pushLineMessages(to, [template], opts);
|
|
249
|
-
}
|
|
250
|
-
async function pushTextMessageWithQuickReplies(to, text, quickReplyLabels, opts) {
|
|
251
|
-
return pushLineMessages(to, [{
|
|
252
|
-
type: "text",
|
|
253
|
-
text,
|
|
254
|
-
quickReply: createQuickReplyItems(quickReplyLabels)
|
|
255
|
-
}], opts);
|
|
256
|
-
}
|
|
257
|
-
function createQuickReplyItems(labels) {
|
|
258
|
-
return { items: labels.map((label) => label.trim()).filter(Boolean).slice(0, 13).map((label) => ({
|
|
259
|
-
type: "action",
|
|
260
|
-
action: messageAction(label, label)
|
|
261
|
-
})) };
|
|
262
|
-
}
|
|
263
|
-
async function showLoadingAnimation(chatId, opts) {
|
|
264
|
-
const { token } = resolveLineMessagingAccount(opts);
|
|
265
|
-
const client = new messagingApi.MessagingApiClient({ channelAccessToken: token });
|
|
266
|
-
try {
|
|
267
|
-
await client.showLoadingAnimation({
|
|
268
|
-
chatId: normalizeTarget(chatId),
|
|
269
|
-
loadingSeconds: 20
|
|
270
|
-
});
|
|
271
|
-
} catch (err) {
|
|
272
|
-
logVerbose(`line: loading animation failed (non-fatal): ${String(err)}`);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
function lineProfileCacheKey(accountId, userId, scope) {
|
|
276
|
-
const conversation = scope.groupId ? ["group", scope.groupId] : scope.roomId ? ["room", scope.roomId] : ["direct"];
|
|
277
|
-
return JSON.stringify([
|
|
278
|
-
accountId,
|
|
279
|
-
"profile",
|
|
280
|
-
...conversation,
|
|
281
|
-
userId
|
|
282
|
-
]);
|
|
283
|
-
}
|
|
284
|
-
function fetchLineMemberProfile(client, userId, scope) {
|
|
285
|
-
if (scope.groupId) return client.getGroupMemberProfile(scope.groupId, userId);
|
|
286
|
-
if (scope.roomId) return client.getRoomMemberProfile(scope.roomId, userId);
|
|
287
|
-
return client.getProfile(userId);
|
|
288
|
-
}
|
|
289
|
-
async function getUserProfile(userId, opts) {
|
|
290
|
-
try {
|
|
291
|
-
const { account, token } = resolveLineMessagingAccount(opts);
|
|
292
|
-
const cacheKey = lineProfileCacheKey(account.accountId, userId, opts);
|
|
293
|
-
const load = async () => {
|
|
294
|
-
try {
|
|
295
|
-
const profile = await fetchLineMemberProfile(new messagingApi.MessagingApiClient({ channelAccessToken: token }), userId, opts);
|
|
296
|
-
return {
|
|
297
|
-
displayName: profile.displayName,
|
|
298
|
-
pictureUrl: profile.pictureUrl
|
|
299
|
-
};
|
|
300
|
-
} catch (err) {
|
|
301
|
-
logVerbose(`line: failed to fetch profile for ${userId}: ${String(err)}`);
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
return (await profileCache.read(cacheKey, load, { allowStale: false })).value;
|
|
306
|
-
} catch (err) {
|
|
307
|
-
logVerbose(`line: failed to fetch profile for ${userId}: ${String(err)}`);
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
async function getUserDisplayName(userId, opts) {
|
|
312
|
-
return (await getUserProfile(userId, opts))?.displayName ?? userId;
|
|
313
|
-
}
|
|
314
|
-
async function getLineGroupName(groupId, opts) {
|
|
315
|
-
try {
|
|
316
|
-
const { account, token } = resolveLineMessagingAccount(opts);
|
|
317
|
-
const cacheKey = JSON.stringify([
|
|
318
|
-
account.accountId,
|
|
319
|
-
"group",
|
|
320
|
-
groupId
|
|
321
|
-
]);
|
|
322
|
-
return (await groupNameCache.read(cacheKey, async () => {
|
|
323
|
-
try {
|
|
324
|
-
return (await new messagingApi.MessagingApiClient({ channelAccessToken: token }).getGroupSummary(groupId)).groupName.trim() || void 0;
|
|
325
|
-
} catch (err) {
|
|
326
|
-
logVerbose(`line: failed to fetch group summary for ${groupId}: ${String(err)}`);
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
}, { allowStale: false })).value;
|
|
330
|
-
} catch (err) {
|
|
331
|
-
logVerbose(`line: failed to fetch group summary for ${groupId}: ${String(err)}`);
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
export { getUserDisplayName as a, pushLocationMessage as c, pushTemplateMessage as d, pushTextMessageWithQuickReplies as f, quotesLineBotMessage as h, getLineGroupName as i, pushMessageLine as l, showLoadingAnimation as m, createLocationMessage as n, getUserProfile as o, replyMessageLine as p, createQuickReplyItems as r, pushFlexMessage as s, createFlexMessage as t, pushMessagesLine as u };
|