@openclaw/whatsapp 2026.5.2-beta.2 → 2026.5.3-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/access-control-BQ3tCkH8.js +288 -0
- package/dist/account-config-CNQ33oav.js +47 -0
- package/dist/account-ids-DG18xddX.js +5 -0
- package/dist/accounts-BDqgpFEB.js +116 -0
- package/dist/action-runtime-DTGNgG-i.js +74 -0
- package/dist/action-runtime-api.js +2 -0
- package/dist/action-runtime.runtime.js +2 -0
- package/dist/active-listener-N7GFKsuN.js +11 -0
- package/dist/agent-tools-login-DpRxLNRB.js +89 -0
- package/dist/api.js +148 -0
- package/dist/audio-preflight.runtime-Bcdsl_ri.js +7 -0
- package/dist/auth-presence.js +32 -0
- package/dist/auth-store-BjCb50Ry.js +381 -0
- package/dist/channel-DQ-5Xoj9.js +542 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel-react-action-Df20qAy9.js +42 -0
- package/dist/channel.runtime-DKXRnA8x.js +55 -0
- package/dist/channel.setup-DOHR2BGp.js +20 -0
- package/dist/command-policy-O8sRnqUV.js +8 -0
- package/dist/config-schema-Dmo66Ubb.js +27 -0
- package/dist/connection-controller-BiHAsTM8.js +596 -0
- package/dist/connection-controller-registry-D_iIGz5m.js +22 -0
- package/dist/constants-DLGCIbfl.js +4 -0
- package/dist/constants.js +2 -0
- package/dist/contract-api.js +19 -0
- package/dist/creds-files-_2V8jzQa.js +19 -0
- package/dist/directory-config-DVs4ffXu.js +37 -0
- package/dist/directory-contract-api.js +2 -0
- package/dist/doctor-A9tXm9Om.js +48 -0
- package/dist/doctor-contract-api.js +10 -0
- package/dist/group-session-contract-B8QBn0I2.js +15 -0
- package/dist/identity-QHAlV7Fu.js +75 -0
- package/dist/index.js +18 -0
- package/dist/legacy-session-surface-api.js +8 -0
- package/dist/legacy-state-migrations-api.js +2 -0
- package/dist/light-runtime-api.js +5 -0
- package/dist/login-DymdrKca.js +52 -0
- package/dist/login-qr-DIS0Iv-7.js +378 -0
- package/dist/login-qr-api.js +2 -0
- package/dist/login-qr-runtime.js +16 -0
- package/dist/monitor-C4Fhg_lD.js +3349 -0
- package/dist/normalize-CWYiGkXw.js +2 -0
- package/dist/normalize-target-BPVHNsM5.js +74 -0
- package/dist/outbound-adapter-BssVnZdz.js +29 -0
- package/dist/outbound-base-Bq1UYEK5.js +119 -0
- package/dist/outbound-media-contract-CGss_QHy.js +163 -0
- package/dist/outbound-payload-test-api.js +2 -0
- package/dist/quoted-message-TENQzyxV.js +108 -0
- package/dist/reaction-level-CRVEVAfi.js +16 -0
- package/dist/reply-resolver.runtime-BRCgoO4C.js +2 -0
- package/dist/resolve-outbound-target-CN-Wo6IY.js +39 -0
- package/dist/rolldown-runtime-RkAeH_Qm.js +27 -0
- package/dist/runtime-6fZ67abR.js +8 -0
- package/dist/runtime-api.js +15 -0
- package/dist/runtime-group-policy-Gp1lQ0at.js +11 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/security-contract-DqH8JDX6.js +26 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-CIyLFxdZ.js +234 -0
- package/dist/session-contract-B0efQf9P.js +27 -0
- package/dist/session-errors-CSuKZPub.js +63 -0
- package/dist/session.runtime-C1eSE_KK.js +13 -0
- package/dist/setup-core-DZKvpzbH.js +46 -0
- package/dist/setup-entry.js +23 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/setup-surface-ieFnIW4g.js +344 -0
- package/dist/shared-D_wzSVar.js +307 -0
- package/dist/state-migrations-DnCdvoYD.js +39 -0
- package/dist/targets.js +2 -0
- package/dist/test-api.js +3 -0
- package/dist/text-runtime-C1zNiZeO.js +116 -0
- package/package.json +14 -6
- package/action-runtime-api.ts +0 -1
- package/action-runtime.runtime.ts +0 -1
- package/api.ts +0 -213
- package/auth-presence.ts +0 -80
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -3
- package/config-api.ts +0 -4
- package/constants.ts +0 -1
- package/contract-api.ts +0 -29
- package/directory-contract-api.ts +0 -4
- package/doctor-contract-api.ts +0 -8
- package/index.test.ts +0 -13
- package/index.ts +0 -16
- package/legacy-session-surface-api.ts +0 -6
- package/legacy-state-migrations-api.ts +0 -1
- package/light-runtime-api.ts +0 -12
- package/login-qr-api.ts +0 -1
- package/login-qr-runtime.ts +0 -23
- package/outbound-payload-test-api.ts +0 -1
- package/runtime-api.ts +0 -84
- package/secret-contract-api.ts +0 -4
- package/security-contract-api.ts +0 -4
- package/setup-entry.test.ts +0 -21
- package/setup-entry.ts +0 -21
- package/setup-plugin-api.ts +0 -3
- package/src/account-config.ts +0 -77
- package/src/account-ids.ts +0 -13
- package/src/account-types.ts +0 -5
- package/src/accounts.test.ts +0 -182
- package/src/accounts.ts +0 -176
- package/src/accounts.whatsapp-auth.test.ts +0 -59
- package/src/action-runtime-target-auth.ts +0 -27
- package/src/action-runtime.test.ts +0 -330
- package/src/action-runtime.ts +0 -76
- package/src/active-listener.test.ts +0 -65
- package/src/active-listener.ts +0 -17
- package/src/agent-tools-login.test.ts +0 -81
- package/src/agent-tools-login.ts +0 -113
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -27
- package/src/auth-store.runtime.ts +0 -1
- package/src/auth-store.test.ts +0 -311
- package/src/auth-store.ts +0 -502
- package/src/auto-reply/config.runtime.ts +0 -16
- package/src/auto-reply/constants.ts +0 -1
- package/src/auto-reply/deliver-reply.test.ts +0 -843
- package/src/auto-reply/deliver-reply.ts +0 -279
- package/src/auto-reply/loggers.ts +0 -6
- package/src/auto-reply/mentions.ts +0 -131
- package/src/auto-reply/monitor/ack-reaction.test.ts +0 -170
- package/src/auto-reply/monitor/ack-reaction.ts +0 -99
- package/src/auto-reply/monitor/audio-preflight.runtime.ts +0 -9
- package/src/auto-reply/monitor/broadcast.ts +0 -153
- package/src/auto-reply/monitor/commands.ts +0 -19
- package/src/auto-reply/monitor/echo.ts +0 -64
- package/src/auto-reply/monitor/group-activation.runtime.ts +0 -1
- package/src/auto-reply/monitor/group-activation.test.ts +0 -189
- package/src/auto-reply/monitor/group-activation.ts +0 -73
- package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +0 -103
- package/src/auto-reply/monitor/group-gating.runtime.ts +0 -8
- package/src/auto-reply/monitor/group-gating.ts +0 -217
- package/src/auto-reply/monitor/group-members.test.ts +0 -56
- package/src/auto-reply/monitor/group-members.ts +0 -65
- package/src/auto-reply/monitor/inbound-context.test.ts +0 -97
- package/src/auto-reply/monitor/inbound-context.ts +0 -92
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +0 -21
- package/src/auto-reply/monitor/inbound-dispatch.test.ts +0 -895
- package/src/auto-reply/monitor/inbound-dispatch.ts +0 -422
- package/src/auto-reply/monitor/last-route.test.ts +0 -37
- package/src/auto-reply/monitor/last-route.ts +0 -61
- package/src/auto-reply/monitor/message-line.runtime.ts +0 -38
- package/src/auto-reply/monitor/message-line.ts +0 -54
- package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +0 -354
- package/src/auto-reply/monitor/on-message.ts +0 -291
- package/src/auto-reply/monitor/peer.ts +0 -17
- package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +0 -420
- package/src/auto-reply/monitor/process-message.test.ts +0 -355
- package/src/auto-reply/monitor/process-message.ts +0 -531
- package/src/auto-reply/monitor/runtime-api.ts +0 -30
- package/src/auto-reply/monitor-state.test.ts +0 -64
- package/src/auto-reply/monitor-state.ts +0 -106
- package/src/auto-reply/monitor.ts +0 -600
- package/src/auto-reply/reply-resolver.runtime.ts +0 -1
- package/src/auto-reply/types.ts +0 -48
- package/src/auto-reply/util.ts +0 -63
- package/src/auto-reply/web-auto-reply-monitor.test.ts +0 -687
- package/src/auto-reply/web-auto-reply-utils.test.ts +0 -392
- package/src/auto-reply.broadcast-groups.combined.test.ts +0 -246
- package/src/auto-reply.broadcast-groups.test-harness.ts +0 -47
- package/src/auto-reply.impl.ts +0 -6
- package/src/auto-reply.test-harness.ts +0 -421
- package/src/auto-reply.ts +0 -1
- package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +0 -427
- package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +0 -908
- package/src/auto-reply.web-auto-reply.last-route.test.ts +0 -184
- package/src/channel-actions.runtime.ts +0 -7
- package/src/channel-actions.test.ts +0 -216
- package/src/channel-actions.ts +0 -84
- package/src/channel-outbound.test.ts +0 -131
- package/src/channel-outbound.ts +0 -36
- package/src/channel-react-action.runtime.ts +0 -7
- package/src/channel-react-action.test.ts +0 -294
- package/src/channel-react-action.ts +0 -84
- package/src/channel.runtime.ts +0 -117
- package/src/channel.setup.test.ts +0 -461
- package/src/channel.setup.ts +0 -28
- package/src/channel.ts +0 -334
- package/src/command-policy.ts +0 -7
- package/src/config-accessors.test.ts +0 -34
- package/src/config-accessors.ts +0 -22
- package/src/config-schema.test.ts +0 -121
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -24
- package/src/connection-controller-registry.test.ts +0 -27
- package/src/connection-controller-registry.ts +0 -49
- package/src/connection-controller.test.ts +0 -282
- package/src/connection-controller.ts +0 -679
- package/src/creds-files.ts +0 -19
- package/src/creds-persistence.ts +0 -102
- package/src/directory-config.test.ts +0 -60
- package/src/directory-config.ts +0 -40
- package/src/directory-contract.test.ts +0 -56
- package/src/doctor-contract.ts +0 -11
- package/src/doctor.test.ts +0 -74
- package/src/doctor.ts +0 -56
- package/src/group-intro.ts +0 -15
- package/src/group-policy.test.ts +0 -36
- package/src/group-policy.ts +0 -40
- package/src/group-session-contract.ts +0 -20
- package/src/group-session-key.test.ts +0 -53
- package/src/group-session-key.ts +0 -41
- package/src/heartbeat.ts +0 -34
- package/src/identity.ts +0 -164
- package/src/inbound/access-control.test-harness.ts +0 -37
- package/src/inbound/access-control.test.ts +0 -375
- package/src/inbound/access-control.ts +0 -237
- package/src/inbound/dedupe.ts +0 -132
- package/src/inbound/extract.test.ts +0 -282
- package/src/inbound/extract.ts +0 -488
- package/src/inbound/lifecycle.ts +0 -39
- package/src/inbound/media.node.test.ts +0 -83
- package/src/inbound/media.ts +0 -102
- package/src/inbound/monitor.ts +0 -890
- package/src/inbound/runtime-api.ts +0 -7
- package/src/inbound/save-media.runtime.ts +0 -1
- package/src/inbound/send-api.test.ts +0 -307
- package/src/inbound/send-api.ts +0 -141
- package/src/inbound/send-result.ts +0 -61
- package/src/inbound/types.ts +0 -106
- package/src/inbound-context.contract.test.ts +0 -32
- package/src/inbound-policy.ts +0 -231
- package/src/inbound.media.test.ts +0 -320
- package/src/inbound.test.ts +0 -290
- package/src/inbound.ts +0 -9
- package/src/login-qr.test.ts +0 -483
- package/src/login-qr.ts +0 -542
- package/src/login.coverage.test.ts +0 -133
- package/src/login.test.ts +0 -89
- package/src/login.ts +0 -70
- package/src/logout.test.ts +0 -162
- package/src/media.test.ts +0 -480
- package/src/media.ts +0 -10
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +0 -400
- package/src/monitor-inbox.append-upsert.test-support.ts +0 -133
- package/src/monitor-inbox.behavior.test.ts +0 -5
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +0 -362
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +0 -306
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +0 -729
- package/src/monitor-inbox.test-harness.ts +0 -304
- package/src/normalize-target.ts +0 -112
- package/src/normalize.ts +0 -6
- package/src/outbound-adapter.poll.test.ts +0 -62
- package/src/outbound-adapter.sendpayload.test.ts +0 -195
- package/src/outbound-adapter.ts +0 -36
- package/src/outbound-base.test.ts +0 -560
- package/src/outbound-base.ts +0 -244
- package/src/outbound-media-contract.ts +0 -278
- package/src/outbound-media.runtime.ts +0 -36
- package/src/outbound-payload.contract.test.ts +0 -61
- package/src/outbound-send-deps.ts +0 -1
- package/src/outbound-test-support.ts +0 -16
- package/src/pairing-security.test-harness.ts +0 -59
- package/src/qr-image.ts +0 -1
- package/src/qr-terminal.ts +0 -1
- package/src/quoted-message.test.ts +0 -83
- package/src/quoted-message.ts +0 -184
- package/src/reaction-level.test.ts +0 -94
- package/src/reaction-level.ts +0 -21
- package/src/reconnect.test.ts +0 -51
- package/src/reconnect.ts +0 -55
- package/src/resolve-outbound-target.test.ts +0 -265
- package/src/resolve-outbound-target.ts +0 -54
- package/src/resolve-target.test.ts +0 -97
- package/src/runtime-api.ts +0 -59
- package/src/runtime-group-policy.ts +0 -16
- package/src/runtime.ts +0 -9
- package/src/security-contract.ts +0 -47
- package/src/security-fix.ts +0 -71
- package/src/send.test.ts +0 -515
- package/src/send.ts +0 -287
- package/src/session-contract.test.ts +0 -31
- package/src/session-contract.ts +0 -43
- package/src/session-errors.ts +0 -125
- package/src/session-route.ts +0 -26
- package/src/session.runtime.ts +0 -8
- package/src/session.test.ts +0 -559
- package/src/session.ts +0 -330
- package/src/setup-core.ts +0 -52
- package/src/setup-finalize.ts +0 -446
- package/src/setup-surface.test.ts +0 -367
- package/src/setup-surface.ts +0 -69
- package/src/setup-test-helpers.ts +0 -216
- package/src/shared.ts +0 -291
- package/src/socket-timing.test.ts +0 -49
- package/src/socket-timing.ts +0 -38
- package/src/state-migrations.ts +0 -54
- package/src/status-issues.test.ts +0 -137
- package/src/status-issues.ts +0 -185
- package/src/system-prompt.test.ts +0 -199
- package/src/system-prompt.ts +0 -31
- package/src/targets-runtime.ts +0 -180
- package/src/test-helpers.ts +0 -690
- package/src/text-runtime.test.ts +0 -162
- package/src/text-runtime.ts +0 -11
- package/src/vcard.ts +0 -84
- package/targets.ts +0 -5
- package/test-api.ts +0 -2
- package/tsconfig.json +0 -16
|
@@ -1,422 +0,0 @@
|
|
|
1
|
-
import { hasVisibleInboundReplyDispatch } from "openclaw/plugin-sdk/inbound-reply-dispatch";
|
|
2
|
-
import {
|
|
3
|
-
type DeliverableWhatsAppOutboundPayload,
|
|
4
|
-
normalizeWhatsAppOutboundPayload,
|
|
5
|
-
normalizeWhatsAppPayloadTextPreservingIndentation,
|
|
6
|
-
} from "../../outbound-media-contract.js";
|
|
7
|
-
import type { WhatsAppReplyDeliveryResult } from "../deliver-reply.js";
|
|
8
|
-
import type { WebInboundMsg } from "../types.js";
|
|
9
|
-
import { formatGroupMembers } from "./group-members.js";
|
|
10
|
-
import type { GroupHistoryEntry } from "./inbound-context.js";
|
|
11
|
-
import {
|
|
12
|
-
createChannelReplyPipeline,
|
|
13
|
-
dispatchReplyWithBufferedBlockDispatcher,
|
|
14
|
-
finalizeInboundContext,
|
|
15
|
-
getAgentScopedMediaLocalRoots,
|
|
16
|
-
jidToE164,
|
|
17
|
-
logVerbose,
|
|
18
|
-
resolveChunkMode,
|
|
19
|
-
resolveIdentityNamePrefix,
|
|
20
|
-
resolveInboundLastRouteSessionKey,
|
|
21
|
-
resolveMarkdownTableMode,
|
|
22
|
-
resolveSendableOutboundReplyParts,
|
|
23
|
-
resolveTextChunkLimit,
|
|
24
|
-
shouldLogVerbose,
|
|
25
|
-
toLocationContext,
|
|
26
|
-
type getChildLogger,
|
|
27
|
-
type getReplyFromConfig,
|
|
28
|
-
type LoadConfigFn,
|
|
29
|
-
type ReplyPayload,
|
|
30
|
-
type resolveAgentRoute,
|
|
31
|
-
} from "./inbound-dispatch.runtime.js";
|
|
32
|
-
|
|
33
|
-
type ReplyLifecycleKind = "tool" | "block" | "final";
|
|
34
|
-
type ChannelReplyOnModelSelected = NonNullable<
|
|
35
|
-
ReturnType<typeof createChannelReplyPipeline>["onModelSelected"]
|
|
36
|
-
>;
|
|
37
|
-
|
|
38
|
-
type WhatsAppDispatchPipeline = {
|
|
39
|
-
responsePrefix?: string;
|
|
40
|
-
} & Record<string, unknown>;
|
|
41
|
-
|
|
42
|
-
type VisibleReplyTarget = {
|
|
43
|
-
id?: string;
|
|
44
|
-
body?: string;
|
|
45
|
-
sender?: {
|
|
46
|
-
label?: string | null;
|
|
47
|
-
} | null;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
type ReplyThreadingContext = {
|
|
51
|
-
implicitCurrentMessage?: "default" | "allow" | "deny";
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type SenderContext = {
|
|
55
|
-
id?: string;
|
|
56
|
-
name?: string;
|
|
57
|
-
e164?: string;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
function logWhatsAppReplyDeliveryError(params: {
|
|
61
|
-
err: unknown;
|
|
62
|
-
info: { kind: ReplyLifecycleKind };
|
|
63
|
-
connectionId: string;
|
|
64
|
-
conversationId: string;
|
|
65
|
-
msg: WebInboundMsg;
|
|
66
|
-
replyLogger: ReturnType<typeof getChildLogger>;
|
|
67
|
-
}) {
|
|
68
|
-
params.replyLogger.error(
|
|
69
|
-
{
|
|
70
|
-
err: params.err,
|
|
71
|
-
replyKind: params.info.kind,
|
|
72
|
-
correlationId: params.msg.id ?? null,
|
|
73
|
-
connectionId: params.connectionId,
|
|
74
|
-
conversationId: params.conversationId,
|
|
75
|
-
chatId: params.msg.chatId ?? null,
|
|
76
|
-
to: params.msg.from ?? null,
|
|
77
|
-
from: params.msg.to ?? null,
|
|
78
|
-
},
|
|
79
|
-
"auto-reply delivery failed",
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function resolveWhatsAppDisableBlockStreaming(cfg: ReturnType<LoadConfigFn>): boolean | undefined {
|
|
84
|
-
if (typeof cfg.channels?.whatsapp?.blockStreaming !== "boolean") {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
return !cfg.channels.whatsapp.blockStreaming;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function resolveWhatsAppDeliverablePayload(
|
|
91
|
-
payload: ReplyPayload,
|
|
92
|
-
info: { kind: ReplyLifecycleKind },
|
|
93
|
-
): ReplyPayload | null {
|
|
94
|
-
if (payload.isReasoning === true || payload.isCompactionNotice === true) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
if (payload.isError === true) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
if (info.kind === "tool") {
|
|
101
|
-
if (!resolveSendableOutboundReplyParts(payload).hasMedia) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
return { ...payload, text: undefined };
|
|
105
|
-
}
|
|
106
|
-
return payload;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function resolveWhatsAppResponsePrefix(params: {
|
|
110
|
-
cfg: ReturnType<LoadConfigFn>;
|
|
111
|
-
agentId: string;
|
|
112
|
-
isSelfChat: boolean;
|
|
113
|
-
pipelineResponsePrefix?: string;
|
|
114
|
-
}): string | undefined {
|
|
115
|
-
const configuredResponsePrefix = params.cfg.messages?.responsePrefix;
|
|
116
|
-
return (
|
|
117
|
-
params.pipelineResponsePrefix ??
|
|
118
|
-
(configuredResponsePrefix === undefined && params.isSelfChat
|
|
119
|
-
? resolveIdentityNamePrefix(params.cfg, params.agentId)
|
|
120
|
-
: undefined)
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function buildWhatsAppInboundContext(params: {
|
|
125
|
-
bodyForAgent?: string;
|
|
126
|
-
combinedBody: string;
|
|
127
|
-
commandBody?: string;
|
|
128
|
-
commandAuthorized?: boolean;
|
|
129
|
-
conversationId: string;
|
|
130
|
-
groupHistory?: GroupHistoryEntry[];
|
|
131
|
-
groupMemberRoster?: Map<string, string>;
|
|
132
|
-
groupSystemPrompt?: string;
|
|
133
|
-
msg: WebInboundMsg;
|
|
134
|
-
rawBody?: string;
|
|
135
|
-
route: ReturnType<typeof resolveAgentRoute>;
|
|
136
|
-
sender: SenderContext;
|
|
137
|
-
transcript?: string;
|
|
138
|
-
mediaTranscribedIndexes?: number[];
|
|
139
|
-
replyThreading?: ReplyThreadingContext;
|
|
140
|
-
visibleReplyTo?: VisibleReplyTarget;
|
|
141
|
-
}) {
|
|
142
|
-
const inboundHistory =
|
|
143
|
-
params.msg.chatType === "group"
|
|
144
|
-
? (params.groupHistory ?? []).map((entry) => ({
|
|
145
|
-
sender: entry.sender,
|
|
146
|
-
body: entry.body,
|
|
147
|
-
timestamp: entry.timestamp,
|
|
148
|
-
}))
|
|
149
|
-
: undefined;
|
|
150
|
-
|
|
151
|
-
const result = finalizeInboundContext({
|
|
152
|
-
Body: params.combinedBody,
|
|
153
|
-
BodyForAgent: params.bodyForAgent ?? params.msg.body,
|
|
154
|
-
InboundHistory: inboundHistory,
|
|
155
|
-
RawBody: params.rawBody ?? params.msg.body,
|
|
156
|
-
CommandBody: params.commandBody ?? params.msg.body,
|
|
157
|
-
Transcript: params.transcript,
|
|
158
|
-
From: params.msg.from,
|
|
159
|
-
To: params.msg.to,
|
|
160
|
-
SessionKey: params.route.sessionKey,
|
|
161
|
-
AccountId: params.route.accountId,
|
|
162
|
-
MessageSid: params.msg.id,
|
|
163
|
-
ReplyToId: params.visibleReplyTo?.id,
|
|
164
|
-
ReplyToBody: params.visibleReplyTo?.body,
|
|
165
|
-
ReplyToSender: params.visibleReplyTo?.sender?.label,
|
|
166
|
-
MediaPath: params.msg.mediaPath,
|
|
167
|
-
MediaUrl: params.msg.mediaUrl,
|
|
168
|
-
MediaType: params.msg.mediaType,
|
|
169
|
-
MediaTranscribedIndexes: params.mediaTranscribedIndexes,
|
|
170
|
-
ChatType: params.msg.chatType,
|
|
171
|
-
Timestamp: params.msg.timestamp,
|
|
172
|
-
ConversationLabel: params.msg.chatType === "group" ? params.conversationId : params.msg.from,
|
|
173
|
-
GroupSubject: params.msg.groupSubject,
|
|
174
|
-
GroupMembers: formatGroupMembers({
|
|
175
|
-
participants: params.msg.groupParticipants,
|
|
176
|
-
roster: params.groupMemberRoster,
|
|
177
|
-
fallbackE164: params.sender.e164,
|
|
178
|
-
}),
|
|
179
|
-
SenderName: params.sender.name,
|
|
180
|
-
SenderId: params.sender.id ?? params.sender.e164,
|
|
181
|
-
SenderE164: params.sender.e164,
|
|
182
|
-
CommandAuthorized: params.commandAuthorized,
|
|
183
|
-
ReplyThreading: params.replyThreading,
|
|
184
|
-
WasMentioned: params.msg.wasMentioned,
|
|
185
|
-
GroupSystemPrompt: params.groupSystemPrompt,
|
|
186
|
-
UntrustedStructuredContext: params.msg.untrustedStructuredContext,
|
|
187
|
-
...(params.msg.location ? toLocationContext(params.msg.location) : {}),
|
|
188
|
-
Provider: "whatsapp",
|
|
189
|
-
Surface: "whatsapp",
|
|
190
|
-
OriginatingChannel: "whatsapp",
|
|
191
|
-
OriginatingTo: params.msg.from,
|
|
192
|
-
});
|
|
193
|
-
return result;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function resolveWhatsAppDmRouteTarget(params: {
|
|
197
|
-
msg: WebInboundMsg;
|
|
198
|
-
senderE164?: string;
|
|
199
|
-
normalizeE164: (value: string) => string | null;
|
|
200
|
-
}): string | undefined {
|
|
201
|
-
if (params.msg.chatType === "group") {
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
if (params.senderE164) {
|
|
205
|
-
return params.normalizeE164(params.senderE164) ?? undefined;
|
|
206
|
-
}
|
|
207
|
-
if (params.msg.from.includes("@")) {
|
|
208
|
-
return jidToE164(params.msg.from) ?? undefined;
|
|
209
|
-
}
|
|
210
|
-
return params.normalizeE164(params.msg.from) ?? undefined;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export function updateWhatsAppMainLastRoute(params: {
|
|
214
|
-
backgroundTasks: Set<Promise<unknown>>;
|
|
215
|
-
cfg: ReturnType<LoadConfigFn>;
|
|
216
|
-
ctx: Record<string, unknown>;
|
|
217
|
-
dmRouteTarget?: string;
|
|
218
|
-
pinnedMainDmRecipient: string | null;
|
|
219
|
-
route: ReturnType<typeof resolveAgentRoute>;
|
|
220
|
-
updateLastRoute: (params: {
|
|
221
|
-
cfg: ReturnType<LoadConfigFn>;
|
|
222
|
-
backgroundTasks: Set<Promise<unknown>>;
|
|
223
|
-
storeAgentId: string;
|
|
224
|
-
sessionKey: string;
|
|
225
|
-
channel: "whatsapp";
|
|
226
|
-
to: string;
|
|
227
|
-
accountId?: string;
|
|
228
|
-
ctx: Record<string, unknown>;
|
|
229
|
-
warn: ReturnType<typeof getChildLogger>["warn"];
|
|
230
|
-
}) => void;
|
|
231
|
-
warn: ReturnType<typeof getChildLogger>["warn"];
|
|
232
|
-
}) {
|
|
233
|
-
const shouldUpdateMainLastRoute =
|
|
234
|
-
!params.pinnedMainDmRecipient || params.pinnedMainDmRecipient === params.dmRouteTarget;
|
|
235
|
-
const inboundLastRouteSessionKey = resolveInboundLastRouteSessionKey({
|
|
236
|
-
route: params.route,
|
|
237
|
-
sessionKey: params.route.sessionKey,
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
if (
|
|
241
|
-
params.dmRouteTarget &&
|
|
242
|
-
inboundLastRouteSessionKey === params.route.mainSessionKey &&
|
|
243
|
-
shouldUpdateMainLastRoute
|
|
244
|
-
) {
|
|
245
|
-
params.updateLastRoute({
|
|
246
|
-
cfg: params.cfg,
|
|
247
|
-
backgroundTasks: params.backgroundTasks,
|
|
248
|
-
storeAgentId: params.route.agentId,
|
|
249
|
-
sessionKey: params.route.mainSessionKey,
|
|
250
|
-
channel: "whatsapp",
|
|
251
|
-
to: params.dmRouteTarget,
|
|
252
|
-
accountId: params.route.accountId,
|
|
253
|
-
ctx: params.ctx,
|
|
254
|
-
warn: params.warn,
|
|
255
|
-
});
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
params.dmRouteTarget &&
|
|
261
|
-
inboundLastRouteSessionKey === params.route.mainSessionKey &&
|
|
262
|
-
params.pinnedMainDmRecipient
|
|
263
|
-
) {
|
|
264
|
-
logVerbose(
|
|
265
|
-
`Skipping main-session last route update for ${params.dmRouteTarget} (pinned owner ${params.pinnedMainDmRecipient})`,
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export async function dispatchWhatsAppBufferedReply(params: {
|
|
271
|
-
cfg: ReturnType<LoadConfigFn>;
|
|
272
|
-
connectionId: string;
|
|
273
|
-
context: Record<string, unknown>;
|
|
274
|
-
conversationId: string;
|
|
275
|
-
deliverReply: (params: {
|
|
276
|
-
replyResult: ReplyPayload;
|
|
277
|
-
normalizedReplyResult?: DeliverableWhatsAppOutboundPayload<ReplyPayload>;
|
|
278
|
-
msg: WebInboundMsg;
|
|
279
|
-
mediaLocalRoots: readonly string[];
|
|
280
|
-
maxMediaBytes: number;
|
|
281
|
-
textLimit: number;
|
|
282
|
-
chunkMode?: ReturnType<typeof resolveChunkMode>;
|
|
283
|
-
replyLogger: ReturnType<typeof getChildLogger>;
|
|
284
|
-
connectionId?: string;
|
|
285
|
-
skipLog?: boolean;
|
|
286
|
-
tableMode?: ReturnType<typeof resolveMarkdownTableMode>;
|
|
287
|
-
}) => Promise<WhatsAppReplyDeliveryResult>;
|
|
288
|
-
groupHistories: Map<string, GroupHistoryEntry[]>;
|
|
289
|
-
groupHistoryKey: string;
|
|
290
|
-
maxMediaBytes: number;
|
|
291
|
-
maxMediaTextChunkLimit?: number;
|
|
292
|
-
msg: WebInboundMsg;
|
|
293
|
-
onModelSelected?: ChannelReplyOnModelSelected;
|
|
294
|
-
rememberSentText: (
|
|
295
|
-
text: string | undefined,
|
|
296
|
-
opts: {
|
|
297
|
-
combinedBody?: string;
|
|
298
|
-
combinedBodySessionKey?: string;
|
|
299
|
-
logVerboseMessage?: boolean;
|
|
300
|
-
},
|
|
301
|
-
) => void;
|
|
302
|
-
replyLogger: ReturnType<typeof getChildLogger>;
|
|
303
|
-
replyPipeline: WhatsAppDispatchPipeline;
|
|
304
|
-
replyResolver: typeof getReplyFromConfig;
|
|
305
|
-
route: ReturnType<typeof resolveAgentRoute>;
|
|
306
|
-
shouldClearGroupHistory: boolean;
|
|
307
|
-
}) {
|
|
308
|
-
const textLimit = params.maxMediaTextChunkLimit ?? resolveTextChunkLimit(params.cfg, "whatsapp");
|
|
309
|
-
const chunkMode = resolveChunkMode(params.cfg, "whatsapp", params.route.accountId);
|
|
310
|
-
const tableMode = resolveMarkdownTableMode({
|
|
311
|
-
cfg: params.cfg,
|
|
312
|
-
channel: "whatsapp",
|
|
313
|
-
accountId: params.route.accountId,
|
|
314
|
-
});
|
|
315
|
-
const mediaLocalRoots = getAgentScopedMediaLocalRoots(params.cfg, params.route.agentId);
|
|
316
|
-
const disableBlockStreaming = resolveWhatsAppDisableBlockStreaming(params.cfg);
|
|
317
|
-
let didSendReply = false;
|
|
318
|
-
let didLogHeartbeatStrip = false;
|
|
319
|
-
|
|
320
|
-
const { queuedFinal, counts } = await dispatchReplyWithBufferedBlockDispatcher({
|
|
321
|
-
ctx: params.context,
|
|
322
|
-
cfg: params.cfg,
|
|
323
|
-
replyResolver: params.replyResolver,
|
|
324
|
-
dispatcherOptions: {
|
|
325
|
-
...params.replyPipeline,
|
|
326
|
-
onHeartbeatStrip: () => {
|
|
327
|
-
if (!didLogHeartbeatStrip) {
|
|
328
|
-
didLogHeartbeatStrip = true;
|
|
329
|
-
logVerbose("Stripped stray HEARTBEAT_OK token from web reply");
|
|
330
|
-
}
|
|
331
|
-
},
|
|
332
|
-
deliver: async (payload: ReplyPayload, info: { kind: ReplyLifecycleKind }) => {
|
|
333
|
-
const deliveryPayload = resolveWhatsAppDeliverablePayload(payload, info);
|
|
334
|
-
if (!deliveryPayload) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
const normalizedOutboundPayload = normalizeWhatsAppOutboundPayload(deliveryPayload, {
|
|
338
|
-
normalizeText: normalizeWhatsAppPayloadTextPreservingIndentation,
|
|
339
|
-
});
|
|
340
|
-
const normalizedDeliveryPayload =
|
|
341
|
-
deliveryPayload.text === undefined
|
|
342
|
-
? { ...normalizedOutboundPayload, text: undefined }
|
|
343
|
-
: normalizedOutboundPayload;
|
|
344
|
-
const reply = resolveSendableOutboundReplyParts(normalizedDeliveryPayload);
|
|
345
|
-
if (!reply.hasMedia && !reply.text.trim()) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const delivery = await params.deliverReply({
|
|
349
|
-
replyResult: normalizedDeliveryPayload,
|
|
350
|
-
normalizedReplyResult: normalizedDeliveryPayload,
|
|
351
|
-
msg: params.msg,
|
|
352
|
-
mediaLocalRoots,
|
|
353
|
-
maxMediaBytes: params.maxMediaBytes,
|
|
354
|
-
textLimit,
|
|
355
|
-
chunkMode,
|
|
356
|
-
replyLogger: params.replyLogger,
|
|
357
|
-
connectionId: params.connectionId,
|
|
358
|
-
skipLog: false,
|
|
359
|
-
tableMode,
|
|
360
|
-
});
|
|
361
|
-
if (!delivery.providerAccepted) {
|
|
362
|
-
params.replyLogger.warn(
|
|
363
|
-
{
|
|
364
|
-
correlationId: params.msg.id ?? null,
|
|
365
|
-
connectionId: params.connectionId,
|
|
366
|
-
conversationId: params.conversationId,
|
|
367
|
-
chatId: params.msg.chatId,
|
|
368
|
-
to: params.msg.from,
|
|
369
|
-
from: params.msg.to,
|
|
370
|
-
replyKind: info.kind,
|
|
371
|
-
},
|
|
372
|
-
"auto-reply was not accepted by WhatsApp provider",
|
|
373
|
-
);
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
didSendReply = true;
|
|
377
|
-
const shouldLog = normalizedDeliveryPayload.text ? true : undefined;
|
|
378
|
-
params.rememberSentText(normalizedDeliveryPayload.text, {
|
|
379
|
-
combinedBody: params.context.Body as string | undefined,
|
|
380
|
-
combinedBodySessionKey: params.route.sessionKey,
|
|
381
|
-
logVerboseMessage: shouldLog,
|
|
382
|
-
});
|
|
383
|
-
const fromDisplay =
|
|
384
|
-
params.msg.chatType === "group" ? params.conversationId : (params.msg.from ?? "unknown");
|
|
385
|
-
if (shouldLogVerbose()) {
|
|
386
|
-
const preview = normalizedDeliveryPayload.text != null ? reply.text : "<media>";
|
|
387
|
-
logVerbose(`Reply body: ${preview}${reply.hasMedia ? " (media)" : ""} -> ${fromDisplay}`);
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
|
-
onReplyStart: params.msg.sendComposing,
|
|
391
|
-
onError: (err, info) => {
|
|
392
|
-
logWhatsAppReplyDeliveryError({
|
|
393
|
-
err,
|
|
394
|
-
info,
|
|
395
|
-
connectionId: params.connectionId,
|
|
396
|
-
conversationId: params.conversationId,
|
|
397
|
-
msg: params.msg,
|
|
398
|
-
replyLogger: params.replyLogger,
|
|
399
|
-
});
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
replyOptions: {
|
|
403
|
-
disableBlockStreaming,
|
|
404
|
-
onModelSelected: params.onModelSelected,
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
const didQueueVisibleReply = hasVisibleInboundReplyDispatch({ queuedFinal, counts });
|
|
409
|
-
if (!didQueueVisibleReply) {
|
|
410
|
-
if (params.shouldClearGroupHistory) {
|
|
411
|
-
params.groupHistories.set(params.groupHistoryKey, []);
|
|
412
|
-
}
|
|
413
|
-
logVerbose("Skipping auto-reply: silent token or no text/media returned from resolver");
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (params.shouldClearGroupHistory) {
|
|
418
|
-
params.groupHistories.set(params.groupHistoryKey, []);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
return didSendReply;
|
|
422
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
-
import { trackBackgroundTask } from "./last-route.js";
|
|
3
|
-
|
|
4
|
-
const waitForAsyncCallbacks = async () => {
|
|
5
|
-
await Promise.resolve();
|
|
6
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
describe("trackBackgroundTask", () => {
|
|
10
|
-
const unhandledRejections: unknown[] = [];
|
|
11
|
-
const onUnhandledRejection = (reason: unknown) => {
|
|
12
|
-
unhandledRejections.push(reason);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
process.off("unhandledRejection", onUnhandledRejection);
|
|
17
|
-
unhandledRejections.length = 0;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("does not leak unhandled rejections when a tracked task fails", async () => {
|
|
21
|
-
process.on("unhandledRejection", onUnhandledRejection);
|
|
22
|
-
const backgroundTasks = new Set<Promise<unknown>>();
|
|
23
|
-
let rejectTask!: (reason?: unknown) => void;
|
|
24
|
-
const task = new Promise<void>((_resolve, reject) => {
|
|
25
|
-
rejectTask = reject;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
trackBackgroundTask(backgroundTasks, task);
|
|
29
|
-
expect(backgroundTasks.size).toBe(1);
|
|
30
|
-
|
|
31
|
-
rejectTask(new Error("boom"));
|
|
32
|
-
await waitForAsyncCallbacks();
|
|
33
|
-
|
|
34
|
-
expect(backgroundTasks.size).toBe(0);
|
|
35
|
-
expect(unhandledRejections).toEqual([]);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
2
|
-
import type { MsgContext } from "openclaw/plugin-sdk/reply-runtime";
|
|
3
|
-
import { formatError } from "../../session.js";
|
|
4
|
-
import { resolveStorePath, updateLastRoute } from "../config.runtime.js";
|
|
5
|
-
|
|
6
|
-
export function trackBackgroundTask(
|
|
7
|
-
backgroundTasks: Set<Promise<unknown>>,
|
|
8
|
-
task: Promise<unknown>,
|
|
9
|
-
) {
|
|
10
|
-
backgroundTasks.add(task);
|
|
11
|
-
const cleanup = () => {
|
|
12
|
-
backgroundTasks.delete(task);
|
|
13
|
-
};
|
|
14
|
-
task.then(cleanup, cleanup);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function updateLastRouteInBackground(params: {
|
|
18
|
-
cfg: OpenClawConfig;
|
|
19
|
-
backgroundTasks: Set<Promise<unknown>>;
|
|
20
|
-
storeAgentId: string;
|
|
21
|
-
sessionKey: string;
|
|
22
|
-
channel: "whatsapp";
|
|
23
|
-
to: string;
|
|
24
|
-
accountId?: string;
|
|
25
|
-
ctx?: MsgContext;
|
|
26
|
-
warn: (obj: unknown, msg: string) => void;
|
|
27
|
-
}) {
|
|
28
|
-
const storePath = resolveStorePath(params.cfg.session?.store, {
|
|
29
|
-
agentId: params.storeAgentId,
|
|
30
|
-
});
|
|
31
|
-
const task = updateLastRoute({
|
|
32
|
-
storePath,
|
|
33
|
-
sessionKey: params.sessionKey,
|
|
34
|
-
deliveryContext: {
|
|
35
|
-
channel: params.channel,
|
|
36
|
-
to: params.to,
|
|
37
|
-
accountId: params.accountId,
|
|
38
|
-
},
|
|
39
|
-
ctx: params.ctx,
|
|
40
|
-
}).catch((err) => {
|
|
41
|
-
params.warn(
|
|
42
|
-
{
|
|
43
|
-
error: formatError(err),
|
|
44
|
-
storePath,
|
|
45
|
-
sessionKey: params.sessionKey,
|
|
46
|
-
to: params.to,
|
|
47
|
-
},
|
|
48
|
-
"failed updating last route",
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
trackBackgroundTask(params.backgroundTasks, task);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function awaitBackgroundTasks(backgroundTasks: Set<Promise<unknown>>) {
|
|
55
|
-
if (backgroundTasks.size === 0) {
|
|
56
|
-
return Promise.resolve();
|
|
57
|
-
}
|
|
58
|
-
return Promise.allSettled(backgroundTasks).then(() => {
|
|
59
|
-
backgroundTasks.clear();
|
|
60
|
-
});
|
|
61
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
formatInboundEnvelope,
|
|
5
|
-
type EnvelopeFormatOptions,
|
|
6
|
-
} from "openclaw/plugin-sdk/channel-envelope";
|
|
7
|
-
|
|
8
|
-
type WhatsAppMessagePrefixConfig = OpenClawConfig;
|
|
9
|
-
|
|
10
|
-
function normalizeAgentId(agentId: string): string {
|
|
11
|
-
return agentId.trim().toLowerCase() || "main";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function resolveIdentityNamePrefix(
|
|
15
|
-
cfg: WhatsAppMessagePrefixConfig,
|
|
16
|
-
agentId: string,
|
|
17
|
-
): string | undefined {
|
|
18
|
-
const normalizedAgentId = normalizeAgentId(agentId);
|
|
19
|
-
const identityName = cfg.agents?.list
|
|
20
|
-
?.find((agent) => normalizeAgentId(agent.id ?? "") === normalizedAgentId)
|
|
21
|
-
?.identity?.name?.trim();
|
|
22
|
-
return identityName ? `[${identityName}]` : undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function resolveMessagePrefix(
|
|
26
|
-
cfg: WhatsAppMessagePrefixConfig,
|
|
27
|
-
agentId: string,
|
|
28
|
-
opts?: { configured?: string; hasAllowFrom?: boolean; fallback?: string },
|
|
29
|
-
): string {
|
|
30
|
-
const configured = opts?.configured ?? cfg.messages?.messagePrefix;
|
|
31
|
-
if (configured !== undefined) {
|
|
32
|
-
return configured;
|
|
33
|
-
}
|
|
34
|
-
if (opts?.hasAllowFrom === true) {
|
|
35
|
-
return "";
|
|
36
|
-
}
|
|
37
|
-
return resolveIdentityNamePrefix(cfg, agentId) ?? opts?.fallback ?? "[openclaw]";
|
|
38
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
2
|
-
import { getPrimaryIdentityId, getReplyContext, getSenderIdentity } from "../../identity.js";
|
|
3
|
-
import type { WebInboundMsg } from "../types.js";
|
|
4
|
-
import {
|
|
5
|
-
formatInboundEnvelope,
|
|
6
|
-
resolveMessagePrefix,
|
|
7
|
-
type EnvelopeFormatOptions,
|
|
8
|
-
} from "./message-line.runtime.js";
|
|
9
|
-
|
|
10
|
-
export function formatReplyContext(msg: WebInboundMsg) {
|
|
11
|
-
const replyTo = getReplyContext(msg);
|
|
12
|
-
if (!replyTo?.body) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
const sender = replyTo.sender?.label ?? replyTo.sender?.e164 ?? "unknown sender";
|
|
16
|
-
const idPart = replyTo.id ? ` id:${replyTo.id}` : "";
|
|
17
|
-
return `[Replying to ${sender}${idPart}]\n${replyTo.body}\n[/Replying]`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function buildInboundLine(params: {
|
|
21
|
-
cfg: OpenClawConfig;
|
|
22
|
-
msg: WebInboundMsg;
|
|
23
|
-
agentId: string;
|
|
24
|
-
previousTimestamp?: number;
|
|
25
|
-
envelope?: EnvelopeFormatOptions;
|
|
26
|
-
}) {
|
|
27
|
-
const { cfg, msg, agentId, previousTimestamp, envelope } = params;
|
|
28
|
-
// WhatsApp inbound prefix: channels.whatsapp.messagePrefix > legacy messages.messagePrefix > identity/defaults
|
|
29
|
-
const messagePrefix = resolveMessagePrefix(cfg, agentId, {
|
|
30
|
-
configured: cfg.channels?.whatsapp?.messagePrefix,
|
|
31
|
-
hasAllowFrom: (cfg.channels?.whatsapp?.allowFrom?.length ?? 0) > 0,
|
|
32
|
-
});
|
|
33
|
-
const prefixStr = messagePrefix ? `${messagePrefix} ` : "";
|
|
34
|
-
const replyContext = formatReplyContext(msg);
|
|
35
|
-
const baseLine = `${prefixStr}${msg.body}${replyContext ? `\n\n${replyContext}` : ""}`;
|
|
36
|
-
const sender = getSenderIdentity(msg);
|
|
37
|
-
|
|
38
|
-
// Wrap with standardized envelope for the agent.
|
|
39
|
-
return formatInboundEnvelope({
|
|
40
|
-
channel: "WhatsApp",
|
|
41
|
-
from: msg.chatType === "group" ? msg.from : msg.from?.replace(/^whatsapp:/, ""),
|
|
42
|
-
timestamp: msg.timestamp,
|
|
43
|
-
body: baseLine,
|
|
44
|
-
chatType: msg.chatType,
|
|
45
|
-
sender: {
|
|
46
|
-
name: sender.name ?? undefined,
|
|
47
|
-
e164: sender.e164 ?? undefined,
|
|
48
|
-
id: getPrimaryIdentityId(sender) ?? undefined,
|
|
49
|
-
},
|
|
50
|
-
previousTimestamp,
|
|
51
|
-
envelope,
|
|
52
|
-
fromMe: msg.fromMe,
|
|
53
|
-
});
|
|
54
|
-
}
|