VapiLLM
03/11/2025, 7:46 PMVapi Support Bot
03/11/2025, 7:48 PMcontrolUrl
is a key component in Vapi's live call control feature that allows you to inject conversation elements dynamically during an ongoing call. It provides a way to control and modify the flow of a phone call by sending specific commands or messages [in real-time](https://docs.vapi.ai/calls/call-features).
## How to control a call in real-time
To control a call in real-time using `controlUrl`:
1. First, obtain the controlUrl by making a POST request to the /call
endpoint. The response will include a monitor
object containing both listenUrl
and controlUrl
[in the payload](https://docs.vapi.ai/calls/call-features).
2. Send POST requests to the controlUrl to inject messages or control the call:
bash
curl -X POST 'https://aws-us-west-2-production1-phone-call-websocket.vapi.ai/7420f27a-30fd-4f49-a995-5549ae7cc00d/control'
-H 'content-type: application/json'
--data-raw '{
"type": "say",
"message": "Welcome to Vapi, this message was injected during the call."
}'
3. Common command types include:
- "say" for speaking messages
- "end-call" to terminate a call
- "transfer" to forward the call to another destination
4. Enable monitoring in your assistant configuration:
typescript
const assistant = {
monitorPlan: {
listenEnabled: true, // For live audio streaming
controlEnabled: true // For live control capabilities
}
};
## Python code for extracting audio with listenUrl
While there isn't a direct Python example in the documentation, here's a conceptual Python implementation using the websocket-client
library:
```python
import websocket
import os
pcm_buffer = bytearray()
def on_message(ws, message):
if isinstance(message, bytes):
pcm_buffer.extend(message)
print(f"Received PCM data, buffer size: {len(pcm_buffer)}")
def on_error(ws, error):
print(f"WebSocket error: {error}")Vapi Support Bot
03/11/2025, 7:48 PMlistenUrl
and buffers the audio data, which you can then save or process in real-time [as shown in the documentation](https://docs.vapi.ai/calls/call-features).
Sources:
- [Vapi Call Features Documentation](https://docs.vapi.ai/calls/call-features)
- [Discord Channel Discussion](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1340737584309211136)VapiLLM
03/11/2025, 8:17 PMReceived PCM data, buffer size: ${pcmBuffer.length}
);
} else {
console.log('Received message:', JSON.parse(data.toString()));
}
});
ws.on('close', () => {
if (pcmBuffer.length > 0) {
fs.writeFileSync('audio.pcm', pcmBuffer);
console.log('Audio data saved to audio.pcm');
}
});
ws.on('error', (error) => console.error('WebSocket error:', error));Mason
03/11/2025, 11:12 PMVapiLLM
03/11/2025, 11:35 PMMason
03/11/2025, 11:40 PMMason
03/11/2025, 11:42 PMMason
03/12/2025, 1:13 AMVapiLLM
03/12/2025, 11:07 PM