@openclaw/whatsapp 2026.5.1-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/action-runtime-api.ts +1 -0
- package/action-runtime.runtime.ts +1 -0
- package/api.ts +213 -0
- package/auth-presence.ts +80 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +3 -0
- package/config-api.ts +4 -0
- package/constants.ts +1 -0
- package/contract-api.ts +29 -0
- package/directory-contract-api.ts +4 -0
- package/dist/.boundary-tsc.stamp +1 -0
- package/dist/.boundary-tsc.tsbuildinfo +1 -0
- package/doctor-contract-api.ts +8 -0
- package/index.test.ts +13 -0
- package/index.ts +16 -0
- package/legacy-session-surface-api.ts +6 -0
- package/legacy-state-migrations-api.ts +1 -0
- package/light-runtime-api.ts +12 -0
- package/login-qr-api.ts +1 -0
- package/login-qr-runtime.ts +23 -0
- package/openclaw.plugin.json +742 -0
- package/outbound-payload-test-api.ts +1 -0
- package/package.json +74 -0
- package/runtime-api.ts +86 -0
- package/secret-contract-api.ts +4 -0
- package/security-contract-api.ts +4 -0
- package/setup-entry.test.ts +21 -0
- package/setup-entry.ts +21 -0
- package/setup-plugin-api.ts +3 -0
- package/src/account-config.ts +77 -0
- package/src/account-ids.ts +13 -0
- package/src/account-types.ts +5 -0
- package/src/accounts.test.ts +182 -0
- package/src/accounts.ts +176 -0
- package/src/accounts.whatsapp-auth.test.ts +59 -0
- package/src/action-runtime-target-auth.ts +27 -0
- package/src/action-runtime.test.ts +330 -0
- package/src/action-runtime.ts +76 -0
- package/src/active-listener.test.ts +65 -0
- package/src/active-listener.ts +17 -0
- package/src/agent-tools-login.test.ts +81 -0
- package/src/agent-tools-login.ts +113 -0
- package/src/approval-auth.test.ts +24 -0
- package/src/approval-auth.ts +27 -0
- package/src/auth-store.runtime.ts +1 -0
- package/src/auth-store.test.ts +311 -0
- package/src/auth-store.ts +502 -0
- package/src/auto-reply/config.runtime.ts +16 -0
- package/src/auto-reply/constants.ts +1 -0
- package/src/auto-reply/deliver-reply.test.ts +843 -0
- package/src/auto-reply/deliver-reply.ts +279 -0
- package/src/auto-reply/heartbeat-runner.runtime.ts +33 -0
- package/src/auto-reply/heartbeat-runner.test.ts +214 -0
- package/src/auto-reply/heartbeat-runner.ts +330 -0
- package/src/auto-reply/loggers.ts +6 -0
- package/src/auto-reply/mentions.ts +131 -0
- package/src/auto-reply/monitor/ack-reaction.test.ts +170 -0
- package/src/auto-reply/monitor/ack-reaction.ts +99 -0
- package/src/auto-reply/monitor/audio-preflight.runtime.ts +9 -0
- package/src/auto-reply/monitor/broadcast.ts +153 -0
- package/src/auto-reply/monitor/commands.ts +19 -0
- package/src/auto-reply/monitor/echo.ts +64 -0
- package/src/auto-reply/monitor/group-activation.runtime.ts +1 -0
- package/src/auto-reply/monitor/group-activation.test.ts +189 -0
- package/src/auto-reply/monitor/group-activation.ts +73 -0
- package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +103 -0
- package/src/auto-reply/monitor/group-gating.runtime.ts +8 -0
- package/src/auto-reply/monitor/group-gating.ts +217 -0
- package/src/auto-reply/monitor/group-members.test.ts +56 -0
- package/src/auto-reply/monitor/group-members.ts +65 -0
- package/src/auto-reply/monitor/inbound-context.test.ts +97 -0
- package/src/auto-reply/monitor/inbound-context.ts +92 -0
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +21 -0
- package/src/auto-reply/monitor/inbound-dispatch.test.ts +895 -0
- package/src/auto-reply/monitor/inbound-dispatch.ts +422 -0
- package/src/auto-reply/monitor/last-route.test.ts +37 -0
- package/src/auto-reply/monitor/last-route.ts +61 -0
- package/src/auto-reply/monitor/message-line.runtime.ts +38 -0
- package/src/auto-reply/monitor/message-line.ts +54 -0
- package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +354 -0
- package/src/auto-reply/monitor/on-message.ts +291 -0
- package/src/auto-reply/monitor/peer.ts +17 -0
- package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +420 -0
- package/src/auto-reply/monitor/process-message.test.ts +355 -0
- package/src/auto-reply/monitor/process-message.ts +531 -0
- package/src/auto-reply/monitor/runtime-api.ts +30 -0
- package/src/auto-reply/monitor-state.test.ts +64 -0
- package/src/auto-reply/monitor-state.ts +106 -0
- package/src/auto-reply/monitor.ts +600 -0
- package/src/auto-reply/reply-resolver.runtime.ts +1 -0
- package/src/auto-reply/session-snapshot.ts +69 -0
- package/src/auto-reply/types.ts +48 -0
- package/src/auto-reply/util.ts +63 -0
- package/src/auto-reply/web-auto-reply-monitor.test.ts +687 -0
- package/src/auto-reply/web-auto-reply-utils.test.ts +327 -0
- package/src/auto-reply.broadcast-groups.combined.test.ts +246 -0
- package/src/auto-reply.broadcast-groups.test-harness.ts +47 -0
- package/src/auto-reply.impl.ts +7 -0
- package/src/auto-reply.test-harness.ts +421 -0
- package/src/auto-reply.ts +1 -0
- package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +427 -0
- package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +908 -0
- package/src/auto-reply.web-auto-reply.last-route.test.ts +184 -0
- package/src/channel-actions.runtime.ts +7 -0
- package/src/channel-actions.test.ts +216 -0
- package/src/channel-actions.ts +84 -0
- package/src/channel-outbound.test.ts +131 -0
- package/src/channel-outbound.ts +36 -0
- package/src/channel-react-action.runtime.ts +7 -0
- package/src/channel-react-action.test.ts +294 -0
- package/src/channel-react-action.ts +84 -0
- package/src/channel.runtime.ts +117 -0
- package/src/channel.setup.test.ts +461 -0
- package/src/channel.setup.ts +28 -0
- package/src/channel.ts +336 -0
- package/src/command-policy.ts +7 -0
- package/src/config-accessors.test.ts +34 -0
- package/src/config-accessors.ts +22 -0
- package/src/config-schema.test.ts +121 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +24 -0
- package/src/connection-controller-registry.test.ts +27 -0
- package/src/connection-controller-registry.ts +49 -0
- package/src/connection-controller.test.ts +282 -0
- package/src/connection-controller.ts +679 -0
- package/src/creds-files.ts +19 -0
- package/src/creds-persistence.ts +102 -0
- package/src/directory-config.test.ts +60 -0
- package/src/directory-config.ts +40 -0
- package/src/directory-contract.test.ts +56 -0
- package/src/doctor-contract.ts +11 -0
- package/src/doctor.test.ts +74 -0
- package/src/doctor.ts +56 -0
- package/src/group-intro.ts +15 -0
- package/src/group-policy.test.ts +36 -0
- package/src/group-policy.ts +40 -0
- package/src/group-session-contract.ts +20 -0
- package/src/group-session-key.test.ts +53 -0
- package/src/group-session-key.ts +41 -0
- package/src/heartbeat-recipients.runtime.ts +6 -0
- package/src/heartbeat-recipients.test.ts +203 -0
- package/src/heartbeat-recipients.ts +104 -0
- package/src/heartbeat.ts +34 -0
- package/src/identity.ts +164 -0
- package/src/inbound/access-control.test-harness.ts +37 -0
- package/src/inbound/access-control.test.ts +375 -0
- package/src/inbound/access-control.ts +237 -0
- package/src/inbound/dedupe.ts +132 -0
- package/src/inbound/extract.test.ts +282 -0
- package/src/inbound/extract.ts +488 -0
- package/src/inbound/lifecycle.ts +39 -0
- package/src/inbound/media.node.test.ts +83 -0
- package/src/inbound/media.ts +102 -0
- package/src/inbound/monitor.ts +890 -0
- package/src/inbound/runtime-api.ts +7 -0
- package/src/inbound/save-media.runtime.ts +1 -0
- package/src/inbound/send-api.test.ts +307 -0
- package/src/inbound/send-api.ts +141 -0
- package/src/inbound/send-result.ts +61 -0
- package/src/inbound/types.ts +106 -0
- package/src/inbound-context.contract.test.ts +32 -0
- package/src/inbound-policy.ts +231 -0
- package/src/inbound.media.test.ts +320 -0
- package/src/inbound.test.ts +290 -0
- package/src/inbound.ts +9 -0
- package/src/login-qr.test.ts +483 -0
- package/src/login-qr.ts +542 -0
- package/src/login.coverage.test.ts +133 -0
- package/src/login.test.ts +89 -0
- package/src/login.ts +70 -0
- package/src/logout.test.ts +162 -0
- package/src/media.test.ts +480 -0
- package/src/media.ts +10 -0
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +400 -0
- package/src/monitor-inbox.append-upsert.test-support.ts +133 -0
- package/src/monitor-inbox.behavior.test.ts +5 -0
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +362 -0
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +306 -0
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +729 -0
- package/src/monitor-inbox.test-harness.ts +304 -0
- package/src/normalize-target.ts +112 -0
- package/src/normalize.ts +6 -0
- package/src/outbound-adapter.poll.test.ts +62 -0
- package/src/outbound-adapter.sendpayload.test.ts +195 -0
- package/src/outbound-adapter.ts +36 -0
- package/src/outbound-base.test.ts +560 -0
- package/src/outbound-base.ts +244 -0
- package/src/outbound-media-contract.ts +278 -0
- package/src/outbound-media.runtime.ts +36 -0
- package/src/outbound-payload.contract.test.ts +61 -0
- package/src/outbound-send-deps.ts +1 -0
- package/src/outbound-test-support.ts +16 -0
- package/src/pairing-security.test-harness.ts +59 -0
- package/src/qr-image.ts +1 -0
- package/src/qr-terminal.ts +1 -0
- package/src/quoted-message.test.ts +83 -0
- package/src/quoted-message.ts +184 -0
- package/src/reaction-level.test.ts +94 -0
- package/src/reaction-level.ts +21 -0
- package/src/reconnect.test.ts +51 -0
- package/src/reconnect.ts +55 -0
- package/src/resolve-outbound-target.test.ts +265 -0
- package/src/resolve-outbound-target.ts +54 -0
- package/src/resolve-target.test.ts +97 -0
- package/src/runtime-api.ts +60 -0
- package/src/runtime-group-policy.ts +16 -0
- package/src/runtime.ts +9 -0
- package/src/security-contract.ts +47 -0
- package/src/security-fix.ts +71 -0
- package/src/send.test.ts +515 -0
- package/src/send.ts +287 -0
- package/src/session-contract.test.ts +31 -0
- package/src/session-contract.ts +43 -0
- package/src/session-errors.ts +125 -0
- package/src/session-route.ts +26 -0
- package/src/session.runtime.ts +8 -0
- package/src/session.test.ts +559 -0
- package/src/session.ts +330 -0
- package/src/setup-core.ts +52 -0
- package/src/setup-finalize.ts +446 -0
- package/src/setup-surface.test.ts +367 -0
- package/src/setup-surface.ts +69 -0
- package/src/setup-test-helpers.ts +216 -0
- package/src/shared.ts +291 -0
- package/src/socket-timing.test.ts +49 -0
- package/src/socket-timing.ts +38 -0
- package/src/state-migrations.ts +54 -0
- package/src/status-issues.test.ts +137 -0
- package/src/status-issues.ts +185 -0
- package/src/system-prompt.test.ts +199 -0
- package/src/system-prompt.ts +31 -0
- package/src/targets-runtime.ts +180 -0
- package/src/test-helpers.ts +690 -0
- package/src/text-runtime.test.ts +162 -0
- package/src/text-runtime.ts +11 -0
- package/src/vcard.ts +84 -0
- package/targets.ts +5 -0
- package/test-api.ts +2 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createClaimableDedupe } from "openclaw/plugin-sdk/persistent-dedupe";
|
|
2
|
+
|
|
3
|
+
const RECENT_WEB_MESSAGE_TTL_MS = 20 * 60_000;
|
|
4
|
+
const RECENT_WEB_MESSAGE_MAX = 5000;
|
|
5
|
+
const RECENT_OUTBOUND_MESSAGE_TTL_MS = 20 * 60_000;
|
|
6
|
+
const RECENT_OUTBOUND_MESSAGE_MAX = 5000;
|
|
7
|
+
|
|
8
|
+
const claimableInboundMessages = createClaimableDedupe({
|
|
9
|
+
ttlMs: RECENT_WEB_MESSAGE_TTL_MS,
|
|
10
|
+
memoryMaxSize: RECENT_WEB_MESSAGE_MAX,
|
|
11
|
+
});
|
|
12
|
+
const recentOutboundMessages = createRecentMessageCache({
|
|
13
|
+
ttlMs: RECENT_OUTBOUND_MESSAGE_TTL_MS,
|
|
14
|
+
maxSize: RECENT_OUTBOUND_MESSAGE_MAX,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function createRecentMessageCache(options: { ttlMs: number; maxSize: number }) {
|
|
18
|
+
const ttlMs = Math.max(0, options.ttlMs);
|
|
19
|
+
const maxSize = Math.max(0, Math.floor(options.maxSize));
|
|
20
|
+
const cache = new Map<string, number>();
|
|
21
|
+
|
|
22
|
+
const prune = (now: number) => {
|
|
23
|
+
if (ttlMs > 0) {
|
|
24
|
+
const cutoff = now - ttlMs;
|
|
25
|
+
for (const [key, timestamp] of cache) {
|
|
26
|
+
if (timestamp < cutoff) {
|
|
27
|
+
cache.delete(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
while (cache.size > maxSize) {
|
|
32
|
+
const oldest = cache.keys().next().value;
|
|
33
|
+
if (!oldest) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
cache.delete(oldest);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const peek = (key: string | null, now = Date.now()): boolean => {
|
|
41
|
+
if (!key) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const timestamp = cache.get(key);
|
|
45
|
+
if (timestamp === undefined) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (ttlMs > 0 && now - timestamp >= ttlMs) {
|
|
49
|
+
cache.delete(key);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
check: (key: string | null, now = Date.now()): boolean => {
|
|
57
|
+
if (!key) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const existed = peek(key, now);
|
|
61
|
+
cache.delete(key);
|
|
62
|
+
cache.set(key, now);
|
|
63
|
+
prune(now);
|
|
64
|
+
return existed;
|
|
65
|
+
},
|
|
66
|
+
peek,
|
|
67
|
+
clear: () => cache.clear(),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class WhatsAppRetryableInboundError extends Error {
|
|
72
|
+
constructor(message: string, options?: ErrorOptions) {
|
|
73
|
+
super(message, options);
|
|
74
|
+
this.name = "WhatsAppRetryableInboundError";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function buildMessageKey(params: {
|
|
79
|
+
accountId: string;
|
|
80
|
+
remoteJid: string;
|
|
81
|
+
messageId: string;
|
|
82
|
+
}): string | null {
|
|
83
|
+
const accountId = params.accountId.trim();
|
|
84
|
+
const remoteJid = params.remoteJid.trim();
|
|
85
|
+
const messageId = params.messageId.trim();
|
|
86
|
+
if (!accountId || !remoteJid || !messageId || messageId === "unknown") {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return `${accountId}:${remoteJid}:${messageId}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function resetWebInboundDedupe(): void {
|
|
93
|
+
claimableInboundMessages.clearMemory();
|
|
94
|
+
recentOutboundMessages.clear();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function claimRecentInboundMessage(key: string): Promise<boolean> {
|
|
98
|
+
const claim = await claimableInboundMessages.claim(key);
|
|
99
|
+
return claim.kind === "claimed";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function commitRecentInboundMessage(key: string): Promise<void> {
|
|
103
|
+
await claimableInboundMessages.commit(key);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function releaseRecentInboundMessage(key: string, error?: unknown): void {
|
|
107
|
+
claimableInboundMessages.release(key, { error });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function rememberRecentOutboundMessage(params: {
|
|
111
|
+
accountId: string;
|
|
112
|
+
remoteJid: string;
|
|
113
|
+
messageId: string;
|
|
114
|
+
}): void {
|
|
115
|
+
const key = buildMessageKey(params);
|
|
116
|
+
if (!key) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
recentOutboundMessages.check(key);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function isRecentOutboundMessage(params: {
|
|
123
|
+
accountId: string;
|
|
124
|
+
remoteJid: string;
|
|
125
|
+
messageId: string;
|
|
126
|
+
}): boolean {
|
|
127
|
+
const key = buildMessageKey(params);
|
|
128
|
+
if (!key) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return recentOutboundMessages.peek(key);
|
|
132
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import type { proto } from "@whiskeysockets/baileys";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { extractMentionedJids, hasInboundUserContent } from "./extract.js";
|
|
4
|
+
|
|
5
|
+
describe("extractMentionedJids", () => {
|
|
6
|
+
const botJid = "5511999999999@s.whatsapp.net";
|
|
7
|
+
const otherJid = "5511888888888@s.whatsapp.net";
|
|
8
|
+
|
|
9
|
+
it("returns direct mentions from the current message", () => {
|
|
10
|
+
const message: proto.IMessage = {
|
|
11
|
+
extendedTextMessage: {
|
|
12
|
+
text: "Hey @bot",
|
|
13
|
+
contextInfo: {
|
|
14
|
+
mentionedJid: [botJid],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
expect(extractMentionedJids(message)).toEqual([botJid]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("ignores mentionedJids from quoted messages", () => {
|
|
22
|
+
const message: proto.IMessage = {
|
|
23
|
+
extendedTextMessage: {
|
|
24
|
+
text: "I agree",
|
|
25
|
+
contextInfo: {
|
|
26
|
+
// The quoted message originally @mentioned the bot, but the
|
|
27
|
+
// current message does not — this should NOT leak through.
|
|
28
|
+
quotedMessage: {
|
|
29
|
+
extendedTextMessage: {
|
|
30
|
+
text: "Hey @bot what do you think?",
|
|
31
|
+
contextInfo: {
|
|
32
|
+
mentionedJid: [botJid],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
expect(extractMentionedJids(message)).toBeUndefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("returns direct mentions even when quoted message also has mentions", () => {
|
|
43
|
+
const message: proto.IMessage = {
|
|
44
|
+
extendedTextMessage: {
|
|
45
|
+
text: "Hey @other",
|
|
46
|
+
contextInfo: {
|
|
47
|
+
mentionedJid: [otherJid],
|
|
48
|
+
quotedMessage: {
|
|
49
|
+
extendedTextMessage: {
|
|
50
|
+
text: "Hey @bot",
|
|
51
|
+
contextInfo: {
|
|
52
|
+
mentionedJid: [botJid],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
// Should return only the direct mention, not the quoted one.
|
|
60
|
+
expect(extractMentionedJids(message)).toEqual([otherJid]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("returns mentions from media message types", () => {
|
|
64
|
+
const message: proto.IMessage = {
|
|
65
|
+
imageMessage: {
|
|
66
|
+
contextInfo: {
|
|
67
|
+
mentionedJid: [botJid],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
expect(extractMentionedJids(message)).toEqual([botJid]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("returns undefined for messages with no mentions", () => {
|
|
75
|
+
const message: proto.IMessage = {
|
|
76
|
+
extendedTextMessage: {
|
|
77
|
+
text: "Just a regular message",
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
expect(extractMentionedJids(message)).toBeUndefined();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("returns undefined for undefined input", () => {
|
|
84
|
+
expect(extractMentionedJids(undefined)).toBeUndefined();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("deduplicates mentions across message types", () => {
|
|
88
|
+
const message: proto.IMessage = {
|
|
89
|
+
extendedTextMessage: {
|
|
90
|
+
text: "Hey @bot",
|
|
91
|
+
contextInfo: {
|
|
92
|
+
mentionedJid: [botJid],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
imageMessage: {
|
|
96
|
+
contextInfo: {
|
|
97
|
+
mentionedJid: [botJid],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
expect(extractMentionedJids(message)).toEqual([botJid]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("hasInboundUserContent", () => {
|
|
106
|
+
it("returns true for plain text conversation", () => {
|
|
107
|
+
expect(hasInboundUserContent({ conversation: "hello" })).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("returns true for extendedTextMessage", () => {
|
|
111
|
+
expect(
|
|
112
|
+
hasInboundUserContent({ extendedTextMessage: { text: "hello" } } as proto.IMessage),
|
|
113
|
+
).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("returns true for image message", () => {
|
|
117
|
+
expect(
|
|
118
|
+
hasInboundUserContent({ imageMessage: { mimetype: "image/png" } } as proto.IMessage),
|
|
119
|
+
).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("returns true for video message", () => {
|
|
123
|
+
expect(
|
|
124
|
+
hasInboundUserContent({ videoMessage: { mimetype: "video/mp4" } } as proto.IMessage),
|
|
125
|
+
).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("returns true for audio message", () => {
|
|
129
|
+
expect(
|
|
130
|
+
hasInboundUserContent({ audioMessage: { mimetype: "audio/ogg" } } as proto.IMessage),
|
|
131
|
+
).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("returns true for document message", () => {
|
|
135
|
+
expect(
|
|
136
|
+
hasInboundUserContent({
|
|
137
|
+
documentMessage: { fileName: "x.pdf" },
|
|
138
|
+
} as proto.IMessage),
|
|
139
|
+
).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("returns true for sticker message", () => {
|
|
143
|
+
expect(
|
|
144
|
+
hasInboundUserContent({ stickerMessage: { mimetype: "image/webp" } } as proto.IMessage),
|
|
145
|
+
).toBe(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("returns true for location message with valid coords", () => {
|
|
149
|
+
expect(
|
|
150
|
+
hasInboundUserContent({
|
|
151
|
+
locationMessage: { degreesLatitude: 1, degreesLongitude: 2 },
|
|
152
|
+
} as proto.IMessage),
|
|
153
|
+
).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("returns true for live location message with valid coords", () => {
|
|
157
|
+
expect(
|
|
158
|
+
hasInboundUserContent({
|
|
159
|
+
liveLocationMessage: { degreesLatitude: 1, degreesLongitude: 2 },
|
|
160
|
+
} as proto.IMessage),
|
|
161
|
+
).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("returns true for contact message", () => {
|
|
165
|
+
expect(
|
|
166
|
+
hasInboundUserContent({
|
|
167
|
+
contactMessage: { displayName: "Alice", vcard: "BEGIN:VCARD\nEND:VCARD" },
|
|
168
|
+
} as proto.IMessage),
|
|
169
|
+
).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("returns true for contactsArrayMessage via contact placeholder extraction", () => {
|
|
173
|
+
expect(
|
|
174
|
+
hasInboundUserContent({
|
|
175
|
+
contactsArrayMessage: {
|
|
176
|
+
contacts: [{ displayName: "Alice", vcard: "BEGIN:VCARD\nEND:VCARD" }],
|
|
177
|
+
},
|
|
178
|
+
} as proto.IMessage),
|
|
179
|
+
).toBe(true);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("returns true for buttons response (user button click)", () => {
|
|
183
|
+
expect(
|
|
184
|
+
hasInboundUserContent({
|
|
185
|
+
buttonsResponseMessage: {
|
|
186
|
+
selectedButtonId: "yes",
|
|
187
|
+
selectedDisplayText: "Yes",
|
|
188
|
+
},
|
|
189
|
+
} as proto.IMessage),
|
|
190
|
+
).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("returns true for list response (user list selection)", () => {
|
|
194
|
+
expect(
|
|
195
|
+
hasInboundUserContent({
|
|
196
|
+
listResponseMessage: {
|
|
197
|
+
title: "Option A",
|
|
198
|
+
singleSelectReply: { selectedRowId: "a" },
|
|
199
|
+
} as unknown as proto.Message.IListResponseMessage,
|
|
200
|
+
} as proto.IMessage),
|
|
201
|
+
).toBe(true);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("returns true for template button reply", () => {
|
|
205
|
+
expect(
|
|
206
|
+
hasInboundUserContent({
|
|
207
|
+
templateButtonReplyMessage: {
|
|
208
|
+
selectedId: "btn-1",
|
|
209
|
+
selectedDisplayText: "Click",
|
|
210
|
+
} as unknown as proto.Message.ITemplateButtonReplyMessage,
|
|
211
|
+
} as proto.IMessage),
|
|
212
|
+
).toBe(true);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("returns true for interactive response", () => {
|
|
216
|
+
expect(
|
|
217
|
+
hasInboundUserContent({
|
|
218
|
+
interactiveResponseMessage: {
|
|
219
|
+
body: { text: "x" },
|
|
220
|
+
nativeFlowResponseMessage: { name: "n", paramsJson: "{}" },
|
|
221
|
+
} as unknown as proto.Message.IInteractiveResponseMessage,
|
|
222
|
+
} as proto.IMessage),
|
|
223
|
+
).toBe(true);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("returns true for buttons response wrapped in ephemeralMessage (regression for #73797 + greptile review)", () => {
|
|
227
|
+
expect(
|
|
228
|
+
hasInboundUserContent({
|
|
229
|
+
ephemeralMessage: {
|
|
230
|
+
message: {
|
|
231
|
+
buttonsResponseMessage: {
|
|
232
|
+
selectedButtonId: "ok",
|
|
233
|
+
selectedDisplayText: "OK",
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
} as proto.IMessage),
|
|
238
|
+
).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("returns false for undefined message (regression for #73797)", () => {
|
|
242
|
+
expect(hasInboundUserContent(undefined)).toBe(false);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("returns false for empty message object (no content keys)", () => {
|
|
246
|
+
expect(hasInboundUserContent({} as proto.IMessage)).toBe(false);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("returns false for protocol message envelope without inner content (regression for #73797)", () => {
|
|
250
|
+
expect(
|
|
251
|
+
hasInboundUserContent({
|
|
252
|
+
protocolMessage: {
|
|
253
|
+
type: 0,
|
|
254
|
+
} as unknown as proto.Message.IProtocolMessage,
|
|
255
|
+
} as proto.IMessage),
|
|
256
|
+
).toBe(false);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("returns false for receipt-style senderKeyDistribution-only payload (regression for #73797)", () => {
|
|
260
|
+
expect(
|
|
261
|
+
hasInboundUserContent({
|
|
262
|
+
senderKeyDistributionMessage: {
|
|
263
|
+
groupId: "g@example",
|
|
264
|
+
} as unknown as proto.Message.ISenderKeyDistributionMessage,
|
|
265
|
+
} as proto.IMessage),
|
|
266
|
+
).toBe(false);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("returns false when location coords are missing (incomplete event, regression for #73797)", () => {
|
|
270
|
+
expect(
|
|
271
|
+
hasInboundUserContent({
|
|
272
|
+
locationMessage: { name: "no coords" },
|
|
273
|
+
} as proto.IMessage),
|
|
274
|
+
).toBe(false);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("returns false when extendedTextMessage has only empty text", () => {
|
|
278
|
+
expect(hasInboundUserContent({ extendedTextMessage: { text: " " } } as proto.IMessage)).toBe(
|
|
279
|
+
false,
|
|
280
|
+
);
|
|
281
|
+
});
|
|
282
|
+
});
|