@openclaw/line 2026.10.10 → 2026.11.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/{api-Bz8QPCGD.mjs → api-ByXjHPMe.mjs} +1 -1
- package/dist/.setup/api-DCMpIrda.mjs +3 -0
- package/dist/.setup/{card-command-XYkg1XvG.mjs → card-command-utjlRvb-.mjs} +26 -43
- package/dist/.setup/{channel-ezTshIoC.mjs → channel-D9i_xlsJ.mjs} +237 -329
- package/dist/.setup/channel.runtime-C-E2qsIu.mjs +4 -0
- package/dist/.setup/{monitor-BBEBldZu.mjs → monitor-BYGe2Y7S.mjs} +240 -328
- package/dist/.setup/{outbound.runtime-BSuF2lax.mjs → outbound.runtime-AQvUJvJV.mjs} +2 -2
- package/dist/.setup/{send-B8TYfTO_.mjs → send-H86JOXWw.mjs} +37 -103
- package/dist/.setup/{send-retry-gHsCgBlf.mjs → send-retry-D6J7bThI.mjs} +174 -80
- package/dist/.setup/{template-messages-CdpQxqqb.mjs → template-messages-KG1GwG0h.mjs} +32 -44
- 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/node_modules/@line/bot-sdk/node_modules/@types/node/README.md +1 -1
- package/node_modules/@line/bot-sdk/node_modules/@types/node/package.json +2 -2
- package/node_modules/@line/bot-sdk/node_modules/@types/node/util.d.ts +7 -4
- package/node_modules/typebox/build/format/duration.d.mts +2 -2
- package/node_modules/typebox/build/format/duration.mjs +2 -2
- package/node_modules/typebox/build/format/idn_email.d.mts +1 -0
- package/node_modules/typebox/build/format/idn_email.mjs +1 -0
- package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
- package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
- package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
- package/node_modules/typebox/build/format/ipv4.mjs +2 -2
- package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
- package/node_modules/typebox/build/format/ipv6.mjs +1 -1
- package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
- package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
- package/node_modules/typebox/build/schema/build.mjs +1 -0
- package/node_modules/typebox/build/schema/engine/_unique.d.mts +4 -2
- package/node_modules/typebox/build/schema/engine/_unique.mjs +7 -3
- package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +0 -3
- package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +15 -17
- package/node_modules/typebox/build/schema/engine/contains.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/index.d.mts +1 -0
- package/node_modules/typebox/build/schema/engine/index.mjs +1 -0
- package/node_modules/typebox/build/schema/engine/items.mjs +7 -4
- package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/minContains.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/oneOf.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/patternProperties.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +2 -2
- package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +2 -2
- package/node_modules/typebox/build/system/hashing/hash.mjs +63 -34
- package/node_modules/typebox/build/system/locale/en_US.mjs +2 -1
- package/node_modules/typebox/build/system/memory/assign.d.mts +2 -8
- package/node_modules/typebox/build/system/memory/assign.mjs +13 -6
- package/node_modules/typebox/build/system/memory/clone.d.mts +4 -5
- package/node_modules/typebox/build/system/memory/clone.mjs +8 -96
- package/node_modules/typebox/build/system/memory/create.d.mts +1 -5
- package/node_modules/typebox/build/system/memory/create.mjs +18 -13
- package/node_modules/typebox/build/system/memory/deep.d.mts +2 -0
- package/node_modules/typebox/build/system/memory/deep.mjs +108 -0
- package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
- package/node_modules/typebox/build/system/memory/discard.mjs +9 -8
- package/node_modules/typebox/build/system/memory/finalize.d.mts +4 -0
- package/node_modules/typebox/build/system/memory/finalize.mjs +30 -0
- package/node_modules/typebox/build/system/memory/keys.d.mts +2 -0
- package/node_modules/typebox/build/system/memory/keys.mjs +8 -0
- package/node_modules/typebox/build/system/memory/update.d.mts +1 -4
- package/node_modules/typebox/build/system/memory/update.mjs +43 -16
- package/node_modules/typebox/build/type/engine/call/index.d.mts +1 -0
- package/node_modules/typebox/build/type/engine/call/index.mjs +1 -0
- package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +2 -24
- package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +2 -29
- package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +1 -0
- package/node_modules/typebox/build/type/engine/evaluate/index.mjs +1 -0
- package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +5 -1
- package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +6 -1
- package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +30 -0
- package/node_modules/typebox/build/type/engine/evaluate/property.mjs +29 -0
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +1 -3
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +1 -4
- package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
- package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +1 -3
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +1 -4
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +1 -3
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +1 -4
- package/node_modules/typebox/build/type/engine/this/index.d.mts +1 -0
- package/node_modules/typebox/build/type/engine/this/index.mjs +1 -0
- package/node_modules/typebox/build/value/clone/clone.d.mts +4 -3
- package/node_modules/typebox/build/value/clone/clone.mjs +5 -7
- package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +2 -0
- package/node_modules/typebox/build/value/repair/from_cyclic.mjs +6 -0
- package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +25 -14
- package/node_modules/typebox/package.json +1 -1
- package/node_modules/typebox/readme.md +1 -1
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
- package/node_modules/zod/src/v4/core/compile.ts +9 -0
- package/node_modules/zod/src/v4/core/schemas.ts +35 -1
- package/node_modules/zod/src/v4/core/util.ts +13 -0
- package/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.d.cts +3 -1
- package/node_modules/zod/v4/core/schemas.d.ts +3 -1
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.d.cts +2 -0
- package/node_modules/zod/v4/core/util.d.ts +2 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +6 -6
- package/dist/.setup/api-EJnP_1cJ.mjs +0 -3
- package/dist/.setup/channel.runtime-4w8EffJb.mjs +0 -4
- package/dist/.setup/monitor.runtime-BWIgUqzC.mjs +0 -1
- package/dist/.setup/probe.runtime-a-fC57xd.mjs +0 -1
- package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
- package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { A as reportLineQuoteCarrierMissing, D as canCarryLineQuoteToken, E as applyLineQuoteToken, N as buildLineMediaMessage, O as readLineQuoteToken, j as resolveLineQuoteToken, k as recordLineQuoteToken, n as findLineHttpError, r as resolveLineNonDispatchRetryable, t as explainLineRefusal } from "./send-retry-D6J7bThI.mjs";
|
|
1
2
|
import { n as resolveDefaultLineAccountId, r as resolveLineAccount } from "./accounts-Dm_NoU7R.mjs";
|
|
2
|
-
import { a as parseLineQuestionPostbackData, c as resolveLineGroupConfigEntry, i as isLineQuestionPostbackData, n as createLineQuickReply, o as resolveLineQuestionPostback, r as prepareLineReplyPayload, s as buildLineQuickReplyFallbackText } from "./channel-ezTshIoC.mjs";
|
|
3
3
|
import { a as normalizeLineAllowEntry } from "./setup-surface-DvbBjHFi.mjs";
|
|
4
|
+
import { a as parseLineQuestionPostbackData, c as resolveLineGroupConfigEntry, i as isLineQuestionPostbackData, n as createLineQuickReply, o as resolveLineQuestionPostback, r as prepareLineReplyPayload, s as buildLineQuickReplyFallbackText } from "./channel-D9i_xlsJ.mjs";
|
|
4
5
|
import { t as getLineRuntime } from "./runtime-C9ldw-V4.mjs";
|
|
5
|
-
import { A as resolveLineQuoteToken, D as readLineQuoteToken, E as canCarryLineQuoteToken, M as buildLineMediaMessage, O as recordLineQuoteToken, T as applyLineQuoteToken, k as reportLineQuoteCarrierMissing, n as findLineHttpError, r as resolveLineNonDispatchRetryable, t as explainLineRefusal } from "./send-retry-gHsCgBlf.mjs";
|
|
6
6
|
import { a as laneKeyFor, i as eventIdFor, n as LINE_WEBHOOK_SPOOL_INVALID_PAYLOAD_MESSAGE, r as LineWebhookPayloadError, t as LINE_WEBHOOK_SPOOL_INVALID_EVENT_REASON } from "./webhook-spool-contract-COhQK5XQ.mjs";
|
|
7
|
-
import { a as getUserDisplayName, h as quotesLineBotMessage, i as getLineGroupName, l as pushMessageLine, m as showLoadingAnimation, n as createLocationMessage, o as getUserProfile, p as replyMessageLine, t as createFlexMessage, u as pushMessagesLine } from "./send-
|
|
8
|
-
import { n as processLineMessage, t as buildTemplateMessageFromPayload } from "./template-messages-
|
|
7
|
+
import { a as getUserDisplayName, h as quotesLineBotMessage, i as getLineGroupName, l as pushMessageLine, m as showLoadingAnimation, n as createLocationMessage, o as getUserProfile, p as replyMessageLine, t as createFlexMessage, u as pushMessagesLine } from "./send-H86JOXWw.mjs";
|
|
8
|
+
import { n as processLineMessage, t as buildTemplateMessageFromPayload } from "./template-messages-KG1GwG0h.mjs";
|
|
9
9
|
import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
|
|
10
10
|
import { resolveChannelGroupsConfigPath } from "openclaw/plugin-sdk/channel-policy";
|
|
11
11
|
import { normalizeOptionalString, normalizeStringEntries, readNonEmptyStringPreservingWhitespace } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
@@ -16,7 +16,7 @@ import { buildChannelInboundEventContext, buildMentionRegexes, formatInboundEnve
|
|
|
16
16
|
import { collectErrorGraphCandidates, extractErrorCode, formatErrorMessage, readErrorName, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
17
17
|
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
|
|
18
18
|
import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking";
|
|
19
|
-
import { danger, logVerbose,
|
|
19
|
+
import { danger, logVerbose, waitForAbortSignal, warn } from "openclaw/plugin-sdk/runtime-env";
|
|
20
20
|
import { safeParseJson } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
21
21
|
import { classifyTransientNetworkErrorCode } from "openclaw/plugin-sdk/retry-runtime";
|
|
22
22
|
import { fetchWithRuntimeDispatcherOrMockedGlobal } from "openclaw/plugin-sdk/runtime-fetch";
|
|
@@ -43,6 +43,7 @@ import { MediaFetchError } from "openclaw/plugin-sdk/media-runtime";
|
|
|
43
43
|
import { saveMediaStream } from "openclaw/plugin-sdk/media-store";
|
|
44
44
|
import { raceWithTimeout } from "openclaw/plugin-sdk/time-runtime";
|
|
45
45
|
import { enqueueKeyedTask } from "openclaw/plugin-sdk/keyed-async-queue";
|
|
46
|
+
import { sendJsonWithoutCharset } from "openclaw/plugin-sdk/http-response-runtime";
|
|
46
47
|
import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
|
|
47
48
|
// extensions/line/src/auto-reply-delivery.ts
|
|
48
49
|
function toLineDeliveryError(error) {
|
|
@@ -346,10 +347,7 @@ async function resolveLineInboundRoute(params) {
|
|
|
346
347
|
});
|
|
347
348
|
const prepared = params.preparedRoute ?? await prepareLineInboundRoute(params);
|
|
348
349
|
const { peerId, runtimeRoute, configuredBinding, configuredBindingSessionKey } = prepared;
|
|
349
|
-
if (runtimeRoute.bindingRecord)
|
|
350
|
-
await getSessionBindingService().touchAsync(runtimeRoute.bindingRecord.bindingId, void 0, runtimeRoute.bindingRecord.conversation);
|
|
351
|
-
logVerbose(runtimeRoute.boundSessionKey ? `line: routed via bound conversation ${peerId} -> ${runtimeRoute.boundSessionKey}` : `line: plugin-bound conversation ${peerId}`);
|
|
352
|
-
}
|
|
350
|
+
if (runtimeRoute.bindingRecord) await getSessionBindingService().touchAsync(runtimeRoute.bindingRecord.bindingId, void 0, runtimeRoute.bindingRecord.conversation);
|
|
353
351
|
if (configuredBinding) {
|
|
354
352
|
const ensured = await ensureConfiguredBindingRouteReady({
|
|
355
353
|
cfg: params.cfg,
|
|
@@ -359,7 +357,6 @@ async function resolveLineInboundRoute(params) {
|
|
|
359
357
|
logVerbose(`line: configured ACP binding unavailable for ${peerId} -> ${configuredBindingSessionKey}: ${ensured.error}`);
|
|
360
358
|
throw new Error(`Configured ACP binding unavailable: ${ensured.error}`);
|
|
361
359
|
}
|
|
362
|
-
logVerbose(`line: using configured ACP binding for ${peerId} -> ${configuredBindingSessionKey}`);
|
|
363
360
|
}
|
|
364
361
|
return prepared;
|
|
365
362
|
}
|
|
@@ -402,6 +399,12 @@ function extractNativeMediaKind(message) {
|
|
|
402
399
|
}
|
|
403
400
|
}
|
|
404
401
|
async function finalizeLineInboundContext(params) {
|
|
402
|
+
const channelIngress = await params.resolveChannelIngress?.({
|
|
403
|
+
agentId: params.route.agentId,
|
|
404
|
+
sessionKey: params.route.sessionKey,
|
|
405
|
+
messageId: params.messageSid,
|
|
406
|
+
inboundEventKind: "user_request"
|
|
407
|
+
});
|
|
405
408
|
const senderId = params.source.userId ?? "unknown";
|
|
406
409
|
const clientOpts = {
|
|
407
410
|
cfg: params.cfg,
|
|
@@ -441,7 +444,7 @@ async function finalizeLineInboundContext(params) {
|
|
|
441
444
|
envelope: envelopeOptions
|
|
442
445
|
});
|
|
443
446
|
const ctxPayload = (params.buildContext ?? buildChannelInboundEventContext)({
|
|
444
|
-
channelIngress
|
|
447
|
+
channelIngress,
|
|
445
448
|
channel: "line",
|
|
446
449
|
accountId: params.route.accountId,
|
|
447
450
|
messageId: params.messageSid,
|
|
@@ -491,11 +494,6 @@ async function finalizeLineInboundContext(params) {
|
|
|
491
494
|
route: params.route,
|
|
492
495
|
sessionKey: params.route.sessionKey
|
|
493
496
|
});
|
|
494
|
-
if (shouldLogVerbose()) {
|
|
495
|
-
const mediaInfo = params.verboseLog.kind === "inbound" && (params.verboseLog.mediaCount ?? 0) > 1 ? ` mediaCount=${params.verboseLog.mediaCount}` : "";
|
|
496
|
-
const label = params.verboseLog.kind === "inbound" ? "line inbound" : "line postback";
|
|
497
|
-
logVerbose(`${label}: from=${ctxPayload.From} len=${body.length}${mediaInfo}`);
|
|
498
|
-
}
|
|
499
497
|
return {
|
|
500
498
|
ctxPayload,
|
|
501
499
|
event: params.event,
|
|
@@ -543,9 +541,11 @@ async function buildLineMessageContext(params) {
|
|
|
543
541
|
const messageId = message.id;
|
|
544
542
|
const rawBody = extractMessageText(message);
|
|
545
543
|
const nativeMediaKind = extractNativeMediaKind(message);
|
|
546
|
-
const mediaFacts = allMedia.length > 0 ? allMedia.map((
|
|
547
|
-
|
|
548
|
-
|
|
544
|
+
const mediaFacts = allMedia.length > 0 ? allMedia.map(({ path, contentType, fileName }) => ({
|
|
545
|
+
path,
|
|
546
|
+
contentType,
|
|
547
|
+
fileName,
|
|
548
|
+
kind: nativeMediaKind === "document" && contentType?.startsWith("image/") ? "image" : nativeMediaKind
|
|
549
549
|
})) : nativeMediaKind ? [{ kind: nativeMediaKind }] : [];
|
|
550
550
|
const shortfallNotice = params.missingParts ? `[line: ${params.missingParts === 1 ? "1 more image in this send was" : `${params.missingParts} more images in this send were`} not delivered]` : void 0;
|
|
551
551
|
const withShortfall = shortfallNotice ? formatInboundMediaUnavailableText({
|
|
@@ -582,19 +582,10 @@ async function buildLineMessageContext(params) {
|
|
|
582
582
|
mentions: params.mentions,
|
|
583
583
|
messageSid: messageId,
|
|
584
584
|
commandAuthorized,
|
|
585
|
-
|
|
586
|
-
agentId: route.agentId,
|
|
587
|
-
sessionKey: route.sessionKey,
|
|
588
|
-
messageId,
|
|
589
|
-
inboundEventKind: "user_request"
|
|
590
|
-
}),
|
|
585
|
+
resolveChannelIngress: params.resolveChannelIngress,
|
|
591
586
|
buildContext: params.buildContext,
|
|
592
587
|
media: mediaFacts,
|
|
593
588
|
locationContext,
|
|
594
|
-
verboseLog: {
|
|
595
|
-
kind: "inbound",
|
|
596
|
-
mediaCount: allMedia.length
|
|
597
|
-
},
|
|
598
589
|
inboundHistory
|
|
599
590
|
});
|
|
600
591
|
}
|
|
@@ -630,15 +621,9 @@ async function buildLinePostbackContext(params) {
|
|
|
630
621
|
agentBody,
|
|
631
622
|
messageSid,
|
|
632
623
|
commandAuthorized,
|
|
633
|
-
|
|
634
|
-
agentId: route.agentId,
|
|
635
|
-
sessionKey: route.sessionKey,
|
|
636
|
-
messageId: messageSid,
|
|
637
|
-
inboundEventKind: "user_request"
|
|
638
|
-
}),
|
|
624
|
+
resolveChannelIngress: params.resolveChannelIngress,
|
|
639
625
|
buildContext: params.buildContext,
|
|
640
|
-
media: []
|
|
641
|
-
verboseLog: { kind: "postback" }
|
|
626
|
+
media: []
|
|
642
627
|
});
|
|
643
628
|
}
|
|
644
629
|
// extensions/line/src/download.ts
|
|
@@ -682,9 +667,7 @@ async function* lineResponseBodyChunks(response, messageId, signal, onComplete)
|
|
|
682
667
|
}
|
|
683
668
|
} finally {
|
|
684
669
|
if (!completed) await reader.cancel(signal.aborted ? signal.reason : void 0).catch(() => void 0);
|
|
685
|
-
|
|
686
|
-
reader.releaseLock();
|
|
687
|
-
} catch {}
|
|
670
|
+
reader.releaseLock();
|
|
688
671
|
}
|
|
689
672
|
}
|
|
690
673
|
async function fetchLineContentWhenReady(messageId, channelAccessToken, signal) {
|
|
@@ -735,11 +718,9 @@ async function downloadLineMedia(messageId, channelAccessToken, maxBytes = 10485
|
|
|
735
718
|
throw err;
|
|
736
719
|
}
|
|
737
720
|
options?.signal?.throwIfAborted();
|
|
738
|
-
logVerbose(`line: persisted media ${messageId} to ${saved.path} (${saved.size} bytes)`);
|
|
739
721
|
return {
|
|
740
722
|
path: saved.path,
|
|
741
|
-
contentType: saved.contentType
|
|
742
|
-
size: saved.size
|
|
723
|
+
contentType: saved.contentType
|
|
743
724
|
};
|
|
744
725
|
} finally {
|
|
745
726
|
clearTimeout(deadline);
|
|
@@ -789,9 +770,6 @@ const LINE_DOWNLOADABLE_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
|
789
770
|
function isDownloadableLineMessageType(messageType) {
|
|
790
771
|
return LINE_DOWNLOADABLE_MESSAGE_TYPES.has(messageType);
|
|
791
772
|
}
|
|
792
|
-
function normalizeLineIngressEntry(value) {
|
|
793
|
-
return normalizeLineAllowEntry(value) || null;
|
|
794
|
-
}
|
|
795
773
|
/**
|
|
796
774
|
* Say one line back to a sender, preferring their reply token so the answer costs no
|
|
797
775
|
* push quota, and falling back to a push when no token is usable. A partial-delivery
|
|
@@ -890,7 +868,7 @@ async function resolveLineEventAdmission(event, context) {
|
|
|
890
868
|
accountId: account.accountId,
|
|
891
869
|
identity: {
|
|
892
870
|
key: "line-user-id",
|
|
893
|
-
normalize:
|
|
871
|
+
normalize: (value) => normalizeLineAllowEntry(value) || null,
|
|
894
872
|
sensitivity: "pii",
|
|
895
873
|
entryIdPrefix: "line-entry"
|
|
896
874
|
},
|
|
@@ -1019,191 +997,11 @@ function resolveEventRawText(event) {
|
|
|
1019
997
|
if (event.type === "postback") return event.postback?.data?.trim() ?? "";
|
|
1020
998
|
return "";
|
|
1021
999
|
}
|
|
1022
|
-
async function handleMessageEvent(event, context, setParts) {
|
|
1023
|
-
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
|
|
1024
|
-
const message = event.message;
|
|
1025
|
-
const decision = await resolveLineEventAdmission(event, context);
|
|
1026
|
-
if (!decision) return;
|
|
1027
|
-
const { isGroup, groupId, roomId, userId } = getLineSourceInfo(event.source);
|
|
1028
|
-
if (isGroup && decision.access.activationAccess.shouldSkip) {
|
|
1029
|
-
const rawText = message.type === "text" ? readLineTextMessageBody(message) : "";
|
|
1030
|
-
const historyKey = groupId ?? roomId;
|
|
1031
|
-
const groupsConfigPath = resolveChannelGroupsConfigPath({
|
|
1032
|
-
cfg,
|
|
1033
|
-
channel: "line",
|
|
1034
|
-
accountId: account.accountId,
|
|
1035
|
-
groups: account.config.groups
|
|
1036
|
-
});
|
|
1037
|
-
logInboundDrop({
|
|
1038
|
-
log: runtime.log,
|
|
1039
|
-
channel: "line",
|
|
1040
|
-
reason: "no mention",
|
|
1041
|
-
target: historyKey,
|
|
1042
|
-
onceKey: JSON.stringify([account.accountId, historyKey]),
|
|
1043
|
-
hint: `Mention patterns can be derived from the agent identity name. Set ${groupsConfigPath}[${JSON.stringify(historyKey)}].requireMention=false to process messages without a mention. Preserve existing groups entries; when adding the first groups map, include "*": {} to keep other chats admitted.`
|
|
1044
|
-
});
|
|
1045
|
-
const senderId = userId ?? "unknown";
|
|
1046
|
-
if (historyKey && context.groupHistories) {
|
|
1047
|
-
const displayName = userId ? await getUserDisplayName(userId, {
|
|
1048
|
-
cfg,
|
|
1049
|
-
accountId: account.accountId,
|
|
1050
|
-
channelAccessToken: account.channelAccessToken,
|
|
1051
|
-
groupId,
|
|
1052
|
-
roomId
|
|
1053
|
-
}) : senderId;
|
|
1054
|
-
const sender = displayName === senderId ? senderId : `${displayName} (${senderId})`;
|
|
1055
|
-
createChannelHistoryWindow({ historyMap: context.groupHistories }).record({
|
|
1056
|
-
historyKey,
|
|
1057
|
-
limit: context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT,
|
|
1058
|
-
entry: {
|
|
1059
|
-
sender,
|
|
1060
|
-
body: rawText || `<${message.type}>`,
|
|
1061
|
-
timestamp: event.timestamp
|
|
1062
|
-
}
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
return;
|
|
1066
|
-
}
|
|
1067
|
-
const groupHistoryKey = isGroup ? groupId ?? roomId : void 0;
|
|
1068
|
-
const historyReservation = reserveLineGroupHistory(context.groupHistories, groupHistoryKey, context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT);
|
|
1069
|
-
try {
|
|
1070
|
-
const allMedia = [];
|
|
1071
|
-
let mediaUnavailable = false;
|
|
1072
|
-
const abortSignal = context.turnAdoptionLifecycle?.abortSignal;
|
|
1073
|
-
for (const part of orderedLineSetMessages(message, setParts)) {
|
|
1074
|
-
if (!isDownloadableLineMessageType(part.type)) continue;
|
|
1075
|
-
try {
|
|
1076
|
-
const originalFilename = part.type === "file" ? normalizeOptionalString(part.fileName) : void 0;
|
|
1077
|
-
const media = await downloadLineMedia(part.id, account.channelAccessToken, mediaMaxBytes, {
|
|
1078
|
-
originalFilename,
|
|
1079
|
-
...abortSignal ? { signal: abortSignal } : {}
|
|
1080
|
-
});
|
|
1081
|
-
abortSignal?.throwIfAborted();
|
|
1082
|
-
allMedia.push({
|
|
1083
|
-
path: media.path,
|
|
1084
|
-
contentType: media.contentType,
|
|
1085
|
-
...originalFilename ? { fileName: originalFilename } : {}
|
|
1086
|
-
});
|
|
1087
|
-
} catch (err) {
|
|
1088
|
-
if (abortSignal?.aborted) throw abortSignal.reason;
|
|
1089
|
-
if (isRetryableLineInboundMediaError(err)) throw err;
|
|
1090
|
-
mediaUnavailable = true;
|
|
1091
|
-
const errMsg = String(err);
|
|
1092
|
-
if (errMsg.includes("exceeds") && errMsg.includes("limit")) logVerbose(`line: media exceeds size limit for message ${part.id}`);
|
|
1093
|
-
else runtime.error?.(danger(`line: failed to download media: ${errMsg}`));
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
const messageContext = await buildLineMessageContext({
|
|
1097
|
-
event: setParts.reduce((freshest, part) => part.timestamp > freshest.timestamp ? part : freshest, event),
|
|
1098
|
-
allMedia: [...allMedia],
|
|
1099
|
-
mediaUnavailable,
|
|
1100
|
-
...context.missingParts === void 0 ? {} : { missingParts: context.missingParts },
|
|
1101
|
-
cfg,
|
|
1102
|
-
account,
|
|
1103
|
-
preparedRoute: decision.preparedRoute,
|
|
1104
|
-
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1105
|
-
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1106
|
-
inboundHistory: historyReservation.inboundHistory,
|
|
1107
|
-
mentions: decision.mentions,
|
|
1108
|
-
buildContext: context.buildContext
|
|
1109
|
-
});
|
|
1110
|
-
if (!messageContext) logVerbose("line: skipping empty message");
|
|
1111
|
-
else {
|
|
1112
|
-
await processMessage(messageContext, {
|
|
1113
|
-
cfg: context.cfg,
|
|
1114
|
-
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1115
|
-
});
|
|
1116
|
-
historyReservation.commit();
|
|
1117
|
-
}
|
|
1118
|
-
} finally {
|
|
1119
|
-
historyReservation.release();
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
async function handleJoinEvent(event, context) {
|
|
1123
|
-
const { groupId, roomId, isGroup } = getLineSourceInfo(event.source);
|
|
1124
|
-
const conversationId = groupId ?? roomId;
|
|
1125
|
-
if (!isGroup || !conversationId) return;
|
|
1126
|
-
logVerbose(`line: bot joined ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1127
|
-
const { cfg, account } = context;
|
|
1128
|
-
const roomAllowed = Boolean(await resolveLineEventAdmission(event, context));
|
|
1129
|
-
await reportChannelRoomJoin({
|
|
1130
|
-
cfg,
|
|
1131
|
-
channel: "line",
|
|
1132
|
-
accountId: account.accountId,
|
|
1133
|
-
conversationId,
|
|
1134
|
-
deliverTo: conversationId,
|
|
1135
|
-
route: resolveAgentRoute({
|
|
1136
|
-
cfg,
|
|
1137
|
-
channel: "line",
|
|
1138
|
-
accountId: account.accountId,
|
|
1139
|
-
peer: {
|
|
1140
|
-
kind: "group",
|
|
1141
|
-
id: conversationId
|
|
1142
|
-
}
|
|
1143
|
-
}),
|
|
1144
|
-
roomAllowed,
|
|
1145
|
-
resolveRoomContext: async () => {
|
|
1146
|
-
const roomContext = { historyUnavailable: true };
|
|
1147
|
-
const title = groupId ? await getLineGroupName(groupId, {
|
|
1148
|
-
cfg,
|
|
1149
|
-
accountId: account.accountId,
|
|
1150
|
-
channelAccessToken: account.channelAccessToken
|
|
1151
|
-
}) : void 0;
|
|
1152
|
-
return title ? {
|
|
1153
|
-
...roomContext,
|
|
1154
|
-
title
|
|
1155
|
-
} : roomContext;
|
|
1156
|
-
}
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
1000
|
/** What a tap that did not answer the question has to tell the person who tapped. */
|
|
1160
1001
|
function lineQuestionOutcomeNotice(status) {
|
|
1161
1002
|
if (status === "already-terminal") return "That question is no longer waiting for an answer.";
|
|
1162
1003
|
return "Could not record that answer. Reply with the option text instead.";
|
|
1163
1004
|
}
|
|
1164
|
-
async function handlePostbackEvent(event, context) {
|
|
1165
|
-
const data = event.postback.data;
|
|
1166
|
-
logVerbose(`line: received postback: ${data}`);
|
|
1167
|
-
const decision = await resolveLineEventAdmission(event, context);
|
|
1168
|
-
if (!decision) return;
|
|
1169
|
-
const question = parseLineQuestionPostbackData(data ?? "");
|
|
1170
|
-
if (question) {
|
|
1171
|
-
const { userId, groupId, roomId } = getLineSourceInfo(event.source);
|
|
1172
|
-
const authorize = async () => isLineEventAdmitted(await decision.resolveBoundAccess());
|
|
1173
|
-
const outcome = await resolveLineQuestionPostback({
|
|
1174
|
-
cfg: context.cfg,
|
|
1175
|
-
callback: question,
|
|
1176
|
-
accountId: context.account.accountId,
|
|
1177
|
-
...userId ? { senderId: userId } : {},
|
|
1178
|
-
authorize
|
|
1179
|
-
});
|
|
1180
|
-
const pushTarget = groupId ?? roomId ?? (userId ? `line:${userId}` : void 0);
|
|
1181
|
-
if (outcome.status === "answered" || outcome.status === "denied" || !pushTarget) return;
|
|
1182
|
-
await sendLineHandlerText({
|
|
1183
|
-
context,
|
|
1184
|
-
replyToken: event.replyToken,
|
|
1185
|
-
pushTarget,
|
|
1186
|
-
logLabel: "line: question answer notice failed",
|
|
1187
|
-
text: lineQuestionOutcomeNotice(outcome.status),
|
|
1188
|
-
authorize
|
|
1189
|
-
});
|
|
1190
|
-
return;
|
|
1191
|
-
}
|
|
1192
|
-
if (isLineQuestionPostbackData(data ?? "")) return;
|
|
1193
|
-
const postbackContext = await buildLinePostbackContext({
|
|
1194
|
-
event,
|
|
1195
|
-
cfg: context.cfg,
|
|
1196
|
-
account: context.account,
|
|
1197
|
-
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1198
|
-
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1199
|
-
buildContext: context.buildContext
|
|
1200
|
-
});
|
|
1201
|
-
if (!postbackContext) return;
|
|
1202
|
-
await context.processMessage(postbackContext, {
|
|
1203
|
-
cfg: context.cfg,
|
|
1204
|
-
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
1005
|
/** Media reads in the order the sender picked, whatever order LINE delivered. */
|
|
1208
1006
|
function orderedLineSetMessages(message, setParts) {
|
|
1209
1007
|
const messages = [message, ...setParts.map((partEvent) => partEvent.message)];
|
|
@@ -1220,26 +1018,195 @@ async function handleLineWebhookEvents(events, context) {
|
|
|
1220
1018
|
if (!event) return;
|
|
1221
1019
|
try {
|
|
1222
1020
|
switch (event.type) {
|
|
1223
|
-
case "message":
|
|
1224
|
-
|
|
1021
|
+
case "message": {
|
|
1022
|
+
const messageSetParts = setParts.filter((part) => part.type === "message");
|
|
1023
|
+
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
|
|
1024
|
+
const message = event.message;
|
|
1025
|
+
const decision = await resolveLineEventAdmission(event, context);
|
|
1026
|
+
if (!decision) return;
|
|
1027
|
+
const { isGroup, groupId, roomId, userId } = getLineSourceInfo(event.source);
|
|
1028
|
+
if (isGroup && decision.access.activationAccess.shouldSkip) {
|
|
1029
|
+
const rawText = message.type === "text" ? readLineTextMessageBody(message) : "";
|
|
1030
|
+
const historyKey = groupId ?? roomId;
|
|
1031
|
+
const groupsConfigPath = resolveChannelGroupsConfigPath({
|
|
1032
|
+
cfg,
|
|
1033
|
+
channel: "line",
|
|
1034
|
+
accountId: account.accountId,
|
|
1035
|
+
groups: account.config.groups
|
|
1036
|
+
});
|
|
1037
|
+
logInboundDrop({
|
|
1038
|
+
log: runtime.log,
|
|
1039
|
+
channel: "line",
|
|
1040
|
+
reason: "no mention",
|
|
1041
|
+
target: historyKey,
|
|
1042
|
+
onceKey: JSON.stringify([account.accountId, historyKey]),
|
|
1043
|
+
hint: `Mention patterns can be derived from the agent identity name. Set ${groupsConfigPath}[${JSON.stringify(historyKey)}].requireMention=false to process messages without a mention. Preserve existing groups entries; when adding the first groups map, include "*": {} to keep other chats admitted.`
|
|
1044
|
+
});
|
|
1045
|
+
const senderId = userId ?? "unknown";
|
|
1046
|
+
if (historyKey && context.groupHistories) {
|
|
1047
|
+
const displayName = userId ? await getUserDisplayName(userId, {
|
|
1048
|
+
cfg,
|
|
1049
|
+
accountId: account.accountId,
|
|
1050
|
+
channelAccessToken: account.channelAccessToken,
|
|
1051
|
+
groupId,
|
|
1052
|
+
roomId
|
|
1053
|
+
}) : senderId;
|
|
1054
|
+
const sender = displayName === senderId ? senderId : `${displayName} (${senderId})`;
|
|
1055
|
+
createChannelHistoryWindow({ historyMap: context.groupHistories }).record({
|
|
1056
|
+
historyKey,
|
|
1057
|
+
limit: context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT,
|
|
1058
|
+
entry: {
|
|
1059
|
+
sender,
|
|
1060
|
+
body: rawText || `<${message.type}>`,
|
|
1061
|
+
timestamp: event.timestamp
|
|
1062
|
+
}
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
const groupHistoryKey = isGroup ? groupId ?? roomId : void 0;
|
|
1068
|
+
const historyReservation = reserveLineGroupHistory(context.groupHistories, groupHistoryKey, context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT);
|
|
1069
|
+
try {
|
|
1070
|
+
const allMedia = [];
|
|
1071
|
+
let mediaUnavailable = false;
|
|
1072
|
+
const abortSignal = context.turnAdoptionLifecycle?.abortSignal;
|
|
1073
|
+
for (const part of orderedLineSetMessages(message, messageSetParts)) {
|
|
1074
|
+
if (!isDownloadableLineMessageType(part.type)) continue;
|
|
1075
|
+
try {
|
|
1076
|
+
const originalFilename = part.type === "file" ? normalizeOptionalString(part.fileName) : void 0;
|
|
1077
|
+
const media = await downloadLineMedia(part.id, account.channelAccessToken, mediaMaxBytes, {
|
|
1078
|
+
originalFilename,
|
|
1079
|
+
...abortSignal ? { signal: abortSignal } : {}
|
|
1080
|
+
});
|
|
1081
|
+
abortSignal?.throwIfAborted();
|
|
1082
|
+
allMedia.push({
|
|
1083
|
+
path: media.path,
|
|
1084
|
+
contentType: media.contentType,
|
|
1085
|
+
...originalFilename ? { fileName: originalFilename } : {}
|
|
1086
|
+
});
|
|
1087
|
+
} catch (err) {
|
|
1088
|
+
if (abortSignal?.aborted) throw abortSignal.reason;
|
|
1089
|
+
if (isRetryableLineInboundMediaError(err)) throw err;
|
|
1090
|
+
mediaUnavailable = true;
|
|
1091
|
+
const errMsg = String(err);
|
|
1092
|
+
if (errMsg.includes("exceeds") && errMsg.includes("limit")) logVerbose(`line: media exceeds size limit for message ${part.id}`);
|
|
1093
|
+
else runtime.error?.(danger(`line: failed to download media: ${errMsg}`));
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
const messageContext = await buildLineMessageContext({
|
|
1097
|
+
event: messageSetParts.reduce((freshest, part) => part.timestamp > freshest.timestamp ? part : freshest, event),
|
|
1098
|
+
allMedia,
|
|
1099
|
+
mediaUnavailable,
|
|
1100
|
+
...context.missingParts === void 0 ? {} : { missingParts: context.missingParts },
|
|
1101
|
+
cfg,
|
|
1102
|
+
account,
|
|
1103
|
+
preparedRoute: decision.preparedRoute,
|
|
1104
|
+
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1105
|
+
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1106
|
+
inboundHistory: historyReservation.inboundHistory,
|
|
1107
|
+
mentions: decision.mentions,
|
|
1108
|
+
buildContext: context.buildContext
|
|
1109
|
+
});
|
|
1110
|
+
if (messageContext) {
|
|
1111
|
+
await processMessage(messageContext, {
|
|
1112
|
+
cfg: context.cfg,
|
|
1113
|
+
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1114
|
+
});
|
|
1115
|
+
historyReservation.commit();
|
|
1116
|
+
}
|
|
1117
|
+
} finally {
|
|
1118
|
+
historyReservation.release();
|
|
1119
|
+
}
|
|
1225
1120
|
break;
|
|
1121
|
+
}
|
|
1226
1122
|
case "follow":
|
|
1227
|
-
case "unfollow":
|
|
1228
|
-
|
|
1229
|
-
|
|
1123
|
+
case "unfollow": break;
|
|
1124
|
+
case "join": {
|
|
1125
|
+
const { groupId, roomId, isGroup } = getLineSourceInfo(event.source);
|
|
1126
|
+
const conversationId = groupId ?? roomId;
|
|
1127
|
+
if (!isGroup || !conversationId) return;
|
|
1128
|
+
logVerbose(`line: bot joined ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1129
|
+
const { cfg, account } = context;
|
|
1130
|
+
const roomAllowed = Boolean(await resolveLineEventAdmission(event, context));
|
|
1131
|
+
await reportChannelRoomJoin({
|
|
1132
|
+
cfg,
|
|
1133
|
+
channel: "line",
|
|
1134
|
+
accountId: account.accountId,
|
|
1135
|
+
conversationId,
|
|
1136
|
+
deliverTo: conversationId,
|
|
1137
|
+
route: resolveAgentRoute({
|
|
1138
|
+
cfg,
|
|
1139
|
+
channel: "line",
|
|
1140
|
+
accountId: account.accountId,
|
|
1141
|
+
peer: {
|
|
1142
|
+
kind: "group",
|
|
1143
|
+
id: conversationId
|
|
1144
|
+
}
|
|
1145
|
+
}),
|
|
1146
|
+
roomAllowed,
|
|
1147
|
+
resolveRoomContext: async () => {
|
|
1148
|
+
const roomContext = { historyUnavailable: true };
|
|
1149
|
+
const title = groupId ? await getLineGroupName(groupId, {
|
|
1150
|
+
cfg,
|
|
1151
|
+
accountId: account.accountId,
|
|
1152
|
+
channelAccessToken: account.channelAccessToken
|
|
1153
|
+
}) : void 0;
|
|
1154
|
+
return title ? {
|
|
1155
|
+
...roomContext,
|
|
1156
|
+
title
|
|
1157
|
+
} : roomContext;
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1230
1160
|
break;
|
|
1231
1161
|
}
|
|
1232
|
-
case "join":
|
|
1233
|
-
await handleJoinEvent(event, context);
|
|
1234
|
-
break;
|
|
1235
1162
|
case "leave": {
|
|
1236
1163
|
const { groupId, roomId } = getLineSourceInfo(event.source);
|
|
1237
1164
|
logVerbose(`line: bot left ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1238
1165
|
break;
|
|
1239
1166
|
}
|
|
1240
|
-
case "postback":
|
|
1241
|
-
|
|
1167
|
+
case "postback": {
|
|
1168
|
+
const data = event.postback.data;
|
|
1169
|
+
const decision = await resolveLineEventAdmission(event, context);
|
|
1170
|
+
if (!decision) return;
|
|
1171
|
+
const question = parseLineQuestionPostbackData(data ?? "");
|
|
1172
|
+
if (question) {
|
|
1173
|
+
const { userId, groupId, roomId } = getLineSourceInfo(event.source);
|
|
1174
|
+
const authorize = async () => isLineEventAdmitted(await decision.resolveBoundAccess());
|
|
1175
|
+
const outcome = await resolveLineQuestionPostback({
|
|
1176
|
+
cfg: context.cfg,
|
|
1177
|
+
callback: question,
|
|
1178
|
+
accountId: context.account.accountId,
|
|
1179
|
+
...userId ? { senderId: userId } : {},
|
|
1180
|
+
authorize
|
|
1181
|
+
});
|
|
1182
|
+
const pushTarget = groupId ?? roomId ?? (userId ? `line:${userId}` : void 0);
|
|
1183
|
+
if (outcome.status === "answered" || outcome.status === "denied" || !pushTarget) return;
|
|
1184
|
+
await sendLineHandlerText({
|
|
1185
|
+
context,
|
|
1186
|
+
replyToken: event.replyToken,
|
|
1187
|
+
pushTarget,
|
|
1188
|
+
logLabel: "line: question answer notice failed",
|
|
1189
|
+
text: lineQuestionOutcomeNotice(outcome.status),
|
|
1190
|
+
authorize
|
|
1191
|
+
});
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
if (isLineQuestionPostbackData(data ?? "")) return;
|
|
1195
|
+
const postbackContext = await buildLinePostbackContext({
|
|
1196
|
+
event,
|
|
1197
|
+
cfg: context.cfg,
|
|
1198
|
+
account: context.account,
|
|
1199
|
+
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1200
|
+
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1201
|
+
buildContext: context.buildContext
|
|
1202
|
+
});
|
|
1203
|
+
if (!postbackContext) return;
|
|
1204
|
+
await context.processMessage(postbackContext, {
|
|
1205
|
+
cfg: context.cfg,
|
|
1206
|
+
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1207
|
+
});
|
|
1242
1208
|
break;
|
|
1209
|
+
}
|
|
1243
1210
|
default: logVerbose(`line: unhandled event type: ${event.type}`);
|
|
1244
1211
|
}
|
|
1245
1212
|
} catch (err) {
|
|
@@ -1461,17 +1428,11 @@ function createLineWebhookSpool(options) {
|
|
|
1461
1428
|
}
|
|
1462
1429
|
const fannedIn = fanInChannelIngressLifecycles(turnLifecycles);
|
|
1463
1430
|
const boundLifecycle = bindIngressLifecycleToReplyOptions(fannedIn.lifecycle ?? lifecycle).turnAdoptionLifecycle;
|
|
1464
|
-
let handedOff = false;
|
|
1465
1431
|
const delivery = options.deliver(turnEvents, destination, {
|
|
1466
1432
|
...missingParts === void 0 ? {} : { missingParts },
|
|
1467
1433
|
turnAdoptionLifecycle: {
|
|
1468
1434
|
...boundLifecycle,
|
|
1469
|
-
onAdopted: async () => {
|
|
1470
|
-
handedOff = true;
|
|
1471
|
-
await boundLifecycle.onAdopted();
|
|
1472
|
-
},
|
|
1473
1435
|
onDeferred: () => {
|
|
1474
|
-
handedOff = true;
|
|
1475
1436
|
if (!acceptsDeferredClaims) {
|
|
1476
1437
|
Promise.resolve().then(() => boundLifecycle.onAbandoned()).catch((error) => {
|
|
1477
1438
|
options.runtime.error?.(danger(`line: failed to abandon a late webhook delivery: ${formatErrorMessage(error)}`));
|
|
@@ -1479,10 +1440,6 @@ function createLineWebhookSpool(options) {
|
|
|
1479
1440
|
return;
|
|
1480
1441
|
}
|
|
1481
1442
|
boundLifecycle.onDeferred();
|
|
1482
|
-
},
|
|
1483
|
-
onAbandoned: async () => {
|
|
1484
|
-
handedOff = true;
|
|
1485
|
-
await boundLifecycle.onAbandoned();
|
|
1486
1443
|
}
|
|
1487
1444
|
}
|
|
1488
1445
|
});
|
|
@@ -1491,20 +1448,13 @@ function createLineWebhookSpool(options) {
|
|
|
1491
1448
|
await delivery;
|
|
1492
1449
|
} catch (error) {
|
|
1493
1450
|
await fannedIn.abandon(error);
|
|
1494
|
-
handedOff = true;
|
|
1495
1451
|
throw error;
|
|
1496
1452
|
} finally {
|
|
1497
1453
|
activeDeliveries.delete(delivery);
|
|
1498
1454
|
releaseLane?.();
|
|
1499
1455
|
}
|
|
1500
|
-
if (
|
|
1501
|
-
|
|
1502
|
-
handedOff = true;
|
|
1503
|
-
}
|
|
1504
|
-
if (stopTask && !handedOff) {
|
|
1505
|
-
await fannedIn.abandon();
|
|
1506
|
-
return;
|
|
1507
|
-
}
|
|
1456
|
+
if (stopTask) await fannedIn.abandon();
|
|
1457
|
+
else await fannedIn.settle();
|
|
1508
1458
|
},
|
|
1509
1459
|
pollIntervalMs: LINE_WEBHOOK_DRAIN_INTERVAL_MS,
|
|
1510
1460
|
retention: {
|
|
@@ -1595,14 +1545,14 @@ function createLineBot(opts) {
|
|
|
1595
1545
|
accountId: opts.accountId
|
|
1596
1546
|
});
|
|
1597
1547
|
const configuredMediaMaxMb = account.config.mediaMaxMb;
|
|
1598
|
-
const mediaMaxBytes = (
|
|
1548
|
+
const mediaMaxBytes = (configuredMediaMaxMb !== void 0 && configuredMediaMaxMb > 0 ? configuredMediaMaxMb : DEFAULT_MEDIA_MAX_MB) * 1024 * 1024;
|
|
1599
1549
|
const groupHistories = /* @__PURE__ */ new Map();
|
|
1600
1550
|
const spool = createLineWebhookSpool({
|
|
1601
1551
|
accountId: account.accountId,
|
|
1602
1552
|
runtime,
|
|
1603
1553
|
deliver: async (events, _destination, control) => {
|
|
1604
1554
|
const cfg = resolveTurnConfig();
|
|
1605
|
-
await handleLineWebhookEvents(
|
|
1555
|
+
await handleLineWebhookEvents(events, {
|
|
1606
1556
|
cfg,
|
|
1607
1557
|
account,
|
|
1608
1558
|
runtime,
|
|
@@ -1623,16 +1573,6 @@ function createLineBot(opts) {
|
|
|
1623
1573
|
stop: spool.stop
|
|
1624
1574
|
};
|
|
1625
1575
|
}
|
|
1626
|
-
// extensions/line/src/monitor-durable.ts
|
|
1627
|
-
function resolveLineDurableReplyOptions(params) {
|
|
1628
|
-
if (params.infoKind !== "final") return false;
|
|
1629
|
-
if (params.replyToken && !params.replyTokenUsed) return false;
|
|
1630
|
-
const lineData = params.payload.channelData?.line;
|
|
1631
|
-
if (lineData && Object.keys(lineData).length > 0) return false;
|
|
1632
|
-
const reply = resolveSendableOutboundReplyParts(params.payload);
|
|
1633
|
-
if (reply.hasMedia || !reply.hasText) return false;
|
|
1634
|
-
return { to: params.to };
|
|
1635
|
-
}
|
|
1636
1576
|
// extensions/line/src/signature.ts
|
|
1637
1577
|
function validateLineSignature(body, signature, channelSecret) {
|
|
1638
1578
|
const hash = crypto.createHmac("SHA256", channelSecret).update(body).digest("base64");
|
|
@@ -1641,32 +1581,7 @@ function validateLineSignature(body, signature, channelSecret) {
|
|
|
1641
1581
|
// extensions/line/src/webhook-node.ts
|
|
1642
1582
|
const LINE_WEBHOOK_PREAUTH_MAX_BODY_BYTES = 65536;
|
|
1643
1583
|
const LINE_WEBHOOK_PREAUTH_BODY_TIMEOUT_MS = 5e3;
|
|
1644
|
-
async function readLineWebhookRequestBody(req, maxBytes, timeoutMs) {
|
|
1645
|
-
return await readRequestBodyWithLimit(req, {
|
|
1646
|
-
maxBytes,
|
|
1647
|
-
timeoutMs,
|
|
1648
|
-
destroyOnLimit: false
|
|
1649
|
-
});
|
|
1650
|
-
}
|
|
1651
|
-
/**
|
|
1652
|
-
* Answer a body-limit failure through the connection owner.
|
|
1653
|
-
*
|
|
1654
|
-
* The reader defers destruction for these two codes, so the connection is already fenced
|
|
1655
|
-
* and only the owner can still write: responding directly would race the teardown and LINE
|
|
1656
|
-
* would see a reset instead of the status.
|
|
1657
|
-
*/
|
|
1658
|
-
async function rejectLineWebhookRequest(req, res, error) {
|
|
1659
|
-
if (!isRequestBodyLimitError(error, "PAYLOAD_TOO_LARGE") && !isRequestBodyLimitError(error, "REQUEST_BODY_TIMEOUT")) return false;
|
|
1660
|
-
await sendHttpRequestRejection(req, res, error.statusCode, JSON.stringify({ error: requestBodyErrorToText(error.code) }), "application/json");
|
|
1661
|
-
return true;
|
|
1662
|
-
}
|
|
1663
|
-
function sendLineWebhookJson(res, statusCode, body) {
|
|
1664
|
-
res.statusCode = statusCode;
|
|
1665
|
-
res.setHeader("Content-Type", "application/json");
|
|
1666
|
-
res.end(JSON.stringify(body));
|
|
1667
|
-
}
|
|
1668
1584
|
function createLineNodeWebhookHandler(params) {
|
|
1669
|
-
const readBody = params.readBody ?? readLineWebhookRequestBody;
|
|
1670
1585
|
return async (req, res) => {
|
|
1671
1586
|
const targets = params.getTargets();
|
|
1672
1587
|
if (req.method !== "POST" && targets.length === 0) {
|
|
@@ -1687,7 +1602,7 @@ function createLineNodeWebhookHandler(params) {
|
|
|
1687
1602
|
}
|
|
1688
1603
|
if (req.method !== "POST") {
|
|
1689
1604
|
res.setHeader("Allow", "GET, HEAD, POST");
|
|
1690
|
-
|
|
1605
|
+
sendJsonWithoutCharset(res, 405, { error: "Method Not Allowed" });
|
|
1691
1606
|
return;
|
|
1692
1607
|
}
|
|
1693
1608
|
try {
|
|
@@ -1695,51 +1610,44 @@ function createLineNodeWebhookHandler(params) {
|
|
|
1695
1610
|
const signature = typeof signatureHeader === "string" ? signatureHeader.trim() : Array.isArray(signatureHeader) ? (signatureHeader[0] ?? "").trim() : "";
|
|
1696
1611
|
if (!signature) {
|
|
1697
1612
|
logVerbose("line: webhook missing X-Line-Signature header");
|
|
1698
|
-
|
|
1613
|
+
sendJsonWithoutCharset(res, 400, { error: "Missing X-Line-Signature header" });
|
|
1699
1614
|
return;
|
|
1700
1615
|
}
|
|
1701
|
-
const rawBody = await
|
|
1616
|
+
const rawBody = await readRequestBodyWithLimit(req, {
|
|
1617
|
+
maxBytes: LINE_WEBHOOK_PREAUTH_MAX_BODY_BYTES,
|
|
1618
|
+
timeoutMs: LINE_WEBHOOK_PREAUTH_BODY_TIMEOUT_MS,
|
|
1619
|
+
destroyOnLimit: false
|
|
1620
|
+
});
|
|
1702
1621
|
const match = resolveSingleWebhookTarget(targets, (target) => validateLineSignature(rawBody, signature, target.channelSecret));
|
|
1703
1622
|
if (match.kind === "none") {
|
|
1704
1623
|
logVerbose("line: webhook signature validation failed");
|
|
1705
|
-
|
|
1624
|
+
sendJsonWithoutCharset(res, 401, { error: "Invalid signature" });
|
|
1706
1625
|
return;
|
|
1707
1626
|
}
|
|
1708
1627
|
if (match.kind === "ambiguous") {
|
|
1709
1628
|
logVerbose("line: webhook signature matched multiple accounts");
|
|
1710
|
-
|
|
1629
|
+
sendJsonWithoutCharset(res, 401, { error: "Ambiguous webhook target" });
|
|
1711
1630
|
return;
|
|
1712
1631
|
}
|
|
1713
1632
|
const body = safeParseJson(rawBody);
|
|
1714
1633
|
if (!body) {
|
|
1715
|
-
|
|
1634
|
+
sendJsonWithoutCharset(res, 400, { error: "Invalid webhook payload" });
|
|
1716
1635
|
return;
|
|
1717
1636
|
}
|
|
1718
1637
|
if (body.events && body.events.length > 0) {
|
|
1719
|
-
logVerbose(`line: received ${body.events.length} webhook events`);
|
|
1720
1638
|
if (await match.target.bot.handleWebhook(body) === "durable") res.setHeader("x-openclaw-delivery-accepted", "durable");
|
|
1721
1639
|
}
|
|
1722
|
-
|
|
1640
|
+
sendJsonWithoutCharset(res, 200, { status: "ok" });
|
|
1723
1641
|
} catch (err) {
|
|
1724
|
-
if (
|
|
1642
|
+
if (isRequestBodyLimitError(err, "PAYLOAD_TOO_LARGE") || isRequestBodyLimitError(err, "REQUEST_BODY_TIMEOUT")) {
|
|
1643
|
+
await sendHttpRequestRejection(req, res, err.statusCode, JSON.stringify({ error: requestBodyErrorToText(err.code) }), "application/json");
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1725
1646
|
params.runtime.error?.(danger(`line webhook error: ${formatErrorMessage(err)}`));
|
|
1726
|
-
if (!res.headersSent)
|
|
1647
|
+
if (!res.headersSent) sendJsonWithoutCharset(res, 500, { error: "Internal server error" });
|
|
1727
1648
|
}
|
|
1728
1649
|
};
|
|
1729
1650
|
}
|
|
1730
|
-
// extensions/line/src/webhook-utils.ts
|
|
1731
|
-
/** Route the gateway serves when an account configures no `webhookPath`. */
|
|
1732
|
-
const LINE_DEFAULT_WEBHOOK_PATH = "/line/webhook";
|
|
1733
|
-
/** The route this account's monitor serves, which is the one an operator has to register
|
|
1734
|
-
* with LINE. Every surface resolves it here so a warning cannot name a path the gateway
|
|
1735
|
-
* does not answer on. Route registration canonicalizes further, and matches requests the
|
|
1736
|
-
* same way, so a path resolved here always reaches the route the monitor registered. */
|
|
1737
|
-
function resolveLineWebhookPath(webhookPath) {
|
|
1738
|
-
return resolveWebhookPath({
|
|
1739
|
-
webhookPath,
|
|
1740
|
-
defaultPath: LINE_DEFAULT_WEBHOOK_PATH
|
|
1741
|
-
}) ?? LINE_DEFAULT_WEBHOOK_PATH;
|
|
1742
|
-
}
|
|
1743
1651
|
// extensions/line/src/monitor.ts
|
|
1744
1652
|
const lineWebhookInFlightLimiter = createWebhookInFlightLimiter();
|
|
1745
1653
|
const lineWebhookTargets = /* @__PURE__ */ new Map();
|
|
@@ -1762,14 +1670,12 @@ async function monitorLineProvider(opts) {
|
|
|
1762
1670
|
const replyPipeline = userId ? { typing: {
|
|
1763
1671
|
start: () => showLoadingAnimation(userId, {
|
|
1764
1672
|
cfg: turnConfig,
|
|
1765
|
-
accountId: ctx.accountId
|
|
1766
|
-
loadingSeconds: 20
|
|
1673
|
+
accountId: ctx.accountId
|
|
1767
1674
|
}),
|
|
1768
1675
|
keepaliveIntervalMs: 18e3,
|
|
1769
1676
|
maxDurationMs: 0,
|
|
1770
1677
|
onStartError: () => {}
|
|
1771
1678
|
} } : {};
|
|
1772
|
-
logVerbose(`line: received message from ${ctxPayload.SenderName ?? ctx.userId ?? ctxPayload.From} (${ctxPayload.From})`);
|
|
1773
1679
|
let replyTokenUsed = false;
|
|
1774
1680
|
let turnAdopted = false;
|
|
1775
1681
|
const ingressLifecycle = deliveryControl.turnAdoptionLifecycle;
|
|
@@ -1819,13 +1725,15 @@ async function monitorLineProvider(opts) {
|
|
|
1819
1725
|
...replyOptions ? { replyOptions } : {},
|
|
1820
1726
|
delivery: {
|
|
1821
1727
|
preparePayload: (payload) => prepareLineReplyPayload(payload, ctxPayload.From),
|
|
1822
|
-
durable: (payload, info) =>
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1728
|
+
durable: (payload, info) => {
|
|
1729
|
+
if (info.kind !== "final") return false;
|
|
1730
|
+
if (replyToken && !replyTokenUsed) return false;
|
|
1731
|
+
const lineData = payload.channelData?.line;
|
|
1732
|
+
if (lineData && Object.keys(lineData).length > 0) return false;
|
|
1733
|
+
const reply = resolveSendableOutboundReplyParts(payload);
|
|
1734
|
+
if (reply.hasMedia || !reply.hasText) return false;
|
|
1735
|
+
return { to: ctxPayload.From };
|
|
1736
|
+
},
|
|
1829
1737
|
deliver: async (payload) => {
|
|
1830
1738
|
const deliveryResult = await deliverLineAutoReply({
|
|
1831
1739
|
payload,
|
|
@@ -1860,7 +1768,11 @@ async function monitorLineProvider(opts) {
|
|
|
1860
1768
|
}
|
|
1861
1769
|
}
|
|
1862
1770
|
});
|
|
1863
|
-
const
|
|
1771
|
+
const defaultPath = "/line/webhook";
|
|
1772
|
+
const normalizedPath = resolveWebhookPath({
|
|
1773
|
+
webhookPath,
|
|
1774
|
+
defaultPath
|
|
1775
|
+
}) ?? defaultPath;
|
|
1864
1776
|
const webhookRouteKey = canonicalizeWebhookRouteKey(normalizedPath);
|
|
1865
1777
|
const handleWebhook = createLineNodeWebhookHandler({
|
|
1866
1778
|
getTargets: () => lineWebhookTargets.get(webhookRouteKey) ?? [],
|
|
@@ -1936,4 +1848,4 @@ async function monitorLineProvider(opts) {
|
|
|
1936
1848
|
}
|
|
1937
1849
|
};
|
|
1938
1850
|
}
|
|
1939
|
-
export { monitorLineProvider
|
|
1851
|
+
export { monitorLineProvider };
|