mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 07:48:38 +00:00
refactor(media): split audio helpers and attachment cache
This commit is contained in:
62
src/media-understanding/echo-transcript.ts
Normal file
62
src/media-understanding/echo-transcript.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { MsgContext } from "../auto-reply/templating.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { logVerbose, shouldLogVerbose } from "../globals.js";
|
||||
import { isDeliverableMessageChannel } from "../utils/message-channel.js";
|
||||
|
||||
export const DEFAULT_ECHO_TRANSCRIPT_FORMAT = '📝 "{transcript}"';
|
||||
|
||||
function formatEchoTranscript(transcript: string, format: string): string {
|
||||
return format.replace("{transcript}", transcript);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the transcript echo back to the originating chat.
|
||||
* Best-effort: logs on failure, never throws.
|
||||
*/
|
||||
export async function sendTranscriptEcho(params: {
|
||||
ctx: MsgContext;
|
||||
cfg: OpenClawConfig;
|
||||
transcript: string;
|
||||
format?: string;
|
||||
}): Promise<void> {
|
||||
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 = channel.trim().toLowerCase();
|
||||
if (!isDeliverableMessageChannel(normalizedChannel)) {
|
||||
if (shouldLogVerbose()) {
|
||||
logVerbose(
|
||||
`media: echo-transcript skipped (channel "${String(normalizedChannel)}" is not deliverable)`,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const text = formatEchoTranscript(transcript, params.format ?? DEFAULT_ECHO_TRANSCRIPT_FORMAT);
|
||||
|
||||
try {
|
||||
const { deliverOutboundPayloads } = await import("../infra/outbound/deliver.js");
|
||||
await deliverOutboundPayloads({
|
||||
cfg,
|
||||
channel: normalizedChannel,
|
||||
to,
|
||||
accountId: ctx.AccountId ?? undefined,
|
||||
threadId: ctx.MessageThreadId ?? undefined,
|
||||
payloads: [{ text }],
|
||||
bestEffort: true,
|
||||
});
|
||||
if (shouldLogVerbose()) {
|
||||
logVerbose(`media: echo-transcript sent to ${normalizedChannel}/${to}`);
|
||||
}
|
||||
} catch (err) {
|
||||
logVerbose(`media: echo-transcript delivery failed: ${String(err)}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user