How to Direct SIP Dialing

View as Markdown

In scenarios where your telephony provider does not offer elastic SIP trunking or if you have a more complex telephony setup unsuitable for elastic SIP trunking, you can use direct SIP dialing to our endpoint.

In this scenario, Synthflow does not directly place or receive calls. Rather, your telephony system manages the dialing process to connect with the specified SIP endpoint. You will need to develop the integration logic tailored to your telephony provider’s requirements. From Synthflow’s standpoint, all call interactions will be treated as incoming, so your integration must explicitly define call direction handling.

The process involves three primary steps:

  1. Importing a custom phone number
  2. Creating the agent and linking it to the phone number
  3. Dialing to the SIP Endpoint

Step 1: Import a Custom Phone Number

Register the number Synthflow should answer for in your workspace. This creates a custom number record your telephony system can dial into, without elastic SIP trunking on the Synthflow side. If your carrier or PBX requires outbound SIP registration before it routes calls, set uac_enabled to true and provide trunk credentials.

Expand the endpoint below to send a test request, then use the table for the fields most relevant to direct SIP dialing.

FieldRequiredDescription
workspace_idYesYour workspace ID
phone_numberYesThe phone number to import
friendly_nameNoA human-readable name for the phone number
termination_uriNoSIP domain used for outbound calls
trunk_usernameNoSIP trunk username for authentication. Required when uac_enabled is true
trunk_pwdNoSIP trunk password for authentication. Required when uac_enabled is true
sip_outbound_proxyNoOutbound proxy for calls and SIP REGISTER requests
sip_auth_usernameNoAuth username for REGISTER when it differs from trunk_username
uac_enabledNoSet to true to enable outbound SIP registration. Defaults to false
uac_register_expiresNoRegistration refresh interval in seconds (60 to 3600). Defaults to 300

Step 2: Create an agent

Create an inbound agent and attach the custom phone number from Step 1. Synthflow treats every call that reaches that number as incoming, so set type to inbound. Wait until Step 1 succeeds before you send this request.

Expand the endpoint below to try the call, then use the table for the minimum fields needed in this flow.

FieldRequiredDescription
typeYesSet to inbound for receiving calls
nameYesA name for your agent
phone_numberYesThe custom phone number created in Step 1
agentYesAgent configuration including llm, language, prompt, greeting_message, and voice_id

Step 3: Configure Twilio

After the trunk is set up on SynthFlow, redirect Twilio calls to it using TwiML commands. Be sure to include the GHL unique call ID or Twilio Call SID in the SIP header using the X-EI key.

Javascript Example:

Dialing via TWIML
1const express = require('express');
2const { twiml: { VoiceResponse } } = require('twilio');
3
4const app = express();
5const PORT = process.env.PORT || 3000;
6const TERMINATION = "sipin.synthflow.ai:32681";
7
8/**
9 * Redirects a call to SynthFlow SIP endpoint.
10 */
11app.get('/redirect_call', (req, res) => {
12 const { Called, CallSid } = req.query;
13
14 if (!Called) {
15 return res.status(400).send('Missing "Called" query parameter');
16 }
17
18 const voiceResponse = new VoiceResponse();
19 voiceResponse.dial().sip(`sip:${Called}@${TERMINATION}?X-EI=${CallSid}`);
20
21 res.set('Content-Type', 'text/xml');
22 res.status(200).send(voiceResponse.toString());
23});
24
25app.listen(PORT, () => {
26 console.log(`Server is running on http://localhost:${PORT}`);
27});

Python Example:

Dialing via TWIML
1from fastapi import FastAPI, Response
2from twilio.twiml.voice_response import VoiceResponse
3
4app = FastAPI()
5TERMINATION = "sipin.synthflow.ai:32681"
6
7@app.get("/redirect_call")
8async def redirect_call(Called: str, CallSid: str): # pylint: disable=invalid-name
9 voice = VoiceResponse()
10 voice.dial().sip(f"sip:{Called}@{TERMINATION}?X-EI={CallSid}")
11 return Response(str(voice), media_type="text/xml", status_code=200)

Pre-actions with pre-call variables

You can use Pre-Actions to fetch pre-call variables via API and incorporate them into the agent prompt for more personalized responses by using the <twilio_call_sid> verb in API request.

Note: The transfer call will work the same as before.