Using Twilio Functions to Enhance Studio Voice Calls with Custom TwiML

This guide is intended to explain how users can get the most out of Twilio Studio by enhancing their flows with Twilio Functions. Please read on for details.

Studio and Functions Together

Studio is Twilio's visual application builder for communication workflows. It provides built-in widgets that you can drag, drop, and connect together to quickly develop robust applications without manually building TwiML.

But for some unique use cases, Studio's widgets alone aren't sufficient to meet all the requirements. That's where Twilio Functions can help.

Functions are small units of server-side code that you write in Node.js and run directly in our cloud, and they natively integrate with Studio Flows so you can add fully customized TwiML responses to your Voice calls.

Returning Custom TwiML with Run Function

To return custom TwiML in your Studio Flow, add the Run Function widget and select the Function from the drop-down that generates your desired TwiML.

Example Function Returning TwiML:

exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
twiml.say('Hello World');
callback(null, twiml);

Studio will automatically detect that this Function returned TwiML, and it will pass that TwiML directly to Programmable Voice for handling the live call.

Returning Control Back to the Studio Flow

Using the Run Function widget to run custom TwiML in your Flow will cause Studio to give up control of the live voice call. If your use case requires returning control of the call back to your Studio Flow after running your custom TwiML, use the TwiML Redirect widget to invoke a custom TwiML URL instead of using Run Function.

Note: To avoid stuck Executions when using custom TwiML, be sure to set the Studio Flow Webhook URL as the Status Callback and Fallback URL in your Twilio Phone Number configuration.

Have more questions? Submit a request
Powered by Zendesk