Menu

Expand
Rate this page:

Handoff

The Autopilot Handoff action enables you to transfer a user from an Autopilot session to a human agent, passing along all the context of the conversation.

  • Handoff to Programmable Voice
  • Handoff a Voice call to Task Router or Flex

NOTE: Handoff is only supported for Twilio Programmbale Voice Autopilot sessions.

Handoff to Programmable Voice

When handing off an Autopilot voice session to Programmable Voice, you need to provide the destination TwiML URL. When the Hand-off is executed the Autopilot session is terminated and TwiML will be fetched and executed from the URL provided. See the Autopilot Request to see the callback params.

Example 1: Transfer Autopilot session to a Programmable Voice TwiML URL.

{
	"actions": [
		{
			"say": "Hold on, we are connecting you with an agent"
		},
		{
			"handoff": {
				"channel": "voice",
				"uri": "INSERT YOUR TWIML_URL HERE",
				"method": "POST"
			}
		}
	]
}

Example 2: Transfer Autopilot session to a Programmable Voice TwiML URL with a Programmable Voice Status Callback URL defined.

{
	"actions": [
		{
			"say": "Hold on, we are connecting you with an agent"
		},
		{
			"handoff": {
				"channel": "voice",
				"uri": "INSERT YOUR TWIML_URL HERE",
				"method": "POST",
				"voice_status_callback_url": "INSERT STATUS_CALLBACK_URL HERE",
				"voice_status_callback_method": "POST"
			}
		}
	]
}

Example 3: Transfer Autopilot session to a Programmable Voice TwiML URL with a Programmable Voice Status Callback URL defined from a Twilio Function, generating dynamic Action JSON. Your Autopilot task may look like this:

{
    "actions": [
        {
            "redirect": "replace-with-your-function.twil.io/dynamichandoff"
	}
    ]
}

Your Function the task redirected to would then contain code to dynamically render Actions JSON:

exports.handler = function(context, event, callback) {
    let actions = [];
    let say = {
        "say": "Hold on, we are connecting you with an agent"
    };
    actions.push(say);
    let handoff = {
        "handoff": {
            "channel": "voice",
			"uri": "INSERT YOUR TWIML_URL HERE",
			"method": "POST",
			"voice_status_callback_url": "INSERT STATUS_CALLBACK_URL HERE",
			"voice_status_callback_method": "POST"
		}
    };
    actions.push(handoff);
    let respObj = {
    	"actions": actions
    };
    callback(null, respObj);	
};

Handoff to Task Router or Flex

When handing off an Autopilot voice session to Task Router or Flex, you need to provide the destination the Task Router workflow Sid. When the Hand-off is executed the Autopilot session is terminated, the call is enqueued with the Dialogue Payload as a task attribute.

Example 4: Transfer Autopilot session to a contact center agent via Task Router or Flex.

{
	"actions": [
		{
			"handoff": {
				"channel": "voice",
				"uri": "taskrouter://WW0123456789abcdef0123456789abcdef"
			}
		}
	]
}

Example 5: Transfer Autopilot session to a contact center agent via Task Router or Flex with all the optional parameters.

{
	"actions": [
		{
			"handoff": {
				"channel": "voice",
				"uri": "taskrouter://WW0123456789abcdef0123456789abcdef",
				"wait_url": "https://example.com/hold_music.php",
				"wait_url_method": "GET",
				"action": "https://example.com/post_bridge_survey.php",
				"priority": "5",
				"timeout": "200"
			}
		}
	]
}

Example 6: Transfer Autopilot session to a contact center agent via Task Router or Flex with all the optional parameters from a Twilio Function, generating dynamic JSON.

{
    "actions": [
        {
            "redirect": "replace-with-your-function.twil.io/dynamichandoff"
	}
    ]
}

Your Function the task redirected to would then contain code to dynamically render Actions JSON:

exports.handler = function(context, event, callback) {
    let actions = [];
    let handoff = {
        "handoff": {
            "channel": "voice",
            "uri": "taskrouter://WW0123456789abcdef0123456789abcdef",
            "wait_url": "https://example.com/hold_music.php",
            "wait_url_method": "GET",
            "action": "https://example.com/post_bridge_survey.php",
            "priority": "5",
            "timeout": "200"
        }
    };
    actions.push(handoff);
    let respObj = {
    	"actions": actions
    };
    callback(null, respObj);	
};
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Loading Code Sample...
        
        
        

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        thanks-feedback-gif