/** * After-call routing with `onSuccessCall` / `onFailedCall` (headless continuation). * * Mutually exclusive with automatic recall (`recallCount` + `recallDelay`) on the same * `platform.call()`. If both are passed, the host keeps `onFailedCall` and drops recall. * * When `onFailedCall` is set, CMS `context.recallCount` / `context.recallDelay` are not * auto-applied to the scheduled `call` row; the after-call branch runs on failure instead. * * On call end the host sets `dialog.params.entry_point` to the configured handler name * and runs the **same** `defineScript` export headlessly. Branch with * `getScriptPhase(context)` (`after_call_success` / `after_call_failed`). */ import { defineScript, getScriptPhase } from '@voctiv/agent-sdk'; export default defineScript(async ({ channel, context, logger, platform }) => { const phase = getScriptPhase(context); if (context.headless && phase === 'after_call_failed') { logger.log('Post-call offline branch after failed outbound'); await platform.messaging.send({ src: 'bot', destination: context.msisdn || '', text: 'Sorry we missed you. Reply to reschedule.', }); platform.dialog.result = 'done'; return { output: { phase } }; } if (context.headless && phase === 'after_call_success') { logger.log('Post-call offline branch after successful call'); return { output: { phase } }; } channel.sip.answer(); await channel.audio.say('Starting outbound attempt.'); const msisdn = context.msisdn || context.callerId; if (!msisdn) return; await platform.call(msisdn, { onSuccessCall: 'on_success_call', onFailedCall: 'on_failed_call', }); logger.log('Scheduled outbound with after-call headless handlers (no automatic recall)'); });