Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Modify Calls In Progress


Learn to modify live phone calls and change active call execution with Twilio Programmable Voice. To update an active Call resource, send a POST request with a Twilio SDK. You can use this guide to send automated notifications, create self-service automation, build inbound and outbound call centers, implement AI or ML transcription, and manage active call sessions.

To learn more about the Call resource and state management parameters used in this guide, see Related reference documentation.

To control the flow of a Twilio phone call, pass TwiML documents to Twilio through its SDKs. The typical workflow involves passing instruction sets in TwiML documents from your app to Twilio in two ways:

  1. Change instructions to Twilio during a call through the action parameters of verbs like <Gather> and <Record>.
  2. Request a different TwiML document from Twilio with the <Redirect> verb.

To change a live phone call outside of the normal Twilio request-response cycle, make a request to the Call resource.


Complete the prerequisites

complete-the-prerequisites page anchor

Complete the Twilio prerequisites

complete-the-twilio-prerequisites page anchor

Complete the language prerequisites

complete-the-language-prerequisites page anchor

Select your programming language and complete the prerequisites:

PythonNode.jsPHPC# or .NETJavaRuby
  • Install Python 3.3 or later(link takes you to an external page).
  • Install Flask(link takes you to an external page) and the Twilio Python Helper Library(link takes you to an external page). Using pip(link takes you to an external page), run the following command:
    pip install flask twilio
  • Install and set up ngrok(link takes you to an external page).

Get credentials and set as environment variables

get-credentials-and-set-as-environment-variables page anchor

Extract your credentials from your Twilio account then save these credentials as environment variables.

Twilio ConsoleLegacy Console
  1. Go to the Twilio Console(link takes you to an external page). The Let's get building page appears.

  2. Click API keys and Auth tokens. The API keys & auth tokens page appears with the Auth Tokens tab selected.

  3. Scroll to your Account SID.

  4. Click the copy button next to your Account SID.

  5. Run the following command, replacing YOUR_ACCOUNT_SID with your Account SID.

    macOS TerminalWindows command linePowerShell
    export TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID

    This command creates an environment variable on your development system for your account SID.

  6. To display the Auth Token, click the eye button in the Primary auth token box.

  7. Highlight and copy the Auth Token.

  8. Run the following command, replacing YOUR_AUTH_TOKEN with your Authentication Token.

    macOS TerminalWindows command linePowerShell
    export TWILIO_AUTH_TOKEN=YOUR_AUTH_TOKEN

    This command creates an environment variable on your development system for your auth token.


Modify an in-progress Twilio phone call

modify-an-in-progress-twilio-phone-call page anchor

The Call resource request requires the CallSid of the ongoing call. To get the CallSid, choose one of the following two options:

  1. Check the sid property in the response from Twilio for an outgoing call request.
  2. Check the CallSid attribute in TwiML document that Twilio sends to your app acting on an incoming call.

Update the call instructions

update-the-call-instructions page anchor

To update a live phone call, pass the update parameter with your Call resource request. This request instructs Twilio to make an immediate change the TwiML document that Twilio is using in a phone call.

PythonNode.jsPHPC# or .NETJavaRuby

Python only requires the Twilio Python helper library as noted in the prerequisites.

Change an in-progress Call with updated TwiML instructionsLink to code sample: Change an in-progress Call with updated TwiML instructions
1
# Download the helper library from https://www.twilio.com/docs/python/install
2
import os
3
from twilio.rest import Client
4
5
# Find your Account SID and Auth Token at twilio.com/console
6
# and set the environment variables. See http://twil.io/secure
7
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
8
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
9
client = Client(account_sid, auth_token)
10
11
call = client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").update(
12
twiml="<Response><Say>Ahoy there</Say></Response>"
13
)
14
15
print(call.sid)

Redirect the Call to another URL

redirect-the-call-to-another-url page anchor

You can choose to redirect a Call to another URL that responds with your requested TwiML.

PythonNode.jsPHPC# or .NETJavaRuby

Python only requires the Twilio Python helper library as noted in the prerequisites.

Redirect an in progress Call to another URLLink to code sample: Redirect an in progress Call to another URL
1
# Download the helper library from https://www.twilio.com/docs/python/install
2
import os
3
from twilio.rest import Client
4
5
# Find your Account SID and Auth Token at twilio.com/console
6
# and set the environment variables. See http://twil.io/secure
7
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
8
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
9
client = Client(account_sid, auth_token)
10
11
call = client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").update(
12
method="POST", url="http://demo.twilio.com/docs/voice.xml"
13
)
14
15
print(call.sid)

