openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
66 lines (65 loc) • 2.69 kB
JavaScript
import { Ft as resolveWhatsAppAccount } from "./pi-embedded-CbCYZxIb.js";
import { c as jsonResult, f as readReactionParams, h as readStringParam, i as createActionGate, n as ToolAuthorizationError } from "./common-zReYuoMM.js";
import { r as resolveWhatsAppOutboundTarget } from "./whatsapp-core-BTUSucnn.js";
import { _ as sendReactionWhatsApp } from "./channel.runtime-Cu2TxQlg.js";
//#region extensions/whatsapp/src/action-runtime-target-auth.ts
function resolveAuthorizedWhatsAppOutboundTarget(params) {
const account = resolveWhatsAppAccount({
cfg: params.cfg,
accountId: params.accountId
});
const resolution = resolveWhatsAppOutboundTarget({
to: params.chatJid,
allowFrom: account.allowFrom ?? [],
mode: "implicit"
});
if (!resolution.ok) throw new ToolAuthorizationError(`WhatsApp ${params.actionLabel} blocked: chatJid "${params.chatJid}" is not in the configured allowFrom list for account "${account.accountId}".`);
return {
to: resolution.to,
accountId: account.accountId
};
}
//#endregion
//#region extensions/whatsapp/src/action-runtime.ts
const whatsAppActionRuntime = {
resolveAuthorizedWhatsAppOutboundTarget,
sendReactionWhatsApp
};
async function handleWhatsAppAction(params, cfg) {
const action = readStringParam(params, "action", { required: true });
const isActionEnabled = createActionGate(cfg.channels?.whatsapp?.actions);
if (action === "react") {
if (!isActionEnabled("reactions")) throw new Error("WhatsApp reactions are disabled.");
const chatJid = readStringParam(params, "chatJid", { required: true });
const messageId = readStringParam(params, "messageId", { required: true });
const { emoji, remove, isEmpty } = readReactionParams(params, { removeErrorMessage: "Emoji is required to remove a WhatsApp reaction." });
const participant = readStringParam(params, "participant");
const accountId = readStringParam(params, "accountId");
const fromMeRaw = params.fromMe;
const fromMe = typeof fromMeRaw === "boolean" ? fromMeRaw : void 0;
const resolved = whatsAppActionRuntime.resolveAuthorizedWhatsAppOutboundTarget({
cfg,
chatJid,
accountId,
actionLabel: "reaction"
});
const resolvedEmoji = remove ? "" : emoji;
await whatsAppActionRuntime.sendReactionWhatsApp(resolved.to, messageId, resolvedEmoji, {
verbose: false,
fromMe,
participant: participant ?? void 0,
accountId: resolved.accountId
});
if (!remove && !isEmpty) return jsonResult({
ok: true,
added: emoji
});
return jsonResult({
ok: true,
removed: true
});
}
throw new Error(`Unsupported WhatsApp action: ${action}`);
}
//#endregion
export { whatsAppActionRuntime as n, handleWhatsAppAction as t };