mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 04:50:51 +00:00
* refactor: move WhatsApp channel from src/web/ to extensions/whatsapp/ Move all WhatsApp implementation code (77 source/test files + 9 channel plugin files) from src/web/ and src/channels/plugins/*/whatsapp* to extensions/whatsapp/src/. - Leave thin re-export shims at all original locations so cross-cutting imports continue to resolve - Update plugin-sdk/whatsapp.ts to only re-export generic framework utilities; channel-specific functions imported locally by the extension - Update vi.mock paths in 15 cross-cutting test files - Rename outbound.ts -> send.ts to match extension naming conventions and avoid false positive in cfg-threading guard test - Widen tsconfig.plugin-sdk.dts.json rootDir to support shim->extension cross-directory references Part of the core-channels-to-extensions migration (PR 6/10). * style: format WhatsApp extension files * fix: correct stale import paths in WhatsApp extension tests Fix vi.importActual, test mock, and hardcoded source paths that weren't updated during the file move: - media.test.ts: vi.importActual path - onboarding.test.ts: vi.importActual path - test-helpers.ts: test/mocks/baileys.js path - monitor-inbox.test-harness.ts: incomplete media/store mock - login.test.ts: hardcoded source file path - message-action-runner.media.test.ts: vi.mock/importActual path
74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import {
|
|
asString,
|
|
collectIssuesForEnabledAccounts,
|
|
isRecord,
|
|
} from "../../../src/channels/plugins/status-issues/shared.js";
|
|
import type {
|
|
ChannelAccountSnapshot,
|
|
ChannelStatusIssue,
|
|
} from "../../../src/channels/plugins/types.js";
|
|
import { formatCliCommand } from "../../../src/cli/command-format.js";
|
|
|
|
type WhatsAppAccountStatus = {
|
|
accountId?: unknown;
|
|
enabled?: unknown;
|
|
linked?: unknown;
|
|
connected?: unknown;
|
|
running?: unknown;
|
|
reconnectAttempts?: unknown;
|
|
lastError?: unknown;
|
|
};
|
|
|
|
function readWhatsAppAccountStatus(value: ChannelAccountSnapshot): WhatsAppAccountStatus | null {
|
|
if (!isRecord(value)) {
|
|
return null;
|
|
}
|
|
return {
|
|
accountId: value.accountId,
|
|
enabled: value.enabled,
|
|
linked: value.linked,
|
|
connected: value.connected,
|
|
running: value.running,
|
|
reconnectAttempts: value.reconnectAttempts,
|
|
lastError: value.lastError,
|
|
};
|
|
}
|
|
|
|
export function collectWhatsAppStatusIssues(
|
|
accounts: ChannelAccountSnapshot[],
|
|
): ChannelStatusIssue[] {
|
|
return collectIssuesForEnabledAccounts({
|
|
accounts,
|
|
readAccount: readWhatsAppAccountStatus,
|
|
collectIssues: ({ account, accountId, issues }) => {
|
|
const linked = account.linked === true;
|
|
const running = account.running === true;
|
|
const connected = account.connected === true;
|
|
const reconnectAttempts =
|
|
typeof account.reconnectAttempts === "number" ? account.reconnectAttempts : null;
|
|
const lastError = asString(account.lastError);
|
|
|
|
if (!linked) {
|
|
issues.push({
|
|
channel: "whatsapp",
|
|
accountId,
|
|
kind: "auth",
|
|
message: "Not linked (no WhatsApp Web session).",
|
|
fix: `Run: ${formatCliCommand("openclaw channels login")} (scan QR on the gateway host).`,
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (running && !connected) {
|
|
issues.push({
|
|
channel: "whatsapp",
|
|
accountId,
|
|
kind: "runtime",
|
|
message: `Linked but disconnected${reconnectAttempts != null ? ` (reconnectAttempts=${reconnectAttempts})` : ""}${lastError ? `: ${lastError}` : "."}`,
|
|
fix: `Run: ${formatCliCommand("openclaw doctor")} (or restart the gateway). If it persists, relink via channels login and check logs.`,
|
|
});
|
|
}
|
|
},
|
|
});
|
|
}
|