|
1 | 1 | // Whatsapp plugin module implements monitor behavior. |
| 2 | +import type { WAMessageKey } from "baileys"; |
2 | 3 | import { resolveAccountEntry } from "openclaw/plugin-sdk/account-core"; |
3 | 4 | import { CHANNEL_APPROVAL_NATIVE_RUNTIME_CONTEXT_CAPABILITY } from "openclaw/plugin-sdk/approval-handler-runtime"; |
4 | 5 | import { resolveInboundDebounceMs } from "openclaw/plugin-sdk/channel-inbound-debounce"; |
@@ -27,7 +28,13 @@ import { |
27 | 28 | } from "../connection-controller.js"; |
28 | 29 | import { resolveWhatsAppInboundPolicy } from "../inbound-policy.js"; |
29 | 30 | import { normalizeWebInboundMessage } from "../inbound/message-aliases.js"; |
30 | | -import { attachWebInboxToSocket, type WhatsAppGroupMetadataCache } from "../inbound/monitor.js"; |
| 31 | +import { |
| 32 | + attachWebInboxToSocket, |
| 33 | + readWhatsAppBaileysCacheEntry, |
| 34 | + type WhatsAppBaileysGroupMetadataCache, |
| 35 | + type WhatsAppBaileysMessageCache, |
| 36 | + type WhatsAppGroupMetadataCache, |
| 37 | +} from "../inbound/monitor.js"; |
31 | 38 | import type { WebInboundMessageInput } from "../inbound/types.js"; |
32 | 39 | import { |
33 | 40 | newConnectionId, |
@@ -193,10 +200,8 @@ export async function monitorWebChannel( |
193 | 200 | >(); |
194 | 201 | const groupMemberNames = new Map<string, Map<string, string>>(); |
195 | 202 | const groupMetadataCache: WhatsAppGroupMetadataCache = new Map(); |
196 | | - // Bounded in-memory message store for Baileys getMessage retry support. |
197 | | - const recentMessageKeys = new Map<string, import("baileys").proto.IMessage>(); |
198 | | - // Baileys-level group metadata cache for cachedGroupMetadata socket option. |
199 | | - const baileysGroupMetaCache = new Map<string, import("baileys").GroupMetadata>(); |
| 203 | + const recentMessageKeys: WhatsAppBaileysMessageCache = new Map(); |
| 204 | + const baileysGroupMetaCache: WhatsAppBaileysGroupMetadataCache = new Map(); |
200 | 205 | const echoTracker = createEchoTracker({ maxItems: 100, logVerbose }); |
201 | 206 |
|
202 | 207 | const sleep = |
@@ -272,13 +277,14 @@ export async function monitorWebChannel( |
272 | 277 | try { |
273 | 278 | connection = await controller.openConnection({ |
274 | 279 | connectionId, |
275 | | - getMessage: async (key: import("baileys").WAMessageKey) => { |
276 | | - if (!key.id || !key.remoteJid) { |
277 | | - return undefined; |
278 | | - } |
279 | | - return recentMessageKeys.get(`${key.remoteJid}:${key.id}`); |
| 280 | + getMessage: async (key: WAMessageKey) => |
| 281 | + key.id && key.remoteJid |
| 282 | + ? readWhatsAppBaileysCacheEntry(recentMessageKeys, `${key.remoteJid}:${key.id}`) |
| 283 | + : undefined, |
| 284 | + cachedGroupMetadata: async (jid: string) => { |
| 285 | + const meta = readWhatsAppBaileysCacheEntry(baileysGroupMetaCache, jid); |
| 286 | + return meta?.participants?.length ? meta : undefined; |
280 | 287 | }, |
281 | | - cachedGroupMetadata: async (jid: string) => baileysGroupMetaCache.get(jid), |
282 | 288 | createListener: async ({ sock, connection: connectionLocal }) => { |
283 | 289 | const onMessage = createWebOnMessageHandler({ |
284 | 290 | cfg, |
|
0 commit comments