/** * Sandboxed script entry that uses custom mediaProviders vendors. * * Pair with `custom-media-providers.ts` deployed as `dist/media-providers/index.js`. * This file must stay free of `ws` / connector imports — the script VM has no `process`. */ import { defineScript } from '@voctiv/agent-sdk'; export default defineScript(async ({ channel, logger }) => { channel.sip.answer(); // Pass credentials via `data` (or channel/platform params). Do not use process.env // in the sandboxed entry — `process` is not defined in the script VM. // Host-side factories in media-providers/ may still read process.env. const apiKey = String( (channel.params as Record).api_key ?? '', ); const asr = await channel.createAsr({ vendor: 'my-asr', language: 'ru-RU', data: { api_key: apiKey }, }); const tts = await channel.createTts({ vendor: 'my-tts', data: { api_key: apiKey, voice_id: '…', output_format: 'pcm_16000', }, }); await tts.say('Hello from a custom TTS connector.', { alias: 'greet' }); tts.say$('One. Two.', { alias: 'reply', ttsStrategy: 'streaming' }).subscribe({ next: (ev) => { logger.log('tts utterance', { state: ev.state, alias: ev.itemAlias }); }, error: (err) => logger.error('tts failed', err), }); await channel.audio.say('Reuse handle', { tts }); asr.destroy(); tts.destroy(); channel.sip.hangup(); });