Hanging up a call in progress

hanging-up-a-call-in-progress page anchor

When Twilio encounters a <Hangup> verb or runs out of TwiML documents to process, Twilio ends your phone call. To end a phone call by your choice, pass a completed status to a CallSid in progress.

PythonNode.jsPHPC# or .NETJavaRuby

Python only requires the Twilio Python helper library as noted in the prerequisites.

1
# Download the helper library from https://www.twilio.com/docs/python/install
2
import os
3
from twilio.rest import Client
4
5
# Find your Account SID and Auth Token at twilio.com/console
6
# and set the environment variables. See http://twil.io/secure
7
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
8
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
9
client = Client(account_sid, auth_token)
10
11
call = client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").update(
12
status="completed"
13
)
14
15
print(call.to)

Use cases for modifying live calls with Twilio Programmable Voice

use-cases-for-modifying-live-calls-with-twilio-programmable-voice page anchor

This guide teaches the basics required for the following use cases:

Notifications with Twilio Programmable Voice

notifications-with-twilio-programmable-voice page anchor

You can use this guide to dynamically manage automated broadcast or alert calls while they are in progress. For example, you can programmatically redirect a notification call to a live agent queue if a customer requests immediate assistance, or terminate a call early once an urgent message has been acknowledged. To learn more advanced features that you can use with notifications, see Voice notifications.

Create self-service automation with Twilio Programmable Voice

create-self-service-automation-with-twilio-programmable-voice page anchor

Together with your IVR workflows, you can use this guide to interrupt automated self-service paths based on real-time events. Seamlessly break a caller out of an automated data-gathering script if they request a human agent, or modify the call's direction dynamically when a backend database updates during the session. To learn more advanced features that you can use with self-service automation, see Voice self-service automation.

Build inbound call centers with Twilio Programmable Voice

build-inbound-call-centers-with-twilio-programmable-voice page anchor

You can use this guide to implement essential call center features like warm transfers, supervisor barge-ins, and call holds. Modify active calls to pull customers out of queues as agents become available, bridge multiple parties together, or redirect callers to different departments based on live agent availability. To learn more advanced features that you can use with inbound call centers, see Voice inbound call centers.

Implement AI or ML transcription with Twilio Programmable Voice

implement-ai-or-ml-transcription-with-twilio-programmable-voice page anchor

Together with Twilio live audio streaming, you can use this guide to control transcription services dynamically during a conversation. Programmatically start or stop transcription streams to protect user privacy when sensitive information is being spoken, or inject new routing rules into a call based on live keywords detected by your transcription engine. To learn more advanced features that you can use with AI or ML transcription, see Voice AI and ML transcription.

Build AI agents with Twilio Programmable Voice

build-ai-agents-with-twilio-programmable-voice page anchor

You can use this guide to manage interactions between human callers and autonomous voice bots in real time. Create human-in-the-loop takeover mechanisms that instantly intercept an active call and redirect it to a human supervisor if the AI agent detects frustration or encounters a complex request. To learn more advanced features that you can use with AI agents, see Voice AI agents.

Build outbound call centers with Twilio Programmable Voice

build-outbound-call-centers-with-twilio-programmable-voice page anchor

You can use this guide to optimize live outbound interactions and agent utilization. Instantly modify the path of an outbound call to play a prerecorded message the moment an answering machine is detected, or dynamically shift active outbound legs between agent tiers based on shifting campaign priorities. To learn more advanced features that you can use with outbound call centers, see Voice outbound call centers.

Build sales dialers with Twilio Programmable Voice

build-sales-dialers-with-twilio-programmable-voice page anchor

You can use this guide to power advanced click-to-talk workflows and lead response systems. Initiate a call to a sales representative first, and then dynamically modify that call in progress to dial and bridge the prospect the exact moment the agent goes off-hook and is ready to talk. To learn more advanced features that you can use with sales dialers, see Voice sales dialers.

Build call tracking with Twilio Programmable Voice

build-call-tracking-with-twilio-programmable-voice page anchor

You can use this guide to control proxy routing and number masking on active lines. Modify live call parameters to dynamically mask phone numbers for privacy, track campaign attribution data mid-flight, or update routing metrics as a call moves through various marketing touchpoints. To learn more advanced features that you can use with call tracking, see Voice call tracking.


After following this guide, you can programmatically modify live phone calls using Twilio Programmable Voice and the Twilio SDKs. You will have built code that can dynamically update call directions or explicitly update the call status to complete active sessions on your account.


Explore the following guides to build on what you've learned in this guide: