/** * Campaign outbound that starts at INVITE (`outboundCallMode: 'from_invite'`). * * The host raises the script first, then dials the campaign number on the same * `channel`. 1xx lands on `progress$`; a 4xx/5xx rejects `waitForAnswer()`. * Gate the greeting on the answer so it does not play into ringback. * * `getScriptPhase` stays `'early'` for the whole live run. Read * `channel.sip.isAnswered` for the live state. Billing stays on the 200 OK. */ import { defineScript, getScriptPhase } from '@voctiv/agent-sdk'; export default defineScript( async ({ channel, logger, context }) => { if (getScriptPhase(context) === 'early') { channel.sip.progress$.subscribe(({ statusCode }) => { logger.log('progress', { statusCode }); }); try { await channel.sip.waitForAnswer(); } catch (err) { logger.warn('outbound failed', { err }); return; } } await channel.audio.say('Hello!'); }, { outboundCallMode: 'from_invite' }, );