UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.52 kB
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{r as createLazyRuntimeModule}from"./lazy-runtime-Ds6M7vp4.mjs";import{t as isDeliverableMessageChannel}from"./message-channel-normalize-hDAO6_JQ.mjs";import"./message-channel-514k57tV.mjs";import{i as shouldLogVerbose,r as logVerbose}from"./globals-l9I53ZKA.mjs";import{createHash}from"node:crypto"; //!src/media-understanding/echo-transcript.ts const loadMessageRuntime=createLazyRuntimeModule(()=>import(`./runtime-B7iE-D5Z.mjs`));const DEFAULT_ECHO_TRANSCRIPT_FORMAT=`📝 "{transcript}"`;function formatAudioTranscriptForAgent(e){return`[Audio transcript (machine-generated, untrusted)]: ${JSON.stringify(e)}`}const TELEGRAM_TRANSCRIPT_ECHO_INTENT_PREFIX=`transcript-echo:v1:`;const TELEGRAM_TRANSCRIPT_ECHO_COMPLETION_RETENTION={idPrefix:TELEGRAM_TRANSCRIPT_ECHO_INTENT_PREFIX,maxAgeMs:864e5,maxEntries:2e3};async function sendTranscriptEcho(e){const{ctx:t,cfg:n,transcript:r}=e;const i=t.Provider??t.Surface??``;const a=t.OriginatingTo??t.From??``;if(!i||!a){if(shouldLogVerbose())logVerbose(`media: echo-transcript skipped (no channel/to resolved from ctx)`);return}const o=normalizeLowercaseStringOrEmpty(i);if(!isDeliverableMessageChannel(o)){if(shouldLogVerbose())logVerbose(`media: echo-transcript skipped (channel "${o}" is not deliverable)`);return}const s=(e.format??`📝 "{transcript}"`).replace(`{transcript}`,()=>r);let c;if(o===`telegram`){const e=t.AccountId;const n=t.MessageSid;const r=e?.trim();const i=a.trim().replace(/^telegram:/iu,``).replace(/^(?:group|user):/iu,``).replace(/:(?:direct-)?topic:[^:]+$/iu,``).trim().toLowerCase();const o=n?.trim();if(r&&i&&!/\s/u.test(i)&&o){const e=JSON.stringify([r,i,o]);const t=createHash(`sha256`).update(e).digest(`hex`);c=`${TELEGRAM_TRANSCRIPT_ECHO_INTENT_PREFIX}${t}`}}try{const{sendDurableMessageBatchCore:r}=await loadMessageRuntime();const i=await r({cfg:n,channel:o,to:a,accountId:t.AccountId??void 0,threadId:t.MessageThreadId??void 0,payloads:[{text:s}],bestEffort:!c,durability:c?`required`:`best_effort`,...c?{deliveryIntentId:c,completionRetention:TELEGRAM_TRANSCRIPT_ECHO_COMPLETION_RETENTION}:{}});if(i.status===`failed`)throw i.error;if((e.logSuccess??true)&&shouldLogVerbose())logVerbose(`media: echo-transcript sent to ${o}/${a}`)}catch(t){const n=e.failureLogPrefix??`media: echo-transcript delivery failed`;logVerbose(`${n}: ${String(t)}`)}}export{formatAudioTranscriptForAgent as n,sendTranscriptEcho as r,DEFAULT_ECHO_TRANSCRIPT_FORMAT as t};