UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

54 lines (53 loc) • 1.98 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { t as captureRuntimeConfigAsyncReader } from "./io.runtime-DsJ2dLCQ.mjs"; import "./config-CMA-J084.mjs"; import { r as PlatformMessageNotDispatchedError } from "./deliver-types-BnSKrpHG.mjs"; import { t as loadChannelOutboundAdapter } from "./load-DSYpu7nM.mjs"; //#region src/cli/send-runtime/channel-outbound-send.ts function resolveRuntimeReplyToId(e) { const t = e.replyToMessageId ?? e.replyToId; return t == null ? void 0 : normalizeOptionalString(String(t)); } async function sendChannelOutboundMessage(e, t, n, r = {}) { const i = await loadChannelOutboundAdapter(e); const a = r.cfg ?? await captureRuntimeConfigAsyncReader()(); const o = r.messageThreadId ?? r.threadId ?? r.threadTs ?? void 0; const s = resolveRuntimeReplyToId(r); const buildContext = () => ({ cfg: a, to: t, text: n, mediaUrl: r.mediaUrl, mediaAccess: r.mediaAccess, mediaLocalRoots: r.mediaLocalRoots, mediaReadFile: r.mediaReadFile, accountId: r.accountId, threadId: o, replyToId: s, silent: r.silent, forceDocument: r.forceDocument, formatting: r.formatting ?? (r.textMode === "html" ? { parseMode: "HTML" } : void 0), gifPlayback: r.gifPlayback, gatewayClientScopes: r.gatewayClientScopes, deliveryQueueId: r.deliveryQueueId, deliveryPartIndex: r.deliveryPartIndex, deliveryPartCount: r.deliveryPartCount, onPlatformSendDispatch: r.onPlatformSendDispatch }); const c = Boolean(r.mediaUrl); if (r.blocks && i?.sendPayload) return await i.sendPayload({ ...buildContext(), payload: { text: n, channelData: { [e]: { blocks: r.blocks } } } }); if (c && i?.sendMedia) return await i.sendMedia(buildContext()); if (!i?.sendText) { const t = `${e} outbound adapter is unavailable.`; throw new PlatformMessageNotDispatchedError(t, { cause: new Error(t) }); } return await i.sendText(buildContext()); } //#endregion export { sendChannelOutboundMessage };