- An inbound agent answers the call and collects the caller’s reason for calling.
- While the inbound agent keeps the caller company, an outbound agent calls a customer service representative and briefs them.
- Once the representative is ready, both calls are transferred into a shared Twilio conference.
Prerequisites
- Two Guava SIP codes, one for the inbound agent and one for the outbound agent. Create them on the SIP page in the Guava dashboard.
- A Twilio phone number, and a Twilio API key.
- A public URL that Twilio can reach for webhooks (e.g. using ngrok during development).
- Python
- TypeScript
Configure your Twilio number
In the Twilio Console, go to Phone Numbers > Manage > Active Numbers and select your number. Under Voice Configuration, set A call comes in to Webhook with the URLhttps://<your-public-url>/inbound-call and method HTTP POST. Then click Save configuration.
Inbound call reaches the inbound agent
When a call comes in, Twilio requests/inbound-call. This returns a Dial command telling Twilio to transfer to the inbound agent’s SIP code. The referUrl attribute tells Twilio to send any later transfers from this agent to /refer.
- Python
- TypeScript
main.py
Inbound agent collects the reason and stalls
The inbound agent collectsreason_for_calling. Once that task is complete, the agent is given a new task: keep the caller on the line while a representative is found.
- Python
- TypeScript
main.py
X- SIP headers.
- Python
- TypeScript
main.py
Twilio only forwards custom SIP headers prefixed with
X-. SipUri URL-encodes the header values, and VoiceResponse XML-escapes the & between headers.Outbound agent briefs the representative
The outbound agent readsX-Call-Reason from the call’s SIP headers, explains the caller’s issue to the representative, and confirms that they’re ready to take the call.
- Python
- TypeScript
main.py
Both calls join the conference
Once the representative is ready, the outbound agent usesguava.RemoteCall with X-Original-Call-Id to control the waiting inbound call, and transfers both calls to sip:<conference_id>@conference.internal. Each agent says a short message before it transfers.
- Python
- TypeScript
main.py
/refer with the target in ReferTransferTarget. The handler extracts the conference ID and returns <Conference> TwiML, which places the caller and the representative in the same room. Setting endConferenceOnExit ends the conference when either party hangs up.
- Python
- TypeScript
main.py
Run the example
Save the full example below asmain.py or main.ts, then set your Twilio credentials and start the server:
- Python
- TypeScript
Full example
- Python
- TypeScript
main.py