|
1 | | -import type { OpenClawConfig } from "../config/types.openclaw.js"; |
2 | 1 | import { |
3 | 2 | drainPendingDeliveries as coreDrainPendingDeliveries, |
4 | 3 | type DeliverFn, |
5 | | -type RecoveryLogger, |
6 | 4 | } from "../infra/outbound/delivery-queue.js"; |
7 | 5 | |
8 | 6 | // Public runtime/transport helpers for plugins that need shared infra behavior. |
9 | 7 | |
10 | | -function normalizeWhatsAppReconnectAccountId(accountId?: string): string { |
11 | | -return (accountId ?? "").trim() || "default"; |
12 | | -} |
13 | | - |
14 | | -const WHATSAPP_NO_LISTENER_ERROR_RE = /No active WhatsApp Web listener/i; |
15 | | - |
16 | 8 | type OutboundDeliverRuntimeModule = typeof import("../infra/outbound/deliver-runtime.js"); |
17 | 9 | type DrainPendingDeliveriesOptions = Omit< |
18 | 10 | Parameters<typeof coreDrainPendingDeliveries>[0], |
@@ -36,37 +28,6 @@ export async function drainPendingDeliveries(opts: DrainPendingDeliveriesOptions
|
36 | 28 | }); |
37 | 29 | } |
38 | 30 | |
39 | | -/** |
40 | | - * @deprecated Prefer plugin-owned reconnect policy wired through |
41 | | - * `drainPendingDeliveries(...)`. This compatibility shim preserves the |
42 | | - * historical public SDK symbol for existing plugin callers. |
43 | | - */ |
44 | | -export async function drainReconnectQueue(opts: { |
45 | | -accountId: string; |
46 | | -cfg: OpenClawConfig; |
47 | | -log: RecoveryLogger; |
48 | | -stateDir?: string; |
49 | | -deliver?: DeliverFn; |
50 | | -}): Promise<void> { |
51 | | -const normalizedAccountId = normalizeWhatsAppReconnectAccountId(opts.accountId); |
52 | | -await drainPendingDeliveries({ |
53 | | -drainKey: `whatsapp:${normalizedAccountId}`, |
54 | | -logLabel: "WhatsApp reconnect drain", |
55 | | -cfg: opts.cfg, |
56 | | -log: opts.log, |
57 | | -stateDir: opts.stateDir, |
58 | | -deliver: opts.deliver, |
59 | | -selectEntry: (entry) => ({ |
60 | | -match: |
61 | | -entry.channel === "whatsapp" && |
62 | | -normalizeWhatsAppReconnectAccountId(entry.accountId) === normalizedAccountId && |
63 | | -typeof entry.lastError === "string" && |
64 | | -WHATSAPP_NO_LISTENER_ERROR_RE.test(entry.lastError), |
65 | | -bypassBackoff: true, |
66 | | -}), |
67 | | -}); |
68 | | -} |
69 | | - |
70 | 31 | export * from "../infra/backoff.js"; |
71 | 32 | export * from "../infra/channel-activity.js"; |
72 | 33 | export * from "../infra/dedupe.js"; |
|