@openclaw/whatsapp 2026.8.1-beta.2 → 2026.8.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/{accounts-BX2fZUyR.js → accounts-CeKQbu_s.js} +9 -26
- package/dist/{action-runtime-B4e3XFOY.js → action-runtime-YA_Yvunu.js} +2 -2
- package/dist/action-runtime-api.js +1 -1
- package/dist/action-runtime.runtime.js +1 -1
- package/dist/{call-tool-api.js → agent-tools-api.js} +11 -4
- package/dist/{agent-tools-login-BjRpD-JQ.js → agent-tools-login-B-2qZPzc.js} +12 -3
- package/dist/api.js +7 -7
- package/dist/{approval-handler.runtime-fgGZhALv.js → approval-handler.runtime-C7jZ8rsD.js} +3 -3
- package/dist/{approval-reactions-CmtJCxe_.js → approval-reactions-rpaNVHzZ.js} +11 -15
- package/dist/{auth-store-B_DQIdzp.js → auth-store-CtpBqH5S.js} +3 -6
- package/dist/{channel-DJVQHz_V.js → channel-Dx09AAmX.js} +11 -13
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel-react-action-d6OacTNj.js → channel-react-action-n9a8Hk5i.js} +14 -12
- package/dist/{channel.runtime-RxuNGZ7w.js → channel.runtime-D_PjmeMT.js} +4 -4
- package/dist/{channel.setup-Cmvd967u.js → channel.setup-CRJQiWbh.js} +1 -1
- package/dist/{connection-controller-CUyZgGpf.js → connection-controller-CIYuBJrs.js} +2 -2
- package/dist/{directory-config-Pc4f07wB.js → directory-config-Ci8Jjsw4.js} +3 -3
- package/dist/directory-contract-api.js +1 -1
- package/dist/{group-session-key-DmFc_Cqi.js → group-session-key-CH9jJIVQ.js} +1 -1
- package/dist/index.js +4 -4
- package/dist/light-runtime-api.js +2 -2
- package/dist/{login-D6_rfxTZ.js → login-1u5WcfTn.js} +4 -4
- package/dist/{login-qr-B0VyVSqQ.js → login-qr-B_1sr0hk.js} +38 -17
- package/dist/login-qr-runtime.js +1 -1
- package/dist/{monitor-BCe5Mm-1.js → monitor-CySzv38g.js} +156 -564
- package/dist/{question-reactions-D3eAeB0i.js → question-reactions-B9D6MHXZ.js} +1 -1
- package/dist/runtime-api.js +8 -8
- package/dist/{send-prK8F7Vj.js → send-C3S-NqyO.js} +24 -10
- package/dist/{send-api-DimZST3E.js → send-api-C-FFC1p_.js} +46 -36
- package/dist/{setup-finalize-D3n71Uyx.js → setup-finalize-CRzMpx84.js} +4 -4
- package/dist/setup-plugin-api.js +1 -1
- package/dist/{setup-surface-BCZszf3l.js → setup-surface-ym4doiv3.js} +3 -3
- package/dist/{shared-Dp9M3ZPX.js → shared-D3B14d45.js} +12 -6
- package/dist/{socket-close-09FojDO2.js → socket-close-2T0_jZTN.js} +1 -1
- package/node_modules/baileys/lib/Defaults/index.js +1 -1
- package/node_modules/baileys/lib/Socket/business.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/chats.d.ts +1 -0
- package/node_modules/baileys/lib/Socket/chats.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/chats.js +10 -5
- package/node_modules/baileys/lib/Socket/chats.js.map +1 -1
- package/node_modules/baileys/lib/Socket/communities.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/groups.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/index.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/messages-recv.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/messages-send.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/newsletter.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/socket.d.ts.map +1 -1
- package/node_modules/baileys/lib/Socket/socket.js +3 -0
- package/node_modules/baileys/lib/Socket/socket.js.map +1 -1
- package/node_modules/baileys/lib/Types/index.d.ts +1 -0
- package/node_modules/baileys/lib/Types/index.d.ts.map +1 -1
- package/node_modules/baileys/lib/Types/index.js.map +1 -1
- package/node_modules/baileys/lib/Utils/browser-utils.d.ts.map +1 -1
- package/node_modules/baileys/lib/Utils/browser-utils.js +1 -0
- package/node_modules/baileys/lib/Utils/browser-utils.js.map +1 -1
- package/node_modules/baileys/lib/Utils/generics.d.ts +1 -0
- package/node_modules/baileys/lib/Utils/generics.d.ts.map +1 -1
- package/node_modules/baileys/lib/Utils/generics.js +1 -1
- package/node_modules/baileys/lib/Utils/generics.js.map +1 -1
- package/node_modules/baileys/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/node_modules/baileys/lib/Utils/tc-token-utils.js +3 -2
- package/node_modules/baileys/lib/Utils/tc-token-utils.js.map +1 -1
- package/node_modules/baileys/lib/Utils/validate-connection.d.ts.map +1 -1
- package/node_modules/baileys/lib/Utils/validate-connection.js +9 -2
- package/node_modules/baileys/lib/Utils/validate-connection.js.map +1 -1
- package/node_modules/baileys/node_modules/content-type/README.md +2 -0
- package/node_modules/baileys/node_modules/content-type/dist/index.d.ts +20 -0
- package/node_modules/baileys/node_modules/content-type/dist/index.js +20 -14
- package/node_modules/baileys/node_modules/content-type/dist/index.js.map +1 -1
- package/node_modules/baileys/node_modules/content-type/package.json +1 -1
- package/node_modules/baileys/node_modules/file-type/package.json +1 -1
- package/node_modules/baileys/node_modules/file-type/readme.md +3 -0
- package/node_modules/baileys/node_modules/file-type/source/detectors/zip.js +6 -1
- package/node_modules/baileys/node_modules/file-type/source/index.d.ts +3 -0
- package/node_modules/baileys/node_modules/file-type/source/index.js +25 -13
- package/node_modules/baileys/node_modules/music-metadata/LICENSE.txt +9 -9
- package/node_modules/baileys/node_modules/music-metadata/README.md +878 -878
- package/node_modules/baileys/node_modules/music-metadata/lib/ParseError.d.ts +1 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/ParseError.js +1 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfObject.d.ts +1 -4
- package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfObject.js +66 -30
- package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfParser.d.ts +5 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/asf/AsfParser.js +94 -25
- package/node_modules/baileys/node_modules/music-metadata/lib/dsf/DsfChunk.js +2 -2
- package/node_modules/baileys/node_modules/music-metadata/lib/dsf/DsfParser.js +38 -13
- package/node_modules/baileys/node_modules/music-metadata/lib/mp4/AtomToken.js +2 -1
- package/node_modules/baileys/node_modules/music-metadata/lib/mp4/MP4Parser.js +34 -7
- package/node_modules/baileys/node_modules/music-metadata/lib/ogg/speex/SpeexStream.d.ts +7 -0
- package/node_modules/baileys/node_modules/music-metadata/lib/ogg/speex/SpeexStream.js +13 -0
- package/node_modules/baileys/node_modules/music-metadata/lib/riff/RiffChunk.js +1 -1
- package/node_modules/baileys/node_modules/music-metadata/package.json +156 -156
- package/node_modules/baileys/node_modules/protobufjs/README.md +61 -84
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.js +66 -45
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
- package/node_modules/baileys/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.js +47 -40
- package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.min.js +3 -3
- package/node_modules/baileys/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.js +92 -68
- package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.min.js +3 -3
- package/node_modules/baileys/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
- package/node_modules/baileys/node_modules/protobufjs/ext/descriptor.js +26 -10
- package/node_modules/baileys/node_modules/protobufjs/index.d.ts +3 -0
- package/node_modules/baileys/node_modules/protobufjs/package.json +1 -1
- package/node_modules/baileys/node_modules/protobufjs/src/converter.js +5 -1
- package/node_modules/baileys/node_modules/protobufjs/src/enum.js +5 -2
- package/node_modules/baileys/node_modules/protobufjs/src/field.js +6 -1
- package/node_modules/baileys/node_modules/protobufjs/src/parse.js +26 -23
- package/node_modules/baileys/node_modules/protobufjs/src/reader.js +36 -9
- package/node_modules/baileys/node_modules/protobufjs/src/util/codegen.js +3 -1
- package/node_modules/baileys/node_modules/protobufjs/src/util/utf8.js +2 -28
- package/node_modules/baileys/node_modules/protobufjs/src/writer.js +7 -1
- package/node_modules/baileys/package.json +1 -1
- package/node_modules/typebox/build/format/date.d.mts +1 -1
- package/node_modules/typebox/build/format/date.mjs +1 -1
- package/node_modules/typebox/build/format/date_time.d.mts +2 -2
- package/node_modules/typebox/build/format/date_time.mjs +3 -3
- package/node_modules/typebox/build/format/email.d.mts +1 -1
- package/node_modules/typebox/build/format/email.mjs +2 -2
- package/node_modules/typebox/build/format/hostname.mjs +2 -10
- package/node_modules/typebox/build/format/idn_email.d.mts +1 -1
- package/node_modules/typebox/build/format/idn_email.mjs +3 -3
- package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -0
- package/node_modules/typebox/build/format/idn_hostname.mjs +3 -11
- package/node_modules/typebox/build/format/idna/format/bidi.d.mts +3 -0
- package/node_modules/typebox/build/format/idna/format/bidi.mjs +98 -0
- package/node_modules/typebox/build/format/idna/format/puny.d.mts +3 -0
- package/node_modules/typebox/build/format/idna/format/puny.mjs +144 -0
- package/node_modules/typebox/build/format/idna/hostname.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/hostname.mjs +16 -0
- package/node_modules/typebox/build/format/idna/idn-hostname.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/idn-hostname.mjs +23 -0
- package/node_modules/typebox/build/format/idna/index.d.mts +2 -0
- package/node_modules/typebox/build/format/idna/index.mjs +2 -0
- package/node_modules/typebox/build/format/idna/label/ascii.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/label/ascii.mjs +9 -0
- package/node_modules/typebox/build/format/idna/label/puny.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/label/puny.mjs +28 -0
- package/node_modules/typebox/build/format/idna/label/unicode.d.mts +1 -0
- package/node_modules/typebox/build/format/idna/label/unicode.mjs +106 -0
- package/node_modules/typebox/build/format/idna/pattern/pattern.d.mts +30 -0
- package/node_modules/typebox/build/format/idna/pattern/pattern.mjs +70 -0
- package/node_modules/typebox/build/format/ipv4.d.mts +0 -1
- package/node_modules/typebox/build/format/ipv4.mjs +2 -32
- package/node_modules/typebox/build/format/ipv6.mjs +2 -61
- package/node_modules/typebox/build/format/iri.d.mts +2 -2
- package/node_modules/typebox/build/format/iri.mjs +26 -8
- package/node_modules/typebox/build/format/iri_reference.d.mts +2 -2
- package/node_modules/typebox/build/format/iri_reference.mjs +9 -55
- package/node_modules/typebox/build/format/regex.d.mts +1 -2
- package/node_modules/typebox/build/format/regex.mjs +2 -6
- package/node_modules/typebox/build/format/time.d.mts +2 -2
- package/node_modules/typebox/build/format/time.mjs +19 -14
- package/node_modules/typebox/build/format/uri.d.mts +1 -1
- package/node_modules/typebox/build/format/uri.mjs +3 -130
- package/node_modules/typebox/build/format/uri_reference.d.mts +1 -1
- package/node_modules/typebox/build/format/uri_reference.mjs +2 -3
- package/node_modules/typebox/build/format/uri_template.d.mts +2 -3
- package/node_modules/typebox/build/format/uri_template.mjs +4 -5
- package/node_modules/typebox/build/format/url.d.mts +3 -3
- package/node_modules/typebox/build/format/url.mjs +4 -5
- package/node_modules/typebox/build/guard/emit.d.mts +3 -1
- package/node_modules/typebox/build/guard/emit.mjs +12 -5
- package/node_modules/typebox/build/guard/guard.d.mts +8 -2
- package/node_modules/typebox/build/guard/guard.mjs +25 -4
- package/node_modules/typebox/build/guard/string.d.mts +2 -2
- package/node_modules/typebox/build/guard/string.mjs +7 -7
- package/node_modules/typebox/build/schema/engine/_context.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -2
- package/node_modules/typebox/build/schema/engine/_regexp.d.mts +2 -0
- package/node_modules/typebox/build/schema/engine/_regexp.mjs +4 -0
- package/node_modules/typebox/build/schema/engine/_stack.mjs +12 -13
- package/node_modules/typebox/build/schema/engine/additionalItems.mjs +17 -7
- package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +4 -3
- package/node_modules/typebox/build/schema/engine/contains.mjs +18 -6
- package/node_modules/typebox/build/schema/engine/enum.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/items.mjs +26 -6
- package/node_modules/typebox/build/schema/engine/maxContains.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/minContains.mjs +14 -4
- package/node_modules/typebox/build/schema/engine/not.mjs +4 -2
- package/node_modules/typebox/build/schema/engine/oneOf.mjs +7 -6
- package/node_modules/typebox/build/schema/engine/pattern.mjs +3 -2
- package/node_modules/typebox/build/schema/engine/patternProperties.mjs +4 -3
- package/node_modules/typebox/build/schema/engine/ref.mjs +1 -7
- package/node_modules/typebox/build/schema/engine/schema.mjs +13 -4
- package/node_modules/typebox/build/schema/engine/type.mjs +1 -1
- package/node_modules/typebox/build/schema/resolve/resolve.d.mts +4 -1
- package/node_modules/typebox/build/schema/resolve/resolve.mjs +202 -1
- package/node_modules/typebox/build/schema/static/propertyNames.d.mts +5 -0
- package/node_modules/typebox/build/schema/static/propertyNames.mjs +3 -0
- package/node_modules/typebox/build/schema/static/schema.d.mts +3 -0
- package/node_modules/typebox/build/schema/types/index.d.mts +0 -2
- package/node_modules/typebox/build/schema/types/index.mjs +0 -2
- package/node_modules/typebox/build/system/memory/clone.mjs +14 -11
- package/node_modules/typebox/build/system/memory/discard.mjs +6 -5
- package/node_modules/typebox/build/system/settings/settings.d.mts +9 -0
- package/node_modules/typebox/build/system/settings/settings.mjs +2 -0
- package/node_modules/typebox/build/type/engine/call/distribute_arguments.d.mts +6 -1
- package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +16 -3
- package/node_modules/typebox/build/type/engine/call/instantiate.mjs +34 -4
- package/node_modules/typebox/build/type/engine/evaluate/broaden.d.mts +5 -5
- package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +20 -26
- package/node_modules/typebox/build/type/engine/evaluate/compare.d.mts +6 -10
- package/node_modules/typebox/build/type/engine/evaluate/compare.mjs +9 -13
- package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +7 -4
- package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +12 -19
- package/node_modules/typebox/build/type/engine/evaluate/distribute.d.mts +4 -20
- package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +8 -20
- package/node_modules/typebox/build/type/engine/evaluate/evaluate.d.mts +4 -4
- package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +11 -8
- package/node_modules/typebox/build/type/engine/evaluate/flatten.d.mts +1 -1
- package/node_modules/typebox/build/type/engine/evaluate/flatten.mjs +3 -4
- package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +17 -2
- package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +26 -6
- package/node_modules/typebox/build/type/engine/exclude/operation.mjs +3 -4
- package/node_modules/typebox/build/type/engine/extract/operation.d.mts +1 -1
- package/node_modules/typebox/build/type/engine/extract/operation.mjs +3 -4
- package/node_modules/typebox/build/type/engine/priority/priority.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/priority/priority.mjs +3 -4
- package/node_modules/typebox/build/type/script/mapping.d.mts +32 -29
- package/node_modules/typebox/build/type/script/mapping.mjs +18 -25
- package/node_modules/typebox/build/type/script/parser.d.mts +19 -25
- package/node_modules/typebox/build/type/script/parser.mjs +27 -23
- package/node_modules/typebox/build/value/errors/errors.d.mts +2 -2
- package/node_modules/typebox/build/value/errors/errors.mjs +1 -1
- package/node_modules/typebox/package.json +27 -27
- package/node_modules/typebox/readme.md +79 -82
- package/openclaw.plugin.json +2 -1
- package/package.json +6 -6
- package/node_modules/typebox/build/format/_idna.d.mts +0 -2
- package/node_modules/typebox/build/format/_idna.mjs +0 -246
- package/node_modules/typebox/build/format/_puny.d.mts +0 -1
- package/node_modules/typebox/build/format/_puny.mjs +0 -77
- package/node_modules/typebox/build/schema/resolve/ref.d.mts +0 -3
- package/node_modules/typebox/build/schema/resolve/ref.mjs +0 -146
- package/node_modules/typebox/build/schema/types/contentEncoding.d.mts +0 -9
- package/node_modules/typebox/build/schema/types/contentEncoding.mjs +0 -13
- package/node_modules/typebox/build/schema/types/contentMediaType.d.mts +0 -9
- package/node_modules/typebox/build/schema/types/contentMediaType.mjs +0 -13
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { a as resolveWhatsAppAccount, s as resolveWhatsAppMediaMaxBytes } from "./accounts-
|
|
2
|
-
import {
|
|
1
|
+
import { a as resolveWhatsAppAccount, s as resolveWhatsAppMediaMaxBytes } from "./accounts-CeKQbu_s.js";
|
|
2
|
+
import { c as normalizeWhatsAppPayloadTextPreservingIndentation, d as listWhatsAppSendResultMessageIds, f as mergeWhatsAppAcceptedSendError, g as withWhatsAppLogicalDeliveryActivity, h as rememberWhatsAppPartialSend, l as prepareWhatsAppOutboundMedia, m as rememberWhatsAppAcceptedSend, o as normalizeWhatsAppOutboundPayload, p as normalizeWhatsAppSendResult, r as sendReactionWhatsApp, v as resolveWhatsAppReactionLevel } from "./send-C3S-NqyO.js";
|
|
3
3
|
import { i as getWhatsAppRuntime } from "./runtime-BLlToOi6.js";
|
|
4
4
|
import { r as getWhatsAppConnectionController } from "./connection-controller-runtime-context-DG0tuYuw.js";
|
|
5
5
|
import { a as markdownToWhatsAppChunks, c as toWhatsappJid, l as toWhatsappJidWithLid, n as isSelfChatMode, o as resolveEquivalentWhatsAppDirectChatJids, r as jidToE164, s as resolveJidToE164 } from "./targets-runtime-TMk0lGuy.js";
|
|
6
6
|
import { t as normalizeE164 } from "./text-runtime-CaKLhowd.js";
|
|
7
|
-
import { a as cacheInboundMessageMeta, i as buildQuotedMessageOptions, n as resolveWhatsAppGroupSessionRoute, o as lookupInboundMessageMeta, r as resolveWhatsAppLegacyGroupSessionKey } from "./group-session-key-
|
|
8
|
-
import { C as getMentionIdentities, D as getSenderIdentity, E as getSelfIdentity, O as identitiesOverlap, S as getComparableIdentityValues, T as getReplyContext, g as readWebSelfId, k as resolveComparableIdentity, o as getWebAuthAgeMs, r as WhatsAppAuthUnstableError, v as readWebSelfIdentityForDecision, w as getPrimaryIdentityId } from "./auth-store-
|
|
7
|
+
import { a as cacheInboundMessageMeta, i as buildQuotedMessageOptions, n as resolveWhatsAppGroupSessionRoute, o as lookupInboundMessageMeta, r as resolveWhatsAppLegacyGroupSessionKey } from "./group-session-key-CH9jJIVQ.js";
|
|
8
|
+
import { C as getMentionIdentities, D as getSenderIdentity, E as getSelfIdentity, O as identitiesOverlap, S as getComparableIdentityValues, T as getReplyContext, g as readWebSelfId, k as resolveComparableIdentity, o as getWebAuthAgeMs, r as WhatsAppAuthUnstableError, v as readWebSelfIdentityForDecision, w as getPrimaryIdentityId } from "./auth-store-CtpBqH5S.js";
|
|
9
9
|
import { n as resolveWhatsAppGroupsConfigPath } from "./group-config-path-BGyzT9Lg.js";
|
|
10
|
-
import { a as waitForWaConnection, c as isWhatsAppSocketOperationTimeoutError, d as withWhatsAppSocketOperationTimeout, l as resolveWhatsAppSocketOperationTimeoutMs, r as createWaSocket, s as createWhatsAppSocketOperationTimeoutAdapter, u as resolveWhatsAppSocketTiming } from "./socket-close-
|
|
10
|
+
import { a as waitForWaConnection, c as isWhatsAppSocketOperationTimeoutError, d as withWhatsAppSocketOperationTimeout, l as resolveWhatsAppSocketOperationTimeoutMs, r as createWaSocket, s as createWhatsAppSocketOperationTimeoutAdapter, u as resolveWhatsAppSocketTiming } from "./socket-close-2T0_jZTN.js";
|
|
11
11
|
import { n as getStatusCode, t as formatError } from "./session-errors-JuazczrA.js";
|
|
12
12
|
import { t as BufferJSON } from "./session.runtime-Nsqaehbd.js";
|
|
13
|
-
import { a as addWhatsAppImagePreviewFields, c as extractContextInfo, d as extractMediaKind, f as extractMentionedJids, g as
|
|
13
|
+
import { _ as resolveInboundMediaMimetype, a as addWhatsAppImagePreviewFields, c as extractContextInfo, d as extractMediaKind, f as extractMentionedJids, g as projectWhatsAppInboundMessage, h as hasInboundUserContent, i as resolveWhatsAppOutboundMentions, l as extractExternalAdReplyContext, n as addWhatsAppOutboundMentionsToContent, o as describeReplyContext, p as extractText, r as mayContainWhatsAppOutboundMention, s as extractContactContext, t as createWebSendApi, u as extractLocationData } from "./send-api-C-FFC1p_.js";
|
|
14
14
|
import { t as resolveWhatsAppRuntimeGroupPolicy } from "./runtime-group-policy-DeSRFXEV.js";
|
|
15
|
-
import { c as computeBackoff, d as resolveReconnectPolicy, f as sleepWithAbort, l as newConnectionId, n as WHATSAPP_WATCHDOG_TIMEOUT_ERROR, r as WhatsAppConnectionController, s as DEFAULT_RECONNECT_POLICY, u as resolveHeartbeatSeconds } from "./connection-controller-
|
|
16
|
-
import { n as maybeResolveWhatsAppApprovalReaction } from "./approval-reactions-
|
|
17
|
-
import { t as maybeResolveWhatsAppQuestionReaction } from "./question-reactions-
|
|
18
|
-
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString
|
|
15
|
+
import { c as computeBackoff, d as resolveReconnectPolicy, f as sleepWithAbort, l as newConnectionId, n as WHATSAPP_WATCHDOG_TIMEOUT_ERROR, r as WhatsAppConnectionController, s as DEFAULT_RECONNECT_POLICY, u as resolveHeartbeatSeconds } from "./connection-controller-CIYuBJrs.js";
|
|
16
|
+
import { n as maybeResolveWhatsAppApprovalReaction } from "./approval-reactions-rpaNVHzZ.js";
|
|
17
|
+
import { t as maybeResolveWhatsAppQuestionReaction } from "./question-reactions-B9D6MHXZ.js";
|
|
18
|
+
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
19
19
|
import { filterSupplementalContextItems, resolvePinnedMainDmOwnerFromAllowlist } from "openclaw/plugin-sdk/security-runtime";
|
|
20
20
|
import { createAckReactionHandle, createStatusReactionController, logAckFailure, removeAckReactionHandleAfterReply, shouldAckReaction } from "openclaw/plugin-sdk/channel-feedback";
|
|
21
21
|
import { formatCliCommand } from "openclaw/plugin-sdk/cli-runtime";
|
|
@@ -28,7 +28,7 @@ import { recordChannelActivity } from "openclaw/plugin-sdk/channel-activity-runt
|
|
|
28
28
|
import { buildChannelInboundEventContext, createChannelPartialDeliveryError, filterChannelInboundQuoteContext, formatInboundEnvelope, formatInboundEnvelope as formatInboundEnvelope$1, formatInboundMediaUnavailableText, formatLocationText, formatMediaPlaceholderText, hasVisibleInboundReplyDispatch, isChannelPartialDeliveryError, readAgentRunTerminalOutcome, resolveInboundSessionEnvelopeContext, resolveInboundSupplementalSenderAllowed, runChannelInboundEvent, shouldDebounceTextInbound, toInboundMediaFactsWithMetadata, toLocationContext } from "openclaw/plugin-sdk/channel-inbound";
|
|
29
29
|
import { bindIngressLifecycleToReplyOptions, createChannelIngressMonitor, createChannelMessageReplyPipeline, createMessageReceiptFromOutboundResults, listMessageReceiptPlatformIds, resolveChannelMessageSourceReplyDeliveryMode, resolveChannelStreamingBlockEnabled } from "openclaw/plugin-sdk/channel-outbound";
|
|
30
30
|
import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
|
|
31
|
-
import { isReasoningReplyPayload, resolveSendableOutboundReplyParts, sendMediaWithLeadingCaption } from "openclaw/plugin-sdk/reply-payload";
|
|
31
|
+
import { isReasoningReplyPayload, resolveSendableOutboundReplyParts, resolveTextChunksWithFallback, sendMediaWithLeadingCaption } from "openclaw/plugin-sdk/reply-payload";
|
|
32
32
|
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
33
33
|
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
34
34
|
import { DisconnectReason, downloadMediaMessage, isHostedLidUser, isHostedPnUser, isJidGroup, isJidGroup as isJidGroup$1, jidDecode, jidEncode, jidNormalizedUser, normalizeMessageContent as normalizeMessageContent$1 } from "baileys";
|
|
@@ -56,12 +56,14 @@ import { channelReadyPatch, channelStoppedPatch, createTransportActivityStatusPa
|
|
|
56
56
|
import { ensureConfiguredBindingRouteReady, resolveConfiguredBindingRoute } from "openclaw/plugin-sdk/conversation-binding-runtime";
|
|
57
57
|
import { resolveAgentIdentity, resolveIdentityNamePrefix as resolveIdentityNamePrefix$1 } from "openclaw/plugin-sdk/agent-runtime";
|
|
58
58
|
import { normalizeGroupActivation, parseActivationCommand } from "openclaw/plugin-sdk/group-activation";
|
|
59
|
+
import { formatAudioTranscriptForAgent } from "openclaw/plugin-sdk/media-understanding-runtime";
|
|
59
60
|
import { hasControlCommand, isControlCommandMessage, shouldComputeCommandAuthorized } from "openclaw/plugin-sdk/command-detection";
|
|
60
61
|
import { createInternalHookEvent, deriveInboundMessageHookContext, fireAndForgetBoundedHook, toInternalMessageReceivedContext, toPluginMessageContext, toPluginMessageReceivedEvent, triggerInternalHook } from "openclaw/plugin-sdk/hook-runtime";
|
|
61
62
|
import { getGlobalHookRunner } from "openclaw/plugin-sdk/plugin-runtime";
|
|
62
63
|
import { resolveBatchedReplyThreadingPolicy } from "openclaw/plugin-sdk/reply-reference";
|
|
63
64
|
import { LocalMediaAccessError, getDefaultLocalRoots, loadWebMedia, loadWebMediaRaw, optimizeImageToJpeg, optimizeImageToPng } from "openclaw/plugin-sdk/web-media";
|
|
64
65
|
import { createChannelApiRetryRunner } from "openclaw/plugin-sdk/retry-runtime";
|
|
66
|
+
import { resolveAgentConfig } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
65
67
|
//#region extensions/whatsapp/src/inbound/group-conversation.ts
|
|
66
68
|
function resolveWhatsAppGroupConversationId(conversationId) {
|
|
67
69
|
return resolveGroupSessionKey({
|
|
@@ -130,66 +132,10 @@ function buildWhatsAppInboundAdmission(params) {
|
|
|
130
132
|
async function resolveWhatsAppAdmissionChannelIngress(admission, contextBinding) {
|
|
131
133
|
return await ingressResolverByAdmission.get(admission)?.(contextBinding);
|
|
132
134
|
}
|
|
133
|
-
function buildDeprecatedFlatWhatsAppInboundAdmission(msg) {
|
|
134
|
-
const conversationId = msg.conversationId || msg.from;
|
|
135
|
-
if (!conversationId || !msg.accountId || !msg.chatType) throw new Error("WhatsApp legacy flat inbound messages must include deprecated top-level admission fields.");
|
|
136
|
-
const accountId = msg.accountId;
|
|
137
|
-
const admitted = msg.accessControlPassed !== false;
|
|
138
|
-
const platformSender = msg.platform?.sender;
|
|
139
|
-
const senderE164 = platformSender?.e164 ?? msg.platform?.senderE164 ?? msg.senderE164;
|
|
140
|
-
const senderJid = platformSender?.jid ?? msg.platform?.senderJid ?? msg.senderJid;
|
|
141
|
-
const senderName = platformSender?.name ?? msg.platform?.senderName ?? msg.senderName;
|
|
142
|
-
const senderId = msg.chatType === "group" ? senderE164 ?? senderJid ?? senderName ?? conversationId : senderE164 ?? conversationId;
|
|
143
|
-
const reasonCode = admitted ? msg.chatType === "group" ? "group_policy_allowed" : "dm_policy_allowlisted" : "no_policy_match";
|
|
144
|
-
return buildWhatsAppInboundAdmission({
|
|
145
|
-
policy: {
|
|
146
|
-
account: {
|
|
147
|
-
accountId,
|
|
148
|
-
enabled: true,
|
|
149
|
-
sendReadReceipts: true
|
|
150
|
-
},
|
|
151
|
-
isSelfChat: false,
|
|
152
|
-
isSamePhone: () => false
|
|
153
|
-
},
|
|
154
|
-
access: {
|
|
155
|
-
ingress: {
|
|
156
|
-
admission: admitted ? "dispatch" : "drop",
|
|
157
|
-
decision: admitted ? "allow" : "block",
|
|
158
|
-
decisiveGateId: "legacy-flat-compat",
|
|
159
|
-
reasonCode
|
|
160
|
-
},
|
|
161
|
-
senderAccess: {
|
|
162
|
-
allowed: admitted,
|
|
163
|
-
decision: admitted ? "allow" : "block",
|
|
164
|
-
reasonCode,
|
|
165
|
-
providerMissingFallbackApplied: false
|
|
166
|
-
},
|
|
167
|
-
commandAccess: {
|
|
168
|
-
requested: false,
|
|
169
|
-
authorized: false,
|
|
170
|
-
shouldBlockControlCommand: false,
|
|
171
|
-
reasonCode: "command_authorized"
|
|
172
|
-
},
|
|
173
|
-
activationAccess: {
|
|
174
|
-
ran: false,
|
|
175
|
-
allowed: admitted,
|
|
176
|
-
shouldSkip: !admitted,
|
|
177
|
-
reasonCode: admitted ? "activation_allowed" : "activation_skipped"
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
isGroup: msg.chatType === "group",
|
|
181
|
-
conversationId,
|
|
182
|
-
senderId
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
135
|
function requireWhatsAppInboundAdmission(params) {
|
|
186
136
|
if (!params.admission) throw new Error("WhatsApp inbound message is missing admission facts");
|
|
187
137
|
return params.admission;
|
|
188
138
|
}
|
|
189
|
-
function requireAdmittedWhatsAppInboundMessage(msg) {
|
|
190
|
-
requireWhatsAppInboundAdmission(msg);
|
|
191
|
-
return msg;
|
|
192
|
-
}
|
|
193
139
|
//#endregion
|
|
194
140
|
//#region extensions/whatsapp/src/inbound-policy.ts
|
|
195
141
|
function normalizeWhatsAppIngressPhone(value) {
|
|
@@ -324,353 +270,6 @@ function readWhatsAppBaileysCacheEntry(cache, key) {
|
|
|
324
270
|
return entry.value;
|
|
325
271
|
}
|
|
326
272
|
//#endregion
|
|
327
|
-
//#region extensions/whatsapp/src/inbound/message-aliases.ts
|
|
328
|
-
function normalizeQuoteSender(sender) {
|
|
329
|
-
if (!sender?.displayName && !sender?.jid && !sender?.e164) return;
|
|
330
|
-
return sender;
|
|
331
|
-
}
|
|
332
|
-
function buildQuoteFromFlatAliases(msg) {
|
|
333
|
-
if (msg.replyTo) return {
|
|
334
|
-
context: msg.replyTo,
|
|
335
|
-
id: msg.replyTo.id,
|
|
336
|
-
body: msg.replyTo.body,
|
|
337
|
-
sender: normalizeQuoteSender({
|
|
338
|
-
displayName: msg.replyTo.sender?.label ?? msg.replyToSender,
|
|
339
|
-
jid: msg.replyTo.sender?.jid ?? msg.replyToSenderJid,
|
|
340
|
-
e164: msg.replyTo.sender?.e164 ?? msg.replyToSenderE164
|
|
341
|
-
})
|
|
342
|
-
};
|
|
343
|
-
if (!msg.replyToId && !msg.replyToBody && !msg.replyToSender && !msg.replyToSenderJid && !msg.replyToSenderE164) return;
|
|
344
|
-
return {
|
|
345
|
-
id: msg.replyToId,
|
|
346
|
-
body: msg.replyToBody,
|
|
347
|
-
sender: normalizeQuoteSender({
|
|
348
|
-
displayName: msg.replyToSender,
|
|
349
|
-
jid: msg.replyToSenderJid,
|
|
350
|
-
e164: msg.replyToSenderE164
|
|
351
|
-
})
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
function buildGroupFromFlatAliases(msg) {
|
|
355
|
-
const mentionJids = msg.mentions ?? msg.mentionedJids;
|
|
356
|
-
if (!msg.groupSubject && !msg.groupParticipants?.length && !mentionJids?.length) return;
|
|
357
|
-
return {
|
|
358
|
-
subject: msg.groupSubject,
|
|
359
|
-
participants: msg.groupParticipants,
|
|
360
|
-
mentions: mentionJids?.length ? { jids: mentionJids } : void 0
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
function ensureQuote(msg) {
|
|
364
|
-
return msg.quote ??= {};
|
|
365
|
-
}
|
|
366
|
-
function ensureQuoteSender(msg) {
|
|
367
|
-
const quote = ensureQuote(msg);
|
|
368
|
-
return quote.sender ??= {};
|
|
369
|
-
}
|
|
370
|
-
function ensureGroup(msg) {
|
|
371
|
-
return msg.group ??= {};
|
|
372
|
-
}
|
|
373
|
-
function ensureGroupMentions(msg) {
|
|
374
|
-
const group = ensureGroup(msg);
|
|
375
|
-
return group.mentions ??= {};
|
|
376
|
-
}
|
|
377
|
-
function ensureMedia(msg) {
|
|
378
|
-
return msg.payload.media ??= {};
|
|
379
|
-
}
|
|
380
|
-
function setMediaField(msg, key, value) {
|
|
381
|
-
if (value === void 0 && !msg.payload.media) return;
|
|
382
|
-
ensureMedia(msg)[key] = value;
|
|
383
|
-
}
|
|
384
|
-
function defineDeprecatedAccessors(msg, descriptors) {
|
|
385
|
-
Object.defineProperties(msg, Object.fromEntries(Object.entries(descriptors).map(([key, descriptor]) => [key, {
|
|
386
|
-
configurable: true,
|
|
387
|
-
enumerable: true,
|
|
388
|
-
get: descriptor.get,
|
|
389
|
-
set: descriptor.set
|
|
390
|
-
}])));
|
|
391
|
-
return msg;
|
|
392
|
-
}
|
|
393
|
-
function defineDeprecatedAliasAccessors(msg, descriptors) {
|
|
394
|
-
defineDeprecatedAccessors(msg, descriptors);
|
|
395
|
-
return msg;
|
|
396
|
-
}
|
|
397
|
-
function defineDeprecatedStructuredContextPayloadAlias(msg) {
|
|
398
|
-
const channelStructuredContext = msg.payload.channelStructuredContext ?? msg.payload.untrustedStructuredContext;
|
|
399
|
-
if (channelStructuredContext !== void 0) msg.payload.channelStructuredContext = channelStructuredContext;
|
|
400
|
-
Object.defineProperty(msg.payload, "untrustedStructuredContext", {
|
|
401
|
-
configurable: true,
|
|
402
|
-
enumerable: true,
|
|
403
|
-
get: () => msg.payload.channelStructuredContext,
|
|
404
|
-
set: (value) => {
|
|
405
|
-
msg.payload.channelStructuredContext = value;
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
function defineDeprecatedAdmissionTopLevelAccessors(msg) {
|
|
410
|
-
let fallbackConversationId = msg.conversationId || msg.from;
|
|
411
|
-
let fallbackAccountId = msg.accountId;
|
|
412
|
-
let fallbackAccessControlPassed = msg.accessControlPassed;
|
|
413
|
-
let fallbackChatType = msg.chatType;
|
|
414
|
-
const conversationId = () => msg.admission?.conversation.id ?? fallbackConversationId;
|
|
415
|
-
const setConversationId = (value) => {
|
|
416
|
-
const next = value;
|
|
417
|
-
fallbackConversationId = next;
|
|
418
|
-
if (msg.admission) {
|
|
419
|
-
msg.admission.conversation.id = next;
|
|
420
|
-
msg.admission.conversation.groupSessionId = resolveWhatsAppGroupConversationId(next);
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
return defineDeprecatedAccessors(msg, {
|
|
424
|
-
from: {
|
|
425
|
-
get: conversationId,
|
|
426
|
-
set: setConversationId
|
|
427
|
-
},
|
|
428
|
-
conversationId: {
|
|
429
|
-
get: conversationId,
|
|
430
|
-
set: setConversationId
|
|
431
|
-
},
|
|
432
|
-
accountId: {
|
|
433
|
-
get: () => msg.admission?.accountId ?? fallbackAccountId,
|
|
434
|
-
set: (value) => {
|
|
435
|
-
const next = value;
|
|
436
|
-
fallbackAccountId = next;
|
|
437
|
-
if (msg.admission) {
|
|
438
|
-
msg.admission.accountId = next;
|
|
439
|
-
msg.admission.account.accountId = next;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
},
|
|
443
|
-
accessControlPassed: {
|
|
444
|
-
get: () => {
|
|
445
|
-
if (msg.admission?.ingress.decisiveGateId === "legacy-flat-compat") return fallbackAccessControlPassed;
|
|
446
|
-
return msg.admission ? msg.admission.ingress.decision === "allow" : fallbackAccessControlPassed;
|
|
447
|
-
},
|
|
448
|
-
set: (value) => {
|
|
449
|
-
if (!msg.admission) fallbackAccessControlPassed = value;
|
|
450
|
-
}
|
|
451
|
-
},
|
|
452
|
-
chatType: {
|
|
453
|
-
get: () => msg.admission?.conversation.kind ?? fallbackChatType,
|
|
454
|
-
set: (value) => {
|
|
455
|
-
const next = value;
|
|
456
|
-
fallbackChatType = next;
|
|
457
|
-
if (msg.admission) msg.admission.conversation.kind = next;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
function withDeprecatedWebInboundMessageFlatAliases(msg) {
|
|
463
|
-
defineDeprecatedStructuredContextPayloadAlias(msg);
|
|
464
|
-
return defineDeprecatedAliasAccessors(defineDeprecatedAdmissionTopLevelAccessors(msg), {
|
|
465
|
-
id: {
|
|
466
|
-
get: () => msg.event.id,
|
|
467
|
-
set: (value) => msg.event.id = value
|
|
468
|
-
},
|
|
469
|
-
to: {
|
|
470
|
-
get: () => msg.platform.recipientJid,
|
|
471
|
-
set: (value) => msg.platform.recipientJid = value
|
|
472
|
-
},
|
|
473
|
-
body: {
|
|
474
|
-
get: () => msg.payload.body,
|
|
475
|
-
set: (value) => msg.payload.body = value
|
|
476
|
-
},
|
|
477
|
-
pushName: {
|
|
478
|
-
get: () => msg.platform.pushName,
|
|
479
|
-
set: (value) => msg.platform.pushName = value
|
|
480
|
-
},
|
|
481
|
-
timestamp: {
|
|
482
|
-
get: () => msg.event.timestamp,
|
|
483
|
-
set: (value) => msg.event.timestamp = value
|
|
484
|
-
},
|
|
485
|
-
chatId: {
|
|
486
|
-
get: () => msg.platform.chatJid,
|
|
487
|
-
set: (value) => msg.platform.chatJid = value
|
|
488
|
-
},
|
|
489
|
-
sender: {
|
|
490
|
-
get: () => msg.platform.sender,
|
|
491
|
-
set: (value) => msg.platform.sender = value
|
|
492
|
-
},
|
|
493
|
-
senderJid: {
|
|
494
|
-
get: () => msg.platform.senderJid,
|
|
495
|
-
set: (value) => msg.platform.senderJid = value
|
|
496
|
-
},
|
|
497
|
-
senderE164: {
|
|
498
|
-
get: () => msg.platform.senderE164,
|
|
499
|
-
set: (value) => msg.platform.senderE164 = value
|
|
500
|
-
},
|
|
501
|
-
senderName: {
|
|
502
|
-
get: () => msg.platform.senderName,
|
|
503
|
-
set: (value) => msg.platform.senderName = value
|
|
504
|
-
},
|
|
505
|
-
replyTo: {
|
|
506
|
-
get: () => msg.quote?.context,
|
|
507
|
-
set: (value) => ensureQuote(msg).context = value
|
|
508
|
-
},
|
|
509
|
-
replyToId: {
|
|
510
|
-
get: () => msg.quote?.id ?? msg.quote?.context?.id,
|
|
511
|
-
set: (value) => ensureQuote(msg).id = value
|
|
512
|
-
},
|
|
513
|
-
replyToBody: {
|
|
514
|
-
get: () => msg.quote?.body ?? msg.quote?.context?.body,
|
|
515
|
-
set: (value) => ensureQuote(msg).body = value
|
|
516
|
-
},
|
|
517
|
-
replyToSender: {
|
|
518
|
-
get: () => msg.quote?.context?.sender?.label ?? msg.quote?.sender?.displayName,
|
|
519
|
-
set: (value) => {
|
|
520
|
-
const sender = ensureQuoteSender(msg);
|
|
521
|
-
sender.displayName = value;
|
|
522
|
-
if (msg.quote?.context?.sender) msg.quote.context.sender.label = value;
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
replyToSenderJid: {
|
|
526
|
-
get: () => msg.quote?.context?.sender?.jid ?? msg.quote?.sender?.jid,
|
|
527
|
-
set: (value) => {
|
|
528
|
-
const jid = value;
|
|
529
|
-
ensureQuoteSender(msg).jid = jid;
|
|
530
|
-
if (msg.quote?.context?.sender) msg.quote.context.sender.jid = jid;
|
|
531
|
-
}
|
|
532
|
-
},
|
|
533
|
-
replyToSenderE164: {
|
|
534
|
-
get: () => msg.quote?.context?.sender?.e164 ?? msg.quote?.sender?.e164,
|
|
535
|
-
set: (value) => {
|
|
536
|
-
const e164 = value;
|
|
537
|
-
ensureQuoteSender(msg).e164 = e164;
|
|
538
|
-
if (msg.quote?.context?.sender) msg.quote.context.sender.e164 = e164;
|
|
539
|
-
}
|
|
540
|
-
},
|
|
541
|
-
groupSubject: {
|
|
542
|
-
get: () => msg.group?.subject,
|
|
543
|
-
set: (value) => ensureGroup(msg).subject = value
|
|
544
|
-
},
|
|
545
|
-
groupParticipants: {
|
|
546
|
-
get: () => msg.group?.participants,
|
|
547
|
-
set: (value) => ensureGroup(msg).participants = value
|
|
548
|
-
},
|
|
549
|
-
mentions: {
|
|
550
|
-
get: () => msg.group?.mentions?.jids,
|
|
551
|
-
set: (value) => ensureGroupMentions(msg).jids = value
|
|
552
|
-
},
|
|
553
|
-
mentionedJids: {
|
|
554
|
-
get: () => msg.group?.mentions?.jids,
|
|
555
|
-
set: (value) => ensureGroupMentions(msg).jids = value
|
|
556
|
-
},
|
|
557
|
-
self: {
|
|
558
|
-
get: () => msg.platform.self,
|
|
559
|
-
set: (value) => msg.platform.self = value
|
|
560
|
-
},
|
|
561
|
-
selfJid: {
|
|
562
|
-
get: () => msg.platform.selfJid,
|
|
563
|
-
set: (value) => msg.platform.selfJid = value
|
|
564
|
-
},
|
|
565
|
-
selfLid: {
|
|
566
|
-
get: () => msg.platform.selfLid,
|
|
567
|
-
set: (value) => msg.platform.selfLid = value
|
|
568
|
-
},
|
|
569
|
-
selfE164: {
|
|
570
|
-
get: () => msg.platform.selfE164,
|
|
571
|
-
set: (value) => msg.platform.selfE164 = value
|
|
572
|
-
},
|
|
573
|
-
fromMe: {
|
|
574
|
-
get: () => msg.platform.fromMe,
|
|
575
|
-
set: (value) => msg.platform.fromMe = value
|
|
576
|
-
},
|
|
577
|
-
location: {
|
|
578
|
-
get: () => msg.payload.location,
|
|
579
|
-
set: (value) => msg.payload.location = value
|
|
580
|
-
},
|
|
581
|
-
sendComposing: {
|
|
582
|
-
get: () => msg.platform.sendComposing,
|
|
583
|
-
set: (value) => msg.platform.sendComposing = value
|
|
584
|
-
},
|
|
585
|
-
reply: {
|
|
586
|
-
get: () => msg.platform.reply,
|
|
587
|
-
set: (value) => msg.platform.reply = value
|
|
588
|
-
},
|
|
589
|
-
sendMedia: {
|
|
590
|
-
get: () => msg.platform.sendMedia,
|
|
591
|
-
set: (value) => msg.platform.sendMedia = value
|
|
592
|
-
},
|
|
593
|
-
mediaPath: {
|
|
594
|
-
get: () => msg.payload.media?.path,
|
|
595
|
-
set: (value) => setMediaField(msg, "path", value)
|
|
596
|
-
},
|
|
597
|
-
mediaType: {
|
|
598
|
-
get: () => msg.payload.media?.type,
|
|
599
|
-
set: (value) => setMediaField(msg, "type", value)
|
|
600
|
-
},
|
|
601
|
-
mediaFileName: {
|
|
602
|
-
get: () => msg.payload.media?.fileName,
|
|
603
|
-
set: (value) => setMediaField(msg, "fileName", value)
|
|
604
|
-
},
|
|
605
|
-
mediaUrl: {
|
|
606
|
-
get: () => msg.payload.media?.url,
|
|
607
|
-
set: (value) => setMediaField(msg, "url", value)
|
|
608
|
-
},
|
|
609
|
-
channelStructuredContext: {
|
|
610
|
-
get: () => msg.payload.channelStructuredContext,
|
|
611
|
-
set: (value) => msg.payload.channelStructuredContext = value
|
|
612
|
-
},
|
|
613
|
-
untrustedStructuredContext: {
|
|
614
|
-
get: () => msg.payload.channelStructuredContext,
|
|
615
|
-
set: (value) => msg.payload.channelStructuredContext = value
|
|
616
|
-
},
|
|
617
|
-
isBatched: {
|
|
618
|
-
get: () => msg.event.isBatched,
|
|
619
|
-
set: (value) => msg.event.isBatched = value
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
function normalizeLegacyFlatWebInboundMessage(msg) {
|
|
624
|
-
const media = msg.mediaPath || msg.mediaType || msg.mediaFileName || msg.mediaUrl ? {
|
|
625
|
-
path: msg.mediaPath,
|
|
626
|
-
type: msg.mediaType,
|
|
627
|
-
fileName: msg.mediaFileName,
|
|
628
|
-
url: msg.mediaUrl
|
|
629
|
-
} : void 0;
|
|
630
|
-
return withDeprecatedWebInboundMessageFlatAliases({
|
|
631
|
-
...msg,
|
|
632
|
-
admission: msg.admission ?? buildDeprecatedFlatWhatsAppInboundAdmission(msg),
|
|
633
|
-
event: {
|
|
634
|
-
id: msg.id,
|
|
635
|
-
timestamp: msg.timestamp,
|
|
636
|
-
isBatched: msg.isBatched
|
|
637
|
-
},
|
|
638
|
-
payload: {
|
|
639
|
-
body: msg.body,
|
|
640
|
-
media,
|
|
641
|
-
location: msg.location,
|
|
642
|
-
channelStructuredContext: msg.channelStructuredContext ?? msg.untrustedStructuredContext
|
|
643
|
-
},
|
|
644
|
-
platform: {
|
|
645
|
-
chatJid: msg.chatId,
|
|
646
|
-
recipientJid: msg.to,
|
|
647
|
-
sender: msg.sender,
|
|
648
|
-
senderJid: msg.senderJid,
|
|
649
|
-
senderE164: msg.senderE164,
|
|
650
|
-
senderName: msg.senderName,
|
|
651
|
-
pushName: msg.pushName,
|
|
652
|
-
self: msg.self,
|
|
653
|
-
selfJid: msg.selfJid,
|
|
654
|
-
selfLid: msg.selfLid,
|
|
655
|
-
selfE164: msg.selfE164,
|
|
656
|
-
fromMe: msg.fromMe,
|
|
657
|
-
sendComposing: msg.sendComposing,
|
|
658
|
-
reply: msg.reply,
|
|
659
|
-
sendMedia: msg.sendMedia
|
|
660
|
-
},
|
|
661
|
-
quote: buildQuoteFromFlatAliases(msg),
|
|
662
|
-
group: buildGroupFromFlatAliases(msg)
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
function normalizeWebInboundMessage(msg) {
|
|
666
|
-
if (msg.event && msg.payload && msg.platform) return withDeprecatedWebInboundMessageFlatAliases(msg);
|
|
667
|
-
if (msg.event || msg.payload || msg.platform || msg.quote || msg.group) throw new Error("WhatsApp inbound messages must be either legacy flat or canonical nested; partial nested contexts are not supported.");
|
|
668
|
-
return normalizeLegacyFlatWebInboundMessage(msg);
|
|
669
|
-
}
|
|
670
|
-
function normalizeAdmittedWebInboundMessage(msg) {
|
|
671
|
-
return requireAdmittedWhatsAppInboundMessage(normalizeWebInboundMessage(msg));
|
|
672
|
-
}
|
|
673
|
-
//#endregion
|
|
674
273
|
//#region extensions/whatsapp/src/inbound/durable-payload.ts
|
|
675
274
|
var WhatsAppIngressPermanentError = class extends Error {
|
|
676
275
|
constructor(reason, message, options) {
|
|
@@ -817,8 +416,7 @@ function readGroupMetadataCacheEntry(cache, jid) {
|
|
|
817
416
|
function createWhatsAppGroupMetadataCacheOwner(params) {
|
|
818
417
|
const reconnectCache = params.reconnectCache ?? /* @__PURE__ */ new Map();
|
|
819
418
|
const localCache = /* @__PURE__ */ new Map();
|
|
820
|
-
const
|
|
821
|
-
const invalidatedJids = /* @__PURE__ */ new Set();
|
|
419
|
+
const groupMetadataGenerations = /* @__PURE__ */ new Map();
|
|
822
420
|
const detachListeners = [];
|
|
823
421
|
let closed = false;
|
|
824
422
|
let started = false;
|
|
@@ -848,46 +446,51 @@ function createWhatsAppGroupMetadataCacheOwner(params) {
|
|
|
848
446
|
});
|
|
849
447
|
const rememberFullUpdate = (jid, meta) => {
|
|
850
448
|
if (closed) return;
|
|
449
|
+
groupMetadataGenerations.set(jid, {});
|
|
851
450
|
rememberWhatsAppBaileysCacheEntry(params.baileysCache, jid, meta, GROUP_META_TTL_MS);
|
|
852
|
-
publishedJids.add(jid);
|
|
853
|
-
invalidatedJids.delete(jid);
|
|
854
451
|
rememberGroupMetadataCacheEntry(reconnectCache, jid, summarizeForReconnect(meta));
|
|
855
452
|
localCache.delete(jid);
|
|
856
453
|
};
|
|
857
454
|
const forgetFullMetadata = (jid) => {
|
|
455
|
+
groupMetadataGenerations.set(jid, {});
|
|
858
456
|
params.baileysCache?.delete(jid);
|
|
859
457
|
reconnectCache.delete(jid);
|
|
860
458
|
localCache.delete(jid);
|
|
861
|
-
publishedJids.delete(jid);
|
|
862
|
-
invalidatedJids.add(jid);
|
|
863
459
|
};
|
|
864
460
|
const get = async (jid) => {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
rememberGroupMetadataCacheEntry(localCache, jid,
|
|
886
|
-
|
|
887
|
-
|
|
461
|
+
for (;;) {
|
|
462
|
+
if (closed) return { expires: resolveGroupMetadataExpiresAt() ?? 0 };
|
|
463
|
+
const cached = readGroupMetadataCacheEntry(localCache, jid);
|
|
464
|
+
if (cached) return cached;
|
|
465
|
+
const generation = groupMetadataGenerations.get(jid);
|
|
466
|
+
try {
|
|
467
|
+
const hydratedEntry = params.baileysCache?.get(jid);
|
|
468
|
+
const providerMetadata = params.baileysCache ? readWhatsAppBaileysCacheEntry(params.baileysCache, jid) : void 0;
|
|
469
|
+
const hydratedMetadata = providerMetadata?.participants?.length ? providerMetadata : void 0;
|
|
470
|
+
const meta = hydratedMetadata ?? await (params.getCurrentSock() ?? params.sock).groupMetadata(jid);
|
|
471
|
+
if (closed || groupMetadataGenerations.get(jid) !== generation) continue;
|
|
472
|
+
const entry = await summarize(meta);
|
|
473
|
+
if (closed || groupMetadataGenerations.get(jid) !== generation) continue;
|
|
474
|
+
if (hydratedMetadata && hydratedEntry) entry.expires = hydratedEntry.expiresAt;
|
|
475
|
+
else rememberWhatsAppBaileysCacheEntry(params.baileysCache, jid, meta, GROUP_META_TTL_MS);
|
|
476
|
+
groupMetadataGenerations.set(jid, {});
|
|
477
|
+
rememberGroupMetadataCacheEntry(reconnectCache, jid, {
|
|
478
|
+
subject: entry.subject,
|
|
479
|
+
expires: entry.expires
|
|
480
|
+
});
|
|
481
|
+
rememberGroupMetadataCacheEntry(localCache, jid, entry);
|
|
482
|
+
return entry;
|
|
483
|
+
} catch (error) {
|
|
484
|
+
if (closed || groupMetadataGenerations.get(jid) !== generation) continue;
|
|
485
|
+
const hydrated = readGroupMetadataCacheEntry(reconnectCache, jid);
|
|
486
|
+
if (hydrated) {
|
|
487
|
+
rememberGroupMetadataCacheEntry(localCache, jid, hydrated);
|
|
488
|
+
params.logVerbose(`Using cached group metadata for ${jid} after fetch failure: ${String(error)}`);
|
|
489
|
+
return hydrated;
|
|
490
|
+
}
|
|
491
|
+
params.logVerbose(`Failed to fetch group metadata for ${jid}: ${String(error)}`);
|
|
492
|
+
return { expires: resolveGroupMetadataExpiresAt() ?? 0 };
|
|
888
493
|
}
|
|
889
|
-
params.logVerbose(`Failed to fetch group metadata for ${jid}: ${String(error)}`);
|
|
890
|
-
return { expires: resolveGroupMetadataExpiresAt() ?? 0 };
|
|
891
494
|
}
|
|
892
495
|
};
|
|
893
496
|
const resolveOutboundMentions = async (jid, text) => {
|
|
@@ -945,10 +548,10 @@ function createWhatsAppGroupMetadataCacheOwner(params) {
|
|
|
945
548
|
try {
|
|
946
549
|
const groups = await params.sock.groupFetchAllParticipating();
|
|
947
550
|
if (closed) return;
|
|
948
|
-
for (const [jid, meta] of Object.entries(groups ?? {})) if (meta && !
|
|
551
|
+
for (const [jid, meta] of Object.entries(groups ?? {})) if (meta && !groupMetadataGenerations.has(jid)) {
|
|
949
552
|
rememberGroupMetadataCacheEntry(reconnectCache, jid, summarizeForReconnect(meta));
|
|
950
553
|
rememberWhatsAppBaileysCacheEntry(params.baileysCache, jid, meta, GROUP_META_TTL_MS);
|
|
951
|
-
|
|
554
|
+
groupMetadataGenerations.set(jid, {});
|
|
952
555
|
}
|
|
953
556
|
params.logVerbose(`Hydrated ${Object.keys(groups ?? {}).length} participating groups on connect`);
|
|
954
557
|
} catch (error) {
|
|
@@ -1063,7 +666,7 @@ function createWhatsAppInboundMessageDebouncer(options) {
|
|
|
1063
666
|
...last.group,
|
|
1064
667
|
mentions: combinedMentions
|
|
1065
668
|
} : void 0;
|
|
1066
|
-
const combinedMessage = attachWhatsAppIngressLifecycle(
|
|
669
|
+
const combinedMessage = attachWhatsAppIngressLifecycle({
|
|
1067
670
|
...last,
|
|
1068
671
|
turnAdoptionLifecycle: admissionLifecycle,
|
|
1069
672
|
payload: {
|
|
@@ -1076,7 +679,7 @@ function createWhatsAppInboundMessageDebouncer(options) {
|
|
|
1076
679
|
...last.event,
|
|
1077
680
|
isBatched: true
|
|
1078
681
|
}
|
|
1079
|
-
}
|
|
682
|
+
}, admissionLifecycle);
|
|
1080
683
|
await options.onMessage(combinedMessage);
|
|
1081
684
|
await settle();
|
|
1082
685
|
await Promise.all(orderedEntries.map((entry) => options.markRead(entry.readReceipt)));
|
|
@@ -1145,8 +748,8 @@ function createWhatsAppInboundMessageDebouncer(options) {
|
|
|
1145
748
|
function unwrapMessage(message) {
|
|
1146
749
|
return normalizeMessageContent$1(message);
|
|
1147
750
|
}
|
|
1148
|
-
async function downloadInboundMedia(msg, sock, maxBytes = 50 * 1024 * 1024) {
|
|
1149
|
-
const message = unwrapMessage(msg.message);
|
|
751
|
+
async function downloadInboundMedia(msg, sock, maxBytes = 50 * 1024 * 1024, normalizedMessage) {
|
|
752
|
+
const message = normalizedMessage ?? unwrapMessage(msg.message);
|
|
1150
753
|
if (!message) return;
|
|
1151
754
|
const mimetype = resolveInboundMediaMimetype(message);
|
|
1152
755
|
const fileName = message.documentMessage?.fileName ?? void 0;
|
|
@@ -1214,17 +817,18 @@ function logMediaMaterializationFailure(params) {
|
|
|
1214
817
|
}
|
|
1215
818
|
async function enrichWhatsAppInboundMessage(params) {
|
|
1216
819
|
const { msg, sock } = params;
|
|
1217
|
-
const
|
|
820
|
+
const messageProjection = projectWhatsAppInboundMessage(msg.message ?? void 0);
|
|
821
|
+
const location = extractLocationData(messageProjection);
|
|
1218
822
|
const locationText = location ? formatLocationText(location) : void 0;
|
|
1219
|
-
const contactContext = extractContactContext(
|
|
1220
|
-
const externalAdReplyContext = extractExternalAdReplyContext(
|
|
1221
|
-
let mediaKind = extractMediaKind(
|
|
1222
|
-
let body = extractText(
|
|
823
|
+
const contactContext = extractContactContext(messageProjection);
|
|
824
|
+
const externalAdReplyContext = extractExternalAdReplyContext(messageProjection);
|
|
825
|
+
let mediaKind = extractMediaKind(messageProjection);
|
|
826
|
+
let body = extractText(messageProjection);
|
|
1223
827
|
if (locationText) body = [body, locationText].filter(Boolean).join("\n").trim();
|
|
1224
828
|
if (!body && !mediaKind) return null;
|
|
1225
829
|
body = body ?? "";
|
|
1226
830
|
const commandBody = body;
|
|
1227
|
-
const replyContext = describeReplyContext(
|
|
831
|
+
const replyContext = describeReplyContext(messageProjection);
|
|
1228
832
|
let mediaPath;
|
|
1229
833
|
let mediaType = mediaKind ? resolveInboundMediaMimetype(msg.message) : void 0;
|
|
1230
834
|
const nativeMedia = mediaKind ? {
|
|
@@ -1240,7 +844,7 @@ async function enrichWhatsAppInboundMessage(params) {
|
|
|
1240
844
|
mediaFileName = inboundMedia.fileName;
|
|
1241
845
|
};
|
|
1242
846
|
try {
|
|
1243
|
-
await saveInboundMedia(await downloadInboundMedia(msg, sock, maxBytes));
|
|
847
|
+
await saveInboundMedia(await downloadInboundMedia(msg, sock, maxBytes, messageProjection[0]));
|
|
1244
848
|
} catch (error) {
|
|
1245
849
|
logMediaMaterializationFailure({
|
|
1246
850
|
messageId: msg.key?.id,
|
|
@@ -1284,7 +888,8 @@ async function enrichWhatsAppInboundMessage(params) {
|
|
|
1284
888
|
mediaType,
|
|
1285
889
|
mediaFileName,
|
|
1286
890
|
mediaKind,
|
|
1287
|
-
nativeMedia
|
|
891
|
+
nativeMedia,
|
|
892
|
+
mentionedJids: extractMentionedJids(messageProjection)
|
|
1288
893
|
};
|
|
1289
894
|
}
|
|
1290
895
|
//#endregion
|
|
@@ -1617,7 +1222,7 @@ function createWhatsAppMessageDeliveryCoordinator(options) {
|
|
|
1617
1222
|
return normalizeWhatsAppSendResult(await sendTrackedMessage(chatJid, await groupMetadata.applyOutboundMentions(chatJid, previewPayload), optionsValue), "media");
|
|
1618
1223
|
};
|
|
1619
1224
|
const timestamp = inbound.messageTimestampMs;
|
|
1620
|
-
const mentionedJids =
|
|
1225
|
+
const mentionedJids = enriched.mentionedJids;
|
|
1621
1226
|
const senderName = msg.pushName ?? void 0;
|
|
1622
1227
|
inboundLogger.info({
|
|
1623
1228
|
from: inbound.from,
|
|
@@ -1660,7 +1265,7 @@ function createWhatsAppMessageDeliveryCoordinator(options) {
|
|
|
1660
1265
|
payload: enriched.externalAdReplyContext
|
|
1661
1266
|
}] : []
|
|
1662
1267
|
];
|
|
1663
|
-
const inboundMessage =
|
|
1268
|
+
const inboundMessage = {
|
|
1664
1269
|
admission: inbound.access.admission,
|
|
1665
1270
|
event: {
|
|
1666
1271
|
id: inbound.id,
|
|
@@ -1709,7 +1314,7 @@ function createWhatsAppMessageDeliveryCoordinator(options) {
|
|
|
1709
1314
|
turnAdoptionLifecycle: durable.turnAdoptionLifecycle,
|
|
1710
1315
|
readReceipt: durable.readReceipt,
|
|
1711
1316
|
receiveOrder: durable.receiveOrder
|
|
1712
|
-
}
|
|
1317
|
+
};
|
|
1713
1318
|
if (inboundMessage.event.id) {
|
|
1714
1319
|
const admission = requireWhatsAppInboundAdmission(inboundMessage);
|
|
1715
1320
|
cacheInboundMessageMeta(admission.accountId, inboundMessage.platform.chatJid, inboundMessage.event.id, {
|
|
@@ -2263,10 +1868,6 @@ async function monitorWebInbox(options) {
|
|
|
2263
1868
|
}
|
|
2264
1869
|
return attachWebInboxToSocket({
|
|
2265
1870
|
...options,
|
|
2266
|
-
onMessage: async (msg) => {
|
|
2267
|
-
await options.onMessage(normalizeAdmittedWebInboundMessage(msg));
|
|
2268
|
-
},
|
|
2269
|
-
shouldDebounce: options.shouldDebounce ? (msg) => options.shouldDebounce?.(normalizeAdmittedWebInboundMessage(msg)) ?? true : void 0,
|
|
2270
1871
|
socketTiming,
|
|
2271
1872
|
sock,
|
|
2272
1873
|
recentMessageKeys,
|
|
@@ -2700,11 +2301,6 @@ async function maybeBroadcastMessage(params) {
|
|
|
2700
2301
|
return true;
|
|
2701
2302
|
}
|
|
2702
2303
|
//#endregion
|
|
2703
|
-
//#region extensions/whatsapp/src/auto-reply/monitor/audio-transcript.ts
|
|
2704
|
-
function formatWhatsAppAudioTranscriptForAgent(transcript) {
|
|
2705
|
-
return `[Audio transcript (machine-generated, untrusted)]: ${JSON.stringify(transcript)}`;
|
|
2706
|
-
}
|
|
2707
|
-
//#endregion
|
|
2708
2304
|
//#region extensions/whatsapp/src/auto-reply/monitor/commands.ts
|
|
2709
2305
|
function stripMentionsForCommand(text, mentionRegexes, selfE164) {
|
|
2710
2306
|
let result = text;
|
|
@@ -2901,7 +2497,7 @@ async function applyGroupGating(params) {
|
|
|
2901
2497
|
needsMentionText: true
|
|
2902
2498
|
};
|
|
2903
2499
|
}
|
|
2904
|
-
const pendingHistoryBody = params.mentionText === void 0 ? void 0 :
|
|
2500
|
+
const pendingHistoryBody = params.mentionText === void 0 ? void 0 : formatAudioTranscriptForAgent(params.mentionText);
|
|
2905
2501
|
return skipGroupMessageAndStoreHistory(params, `Group message stored for context (no mention detected) in ${conversationId}: ${mentionMsg.payload.body}`, pendingHistoryBody);
|
|
2906
2502
|
}
|
|
2907
2503
|
return { shouldProcess: true };
|
|
@@ -3121,6 +2717,11 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3121
2717
|
const isGroupConversation = transport.conversationKind === "group";
|
|
3122
2718
|
const replyStarted = Date.now();
|
|
3123
2719
|
const sendResults = [];
|
|
2720
|
+
const acceptedMediaUrls = /* @__PURE__ */ new Set();
|
|
2721
|
+
const recordMediaAccepted = (mediaUrl) => {
|
|
2722
|
+
acceptedMediaUrls.add(mediaUrl);
|
|
2723
|
+
params.onMediaAccepted?.(mediaUrl);
|
|
2724
|
+
};
|
|
3124
2725
|
const finishDelivery = () => {
|
|
3125
2726
|
const receipt = createWhatsAppReplyDeliveryReceipt(sendResults);
|
|
3126
2727
|
return {
|
|
@@ -3129,20 +2730,22 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3129
2730
|
providerAccepted: sendResults.some((result) => result.providerAccepted)
|
|
3130
2731
|
};
|
|
3131
2732
|
};
|
|
3132
|
-
const preserveAcceptedDeliveryError = (error, kind) => {
|
|
2733
|
+
const preserveAcceptedDeliveryError = (error, kind, mediaUrl) => {
|
|
3133
2734
|
const sendKind = kind ?? sendResults[0]?.kind ?? "text";
|
|
3134
|
-
if (isChannelPartialDeliveryError(error))
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
2735
|
+
if (isChannelPartialDeliveryError(error)) {
|
|
2736
|
+
if (rememberWhatsAppPartialSend({
|
|
2737
|
+
error,
|
|
2738
|
+
kind: sendKind,
|
|
2739
|
+
results: sendResults
|
|
2740
|
+
}) && mediaUrl) recordMediaAccepted(mediaUrl);
|
|
2741
|
+
}
|
|
3139
2742
|
return mergeWhatsAppAcceptedSendError({
|
|
3140
2743
|
error,
|
|
3141
2744
|
kind: sendKind,
|
|
3142
2745
|
results: sendResults
|
|
3143
2746
|
});
|
|
3144
2747
|
};
|
|
3145
|
-
const rememberSendResult = (result) => {
|
|
2748
|
+
const rememberSendResult = (result, mediaUrl) => {
|
|
3146
2749
|
if (!result) return;
|
|
3147
2750
|
try {
|
|
3148
2751
|
rememberWhatsAppAcceptedSend({
|
|
@@ -3153,6 +2756,8 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3153
2756
|
} catch (error) {
|
|
3154
2757
|
if (sendResults.some((accepted) => accepted.providerAccepted)) throw preserveAcceptedDeliveryError(error, result.kind);
|
|
3155
2758
|
throw error;
|
|
2759
|
+
} finally {
|
|
2760
|
+
if (mediaUrl && sendResults.includes(result)) recordMediaAccepted(mediaUrl);
|
|
3156
2761
|
}
|
|
3157
2762
|
};
|
|
3158
2763
|
if (isReasoningReplyPayload(replyResult)) {
|
|
@@ -3162,7 +2767,8 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3162
2767
|
const tableMode = params.tableMode ?? "code";
|
|
3163
2768
|
const chunkMode = params.chunkMode ?? "length";
|
|
3164
2769
|
const normalizedReply = params.normalizedReplyResult ?? normalizeWhatsAppOutboundPayload(replyResult, { normalizeText: normalizeWhatsAppPayloadTextPreservingIndentation });
|
|
3165
|
-
const
|
|
2770
|
+
const text = normalizedReply.text ?? "";
|
|
2771
|
+
const textChunks = resolveTextChunksWithFallback(text, markdownToWhatsAppChunks(text, textLimit, tableMode, chunkMode));
|
|
3166
2772
|
const mediaList = normalizedReply.mediaUrls ?? [];
|
|
3167
2773
|
const getQuote = () => {
|
|
3168
2774
|
if (!replyResult.replyToId) return;
|
|
@@ -3176,7 +2782,7 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3176
2782
|
media: cached?.media
|
|
3177
2783
|
});
|
|
3178
2784
|
};
|
|
3179
|
-
const sendWithRetry = async (fn, label, kind) => {
|
|
2785
|
+
const sendWithRetry = async (fn, label, kind, mediaUrl) => {
|
|
3180
2786
|
try {
|
|
3181
2787
|
return await sendWhatsAppOutboundWithRetry({
|
|
3182
2788
|
send: fn,
|
|
@@ -3185,7 +2791,7 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3185
2791
|
}
|
|
3186
2792
|
});
|
|
3187
2793
|
} catch (error) {
|
|
3188
|
-
if (isChannelPartialDeliveryError(error) || sendResults.some((result) => result.providerAccepted)) throw preserveAcceptedDeliveryError(error, kind);
|
|
2794
|
+
if (isChannelPartialDeliveryError(error) || sendResults.some((result) => result.providerAccepted)) throw preserveAcceptedDeliveryError(error, kind, mediaUrl);
|
|
3189
2795
|
throw error;
|
|
3190
2796
|
}
|
|
3191
2797
|
};
|
|
@@ -3217,13 +2823,10 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3217
2823
|
return delivery;
|
|
3218
2824
|
}
|
|
3219
2825
|
const remainingText = [...textChunks];
|
|
3220
|
-
const leadingCaption = remainingText.shift() || "";
|
|
3221
|
-
let acceptedIdsBeforeCurrentMedia = /* @__PURE__ */ new Set();
|
|
3222
2826
|
await sendMediaWithLeadingCaption({
|
|
3223
2827
|
mediaUrls: mediaList,
|
|
3224
|
-
caption:
|
|
2828
|
+
caption: remainingText.shift() || "",
|
|
3225
2829
|
send: async ({ mediaUrl, caption }) => {
|
|
3226
|
-
acceptedIdsBeforeCurrentMedia = new Set(sendResults.flatMap(listWhatsAppSendResultMessageIds));
|
|
3227
2830
|
const media = await prepareWhatsAppOutboundMedia(await loadWebMedia(mediaUrl, {
|
|
3228
2831
|
maxBytes: maxMediaBytes,
|
|
3229
2832
|
localRoots: params.mediaLocalRoots
|
|
@@ -3232,37 +2835,26 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3232
2835
|
logVerbose(`Web auto-reply media size: ${(media.buffer.length / (1024 * 1024)).toFixed(2)}MB`);
|
|
3233
2836
|
logVerbose(`Web auto-reply media source: ${mediaUrl} (kind ${media.kind})`);
|
|
3234
2837
|
}
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
}
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
mimetype: media.mimetype
|
|
3256
|
-
}, quote), "media:video", "media"));
|
|
3257
|
-
} else {
|
|
3258
|
-
const quote = getQuote();
|
|
3259
|
-
rememberSendResult(await sendWithRetry(() => transport.sendMedia({
|
|
3260
|
-
document: media.buffer,
|
|
3261
|
-
fileName: media.fileName,
|
|
3262
|
-
caption,
|
|
3263
|
-
mimetype: media.mimetype
|
|
3264
|
-
}, quote), "media:document", "media"));
|
|
3265
|
-
}
|
|
2838
|
+
const quote = getQuote();
|
|
2839
|
+
const mediaContent = media.kind === "image" ? {
|
|
2840
|
+
image: media.buffer,
|
|
2841
|
+
caption
|
|
2842
|
+
} : media.kind === "audio" ? {
|
|
2843
|
+
audio: media.buffer,
|
|
2844
|
+
ptt: true
|
|
2845
|
+
} : media.kind === "video" ? {
|
|
2846
|
+
video: media.buffer,
|
|
2847
|
+
caption
|
|
2848
|
+
} : {
|
|
2849
|
+
document: media.buffer,
|
|
2850
|
+
fileName: media.fileName,
|
|
2851
|
+
caption
|
|
2852
|
+
};
|
|
2853
|
+
rememberSendResult(await sendWithRetry(() => transport.sendMedia({
|
|
2854
|
+
...mediaContent,
|
|
2855
|
+
mimetype: media.mimetype
|
|
2856
|
+
}, quote), `media:${media.kind}`, "media", mediaUrl), mediaUrl);
|
|
2857
|
+
if (media.kind === "audio" && caption) rememberSendResult(await sendWithRetry(() => transport.reply(caption, quote), "media:audio-text", "text"));
|
|
3266
2858
|
whatsappOutboundLog.info(`Sent media reply to ${conversationId} (${(media.buffer.length / (1024 * 1024)).toFixed(2)}MB)`);
|
|
3267
2859
|
replyLogger.info({
|
|
3268
2860
|
correlationId: transport.correlationId ?? newConnectionId(),
|
|
@@ -3277,7 +2869,7 @@ async function deliverWebReplyInActivityScope(params) {
|
|
|
3277
2869
|
}, "auto-reply sent (media)");
|
|
3278
2870
|
},
|
|
3279
2871
|
onError: async ({ error, mediaUrl, caption, isFirst }) => {
|
|
3280
|
-
if (
|
|
2872
|
+
if (acceptedMediaUrls.has(mediaUrl)) throw preserveAcceptedDeliveryError(error);
|
|
3281
2873
|
whatsappOutboundLog.error(`Failed sending web media to ${conversationId}: ${formatError(error)}`);
|
|
3282
2874
|
replyLogger.warn({
|
|
3283
2875
|
err: error,
|
|
@@ -3480,9 +3072,6 @@ function resolveWhatsAppDeliverablePayload(payload, info) {
|
|
|
3480
3072
|
}
|
|
3481
3073
|
return payload;
|
|
3482
3074
|
}
|
|
3483
|
-
function getWhatsAppPayloadMediaUrls(payload) {
|
|
3484
|
-
return new Set(normalizeStringEntries([...Array.isArray(payload.mediaUrls) ? payload.mediaUrls : [], ...typeof payload.mediaUrl === "string" ? [payload.mediaUrl] : []]));
|
|
3485
|
-
}
|
|
3486
3075
|
function hasWhatsAppMediaUrlOverlap(left, right) {
|
|
3487
3076
|
for (const url of left) if (right.has(url)) return true;
|
|
3488
3077
|
return false;
|
|
@@ -3530,16 +3119,28 @@ function createWhatsAppMediaOnlyReplyCoalescer(params) {
|
|
|
3530
3119
|
return finalization;
|
|
3531
3120
|
},
|
|
3532
3121
|
flushNonDuplicateMedia: (mediaUrls) => flushWhere((pending) => !hasWhatsAppMediaUrlOverlap(pending.mediaUrls, mediaUrls)),
|
|
3533
|
-
|
|
3122
|
+
supersedeMedia(mediaUrl) {
|
|
3534
3123
|
const flushResult = {
|
|
3535
3124
|
delivered: 0,
|
|
3536
3125
|
droppedDuplicateMedia: 0
|
|
3537
3126
|
};
|
|
3538
3127
|
const retained = [];
|
|
3539
|
-
for (const pending of pendingMediaOnlyPayloads.splice(0))
|
|
3540
|
-
pending.
|
|
3541
|
-
|
|
3542
|
-
|
|
3128
|
+
for (const pending of pendingMediaOnlyPayloads.splice(0)) {
|
|
3129
|
+
if (pending.mediaUrls.delete(mediaUrl)) {
|
|
3130
|
+
flushResult.droppedDuplicateMedia += 1;
|
|
3131
|
+
const mediaUrls = [...pending.mediaUrls];
|
|
3132
|
+
pending.payload = {
|
|
3133
|
+
...pending.payload,
|
|
3134
|
+
mediaUrl: mediaUrls[0],
|
|
3135
|
+
mediaUrls
|
|
3136
|
+
};
|
|
3137
|
+
}
|
|
3138
|
+
if (pending.mediaUrls.size === 0) {
|
|
3139
|
+
pending.resolveFinalization(whatsAppReplyDeliveryVisibility(false));
|
|
3140
|
+
continue;
|
|
3141
|
+
}
|
|
3142
|
+
retained.push(pending);
|
|
3143
|
+
}
|
|
3543
3144
|
pendingMediaOnlyPayloads.push(...retained);
|
|
3544
3145
|
return flushResult;
|
|
3545
3146
|
},
|
|
@@ -3548,7 +3149,7 @@ function createWhatsAppMediaOnlyReplyCoalescer(params) {
|
|
|
3548
3149
|
}
|
|
3549
3150
|
function logWhatsAppMediaOnlyFlushResult(result) {
|
|
3550
3151
|
if (!shouldLogVerbose$1()) return;
|
|
3551
|
-
if (result.droppedDuplicateMedia > 0) logVerbose$1(`
|
|
3152
|
+
if (result.droppedDuplicateMedia > 0) logVerbose$1(`Superseded ${result.droppedDuplicateMedia} deferred WhatsApp attachment(s) with accepted replacement media`);
|
|
3552
3153
|
if (result.delivered > 0) logVerbose$1(`Flushed ${result.delivered} deferred media-only WhatsApp reply payload(s)`);
|
|
3553
3154
|
}
|
|
3554
3155
|
function resolveWhatsAppResponsePrefix(params) {
|
|
@@ -3610,7 +3211,8 @@ async function prepareWhatsAppInboundContext(params) {
|
|
|
3610
3211
|
from: conversationId,
|
|
3611
3212
|
sender: {
|
|
3612
3213
|
id: params.sender.id ?? params.sender.e164,
|
|
3613
|
-
name: params.sender.name
|
|
3214
|
+
name: params.sender.name,
|
|
3215
|
+
isSelf: params.msg.platform.fromMe === true
|
|
3614
3216
|
},
|
|
3615
3217
|
conversation: {
|
|
3616
3218
|
kind: conversationKind,
|
|
@@ -3738,7 +3340,8 @@ function createWhatsAppReplyPlan(params) {
|
|
|
3738
3340
|
replyLogger: params.replyLogger,
|
|
3739
3341
|
connectionId: params.connectionId,
|
|
3740
3342
|
skipLog: false,
|
|
3741
|
-
tableMode
|
|
3343
|
+
tableMode,
|
|
3344
|
+
onMediaAccepted: options?.onMediaAccepted
|
|
3742
3345
|
});
|
|
3743
3346
|
} catch (error) {
|
|
3744
3347
|
if (isWhatsAppVisibleDeliveryError(error) && !isChannelPartialDeliveryError(error)) throw createChannelPartialDeliveryError(error, {
|
|
@@ -3800,7 +3403,7 @@ function createWhatsAppReplyPlan(params) {
|
|
|
3800
3403
|
} : normalizedOutboundPayload;
|
|
3801
3404
|
const reply = resolveSendableOutboundReplyParts(normalizedDeliveryPayload);
|
|
3802
3405
|
if (!reply.hasMedia && !reply.text.trim()) return normalizedDeliveryPayload;
|
|
3803
|
-
const mediaUrls =
|
|
3406
|
+
const mediaUrls = new Set(normalizedDeliveryPayload.mediaUrls);
|
|
3804
3407
|
logWhatsAppMediaOnlyFlushResult(reply.hasMedia ? shouldDeferWhatsAppMediaOnlyPayload({
|
|
3805
3408
|
info,
|
|
3806
3409
|
mediaUrls,
|
|
@@ -3834,7 +3437,7 @@ function createWhatsAppReplyPlan(params) {
|
|
|
3834
3437
|
const reply = resolveSendableOutboundReplyParts(normalizedDeliveryPayload);
|
|
3835
3438
|
if (!reply.hasMedia && !reply.text.trim()) return whatsAppReplyDeliveryVisibility(false);
|
|
3836
3439
|
if (!reply.hasMedia) return await deliverNormalizedPayload(normalizedDeliveryPayload, info, { recordDelivery: false });
|
|
3837
|
-
const mediaUrls =
|
|
3440
|
+
const mediaUrls = new Set(normalizedDeliveryPayload.mediaUrls);
|
|
3838
3441
|
if (shouldDeferWhatsAppMediaOnlyPayload({
|
|
3839
3442
|
info,
|
|
3840
3443
|
mediaUrls,
|
|
@@ -3847,14 +3450,10 @@ function createWhatsAppReplyPlan(params) {
|
|
|
3847
3450
|
payload: normalizedDeliveryPayload
|
|
3848
3451
|
})
|
|
3849
3452
|
};
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
} catch (error) {
|
|
3855
|
-
if (isWhatsAppVisibleDeliveryError(error)) logWhatsAppMediaOnlyFlushResult(mediaOnlyCoalescer.dropDuplicateMedia(mediaUrls));
|
|
3856
|
-
throw error;
|
|
3857
|
-
}
|
|
3453
|
+
return await deliverNormalizedPayload(normalizedDeliveryPayload, info, { onMediaAccepted: (mediaUrl) => {
|
|
3454
|
+
didSendReply = true;
|
|
3455
|
+
logWhatsAppMediaOnlyFlushResult(mediaOnlyCoalescer.supersedeMedia(mediaUrl));
|
|
3456
|
+
} });
|
|
3858
3457
|
},
|
|
3859
3458
|
onDelivered: (payload, _info, result) => {
|
|
3860
3459
|
if (!resolveSendableOutboundReplyParts(payload).hasMedia && result?.visibleReplySent === true) recordDeliveredPayload(payload);
|
|
@@ -3923,8 +3522,7 @@ async function finalizeWhatsAppStatusReaction(params) {
|
|
|
3923
3522
|
//#endregion
|
|
3924
3523
|
//#region extensions/whatsapp/src/auto-reply/monitor/message-line.runtime.ts
|
|
3925
3524
|
function resolveIdentityNamePrefix(cfg, agentId) {
|
|
3926
|
-
const
|
|
3927
|
-
const identityName = cfg.agents?.list?.find((agent) => normalizeAgentId(agent.id ?? "") === normalizedAgentId)?.identity?.name?.trim();
|
|
3525
|
+
const identityName = resolveAgentConfig(cfg, agentId)?.identity?.name?.trim();
|
|
3928
3526
|
return identityName ? `[${identityName}]` : void 0;
|
|
3929
3527
|
}
|
|
3930
3528
|
function resolveMessagePrefix(cfg, agentId, opts) {
|
|
@@ -4092,7 +3690,7 @@ async function processMessage(params) {
|
|
|
4092
3690
|
...params.msg,
|
|
4093
3691
|
payload: {
|
|
4094
3692
|
...params.msg.payload,
|
|
4095
|
-
body:
|
|
3693
|
+
body: formatAudioTranscriptForAgent(audioTranscript)
|
|
4096
3694
|
}
|
|
4097
3695
|
} : params.msg;
|
|
4098
3696
|
const visibleReplyTo = resolveVisibleWhatsAppReplyContext({
|
|
@@ -4323,6 +3921,7 @@ async function processMessage(params) {
|
|
|
4323
3921
|
sessionKey: params.route.sessionKey
|
|
4324
3922
|
},
|
|
4325
3923
|
ctxPayload,
|
|
3924
|
+
dispatchReplyFromConfig: params.dispatchReplyFromConfig,
|
|
4326
3925
|
record: {
|
|
4327
3926
|
onRecordError: (err) => {
|
|
4328
3927
|
params.replyLogger.warn({
|
|
@@ -4357,19 +3956,13 @@ async function processMessage(params) {
|
|
|
4357
3956
|
}
|
|
4358
3957
|
//#endregion
|
|
4359
3958
|
//#region extensions/whatsapp/src/auto-reply/monitor/on-message.ts
|
|
4360
|
-
function readDeprecatedAccessControlPassed(msg) {
|
|
4361
|
-
return msg.accessControlPassed;
|
|
4362
|
-
}
|
|
4363
3959
|
function createWebOnMessageHandler(params) {
|
|
4364
|
-
const hasExplicitlyPassedInboundAccess = (msg) =>
|
|
4365
|
-
if (msg.admission.ingress.decisiveGateId === "legacy-flat-compat") return readDeprecatedAccessControlPassed(msg) === true;
|
|
4366
|
-
return msg.admission.ingress.decision === "allow";
|
|
4367
|
-
};
|
|
3960
|
+
const hasExplicitlyPassedInboundAccess = (msg) => msg.admission.ingress.decision === "allow";
|
|
4368
3961
|
const withDirectSenderPeer = (msg, peerId) => {
|
|
4369
3962
|
if (requireWhatsAppInboundAdmission(msg).conversation.kind === "group" || msg.platform.sender?.e164 || msg.platform.senderE164 || !peerId.startsWith("+")) return msg;
|
|
4370
3963
|
const normalized = normalizeE164(peerId);
|
|
4371
3964
|
if (!normalized) return msg;
|
|
4372
|
-
return
|
|
3965
|
+
return {
|
|
4373
3966
|
...msg,
|
|
4374
3967
|
platform: {
|
|
4375
3968
|
...msg.platform,
|
|
@@ -4379,7 +3972,7 @@ function createWebOnMessageHandler(params) {
|
|
|
4379
3972
|
},
|
|
4380
3973
|
senderE164: normalized
|
|
4381
3974
|
}
|
|
4382
|
-
}
|
|
3975
|
+
};
|
|
4383
3976
|
};
|
|
4384
3977
|
const processForRoute = async (cfg, msg, route, groupHistoryKey, opts) => {
|
|
4385
3978
|
const processParams = {
|
|
@@ -4396,7 +3989,8 @@ function createWebOnMessageHandler(params) {
|
|
|
4396
3989
|
replyResolver: params.replyResolver,
|
|
4397
3990
|
replyLogger: params.replyLogger,
|
|
4398
3991
|
backgroundTasks: params.backgroundTasks,
|
|
4399
|
-
buildContext: params.buildContext
|
|
3992
|
+
buildContext: params.buildContext,
|
|
3993
|
+
dispatchReplyFromConfig: params.dispatchReplyFromConfig
|
|
4400
3994
|
};
|
|
4401
3995
|
if (opts?.groupHistory !== void 0) processParams.groupHistory = opts.groupHistory;
|
|
4402
3996
|
if (opts?.suppressGroupHistoryClear !== void 0) processParams.suppressGroupHistoryClear = opts.suppressGroupHistoryClear;
|
|
@@ -4745,15 +4339,12 @@ async function monitorWebChannel(verbose, listenerFactory = attachWebInboxToSock
|
|
|
4745
4339
|
cfg,
|
|
4746
4340
|
channel: "whatsapp"
|
|
4747
4341
|
});
|
|
4748
|
-
const shouldDebounce = (msg) => {
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
allowDebounce: !(admitted.payload.location || admitted.quote?.id || admitted.quote?.body)
|
|
4755
|
-
});
|
|
4756
|
-
};
|
|
4342
|
+
const shouldDebounce = (msg) => shouldDebounceTextInbound({
|
|
4343
|
+
text: msg.payload.commandBody ?? msg.payload.body,
|
|
4344
|
+
cfg,
|
|
4345
|
+
hasMedia: Boolean(msg.payload.media?.path || msg.payload.media?.type),
|
|
4346
|
+
allowDebounce: !(msg.payload.location || msg.quote?.id || msg.quote?.body)
|
|
4347
|
+
});
|
|
4757
4348
|
let connection;
|
|
4758
4349
|
try {
|
|
4759
4350
|
connection = await controller.openConnection({
|
|
@@ -4764,6 +4355,7 @@ async function monitorWebChannel(verbose, listenerFactory = attachWebInboxToSock
|
|
|
4764
4355
|
return meta?.participants?.length ? meta : void 0;
|
|
4765
4356
|
},
|
|
4766
4357
|
createListener: async ({ sock, connection: connectionLocal }) => {
|
|
4358
|
+
const pluginChannelRuntime = tuning.channelRuntime;
|
|
4767
4359
|
const onMessage = createWebOnMessageHandler({
|
|
4768
4360
|
cfg,
|
|
4769
4361
|
loadConfig: loadCurrentMonitorConfig,
|
|
@@ -4778,7 +4370,8 @@ async function monitorWebChannel(verbose, listenerFactory = attachWebInboxToSock
|
|
|
4778
4370
|
replyLogger,
|
|
4779
4371
|
baseMentionConfig,
|
|
4780
4372
|
account,
|
|
4781
|
-
buildContext:
|
|
4373
|
+
buildContext: pluginChannelRuntime?.inbound.buildContext,
|
|
4374
|
+
dispatchReplyFromConfig: pluginChannelRuntime?.reply?.dispatchReplyFromConfig
|
|
4782
4375
|
});
|
|
4783
4376
|
return await (listenerFactory ?? attachWebInboxToSocket)({
|
|
4784
4377
|
cfg,
|
|
@@ -4805,11 +4398,10 @@ async function monitorWebChannel(verbose, listenerFactory = attachWebInboxToSock
|
|
|
4805
4398
|
recentMessageKeys,
|
|
4806
4399
|
baileysGroupMetaCache,
|
|
4807
4400
|
onMessage: async (msg) => {
|
|
4808
|
-
const admitted = normalizeAdmittedWebInboundMessage(msg);
|
|
4809
4401
|
const inboundAt = Date.now();
|
|
4810
4402
|
controller.noteInbound(inboundAt);
|
|
4811
4403
|
statusController.noteInbound(inboundAt);
|
|
4812
|
-
await onMessage(
|
|
4404
|
+
await onMessage(msg);
|
|
4813
4405
|
},
|
|
4814
4406
|
onPendingWorkChanged: (pendingWorkCount, at) => {
|
|
4815
4407
|
statusController.noteBusy(pendingWorkCount > 0, at);
|