*** title: Outbound calls subtitle: Flows where your scenario initiates the call ------------------------------------------------------ Outbound flows start when you trigger a routing rule manually (Control Panel) or through the Management API (`startScenarios`). VoxEngine then starts `AppEvents.Started`. ### Outbound Voice AI pattern Outbound calls have different methods depending on the destination channel (PSTN, SIP, WhatsApp, app user), but the overall pattern is similar: trigger the call, listen for `CallEvents.Connected`, then set up the Voice AI client and media bridging. The call methods require a `callerId`. For phone numbers this must be a verified caller ID or a purchased Voximplant number. For WhatsApp, this must be a verified WhatsApp Business number. ```js title="Outbound Voice AI pattern" VoxEngine.addEventListener(AppEvents.Started, () => { // Retrieve information passed when the scenario was triggered const { destination, callerId } = JSON.parse(VoxEngine.customData()); // Choose your call method based on the destination & desired network const call = VoxEngine.callPSTN(destination, callerId); // const call = VoxEngine.callUser({ username: destination, callerid: callerId }); // const call = VoxEngine.callSIP(`sip:${destination}@your-sip-domain`, callerId); // const call = VoxEngine.callWhatsappUser({ number: destination, callerid: callerId }); // Handle call events call.addEventListener(CallEvents.Disconnected, ()=>VoxEngine.terminate()); call.addEventListener(CallEvents.Failed, ()=>VoxEngine.terminate()); // Set up the Voice AI client and media bridging only after the call is connected call.addEventListener(CallEvents.Connected, async () => { const voiceAIClient = OpenAI.createRealtimeAPIClient({apiKey: "your-key", model: "your-realtime-model"}); // Bridge media between the call and the Voice AI client so they can speak and hear each other VoxEngine.sendMediaBetween(call, voiceAIClient); }); }); ``` ### Start the outbound flow Choose one of these options: #### Start from the GUI (Control Panel) In `manage.voximplant.com`, open your application, go to **Routing**, choose the rule that points to your outbound scenario, then start it with `script_custom_data` that includes destination and caller ID.