Twilio Telephony Integration
The engine can conduct a conversation over a phone call. Audio is exchanged with Twilio using the standard Media Streams protocol over a WebSocket; the engine translates it into the same pipeline session that a web or mobile client would run.
Connection
wss://{host}/socket/twilio/{key}
{key} is the pipeline key of the agent that should answer.
Because a colon is awkward in a stream URL, a hyphen in the last path segment is translated back
to a colon — agent-acme-support addresses the key agent:acme-support.
Unlike the other transports, no pipeline configuration parameters are read from the URL. The session is configured from the call itself: μ-law audio at the sample rate Twilio announces, continuous input mode, server-side speech processing and TTS caching disabled.
Inbound Calls
Point the phone number’s voice webhook at a TwiML document that connects the call to the engine:
<Response>
<Connect>
<Stream url="wss://{host}/socket/twilio/agent-acme-support">
<Parameter name="from" value="+420111222333"/>
<Parameter name="input" value="#intro"/>
<Parameter name="acceptedLanguages" value="en-US"/>
<Parameter name="zoneId" value="Europe/Prague"/>
<Parameter name="trackingRef" value="…"/>
</Stream>
</Connect>
</Response>
The custom parameters arrive on the start event and configure the session:
| Parameter | Required | Description |
|---|---|---|
|
Yes |
Caller’s number. It identifies the user — the engine derives the session’s device ref and username from it — so a returning caller is recognized across calls. |
|
No |
First input handed to the pipeline once the stream starts. Defaults to |
|
No |
Locale of the conversation. Defaults to the deployment default. |
|
No |
IANA time zone used for time-aware responses. |
|
No |
Reference stored on the session for correlation with your own records. |
Outbound Calls
To have the platform place the call, use
POST /api/call/initiate. The engine builds the
TwiML shown above from the request and dials out; the resulting stream connects to this endpoint.
Protocol
The implementation follows Twilio’s Media Streams message format. Messages are JSON text frames
discriminated by their event property.
Messages from Twilio
event |
Handling |
|---|---|
|
Acknowledged; carries |
|
Starts the session. Carries |
|
Inbound audio. |
|
A key press. |
|
Ends the input stream and thus the conversation. |
|
Playback acknowledgement. When the engine’s final |
Messages to Twilio
event |
Meaning |
|---|---|
|
A chunk of the agent’s synthesized speech. The engine converts 16-bit PCM to μ-law and
base64-encodes it into |
|
Discard audio Twilio has buffered but not yet played. Sent when the engine emits a transcript, i.e. when the caller starts speaking — this is how barge-in is implemented on the phone. |
|
Turn boundary. |
Limitations
-
Telephony audio is μ-law 8 kHz mono, so speech quality is lower than on the other transports.
-
Server-side speech processing (facial animation data) is disabled — there is no visual channel.
-
The wire formats described in Wire Formats do not apply here; this transport always speaks Twilio’s own protocol.