openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 2.3 kB
JavaScript
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CIXf7egm.js";
import { r as createLazyRuntimeModule } from "./lazy-runtime-CgCh8H_K.js";
import { i as shouldLogVerbose, r as logVerbose } from "./globals-CTaGxEqj.js";
import { t as isDeliverableMessageChannel } from "./message-channel-normalize-B81s0XMO.js";
import "./message-channel-BQrhwUEA.js";
//#region src/media-understanding/echo-transcript.ts
const loadMessageRuntime = createLazyRuntimeModule(() => import("./runtime-Seugmqy-.js"));
/** Default operator-visible transcript echo format for preflight audio transcription. */
const DEFAULT_ECHO_TRANSCRIPT_FORMAT = "📝 \"{transcript}\"";
function formatEchoTranscript(transcript, format) {
return format.replace("{transcript}", () => transcript);
}
/** Sends a best-effort transcript echo back to the originating deliverable chat. */
async function sendTranscriptEcho(params) {
const { ctx, cfg, transcript } = params;
const channel = ctx.Provider ?? ctx.Surface ?? "";
const to = ctx.OriginatingTo ?? ctx.From ?? "";
if (!channel || !to) {
if (shouldLogVerbose()) logVerbose("media: echo-transcript skipped (no channel/to resolved from ctx)");
return;
}
const normalizedChannel = normalizeLowercaseStringOrEmpty(channel);
if (!isDeliverableMessageChannel(normalizedChannel)) {
if (shouldLogVerbose()) logVerbose(`media: echo-transcript skipped (channel "${normalizedChannel}" is not deliverable)`);
return;
}
const text = formatEchoTranscript(transcript, params.format ?? "📝 \"{transcript}\"");
try {
const { sendDurableMessageBatchCore } = await loadMessageRuntime();
const send = await sendDurableMessageBatchCore({
cfg,
channel: normalizedChannel,
to,
accountId: ctx.AccountId ?? void 0,
threadId: ctx.MessageThreadId ?? void 0,
payloads: [{ text }],
bestEffort: true,
durability: "best_effort"
});
if (send.status === "failed") throw send.error;
if ((params.logSuccess ?? true) && shouldLogVerbose()) logVerbose(`media: echo-transcript sent to ${normalizedChannel}/${to}`);
} catch (err) {
const prefix = params.failureLogPrefix ?? "media: echo-transcript delivery failed";
logVerbose(`${prefix}: ${String(err)}`);
}
}
//#endregion
export { sendTranscriptEcho as n, DEFAULT_ECHO_TRANSCRIPT_FORMAT as t };