@openclaw/line 2026.11.3 → 2026.11.5-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-4BpGVN1-.mjs +3 -0
- package/dist/.setup/{api-WIupE7U1.mjs → api-BRnngy5R.mjs} +1 -1
- package/dist/.setup/{card-command-Dnkl21vg.mjs → card-command-2y-RSLPg.mjs} +26 -43
- package/dist/.setup/{channel-DIEVJ4PQ.mjs → channel-DJcpjKpx.mjs} +237 -332
- package/dist/.setup/channel.runtime-CdfKsNz4.mjs +4 -0
- package/dist/.setup/{monitor-JlOPDECF.mjs → monitor-BkuPFFxZ.mjs} +240 -329
- package/dist/.setup/{outbound.runtime-pciQUWJd.mjs → outbound.runtime-BPo_111h.mjs} +2 -2
- package/dist/.setup/{send-kjjjemFi.mjs → send-C1JZOFMA.mjs} +32 -81
- package/dist/.setup/{send-retry-Dzbkz5wG.mjs → send-retry-Bf2Xr6ZN.mjs} +175 -80
- package/dist/.setup/{template-messages-COcdie6C.mjs → template-messages-C1Kkr0-e.mjs} +32 -44
- package/dist/.source-module-urls/2c97352967966b7ab9f67f528eb25c098b6fe10ea0e4616ffae3851ed839d81e.json +1 -0
- package/dist/api.js +2 -2
- package/dist/channel-plugin-api.js +1 -2
- package/dist/contract-api.js +1 -2
- package/dist/index.js +1 -1
- package/dist/runtime-api.js +1 -2
- package/dist/setup-api.js +1 -2
- 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-BMSLc5Fi.mjs +0 -3
- package/dist/.setup/channel.runtime-CDy9DQUW.mjs +0 -4
- package/dist/.setup/monitor.runtime-DsIFiXEZ.mjs +0 -2
- package/dist/.setup/probe.runtime-D2MUF_B_.mjs +0 -2
- 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-Bf2Xr6ZN.mjs";
|
|
1
2
|
import { n as resolveDefaultLineAccountId, r as resolveLineAccount } from "./accounts-DOiM8-y3.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-DIEVJ4PQ.mjs";
|
|
3
3
|
import { a as normalizeLineAllowEntry } from "./setup-surface-CYd8oqzt.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-DJcpjKpx.mjs";
|
|
4
5
|
import { t as getLineRuntime } from "./runtime-V7yh9OeC.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-Dzbkz5wG.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-msjTl60Q.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-C1JZOFMA.mjs";
|
|
8
|
+
import { n as processLineMessage, t as buildTemplateMessageFromPayload } from "./template-messages-C1Kkr0-e.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
|
//#region extensions/line/src/auto-reply-delivery.ts
|
|
48
49
|
function toLineDeliveryError(error) {
|
|
@@ -348,10 +349,7 @@ async function resolveLineInboundRoute(params) {
|
|
|
348
349
|
});
|
|
349
350
|
const prepared = params.preparedRoute ?? await prepareLineInboundRoute(params);
|
|
350
351
|
const { peerId, runtimeRoute, configuredBinding, configuredBindingSessionKey } = prepared;
|
|
351
|
-
if (runtimeRoute.bindingRecord)
|
|
352
|
-
await getSessionBindingService().touchAsync(runtimeRoute.bindingRecord.bindingId, void 0, runtimeRoute.bindingRecord.conversation);
|
|
353
|
-
logVerbose(runtimeRoute.boundSessionKey ? `line: routed via bound conversation ${peerId} -> ${runtimeRoute.boundSessionKey}` : `line: plugin-bound conversation ${peerId}`);
|
|
354
|
-
}
|
|
352
|
+
if (runtimeRoute.bindingRecord) await getSessionBindingService().touchAsync(runtimeRoute.bindingRecord.bindingId, void 0, runtimeRoute.bindingRecord.conversation);
|
|
355
353
|
if (configuredBinding) {
|
|
356
354
|
const ensured = await ensureConfiguredBindingRouteReady({
|
|
357
355
|
cfg: params.cfg,
|
|
@@ -361,7 +359,6 @@ async function resolveLineInboundRoute(params) {
|
|
|
361
359
|
logVerbose(`line: configured ACP binding unavailable for ${peerId} -> ${configuredBindingSessionKey}: ${ensured.error}`);
|
|
362
360
|
throw new Error(`Configured ACP binding unavailable: ${ensured.error}`);
|
|
363
361
|
}
|
|
364
|
-
logVerbose(`line: using configured ACP binding for ${peerId} -> ${configuredBindingSessionKey}`);
|
|
365
362
|
}
|
|
366
363
|
return prepared;
|
|
367
364
|
}
|
|
@@ -404,6 +401,12 @@ function extractNativeMediaKind(message) {
|
|
|
404
401
|
}
|
|
405
402
|
}
|
|
406
403
|
async function finalizeLineInboundContext(params) {
|
|
404
|
+
const channelIngress = await params.resolveChannelIngress?.({
|
|
405
|
+
agentId: params.route.agentId,
|
|
406
|
+
sessionKey: params.route.sessionKey,
|
|
407
|
+
messageId: params.messageSid,
|
|
408
|
+
inboundEventKind: "user_request"
|
|
409
|
+
});
|
|
407
410
|
const senderId = params.source.userId ?? "unknown";
|
|
408
411
|
const clientOpts = {
|
|
409
412
|
cfg: params.cfg,
|
|
@@ -443,7 +446,7 @@ async function finalizeLineInboundContext(params) {
|
|
|
443
446
|
envelope: envelopeOptions
|
|
444
447
|
});
|
|
445
448
|
const ctxPayload = (params.buildContext ?? buildChannelInboundEventContext)({
|
|
446
|
-
channelIngress
|
|
449
|
+
channelIngress,
|
|
447
450
|
channel: "line",
|
|
448
451
|
accountId: params.route.accountId,
|
|
449
452
|
messageId: params.messageSid,
|
|
@@ -493,11 +496,6 @@ async function finalizeLineInboundContext(params) {
|
|
|
493
496
|
route: params.route,
|
|
494
497
|
sessionKey: params.route.sessionKey
|
|
495
498
|
});
|
|
496
|
-
if (shouldLogVerbose()) {
|
|
497
|
-
const mediaInfo = params.verboseLog.kind === "inbound" && (params.verboseLog.mediaCount ?? 0) > 1 ? ` mediaCount=${params.verboseLog.mediaCount}` : "";
|
|
498
|
-
const label = params.verboseLog.kind === "inbound" ? "line inbound" : "line postback";
|
|
499
|
-
logVerbose(`${label}: from=${ctxPayload.From} len=${body.length}${mediaInfo}`);
|
|
500
|
-
}
|
|
501
499
|
return {
|
|
502
500
|
ctxPayload,
|
|
503
501
|
event: params.event,
|
|
@@ -545,9 +543,11 @@ async function buildLineMessageContext(params) {
|
|
|
545
543
|
const messageId = message.id;
|
|
546
544
|
const rawBody = extractMessageText(message);
|
|
547
545
|
const nativeMediaKind = extractNativeMediaKind(message);
|
|
548
|
-
const mediaFacts = allMedia.length > 0 ? allMedia.map((
|
|
549
|
-
|
|
550
|
-
|
|
546
|
+
const mediaFacts = allMedia.length > 0 ? allMedia.map(({ path, contentType, fileName }) => ({
|
|
547
|
+
path,
|
|
548
|
+
contentType,
|
|
549
|
+
fileName,
|
|
550
|
+
kind: nativeMediaKind === "document" && contentType?.startsWith("image/") ? "image" : nativeMediaKind
|
|
551
551
|
})) : nativeMediaKind ? [{ kind: nativeMediaKind }] : [];
|
|
552
552
|
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;
|
|
553
553
|
const withShortfall = shortfallNotice ? formatInboundMediaUnavailableText({
|
|
@@ -584,19 +584,10 @@ async function buildLineMessageContext(params) {
|
|
|
584
584
|
mentions: params.mentions,
|
|
585
585
|
messageSid: messageId,
|
|
586
586
|
commandAuthorized,
|
|
587
|
-
|
|
588
|
-
agentId: route.agentId,
|
|
589
|
-
sessionKey: route.sessionKey,
|
|
590
|
-
messageId,
|
|
591
|
-
inboundEventKind: "user_request"
|
|
592
|
-
}),
|
|
587
|
+
resolveChannelIngress: params.resolveChannelIngress,
|
|
593
588
|
buildContext: params.buildContext,
|
|
594
589
|
media: mediaFacts,
|
|
595
590
|
locationContext,
|
|
596
|
-
verboseLog: {
|
|
597
|
-
kind: "inbound",
|
|
598
|
-
mediaCount: allMedia.length
|
|
599
|
-
},
|
|
600
591
|
inboundHistory
|
|
601
592
|
});
|
|
602
593
|
}
|
|
@@ -632,15 +623,9 @@ async function buildLinePostbackContext(params) {
|
|
|
632
623
|
agentBody,
|
|
633
624
|
messageSid,
|
|
634
625
|
commandAuthorized,
|
|
635
|
-
|
|
636
|
-
agentId: route.agentId,
|
|
637
|
-
sessionKey: route.sessionKey,
|
|
638
|
-
messageId: messageSid,
|
|
639
|
-
inboundEventKind: "user_request"
|
|
640
|
-
}),
|
|
626
|
+
resolveChannelIngress: params.resolveChannelIngress,
|
|
641
627
|
buildContext: params.buildContext,
|
|
642
|
-
media: []
|
|
643
|
-
verboseLog: { kind: "postback" }
|
|
628
|
+
media: []
|
|
644
629
|
});
|
|
645
630
|
}
|
|
646
631
|
//#endregion
|
|
@@ -685,9 +670,7 @@ async function* lineResponseBodyChunks(response, messageId, signal, onComplete)
|
|
|
685
670
|
}
|
|
686
671
|
} finally {
|
|
687
672
|
if (!completed) await reader.cancel(signal.aborted ? signal.reason : void 0).catch(() => void 0);
|
|
688
|
-
|
|
689
|
-
reader.releaseLock();
|
|
690
|
-
} catch {}
|
|
673
|
+
reader.releaseLock();
|
|
691
674
|
}
|
|
692
675
|
}
|
|
693
676
|
async function fetchLineContentWhenReady(messageId, channelAccessToken, signal) {
|
|
@@ -738,11 +721,9 @@ async function downloadLineMedia(messageId, channelAccessToken, maxBytes = 10485
|
|
|
738
721
|
throw err;
|
|
739
722
|
}
|
|
740
723
|
options?.signal?.throwIfAborted();
|
|
741
|
-
logVerbose(`line: persisted media ${messageId} to ${saved.path} (${saved.size} bytes)`);
|
|
742
724
|
return {
|
|
743
725
|
path: saved.path,
|
|
744
|
-
contentType: saved.contentType
|
|
745
|
-
size: saved.size
|
|
726
|
+
contentType: saved.contentType
|
|
746
727
|
};
|
|
747
728
|
} finally {
|
|
748
729
|
clearTimeout(deadline);
|
|
@@ -794,9 +775,6 @@ const LINE_DOWNLOADABLE_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
|
794
775
|
function isDownloadableLineMessageType(messageType) {
|
|
795
776
|
return LINE_DOWNLOADABLE_MESSAGE_TYPES.has(messageType);
|
|
796
777
|
}
|
|
797
|
-
function normalizeLineIngressEntry(value) {
|
|
798
|
-
return normalizeLineAllowEntry(value) || null;
|
|
799
|
-
}
|
|
800
778
|
/**
|
|
801
779
|
* Say one line back to a sender, preferring their reply token so the answer costs no
|
|
802
780
|
* push quota, and falling back to a push when no token is usable. A partial-delivery
|
|
@@ -895,7 +873,7 @@ async function resolveLineEventAdmission(event, context) {
|
|
|
895
873
|
accountId: account.accountId,
|
|
896
874
|
identity: {
|
|
897
875
|
key: "line-user-id",
|
|
898
|
-
normalize:
|
|
876
|
+
normalize: (value) => normalizeLineAllowEntry(value) || null,
|
|
899
877
|
sensitivity: "pii",
|
|
900
878
|
entryIdPrefix: "line-entry"
|
|
901
879
|
},
|
|
@@ -1024,190 +1002,11 @@ function resolveEventRawText(event) {
|
|
|
1024
1002
|
if (event.type === "postback") return event.postback?.data?.trim() ?? "";
|
|
1025
1003
|
return "";
|
|
1026
1004
|
}
|
|
1027
|
-
async function handleMessageEvent(event, context, setParts) {
|
|
1028
|
-
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
|
|
1029
|
-
const message = event.message;
|
|
1030
|
-
const decision = await resolveLineEventAdmission(event, context);
|
|
1031
|
-
if (!decision) return;
|
|
1032
|
-
const { isGroup, groupId, roomId, userId } = getLineSourceInfo(event.source);
|
|
1033
|
-
if (isGroup && decision.access.activationAccess.shouldSkip) {
|
|
1034
|
-
const rawText = message.type === "text" ? readLineTextMessageBody(message) : "";
|
|
1035
|
-
const historyKey = groupId ?? roomId;
|
|
1036
|
-
const groupsConfigPath = resolveChannelGroupsConfigPath({
|
|
1037
|
-
cfg,
|
|
1038
|
-
channel: "line",
|
|
1039
|
-
accountId: account.accountId,
|
|
1040
|
-
groups: account.config.groups
|
|
1041
|
-
});
|
|
1042
|
-
logInboundDrop({
|
|
1043
|
-
log: runtime.log,
|
|
1044
|
-
channel: "line",
|
|
1045
|
-
reason: "no mention",
|
|
1046
|
-
target: historyKey,
|
|
1047
|
-
onceKey: JSON.stringify([account.accountId, historyKey]),
|
|
1048
|
-
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.`
|
|
1049
|
-
});
|
|
1050
|
-
const senderId = userId ?? "unknown";
|
|
1051
|
-
if (historyKey && context.groupHistories) {
|
|
1052
|
-
const displayName = userId ? await getUserDisplayName(userId, {
|
|
1053
|
-
cfg,
|
|
1054
|
-
accountId: account.accountId,
|
|
1055
|
-
channelAccessToken: account.channelAccessToken,
|
|
1056
|
-
groupId,
|
|
1057
|
-
roomId
|
|
1058
|
-
}) : senderId;
|
|
1059
|
-
const sender = displayName === senderId ? senderId : `${displayName} (${senderId})`;
|
|
1060
|
-
createChannelHistoryWindow({ historyMap: context.groupHistories }).record({
|
|
1061
|
-
historyKey,
|
|
1062
|
-
limit: context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT,
|
|
1063
|
-
entry: {
|
|
1064
|
-
sender,
|
|
1065
|
-
body: rawText || `<${message.type}>`,
|
|
1066
|
-
timestamp: event.timestamp
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
return;
|
|
1071
|
-
}
|
|
1072
|
-
const groupHistoryKey = isGroup ? groupId ?? roomId : void 0;
|
|
1073
|
-
const historyReservation = reserveLineGroupHistory(context.groupHistories, groupHistoryKey, context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT);
|
|
1074
|
-
try {
|
|
1075
|
-
const allMedia = [];
|
|
1076
|
-
let mediaUnavailable = false;
|
|
1077
|
-
const abortSignal = context.turnAdoptionLifecycle?.abortSignal;
|
|
1078
|
-
for (const part of orderedLineSetMessages(message, setParts)) {
|
|
1079
|
-
if (!isDownloadableLineMessageType(part.type)) continue;
|
|
1080
|
-
try {
|
|
1081
|
-
const originalFilename = part.type === "file" ? normalizeOptionalString(part.fileName) : void 0;
|
|
1082
|
-
const media = await downloadLineMedia(part.id, account.channelAccessToken, mediaMaxBytes, {
|
|
1083
|
-
originalFilename,
|
|
1084
|
-
...abortSignal ? { signal: abortSignal } : {}
|
|
1085
|
-
});
|
|
1086
|
-
abortSignal?.throwIfAborted();
|
|
1087
|
-
allMedia.push({
|
|
1088
|
-
path: media.path,
|
|
1089
|
-
contentType: media.contentType,
|
|
1090
|
-
...originalFilename ? { fileName: originalFilename } : {}
|
|
1091
|
-
});
|
|
1092
|
-
} catch (err) {
|
|
1093
|
-
if (abortSignal?.aborted) throw abortSignal.reason;
|
|
1094
|
-
if (isRetryableLineInboundMediaError(err)) throw err;
|
|
1095
|
-
mediaUnavailable = true;
|
|
1096
|
-
const errMsg = String(err);
|
|
1097
|
-
if (errMsg.includes("exceeds") && errMsg.includes("limit")) logVerbose(`line: media exceeds size limit for message ${part.id}`);
|
|
1098
|
-
else runtime.error?.(danger(`line: failed to download media: ${errMsg}`));
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
const messageContext = await buildLineMessageContext({
|
|
1102
|
-
event: setParts.reduce((freshest, part) => part.timestamp > freshest.timestamp ? part : freshest, event),
|
|
1103
|
-
allMedia: [...allMedia],
|
|
1104
|
-
mediaUnavailable,
|
|
1105
|
-
...context.missingParts === void 0 ? {} : { missingParts: context.missingParts },
|
|
1106
|
-
cfg,
|
|
1107
|
-
account,
|
|
1108
|
-
preparedRoute: decision.preparedRoute,
|
|
1109
|
-
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1110
|
-
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1111
|
-
inboundHistory: historyReservation.inboundHistory,
|
|
1112
|
-
mentions: decision.mentions,
|
|
1113
|
-
buildContext: context.buildContext
|
|
1114
|
-
});
|
|
1115
|
-
if (!messageContext) logVerbose("line: skipping empty message");
|
|
1116
|
-
else {
|
|
1117
|
-
await processMessage(messageContext, {
|
|
1118
|
-
cfg: context.cfg,
|
|
1119
|
-
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1120
|
-
});
|
|
1121
|
-
historyReservation.commit();
|
|
1122
|
-
}
|
|
1123
|
-
} finally {
|
|
1124
|
-
historyReservation.release();
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
async function handleJoinEvent(event, context) {
|
|
1128
|
-
const { groupId, roomId, isGroup } = getLineSourceInfo(event.source);
|
|
1129
|
-
const conversationId = groupId ?? roomId;
|
|
1130
|
-
if (!isGroup || !conversationId) return;
|
|
1131
|
-
logVerbose(`line: bot joined ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1132
|
-
const { cfg, account } = context;
|
|
1133
|
-
const roomAllowed = Boolean(await resolveLineEventAdmission(event, context));
|
|
1134
|
-
await reportChannelRoomJoin({
|
|
1135
|
-
cfg,
|
|
1136
|
-
channel: "line",
|
|
1137
|
-
accountId: account.accountId,
|
|
1138
|
-
conversationId,
|
|
1139
|
-
deliverTo: conversationId,
|
|
1140
|
-
route: resolveAgentRoute({
|
|
1141
|
-
cfg,
|
|
1142
|
-
channel: "line",
|
|
1143
|
-
accountId: account.accountId,
|
|
1144
|
-
peer: {
|
|
1145
|
-
kind: "group",
|
|
1146
|
-
id: conversationId
|
|
1147
|
-
}
|
|
1148
|
-
}),
|
|
1149
|
-
roomAllowed,
|
|
1150
|
-
resolveRoomContext: async () => {
|
|
1151
|
-
const roomContext = { historyUnavailable: true };
|
|
1152
|
-
const title = groupId ? await getLineGroupName(groupId, {
|
|
1153
|
-
cfg,
|
|
1154
|
-
accountId: account.accountId,
|
|
1155
|
-
channelAccessToken: account.channelAccessToken
|
|
1156
|
-
}) : void 0;
|
|
1157
|
-
return title ? {
|
|
1158
|
-
...roomContext,
|
|
1159
|
-
title
|
|
1160
|
-
} : roomContext;
|
|
1161
|
-
}
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
1005
|
/** What a tap that did not answer the question has to tell the person who tapped. */
|
|
1165
1006
|
function lineQuestionOutcomeNotice(status) {
|
|
1166
1007
|
if (status === "already-terminal") return "That question is no longer waiting for an answer.";
|
|
1167
1008
|
return "Could not record that answer. Reply with the option text instead.";
|
|
1168
1009
|
}
|
|
1169
|
-
async function handlePostbackEvent(event, context) {
|
|
1170
|
-
const data = event.postback.data;
|
|
1171
|
-
const decision = await resolveLineEventAdmission(event, context);
|
|
1172
|
-
if (!decision) return;
|
|
1173
|
-
const question = parseLineQuestionPostbackData(data ?? "");
|
|
1174
|
-
if (question) {
|
|
1175
|
-
const { userId, groupId, roomId } = getLineSourceInfo(event.source);
|
|
1176
|
-
const authorize = async () => isLineEventAdmitted(await decision.resolveBoundAccess());
|
|
1177
|
-
const outcome = await resolveLineQuestionPostback({
|
|
1178
|
-
cfg: context.cfg,
|
|
1179
|
-
callback: question,
|
|
1180
|
-
accountId: context.account.accountId,
|
|
1181
|
-
...userId ? { senderId: userId } : {},
|
|
1182
|
-
authorize
|
|
1183
|
-
});
|
|
1184
|
-
const pushTarget = groupId ?? roomId ?? (userId ? `line:${userId}` : void 0);
|
|
1185
|
-
if (outcome.status === "answered" || outcome.status === "denied" || !pushTarget) return;
|
|
1186
|
-
await sendLineHandlerText({
|
|
1187
|
-
context,
|
|
1188
|
-
replyToken: event.replyToken,
|
|
1189
|
-
pushTarget,
|
|
1190
|
-
logLabel: "line: question answer notice failed",
|
|
1191
|
-
text: lineQuestionOutcomeNotice(outcome.status),
|
|
1192
|
-
authorize
|
|
1193
|
-
});
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
if (isLineQuestionPostbackData(data ?? "")) return;
|
|
1197
|
-
const postbackContext = await buildLinePostbackContext({
|
|
1198
|
-
event,
|
|
1199
|
-
cfg: context.cfg,
|
|
1200
|
-
account: context.account,
|
|
1201
|
-
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1202
|
-
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1203
|
-
buildContext: context.buildContext
|
|
1204
|
-
});
|
|
1205
|
-
if (!postbackContext) return;
|
|
1206
|
-
await context.processMessage(postbackContext, {
|
|
1207
|
-
cfg: context.cfg,
|
|
1208
|
-
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1209
|
-
});
|
|
1210
|
-
}
|
|
1211
1010
|
/** Media reads in the order the sender picked, whatever order LINE delivered. */
|
|
1212
1011
|
function orderedLineSetMessages(message, setParts) {
|
|
1213
1012
|
const messages = [message, ...setParts.map((partEvent) => partEvent.message)];
|
|
@@ -1224,26 +1023,195 @@ async function handleLineWebhookEvents(events, context) {
|
|
|
1224
1023
|
if (!event) return;
|
|
1225
1024
|
try {
|
|
1226
1025
|
switch (event.type) {
|
|
1227
|
-
case "message":
|
|
1228
|
-
|
|
1026
|
+
case "message": {
|
|
1027
|
+
const messageSetParts = setParts.filter((part) => part.type === "message");
|
|
1028
|
+
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
|
|
1029
|
+
const message = event.message;
|
|
1030
|
+
const decision = await resolveLineEventAdmission(event, context);
|
|
1031
|
+
if (!decision) return;
|
|
1032
|
+
const { isGroup, groupId, roomId, userId } = getLineSourceInfo(event.source);
|
|
1033
|
+
if (isGroup && decision.access.activationAccess.shouldSkip) {
|
|
1034
|
+
const rawText = message.type === "text" ? readLineTextMessageBody(message) : "";
|
|
1035
|
+
const historyKey = groupId ?? roomId;
|
|
1036
|
+
const groupsConfigPath = resolveChannelGroupsConfigPath({
|
|
1037
|
+
cfg,
|
|
1038
|
+
channel: "line",
|
|
1039
|
+
accountId: account.accountId,
|
|
1040
|
+
groups: account.config.groups
|
|
1041
|
+
});
|
|
1042
|
+
logInboundDrop({
|
|
1043
|
+
log: runtime.log,
|
|
1044
|
+
channel: "line",
|
|
1045
|
+
reason: "no mention",
|
|
1046
|
+
target: historyKey,
|
|
1047
|
+
onceKey: JSON.stringify([account.accountId, historyKey]),
|
|
1048
|
+
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.`
|
|
1049
|
+
});
|
|
1050
|
+
const senderId = userId ?? "unknown";
|
|
1051
|
+
if (historyKey && context.groupHistories) {
|
|
1052
|
+
const displayName = userId ? await getUserDisplayName(userId, {
|
|
1053
|
+
cfg,
|
|
1054
|
+
accountId: account.accountId,
|
|
1055
|
+
channelAccessToken: account.channelAccessToken,
|
|
1056
|
+
groupId,
|
|
1057
|
+
roomId
|
|
1058
|
+
}) : senderId;
|
|
1059
|
+
const sender = displayName === senderId ? senderId : `${displayName} (${senderId})`;
|
|
1060
|
+
createChannelHistoryWindow({ historyMap: context.groupHistories }).record({
|
|
1061
|
+
historyKey,
|
|
1062
|
+
limit: context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT,
|
|
1063
|
+
entry: {
|
|
1064
|
+
sender,
|
|
1065
|
+
body: rawText || `<${message.type}>`,
|
|
1066
|
+
timestamp: event.timestamp
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
const groupHistoryKey = isGroup ? groupId ?? roomId : void 0;
|
|
1073
|
+
const historyReservation = reserveLineGroupHistory(context.groupHistories, groupHistoryKey, context.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT);
|
|
1074
|
+
try {
|
|
1075
|
+
const allMedia = [];
|
|
1076
|
+
let mediaUnavailable = false;
|
|
1077
|
+
const abortSignal = context.turnAdoptionLifecycle?.abortSignal;
|
|
1078
|
+
for (const part of orderedLineSetMessages(message, messageSetParts)) {
|
|
1079
|
+
if (!isDownloadableLineMessageType(part.type)) continue;
|
|
1080
|
+
try {
|
|
1081
|
+
const originalFilename = part.type === "file" ? normalizeOptionalString(part.fileName) : void 0;
|
|
1082
|
+
const media = await downloadLineMedia(part.id, account.channelAccessToken, mediaMaxBytes, {
|
|
1083
|
+
originalFilename,
|
|
1084
|
+
...abortSignal ? { signal: abortSignal } : {}
|
|
1085
|
+
});
|
|
1086
|
+
abortSignal?.throwIfAborted();
|
|
1087
|
+
allMedia.push({
|
|
1088
|
+
path: media.path,
|
|
1089
|
+
contentType: media.contentType,
|
|
1090
|
+
...originalFilename ? { fileName: originalFilename } : {}
|
|
1091
|
+
});
|
|
1092
|
+
} catch (err) {
|
|
1093
|
+
if (abortSignal?.aborted) throw abortSignal.reason;
|
|
1094
|
+
if (isRetryableLineInboundMediaError(err)) throw err;
|
|
1095
|
+
mediaUnavailable = true;
|
|
1096
|
+
const errMsg = String(err);
|
|
1097
|
+
if (errMsg.includes("exceeds") && errMsg.includes("limit")) logVerbose(`line: media exceeds size limit for message ${part.id}`);
|
|
1098
|
+
else runtime.error?.(danger(`line: failed to download media: ${errMsg}`));
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
const messageContext = await buildLineMessageContext({
|
|
1102
|
+
event: messageSetParts.reduce((freshest, part) => part.timestamp > freshest.timestamp ? part : freshest, event),
|
|
1103
|
+
allMedia,
|
|
1104
|
+
mediaUnavailable,
|
|
1105
|
+
...context.missingParts === void 0 ? {} : { missingParts: context.missingParts },
|
|
1106
|
+
cfg,
|
|
1107
|
+
account,
|
|
1108
|
+
preparedRoute: decision.preparedRoute,
|
|
1109
|
+
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1110
|
+
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1111
|
+
inboundHistory: historyReservation.inboundHistory,
|
|
1112
|
+
mentions: decision.mentions,
|
|
1113
|
+
buildContext: context.buildContext
|
|
1114
|
+
});
|
|
1115
|
+
if (messageContext) {
|
|
1116
|
+
await processMessage(messageContext, {
|
|
1117
|
+
cfg: context.cfg,
|
|
1118
|
+
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1119
|
+
});
|
|
1120
|
+
historyReservation.commit();
|
|
1121
|
+
}
|
|
1122
|
+
} finally {
|
|
1123
|
+
historyReservation.release();
|
|
1124
|
+
}
|
|
1229
1125
|
break;
|
|
1126
|
+
}
|
|
1230
1127
|
case "follow":
|
|
1231
|
-
case "unfollow":
|
|
1232
|
-
|
|
1233
|
-
|
|
1128
|
+
case "unfollow": break;
|
|
1129
|
+
case "join": {
|
|
1130
|
+
const { groupId, roomId, isGroup } = getLineSourceInfo(event.source);
|
|
1131
|
+
const conversationId = groupId ?? roomId;
|
|
1132
|
+
if (!isGroup || !conversationId) return;
|
|
1133
|
+
logVerbose(`line: bot joined ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1134
|
+
const { cfg, account } = context;
|
|
1135
|
+
const roomAllowed = Boolean(await resolveLineEventAdmission(event, context));
|
|
1136
|
+
await reportChannelRoomJoin({
|
|
1137
|
+
cfg,
|
|
1138
|
+
channel: "line",
|
|
1139
|
+
accountId: account.accountId,
|
|
1140
|
+
conversationId,
|
|
1141
|
+
deliverTo: conversationId,
|
|
1142
|
+
route: resolveAgentRoute({
|
|
1143
|
+
cfg,
|
|
1144
|
+
channel: "line",
|
|
1145
|
+
accountId: account.accountId,
|
|
1146
|
+
peer: {
|
|
1147
|
+
kind: "group",
|
|
1148
|
+
id: conversationId
|
|
1149
|
+
}
|
|
1150
|
+
}),
|
|
1151
|
+
roomAllowed,
|
|
1152
|
+
resolveRoomContext: async () => {
|
|
1153
|
+
const roomContext = { historyUnavailable: true };
|
|
1154
|
+
const title = groupId ? await getLineGroupName(groupId, {
|
|
1155
|
+
cfg,
|
|
1156
|
+
accountId: account.accountId,
|
|
1157
|
+
channelAccessToken: account.channelAccessToken
|
|
1158
|
+
}) : void 0;
|
|
1159
|
+
return title ? {
|
|
1160
|
+
...roomContext,
|
|
1161
|
+
title
|
|
1162
|
+
} : roomContext;
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1234
1165
|
break;
|
|
1235
1166
|
}
|
|
1236
|
-
case "join":
|
|
1237
|
-
await handleJoinEvent(event, context);
|
|
1238
|
-
break;
|
|
1239
1167
|
case "leave": {
|
|
1240
1168
|
const { groupId, roomId } = getLineSourceInfo(event.source);
|
|
1241
1169
|
logVerbose(`line: bot left ${groupId ? `group ${groupId}` : `room ${roomId}`}`);
|
|
1242
1170
|
break;
|
|
1243
1171
|
}
|
|
1244
|
-
case "postback":
|
|
1245
|
-
|
|
1172
|
+
case "postback": {
|
|
1173
|
+
const data = event.postback.data;
|
|
1174
|
+
const decision = await resolveLineEventAdmission(event, context);
|
|
1175
|
+
if (!decision) return;
|
|
1176
|
+
const question = parseLineQuestionPostbackData(data ?? "");
|
|
1177
|
+
if (question) {
|
|
1178
|
+
const { userId, groupId, roomId } = getLineSourceInfo(event.source);
|
|
1179
|
+
const authorize = async () => isLineEventAdmitted(await decision.resolveBoundAccess());
|
|
1180
|
+
const outcome = await resolveLineQuestionPostback({
|
|
1181
|
+
cfg: context.cfg,
|
|
1182
|
+
callback: question,
|
|
1183
|
+
accountId: context.account.accountId,
|
|
1184
|
+
...userId ? { senderId: userId } : {},
|
|
1185
|
+
authorize
|
|
1186
|
+
});
|
|
1187
|
+
const pushTarget = groupId ?? roomId ?? (userId ? `line:${userId}` : void 0);
|
|
1188
|
+
if (outcome.status === "answered" || outcome.status === "denied" || !pushTarget) return;
|
|
1189
|
+
await sendLineHandlerText({
|
|
1190
|
+
context,
|
|
1191
|
+
replyToken: event.replyToken,
|
|
1192
|
+
pushTarget,
|
|
1193
|
+
logLabel: "line: question answer notice failed",
|
|
1194
|
+
text: lineQuestionOutcomeNotice(outcome.status),
|
|
1195
|
+
authorize
|
|
1196
|
+
});
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
if (isLineQuestionPostbackData(data ?? "")) return;
|
|
1200
|
+
const postbackContext = await buildLinePostbackContext({
|
|
1201
|
+
event,
|
|
1202
|
+
cfg: context.cfg,
|
|
1203
|
+
account: context.account,
|
|
1204
|
+
commandAuthorized: decision.access.commandAccess.authorized,
|
|
1205
|
+
resolveChannelIngress: decision.resolveBoundAccess,
|
|
1206
|
+
buildContext: context.buildContext
|
|
1207
|
+
});
|
|
1208
|
+
if (!postbackContext) return;
|
|
1209
|
+
await context.processMessage(postbackContext, {
|
|
1210
|
+
cfg: context.cfg,
|
|
1211
|
+
...context.turnAdoptionLifecycle ? { turnAdoptionLifecycle: context.turnAdoptionLifecycle } : {}
|
|
1212
|
+
});
|
|
1246
1213
|
break;
|
|
1214
|
+
}
|
|
1247
1215
|
default: logVerbose(`line: unhandled event type: ${event.type}`);
|
|
1248
1216
|
}
|
|
1249
1217
|
} catch (err) {
|
|
@@ -1467,17 +1435,11 @@ function createLineWebhookSpool(options) {
|
|
|
1467
1435
|
}
|
|
1468
1436
|
const fannedIn = fanInChannelIngressLifecycles(turnLifecycles);
|
|
1469
1437
|
const boundLifecycle = bindIngressLifecycleToReplyOptions(fannedIn.lifecycle ?? lifecycle).turnAdoptionLifecycle;
|
|
1470
|
-
let handedOff = false;
|
|
1471
1438
|
const delivery = options.deliver(turnEvents, destination, {
|
|
1472
1439
|
...missingParts === void 0 ? {} : { missingParts },
|
|
1473
1440
|
turnAdoptionLifecycle: {
|
|
1474
1441
|
...boundLifecycle,
|
|
1475
|
-
onAdopted: async () => {
|
|
1476
|
-
handedOff = true;
|
|
1477
|
-
await boundLifecycle.onAdopted();
|
|
1478
|
-
},
|
|
1479
1442
|
onDeferred: () => {
|
|
1480
|
-
handedOff = true;
|
|
1481
1443
|
if (!acceptsDeferredClaims) {
|
|
1482
1444
|
Promise.resolve().then(() => boundLifecycle.onAbandoned()).catch((error) => {
|
|
1483
1445
|
options.runtime.error?.(danger(`line: failed to abandon a late webhook delivery: ${formatErrorMessage(error)}`));
|
|
@@ -1485,10 +1447,6 @@ function createLineWebhookSpool(options) {
|
|
|
1485
1447
|
return;
|
|
1486
1448
|
}
|
|
1487
1449
|
boundLifecycle.onDeferred();
|
|
1488
|
-
},
|
|
1489
|
-
onAbandoned: async () => {
|
|
1490
|
-
handedOff = true;
|
|
1491
|
-
await boundLifecycle.onAbandoned();
|
|
1492
1450
|
}
|
|
1493
1451
|
}
|
|
1494
1452
|
});
|
|
@@ -1497,20 +1455,13 @@ function createLineWebhookSpool(options) {
|
|
|
1497
1455
|
await delivery;
|
|
1498
1456
|
} catch (error) {
|
|
1499
1457
|
await fannedIn.abandon(error);
|
|
1500
|
-
handedOff = true;
|
|
1501
1458
|
throw error;
|
|
1502
1459
|
} finally {
|
|
1503
1460
|
activeDeliveries.delete(delivery);
|
|
1504
1461
|
releaseLane?.();
|
|
1505
1462
|
}
|
|
1506
|
-
if (
|
|
1507
|
-
|
|
1508
|
-
handedOff = true;
|
|
1509
|
-
}
|
|
1510
|
-
if (stopTask && !handedOff) {
|
|
1511
|
-
await fannedIn.abandon();
|
|
1512
|
-
return;
|
|
1513
|
-
}
|
|
1463
|
+
if (stopTask) await fannedIn.abandon();
|
|
1464
|
+
else await fannedIn.settle();
|
|
1514
1465
|
},
|
|
1515
1466
|
pollIntervalMs: LINE_WEBHOOK_DRAIN_INTERVAL_MS,
|
|
1516
1467
|
retention: {
|
|
@@ -1602,14 +1553,14 @@ function createLineBot(opts) {
|
|
|
1602
1553
|
accountId: opts.accountId
|
|
1603
1554
|
});
|
|
1604
1555
|
const configuredMediaMaxMb = account.config.mediaMaxMb;
|
|
1605
|
-
const mediaMaxBytes = (
|
|
1556
|
+
const mediaMaxBytes = (configuredMediaMaxMb !== void 0 && configuredMediaMaxMb > 0 ? configuredMediaMaxMb : DEFAULT_MEDIA_MAX_MB) * 1024 * 1024;
|
|
1606
1557
|
const groupHistories = /* @__PURE__ */ new Map();
|
|
1607
1558
|
const spool = createLineWebhookSpool({
|
|
1608
1559
|
accountId: account.accountId,
|
|
1609
1560
|
runtime,
|
|
1610
1561
|
deliver: async (events, _destination, control) => {
|
|
1611
1562
|
const cfg = resolveTurnConfig();
|
|
1612
|
-
await handleLineWebhookEvents(
|
|
1563
|
+
await handleLineWebhookEvents(events, {
|
|
1613
1564
|
cfg,
|
|
1614
1565
|
account,
|
|
1615
1566
|
runtime,
|
|
@@ -1631,17 +1582,6 @@ function createLineBot(opts) {
|
|
|
1631
1582
|
};
|
|
1632
1583
|
}
|
|
1633
1584
|
//#endregion
|
|
1634
|
-
//#region extensions/line/src/monitor-durable.ts
|
|
1635
|
-
function resolveLineDurableReplyOptions(params) {
|
|
1636
|
-
if (params.infoKind !== "final") return false;
|
|
1637
|
-
if (params.replyToken && !params.replyTokenUsed) return false;
|
|
1638
|
-
const lineData = params.payload.channelData?.line;
|
|
1639
|
-
if (lineData && Object.keys(lineData).length > 0) return false;
|
|
1640
|
-
const reply = resolveSendableOutboundReplyParts(params.payload);
|
|
1641
|
-
if (reply.hasMedia || !reply.hasText) return false;
|
|
1642
|
-
return { to: params.to };
|
|
1643
|
-
}
|
|
1644
|
-
//#endregion
|
|
1645
1585
|
//#region extensions/line/src/signature.ts
|
|
1646
1586
|
function validateLineSignature(body, signature, channelSecret) {
|
|
1647
1587
|
const hash = crypto.createHmac("SHA256", channelSecret).update(body).digest("base64");
|
|
@@ -1651,32 +1591,7 @@ function validateLineSignature(body, signature, channelSecret) {
|
|
|
1651
1591
|
//#region extensions/line/src/webhook-node.ts
|
|
1652
1592
|
const LINE_WEBHOOK_PREAUTH_MAX_BODY_BYTES = 65536;
|
|
1653
1593
|
const LINE_WEBHOOK_PREAUTH_BODY_TIMEOUT_MS = 5e3;
|
|
1654
|
-
async function readLineWebhookRequestBody(req, maxBytes, timeoutMs) {
|
|
1655
|
-
return await readRequestBodyWithLimit(req, {
|
|
1656
|
-
maxBytes,
|
|
1657
|
-
timeoutMs,
|
|
1658
|
-
destroyOnLimit: false
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
/**
|
|
1662
|
-
* Answer a body-limit failure through the connection owner.
|
|
1663
|
-
*
|
|
1664
|
-
* The reader defers destruction for these two codes, so the connection is already fenced
|
|
1665
|
-
* and only the owner can still write: responding directly would race the teardown and LINE
|
|
1666
|
-
* would see a reset instead of the status.
|
|
1667
|
-
*/
|
|
1668
|
-
async function rejectLineWebhookRequest(req, res, error) {
|
|
1669
|
-
if (!isRequestBodyLimitError(error, "PAYLOAD_TOO_LARGE") && !isRequestBodyLimitError(error, "REQUEST_BODY_TIMEOUT")) return false;
|
|
1670
|
-
await sendHttpRequestRejection(req, res, error.statusCode, JSON.stringify({ error: requestBodyErrorToText(error.code) }), "application/json");
|
|
1671
|
-
return true;
|
|
1672
|
-
}
|
|
1673
|
-
function sendLineWebhookJson(res, statusCode, body) {
|
|
1674
|
-
res.statusCode = statusCode;
|
|
1675
|
-
res.setHeader("Content-Type", "application/json");
|
|
1676
|
-
res.end(JSON.stringify(body));
|
|
1677
|
-
}
|
|
1678
1594
|
function createLineNodeWebhookHandler(params) {
|
|
1679
|
-
const readBody = params.readBody ?? readLineWebhookRequestBody;
|
|
1680
1595
|
return async (req, res) => {
|
|
1681
1596
|
const targets = params.getTargets();
|
|
1682
1597
|
if (req.method !== "POST" && targets.length === 0) {
|
|
@@ -1697,7 +1612,7 @@ function createLineNodeWebhookHandler(params) {
|
|
|
1697
1612
|
}
|
|
1698
1613
|
if (req.method !== "POST") {
|
|
1699
1614
|
res.setHeader("Allow", "GET, HEAD, POST");
|
|
1700
|
-
|
|
1615
|
+
sendJsonWithoutCharset(res, 405, { error: "Method Not Allowed" });
|
|
1701
1616
|
return;
|
|
1702
1617
|
}
|
|
1703
1618
|
try {
|
|
@@ -1705,53 +1620,45 @@ function createLineNodeWebhookHandler(params) {
|
|
|
1705
1620
|
const signature = typeof signatureHeader === "string" ? signatureHeader.trim() : Array.isArray(signatureHeader) ? (signatureHeader[0] ?? "").trim() : "";
|
|
1706
1621
|
if (!signature) {
|
|
1707
1622
|
logVerbose("line: webhook missing X-Line-Signature header");
|
|
1708
|
-
|
|
1623
|
+
sendJsonWithoutCharset(res, 400, { error: "Missing X-Line-Signature header" });
|
|
1709
1624
|
return;
|
|
1710
1625
|
}
|
|
1711
|
-
const rawBody = await
|
|
1626
|
+
const rawBody = await readRequestBodyWithLimit(req, {
|
|
1627
|
+
maxBytes: LINE_WEBHOOK_PREAUTH_MAX_BODY_BYTES,
|
|
1628
|
+
timeoutMs: LINE_WEBHOOK_PREAUTH_BODY_TIMEOUT_MS,
|
|
1629
|
+
destroyOnLimit: false
|
|
1630
|
+
});
|
|
1712
1631
|
const match = resolveSingleWebhookTarget(targets, (target) => validateLineSignature(rawBody, signature, target.channelSecret));
|
|
1713
1632
|
if (match.kind === "none") {
|
|
1714
1633
|
logVerbose("line: webhook signature validation failed");
|
|
1715
|
-
|
|
1634
|
+
sendJsonWithoutCharset(res, 401, { error: "Invalid signature" });
|
|
1716
1635
|
return;
|
|
1717
1636
|
}
|
|
1718
1637
|
if (match.kind === "ambiguous") {
|
|
1719
1638
|
logVerbose("line: webhook signature matched multiple accounts");
|
|
1720
|
-
|
|
1639
|
+
sendJsonWithoutCharset(res, 401, { error: "Ambiguous webhook target" });
|
|
1721
1640
|
return;
|
|
1722
1641
|
}
|
|
1723
1642
|
const body = safeParseJson(rawBody);
|
|
1724
1643
|
if (!body) {
|
|
1725
|
-
|
|
1644
|
+
sendJsonWithoutCharset(res, 400, { error: "Invalid webhook payload" });
|
|
1726
1645
|
return;
|
|
1727
1646
|
}
|
|
1728
1647
|
if (body.events && body.events.length > 0) {
|
|
1729
|
-
logVerbose(`line: received ${body.events.length} webhook events`);
|
|
1730
1648
|
if (await match.target.bot.handleWebhook(body) === "durable") res.setHeader("x-openclaw-delivery-accepted", "durable");
|
|
1731
1649
|
}
|
|
1732
|
-
|
|
1650
|
+
sendJsonWithoutCharset(res, 200, { status: "ok" });
|
|
1733
1651
|
} catch (err) {
|
|
1734
|
-
if (
|
|
1652
|
+
if (isRequestBodyLimitError(err, "PAYLOAD_TOO_LARGE") || isRequestBodyLimitError(err, "REQUEST_BODY_TIMEOUT")) {
|
|
1653
|
+
await sendHttpRequestRejection(req, res, err.statusCode, JSON.stringify({ error: requestBodyErrorToText(err.code) }), "application/json");
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1735
1656
|
params.runtime.error?.(danger(`line webhook error: ${formatErrorMessage(err)}`));
|
|
1736
|
-
if (!res.headersSent)
|
|
1657
|
+
if (!res.headersSent) sendJsonWithoutCharset(res, 500, { error: "Internal server error" });
|
|
1737
1658
|
}
|
|
1738
1659
|
};
|
|
1739
1660
|
}
|
|
1740
1661
|
//#endregion
|
|
1741
|
-
//#region extensions/line/src/webhook-utils.ts
|
|
1742
|
-
/** Route the gateway serves when an account configures no `webhookPath`. */
|
|
1743
|
-
const LINE_DEFAULT_WEBHOOK_PATH = "/line/webhook";
|
|
1744
|
-
/** The route this account's monitor serves, which is the one an operator has to register
|
|
1745
|
-
* with LINE. Every surface resolves it here so a warning cannot name a path the gateway
|
|
1746
|
-
* does not answer on. Route registration canonicalizes further, and matches requests the
|
|
1747
|
-
* same way, so a path resolved here always reaches the route the monitor registered. */
|
|
1748
|
-
function resolveLineWebhookPath(webhookPath) {
|
|
1749
|
-
return resolveWebhookPath({
|
|
1750
|
-
webhookPath,
|
|
1751
|
-
defaultPath: LINE_DEFAULT_WEBHOOK_PATH
|
|
1752
|
-
}) ?? LINE_DEFAULT_WEBHOOK_PATH;
|
|
1753
|
-
}
|
|
1754
|
-
//#endregion
|
|
1755
1662
|
//#region extensions/line/src/monitor.ts
|
|
1756
1663
|
const lineWebhookInFlightLimiter = createWebhookInFlightLimiter();
|
|
1757
1664
|
const lineWebhookTargets = /* @__PURE__ */ new Map();
|
|
@@ -1774,14 +1681,12 @@ async function monitorLineProvider(opts) {
|
|
|
1774
1681
|
const replyPipeline = userId ? { typing: {
|
|
1775
1682
|
start: () => showLoadingAnimation(userId, {
|
|
1776
1683
|
cfg: turnConfig,
|
|
1777
|
-
accountId: ctx.accountId
|
|
1778
|
-
loadingSeconds: 20
|
|
1684
|
+
accountId: ctx.accountId
|
|
1779
1685
|
}),
|
|
1780
1686
|
keepaliveIntervalMs: 18e3,
|
|
1781
1687
|
maxDurationMs: 0,
|
|
1782
1688
|
onStartError: () => {}
|
|
1783
1689
|
} } : {};
|
|
1784
|
-
logVerbose(`line: received message from ${ctxPayload.SenderName ?? ctx.userId ?? ctxPayload.From} (${ctxPayload.From})`);
|
|
1785
1690
|
let replyTokenUsed = false;
|
|
1786
1691
|
let turnAdopted = false;
|
|
1787
1692
|
const ingressLifecycle = deliveryControl.turnAdoptionLifecycle;
|
|
@@ -1831,13 +1736,15 @@ async function monitorLineProvider(opts) {
|
|
|
1831
1736
|
...replyOptions ? { replyOptions } : {},
|
|
1832
1737
|
delivery: {
|
|
1833
1738
|
preparePayload: (payload) => prepareLineReplyPayload(payload, ctxPayload.From),
|
|
1834
|
-
durable: (payload, info) =>
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1739
|
+
durable: (payload, info) => {
|
|
1740
|
+
if (info.kind !== "final") return false;
|
|
1741
|
+
if (replyToken && !replyTokenUsed) return false;
|
|
1742
|
+
const lineData = payload.channelData?.line;
|
|
1743
|
+
if (lineData && Object.keys(lineData).length > 0) return false;
|
|
1744
|
+
const reply = resolveSendableOutboundReplyParts(payload);
|
|
1745
|
+
if (reply.hasMedia || !reply.hasText) return false;
|
|
1746
|
+
return { to: ctxPayload.From };
|
|
1747
|
+
},
|
|
1841
1748
|
deliver: async (payload) => {
|
|
1842
1749
|
const deliveryResult = await deliverLineAutoReply({
|
|
1843
1750
|
payload,
|
|
@@ -1872,7 +1779,11 @@ async function monitorLineProvider(opts) {
|
|
|
1872
1779
|
}
|
|
1873
1780
|
}
|
|
1874
1781
|
});
|
|
1875
|
-
const
|
|
1782
|
+
const defaultPath = "/line/webhook";
|
|
1783
|
+
const normalizedPath = resolveWebhookPath({
|
|
1784
|
+
webhookPath,
|
|
1785
|
+
defaultPath
|
|
1786
|
+
}) ?? defaultPath;
|
|
1876
1787
|
const webhookRouteKey = canonicalizeWebhookRouteKey(normalizedPath);
|
|
1877
1788
|
const handleWebhook = createLineNodeWebhookHandler({
|
|
1878
1789
|
getTargets: () => lineWebhookTargets.get(webhookRouteKey) ?? [],
|
|
@@ -1949,4 +1860,4 @@ async function monitorLineProvider(opts) {
|
|
|
1949
1860
|
};
|
|
1950
1861
|
}
|
|
1951
1862
|
//#endregion
|
|
1952
|
-
export { monitorLineProvider
|
|
1863
|
+
export { monitorLineProvider };
|