openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
576 lines (575 loc) • 23.9 kB
JavaScript
import "../../redact-BDinS1q9.js";
import "../../errors-BxyFnvP3.js";
import "../../unhandled-rejections-CDJ8dOVP.js";
import "../../logger-kwZIqwuw.js";
import "../../paths-ViKUYWUK.js";
import "../../tmp-openclaw-dir-idKIOMmb.js";
import "../../theme-CdOoMzRk.js";
import "../../globals-DBUMOBZ8.js";
import "../../subsystem-DISldKSB.js";
import "../../ansi-BEJF8NKS.js";
import "../../boolean-C3GkJetE.js";
import "../../env-Dnra1IpT.js";
import "../../warning-filter-CBhOcgHd.js";
import { d as isRecord } from "../../utils-CS0Ikux6.js";
import "../../links-8xRhWBQL.js";
import "../../paths-C4Oy7wjk.js";
import "../../auth-profiles-DRuJBw5y.js";
import { g as DEFAULT_ACCOUNT_ID } from "../../session-key-DAhnzjyr.js";
import "../../agent-scope-bjWqU22i.js";
import "../../boundary-path-Dm0QJ7-y.js";
import "../../boundary-file-read-DcZxlWD8.js";
import "../../logger-BmpSCz93.js";
import "../../exec-B5_AYfQG.js";
import "../../workspace-D4K6QX9X.js";
import "../../model-selection-BnFtDmP7.js";
import "../../io-y3Az_Onx.js";
import "../../shell-env-BOu7XeT_.js";
import "../../safe-text-yavot2qw.js";
import "../../version-CD3oP1-d.js";
import "../../env-substitution-O6uabUmO.js";
import "../../includes-Bj3eLUWH.js";
import "../../zod-schema.providers-core-COy5nBQ0.js";
import "../../legacy-web-search-BB-ZHEhz.js";
import "../../registry-C5UkPpaO.js";
import "../../config-state-Br0ucqMb.js";
import "../../min-host-version-RMBWtIAR.js";
import "../../manifest-registry-B5JNQdOM.js";
import "../../runtime-guard-PhQ6PwQa.js";
import "../../avatar-policy-B5nOfso_.js";
import "../../ip-Ce8EDTBZ.js";
import "../../zod-schema.agent-runtime-Dtg4Jy6G.js";
import "../../zod-schema.core-BuVz8Rk7.js";
import "../../config-D4zN4BRl.js";
import "../../file-lock-DEiVq2ow.js";
import "../../audit-fs-DTQIjp2r.js";
import "../../resolve-B7S4PlnO.js";
import "../../profiles-COPO-hHI.js";
import { t as formatCliCommand } from "../../command-format-DBQUhADm.js";
import "../../tailscale-CxY-91GZ.js";
import "../../tailnet-DHiKSG7V.js";
import "../../net-JAg9zL0G.js";
import "../../auth-Buq0Niri.js";
import "../../credentials-D8pfRimu.js";
import "../../message-channel-BliByQBl.js";
import "../../store-C5UK26Ce.js";
import "../../runtime-Iz8uZ7EU.js";
import "../../plugins-B09-vgme.js";
import "../../sessions-D9ZgHCHb.js";
import "../../paths-rhN9LKM_.js";
import "../../session-write-lock-va3qZE6f.js";
import "../../method-scopes-BiEi0X2g.js";
import "../../call-CQbSO4Fr.js";
import "../../prompt-style-C4CV4Y_p.js";
import "../../ports-lsof-BLEgL_Gn.js";
import "../../restart-stale-pids-BsPvlGJd.js";
import "../../ports-FldL_Lhq.js";
import "../../logging-CznuqaMu.js";
import "../../commands-C6oAw_H-.js";
import "../../issue-format-BtLIwOtN.js";
import "../../identity-Dp-UIak4.js";
import "../../heartbeat-Bdfr_onc.js";
import { Ft as resolveWhatsAppAccount, Hb as defineChannelPluginEntry, Vb as createChatChannelPlugin, bx as resolveWhatsAppGroupIntroHint, dx as looksLikeWhatsAppTargetId, gx as isWhatsAppGroupJid, ix as formatWhatsAppConfigAllowFromEntries, px as normalizeWhatsAppMessagingTarget, vx as normalizeWhatsAppTarget, xx as resolveWhatsAppMentionStripRegexes, yx as createWhatsAppOutboundBase, zb as buildChannelOutboundSessionRoute } from "../../pi-embedded-CbCYZxIb.js";
import "../../internal-hooks-CIUghoK4.js";
import "../../multimodal-B8yEZcl5.js";
import "../../memory-search-B_aq08y5.js";
import "../../provider-catalog-rVN7ZbR5.js";
import "../../secret-input-DXoOLNgb.js";
import "../../bindings-CFudGB9Z.js";
import "../../resolve-route-DwFWP4JW.js";
import "../../routing-zOQ0wwtV.js";
import "../../identity-file-DVLib087.js";
import "../../outbound-runtime-m-y0nd6F.js";
import "../../provider-env-vars-CpUJqT5v.js";
import "../../provider-auth-input-Bus9W_qh.js";
import "../../provider-model-minimax-DSmX4BNO.js";
import "../../provider-models-BKjzpTsb.js";
import "../../anthropic-vertex-provider-B2x4YywE.js";
import "../../provider-catalog-BTgF8VyO.js";
import "../../provider-catalog-D0IlX18O.js";
import "../../provider-catalog-BTmUX0Mp.js";
import "../../provider-catalog-sph_Rl63.js";
import "../../provider-catalog-C7tUyBwV.js";
import "../../provider-catalog-C8dPZpHW.js";
import "../../provider-catalog-BJNff1VI.js";
import "../../provider-catalog-IAdymoqT.js";
import "../../provider-catalog-Bjc7evzh.js";
import "../../models-config.providers.discovery-CjkO08q6.js";
import "../../text-runtime-DVXt5xhi.js";
import "../../tool-catalog-BjSY4C4F.js";
import "../../docker-Bhjg8g2t.js";
import "../../sandbox-DTlKNieF.js";
import { h as readStringParam, i as createActionGate } from "../../common-zReYuoMM.js";
import "../../image-ops-By4YfyWa.js";
import "../../thinking-CJoSRIGR.js";
import "../../path-alias-guards-CwRM04O1.js";
import "../../sandbox-paths-Cn8i8Jxm.js";
import "../../channel-actions-fV93bLjV.js";
import "../../mime-CsUtzcn2.js";
import "../../ssrf-0bPJMoZR.js";
import "../../fetch-guard-CYl1q2XH.js";
import "../../provider-web-search-COZNygbd.js";
import "../../manager-Bw8JrihM.js";
import "../../config-schema-CPzP2Ds6.js";
import "../../channel-plugin-common-ClptUZHU.js";
import { c as createAsyncComputedAccountStatusAdapter, f as asString, p as collectIssuesForEnabledAccounts, u as createDefaultChannelRuntimeState } from "../../status-helpers-Cflmo90d.js";
import "../../conversation-runtime-nmWgJSXS.js";
import { x as resolveWhatsAppHeartbeatRecipients } from "../../runtime-whatsapp-boundary-XjdkYMz_.js";
import "../../pairing-store-BGKLrjo6.js";
import "../../json-store--JDX3zNL.js";
import "../../secret-file-Bif7RlZ-.js";
import "../../channel-config-schema-CgpS17zB.js";
import "../../setup-binary-C2MYZTCc.js";
import "../../archive-pOxyr9r4.js";
import "../../fs-safe-DZyOgpPN.js";
import "../../signal-cli-install-fVOL9FvX.js";
import "../../setup-wizard-proxy-DoOpOF8S.js";
import "../../setup-BI3ohdrT.js";
import "../../dm-policy-shared-DtcQProI.js";
import "../../runtime-env-DQOYrXVl.js";
import "../../temp-path-B91lt0LF.js";
import "../../diagnostic-CDTtMQBT.js";
import "../../logging-CCTKg_fh.js";
import "../../config-runtime-BYNizC50.js";
import "../../level-overrides-DzIzQ3ZY.js";
import "../../exec-approvals-BF_Qfdq8.js";
import "../../webhook-ingress-D-H5frou.js";
import "../../system-events-BU_NYynX.js";
import "../../ssrf-policy-DYINyIKC.js";
import "../../hook-runtime-BUYmDbaA.js";
import "../../templating-BDXRiJUh.js";
import "../../channel-reply-pipeline-BxH4-AP2.js";
import "../../reply-history-n7nOPLta.js";
import "../../commands-registry.data-BFXJWoqi.js";
import "../../commands-registry-Bh9pJ817.js";
import "../../frontmatter-CP5371Rm.js";
import "../../env-overrides-BNSo89u5.js";
import "../../skills-M0AZJeXx.js";
import "../../skills-remote-BHxDA4Jw.js";
import "../../workspace-dirs-DqDLiRvZ.js";
import "../../pairing-token-DAszGmwD.js";
import "../../skill-commands-D73dGR_l.js";
import "../../config-CLRQPUSt.js";
import "../../routes-XT2JfvT-.js";
import "../../ssh-tunnel-LM52qY6N.js";
import "../../server-middleware-BP59C6FL.js";
import "../../provider-auth-ref-CQEp9sp3.js";
import "../../provider-auth-helpers-Do3RFvdi.js";
import "../../provider-api-key-auth-BEeRW3dq.js";
import "../../pairing-labels-D27Y4Vv6.js";
import "../../directory-runtime-D9Y42mW-.js";
import "../../read-only-account-inspect-CJPRBFj7.js";
import "../../src-BoNU6eQs.js";
import "../../web-media-PKy3RbRG.js";
import "../../media-understanding-BDOSvuM9.js";
import "../../web-media-CiSbdGPs.js";
import "../../state-paths-Dvb3Mfl3.js";
import "../../llm-task-Br6Ixjlh.js";
import "../../pi-model-discovery-DO3tFksS.js";
import "../../exec-inline-eval-CpmxWJsW.js";
import "../../target-registry-9OUOvlxj.js";
import "../../external-content-DZI9vlJn.js";
import "../../brave-onFD06fq.js";
import "../../duckduckgo-CZuAOfiQ.js";
import "../../exa-5bwgY04k.js";
import "../../security-runtime-xlw0Fxx2.js";
import "../../provider-usage-ClxTGn5c.js";
import "../../provider-models-Bjv0V4OP.js";
import "../../media-understanding-provider-DllGbg-v.js";
import "../../media-understanding-provider-BDq4rFL-.js";
import "../../provider-onboard-CSnPvkMM.js";
import "../../onboard-BU8aRvq7.js";
import "../../perplexity-web-search-provider-CI38RNUU.js";
import "../../perplexity-CMZbsreI.js";
import "../../model-definitions-CLagLj0g.js";
import "../../onboard-0P7GBI2D.js";
import "../../provider-catalog-CKHo9CRM.js";
import "../../provider-models-Dmjtw6kn.js";
import "../../stream-C-KGzzT0.js";
import "../../web-search-CO1hvu_l.js";
import "../../stagger-CFqdtCYL.js";
import "../../command-secret-targets-DLs8jC2H.js";
import "../../delivery-queue-DHURMSqX.js";
import "../../channel-summary-Ctrv7moa.js";
import "../../follow-redirects-CVAaqIk4.js";
import "../../tool-policy-match-DQWWRSN4.js";
import "../../runtime-CAdCdG-M.js";
import "../../channel-status-BfM90KqH.js";
import "../../discord-core-DLbIyXWy.js";
import "../../cli-runtime-Cx1v7N7v.js";
import "../../config-presence-DA3j8Nmi.js";
import "../../query-expansion-BOJBTXsp.js";
import "../../search-manager-DNBHwaee.js";
import "../../acp-runtime-BHZj-SLU.js";
import "../../telegram-core-DD8gCuaX.js";
import "../../audit-BI48Fi3j.js";
import "../../gateway-runtime-Dn2qAGY7.js";
import "../../connection-auth-Nl2a3tDb.js";
import "../../mcp-config-CDIWSqVk.js";
import { t as createPluginRuntimeStore } from "../../runtime-store-CpniCRIn.js";
import "../../setup-tools-CYv8hVOc.js";
import { n as buildDmGroupAccountAllowlistAdapter } from "../../allowlist-config-edit-DBeLbvpH.js";
import { a as resolveWhatsAppGroupToolPolicy, i as resolveWhatsAppGroupRequireMention, n as listWhatsAppDirectoryPeersFromConfig, r as resolveWhatsAppOutboundTarget, t as listWhatsAppDirectoryGroupsFromConfig } from "../../whatsapp-core-BTUSucnn.js";
import "../../active-listener-Dbfg0fFk.js";
import { f as whatsappSetupAdapter } from "../../channel.runtime-Cu2TxQlg.js";
import "../../session-BFZksknu.js";
import { i as whatsappSetupWizardProxy, n as createWhatsAppPluginBase, r as loadWhatsAppChannelRuntime, t as WHATSAPP_CHANNEL } from "../../shared-Dfpk7lLm.js";
//#region extensions/whatsapp/src/runtime.ts
const { setRuntime: setWhatsAppRuntime, getRuntime: getWhatsAppRuntime } = createPluginRuntimeStore("WhatsApp runtime not initialized");
//#endregion
//#region extensions/whatsapp/src/session-route.ts
function resolveWhatsAppOutboundSessionRoute(params) {
const normalized = normalizeWhatsAppTarget(params.target);
if (!normalized) return null;
const isGroup = isWhatsAppGroupJid(normalized);
return buildChannelOutboundSessionRoute({
cfg: params.cfg,
agentId: params.agentId,
channel: "whatsapp",
accountId: params.accountId,
peer: {
kind: isGroup ? "group" : "direct",
id: normalized
},
chatType: isGroup ? "group" : "direct",
from: normalized,
to: normalized
});
}
//#endregion
//#region extensions/whatsapp/src/status-issues.ts
function readWhatsAppAccountStatus(value) {
if (!isRecord(value)) return null;
return {
accountId: value.accountId,
enabled: value.enabled,
linked: value.linked,
connected: value.connected,
running: value.running,
reconnectAttempts: value.reconnectAttempts,
lastInboundAt: value.lastInboundAt,
lastError: value.lastError,
healthState: value.healthState
};
}
function collectWhatsAppStatusIssues(accounts) {
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 lastInboundAt = typeof account.lastInboundAt === "number" ? account.lastInboundAt : null;
const lastError = asString(account.lastError);
const healthState = asString(account.healthState);
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 (healthState === "stale") {
const staleSuffix = lastInboundAt != null ? ` (last inbound ${Math.max(0, Math.floor((Date.now() - lastInboundAt) / 6e4))}m ago)` : "";
issues.push({
channel: "whatsapp",
accountId,
kind: "runtime",
message: `Linked but stale${staleSuffix}${lastError ? `: ${lastError}` : "."}`,
fix: `Run: ${formatCliCommand("openclaw doctor")} (or restart the gateway). If it persists, relink via channels login and check logs.`
});
return;
}
if (healthState === "reconnecting" || healthState === "conflict" || healthState === "stopped") {
const stateLabel = healthState === "conflict" ? "session conflict" : healthState === "reconnecting" ? "reconnecting" : "stopped";
issues.push({
channel: "whatsapp",
accountId,
kind: "runtime",
message: `Linked but ${stateLabel}${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.`
});
return;
}
if (healthState === "logged-out") {
issues.push({
channel: "whatsapp",
accountId,
kind: "auth",
message: `Linked session logged out${lastError ? `: ${lastError}` : "."}`,
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.`
});
}
});
}
//#endregion
//#region extensions/whatsapp/src/channel.ts
function normalizeWhatsAppPayloadText(text) {
return (text ?? "").replace(/^(?:[ \t]*\r?\n)+/, "");
}
function parseWhatsAppExplicitTarget(raw) {
const normalized = normalizeWhatsAppTarget(raw);
if (!normalized) return null;
return {
to: normalized,
chatType: isWhatsAppGroupJid(normalized) ? "group" : "direct"
};
}
const whatsappPlugin = createChatChannelPlugin({
pairing: { idLabel: "whatsappSenderId" },
outbound: {
...createWhatsAppOutboundBase({
chunker: (text, limit) => getWhatsAppRuntime().channel.text.chunkText(text, limit),
sendMessageWhatsApp: async (...args) => await getWhatsAppRuntime().channel.whatsapp.sendMessageWhatsApp(...args),
sendPollWhatsApp: async (...args) => await getWhatsAppRuntime().channel.whatsapp.sendPollWhatsApp(...args),
shouldLogVerbose: () => getWhatsAppRuntime().logging.shouldLogVerbose(),
resolveTarget: ({ to, allowFrom, mode }) => resolveWhatsAppOutboundTarget({
to,
allowFrom,
mode
})
}),
normalizePayload: ({ payload }) => ({
...payload,
text: normalizeWhatsAppPayloadText(payload.text)
})
},
base: {
...createWhatsAppPluginBase({
groups: {
resolveRequireMention: resolveWhatsAppGroupRequireMention,
resolveToolPolicy: resolveWhatsAppGroupToolPolicy,
resolveGroupIntroHint: resolveWhatsAppGroupIntroHint
},
setupWizard: whatsappSetupWizardProxy,
setup: whatsappSetupAdapter,
isConfigured: async (account) => await getWhatsAppRuntime().channel.whatsapp.webAuthExists(account.authDir)
}),
agentTools: () => [getWhatsAppRuntime().channel.whatsapp.createLoginTool()],
allowlist: buildDmGroupAccountAllowlistAdapter({
channelId: "whatsapp",
resolveAccount: resolveWhatsAppAccount,
normalize: ({ values }) => formatWhatsAppConfigAllowFromEntries(values),
resolveDmAllowFrom: (account) => account.allowFrom,
resolveGroupAllowFrom: (account) => account.groupAllowFrom,
resolveDmPolicy: (account) => account.dmPolicy,
resolveGroupPolicy: (account) => account.groupPolicy
}),
mentions: { stripRegexes: ({ ctx }) => resolveWhatsAppMentionStripRegexes(ctx) },
commands: {
enforceOwnerForCommands: true,
skipWhenConfigEmpty: true
},
messaging: {
normalizeTarget: normalizeWhatsAppMessagingTarget,
resolveOutboundSessionRoute: (params) => resolveWhatsAppOutboundSessionRoute(params),
parseExplicitTarget: ({ raw }) => parseWhatsAppExplicitTarget(raw),
inferTargetChatType: ({ to }) => parseWhatsAppExplicitTarget(to)?.chatType,
targetResolver: {
looksLikeId: looksLikeWhatsAppTargetId,
hint: "<E.164|group JID>"
}
},
directory: {
self: async ({ cfg, accountId }) => {
const account = resolveWhatsAppAccount({
cfg,
accountId
});
const { e164, jid } = (await loadWhatsAppChannelRuntime()).readWebSelfId(account.authDir);
const id = e164 ?? jid;
if (!id) return null;
return {
kind: "user",
id,
name: account.name,
raw: {
e164,
jid
}
};
},
listPeers: async (params) => listWhatsAppDirectoryPeersFromConfig(params),
listGroups: async (params) => listWhatsAppDirectoryGroupsFromConfig(params)
},
actions: {
describeMessageTool: ({ cfg }) => {
if (!cfg.channels?.whatsapp) return null;
const gate = createActionGate(cfg.channels.whatsapp.actions);
const actions = /* @__PURE__ */ new Set();
if (gate("reactions")) actions.add("react");
if (gate("polls")) actions.add("poll");
return { actions: Array.from(actions) };
},
supportsAction: ({ action }) => action === "react",
handleAction: async ({ action, params, cfg, accountId }) => {
if (action !== "react") throw new Error(`Action ${action} is not supported for provider ${WHATSAPP_CHANNEL}.`);
const messageId = readStringParam(params, "messageId", { required: true });
const emoji = readStringParam(params, "emoji", { allowEmpty: true });
const remove = typeof params.remove === "boolean" ? params.remove : void 0;
return await getWhatsAppRuntime().channel.whatsapp.handleWhatsAppAction({
action: "react",
chatJid: readStringParam(params, "chatJid") ?? readStringParam(params, "to", { required: true }),
messageId,
emoji,
remove,
participant: readStringParam(params, "participant"),
accountId: accountId ?? void 0,
fromMe: typeof params.fromMe === "boolean" ? params.fromMe : void 0
}, cfg);
}
},
auth: { login: async ({ cfg, accountId, runtime, verbose }) => {
const resolvedAccountId = accountId?.trim() || whatsappPlugin.config.defaultAccountId?.(cfg) || "default";
await (await loadWhatsAppChannelRuntime()).loginWeb(Boolean(verbose), void 0, runtime, resolvedAccountId);
} },
heartbeat: {
checkReady: async ({ cfg, accountId, deps }) => {
if (cfg.web?.enabled === false) return {
ok: false,
reason: "whatsapp-disabled"
};
const account = resolveWhatsAppAccount({
cfg,
accountId
});
if (!await (deps?.webAuthExists ?? (await loadWhatsAppChannelRuntime()).webAuthExists)(account.authDir)) return {
ok: false,
reason: "whatsapp-not-linked"
};
if (!(deps?.hasActiveWebListener ? deps.hasActiveWebListener() : Boolean((await loadWhatsAppChannelRuntime()).getActiveWebListener()))) return {
ok: false,
reason: "whatsapp-not-running"
};
return {
ok: true,
reason: "ok"
};
},
resolveRecipients: ({ cfg, opts }) => resolveWhatsAppHeartbeatRecipients(cfg, opts)
},
status: createAsyncComputedAccountStatusAdapter({
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID, {
connected: false,
reconnectAttempts: 0,
lastConnectedAt: null,
lastDisconnect: null,
lastInboundAt: null,
lastMessageAt: null,
lastEventAt: null,
healthState: "stopped"
}),
collectStatusIssues: collectWhatsAppStatusIssues,
buildChannelSummary: async ({ account, snapshot }) => {
const authDir = account.authDir;
const linked = typeof snapshot.linked === "boolean" ? snapshot.linked : authDir ? await (await loadWhatsAppChannelRuntime()).webAuthExists(authDir) : false;
return {
configured: linked,
linked,
authAgeMs: linked && authDir ? (await loadWhatsAppChannelRuntime()).getWebAuthAgeMs(authDir) : null,
self: linked && authDir ? (await loadWhatsAppChannelRuntime()).readWebSelfId(authDir) : {
e164: null,
jid: null
},
running: snapshot.running ?? false,
connected: snapshot.connected ?? false,
lastConnectedAt: snapshot.lastConnectedAt ?? null,
lastDisconnect: snapshot.lastDisconnect ?? null,
reconnectAttempts: snapshot.reconnectAttempts,
lastInboundAt: snapshot.lastInboundAt ?? snapshot.lastMessageAt ?? null,
lastMessageAt: snapshot.lastMessageAt ?? null,
lastEventAt: snapshot.lastEventAt ?? null,
lastError: snapshot.lastError ?? null,
healthState: snapshot.healthState ?? void 0
};
},
resolveAccountSnapshot: async ({ account, runtime }) => {
const linked = await (await loadWhatsAppChannelRuntime()).webAuthExists(account.authDir);
return {
accountId: account.accountId,
name: account.name,
enabled: account.enabled,
configured: true,
extra: {
linked,
connected: runtime?.connected ?? false,
reconnectAttempts: runtime?.reconnectAttempts,
lastConnectedAt: runtime?.lastConnectedAt ?? null,
lastDisconnect: runtime?.lastDisconnect ?? null,
lastInboundAt: runtime?.lastInboundAt ?? runtime?.lastMessageAt ?? null,
lastMessageAt: runtime?.lastMessageAt ?? null,
lastEventAt: runtime?.lastEventAt ?? null,
healthState: runtime?.healthState ?? void 0,
dmPolicy: account.dmPolicy,
allowFrom: account.allowFrom
}
};
},
resolveAccountState: ({ configured }) => configured ? "linked" : "not linked",
logSelfId: ({ account, runtime, includeChannelPrefix }) => {
loadWhatsAppChannelRuntime().then((runtimeExports) => runtimeExports.logWebSelfId(account.authDir, runtime, includeChannelPrefix));
}
}),
gateway: {
startAccount: async (ctx) => {
const account = ctx.account;
const { e164, jid } = (await loadWhatsAppChannelRuntime()).readWebSelfId(account.authDir);
const identity = e164 ? e164 : jid ? `jid ${jid}` : "unknown";
ctx.log?.info(`[${account.accountId}] starting provider (${identity})`);
return (await loadWhatsAppChannelRuntime()).monitorWebChannel(getWhatsAppRuntime().logging.shouldLogVerbose(), void 0, true, void 0, ctx.runtime, ctx.abortSignal, {
statusSink: (next) => ctx.setStatus({
accountId: ctx.accountId,
...next
}),
accountId: account.accountId
});
},
loginWithQrStart: async ({ accountId, force, timeoutMs, verbose }) => await (await loadWhatsAppChannelRuntime()).startWebLoginWithQr({
accountId,
force,
timeoutMs,
verbose
}),
loginWithQrWait: async ({ accountId, timeoutMs }) => await (await loadWhatsAppChannelRuntime()).waitForWebLogin({
accountId,
timeoutMs
}),
logoutAccount: async ({ account, runtime }) => {
const cleared = await (await loadWhatsAppChannelRuntime()).logoutWeb({
authDir: account.authDir,
isLegacyAuthDir: account.isLegacyAuthDir,
runtime
});
return {
cleared,
loggedOut: cleared
};
}
}
}
});
//#endregion
//#region extensions/whatsapp/index.ts
var whatsapp_default = defineChannelPluginEntry({
id: "whatsapp",
name: "WhatsApp",
description: "WhatsApp channel plugin",
plugin: whatsappPlugin,
setRuntime: setWhatsAppRuntime
});
//#endregion
export { whatsapp_default as default, setWhatsAppRuntime, whatsappPlugin };