openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
51 lines (50 loc) • 2 kB
JavaScript
import { c as normalizeOptionalString } from "./string-coerce-mnp54Vah.js";
import { i as getRuntimeConfig } from "./io-Gi7-pyU-.js";
import "./config-C9RxTsn1.js";
import { t as loadChannelOutboundAdapter } from "./load-BBQWnOQX.js";
//#region src/cli/send-runtime/channel-outbound-send.ts
function resolveRuntimeThreadId(opts) {
return opts.messageThreadId ?? opts.threadId ?? opts.threadTs ?? void 0;
}
function resolveRuntimeReplyToId(opts) {
const raw = opts.replyToMessageId ?? opts.replyToId;
return raw == null ? void 0 : normalizeOptionalString(String(raw));
}
/** Create a send runtime that dispatches text, media, or rich blocks through a channel plugin. */
function createChannelOutboundRuntimeSend(params) {
return { sendMessage: async (to, text, opts = {}) => {
const outbound = await loadChannelOutboundAdapter(params.channelId);
const threadId = resolveRuntimeThreadId(opts);
const replyToId = resolveRuntimeReplyToId(opts);
const buildContext = () => ({
cfg: opts.cfg ?? getRuntimeConfig(),
to,
text,
mediaUrl: opts.mediaUrl,
mediaAccess: opts.mediaAccess,
mediaLocalRoots: opts.mediaLocalRoots,
mediaReadFile: opts.mediaReadFile,
accountId: opts.accountId,
threadId,
replyToId,
silent: opts.silent,
forceDocument: opts.forceDocument,
formatting: opts.formatting ?? (opts.textMode === "html" ? { parseMode: "HTML" } : void 0),
gifPlayback: opts.gifPlayback,
gatewayClientScopes: opts.gatewayClientScopes
});
const hasMedia = Boolean(opts.mediaUrl);
if (opts.blocks && outbound?.sendPayload) return await outbound.sendPayload({
...buildContext(),
payload: {
text,
channelData: { [params.channelId]: { blocks: opts.blocks } }
}
});
if (hasMedia && outbound?.sendMedia) return await outbound.sendMedia(buildContext());
if (!outbound?.sendText) throw new Error(params.unavailableMessage);
return await outbound.sendText(buildContext());
} };
}
//#endregion
export { createChannelOutboundRuntimeSend };