How to hand-off messaging conversations from Autopilot to your Contact Center
Please review the How to hand off guide first to make sure your use case is supported and that you are following the correct documentation.
To hand off voice calls from Autopilot to your Contact Center, use the Handoff Action as shown in the How to build a conversational IVR guide. This guide shows you how to hand off messaging conversations, which requires a different approach.
This guide will give you the resources and information you need to know to hand-off messaging conversations from Autopilot to a contact center.
The ability to hand-off tasks from a bot to a human agent is critical to building bot experiences that don’t frustrate your users. There will be situations your bot is not equipped to handle that should be escalated to an agent. You may also need to build hybrid customer journeys where the bot handles a part of the customer request before handing off to a human being to complete. With Autopilot, you can hand-off messaging conversations from a bot to human agents with the entire context of the customer conversation intact.
In this guide, you’re going to:
- Create an Autopilot bot with a template from the Twilio Console.
- Modify the bot to work with your Twilio account.
- Program and train the bot to hand off conversations to a contact center with their context intact.
- Use the Autopilot Studio Widget to add the bot to a Studio flow.
- Implement simple logic in the Studio flow to facilitate agent handoff.
- Deploy the bot on the messaging channel and contact center of your choice.
Twilio Studio is a visual builder for communications workflows. It provides a number of different widgets that you can arrange in a drag-and-drop interface to build custom communications workflows over messaging or voice.
1. Create a bot
We’ll be using the Hospitality template available in the Twilio console. Select the template in the Build a bot page to create the bot. This usually takes a few seconds.
2. Review the bot configuration
Tasks
The bot template comes with nine built-in tasks.
1.greeting
The default task triggered when the user greets the chatbot. You should train this task based on how you’re asking your users to begin interacting with the chatbot. This task also responds with a list of specific requests the bot can help the user with. This ensures the conversation is tightly scoped to what the bot has been trained for, increasing it's chances of successfully helping the user.
2.deliver_room_items
Asks the user which extra items they need delivered to their room. This task uses a Collect flow to gather this information from the user before redirecting to the complete_collect_roomitems that completes the request.
3.complete_collect_roomitems
Completes the user's request to deliver the extra items. Note that this task is programmed to keep the conversation alive by setting listen to true, which allows the user to end the conversation. This is a general best practice — you always want to give the user the option to initiate another request in the same dialogue.
4.order_roomservice
Asks the user for their room service order. This task also uses a Collect flow to gather this information from the user before redirecting to the complete_collect_roomservice
task that completes the request.
5.complete_collect_roomservice
Similar to complete_collect_roomitems
, completes the user's request to deliver the extra items. Note that this task is also programmed to keep the conversation alive by setting listen
to true
, which allows the user to end the conversation.
6.get_quantity
This task illustrates how you can use another mechanism for receiving a request to order more items — Field extraction. It's trained on a number of samples that can identify what item the user wants if they directly make their request instead of first greeting the bot. For example, if the user says "Can I have more towels?", the bot extracts "towels" from their request, follows up by asking for the quantity and triggers the complete_collect_roomitems
task.
7.collect_fallback
This task is triggered if any of the Collect sequences used fail to handle the user's request. By default, it's configured to try again to help the user. However, you could modify it to hand-off to a live agent depending on the type of customer experience you're looking to create. Refer to How to hand-off messaging conversations from Autopilot to your Contact Center to see how to implement hand-off.8.fallback
This task is triggered if your bot can't match the user's query to one of these 9 tasks. By default, it's also configured to try again to help the user. You could also similarly modify it to hand-off to a live agent depending on the type of customer experience you're looking to create. Refer to How to hand-off messaging conversations from Autopilot to your Contact Center to see how to implement hand-off.
9.goodbye
Ends the dialogue. Doing so erases any context stored in the Autopilot Memory and treats any subsequent requests from the user as a new dialogue.
Default Behaviors
Defaults determine your bot's behavior in three different situations:
- Assistant Initiation: used when the bot is responsible for beginning a conversation. Only used for inbound phone calls. Points to the
greeting
task in the Hospitality template. - Fallback: used when the natural language engine cannot map human input to an existing task and needs to provide the user with additional direction. Points to the
fallback
task in the Hospitality template. - Collect on Failure: used when the bot needs to know which task to use if there is a failure when collecting data. Points to the
collect_fallback
task in the Hospitality template.
In general, defaults should point either to:
- An existing task. With our airline reservation bot, the
assistant_initiation
default points to thewelcome_message
task. - A publicly accessible URL that responds with Actions. With our bot, the fallback points to a Twilio Function.
Learn more about Defaults in the documentation.
Stylesheets
StyleSheets enable you to give your bot a style by specifying its voice, error messages, success messages, and data collection validation behavior.
Learn more about Stylesheets in the documentation.
3. Add hand off task
send_to_agent
This task is essential for building hand-off to Flex or any other contact center platform. It gets triggered when Autopilot recognizes that the user wants to skip the chatbot and talk directly to an agent. We do this by training it on phrases that a customer might say to want to talk to an agent (see Step 4 for more details on training). We'll program this task using a Twilio Function because we need to dynamically add a new variable called sendToAgent
to your bot's memory to indicate that the conversation needs to be handed off to an agent. Autopilot provides the current memory of the bot as a JSON object in each request it makes to your application. The Autopilot Studio widget also passes this request data in the Studio Flow, allowing you to parse this variable to execute the hand-off. We’ll cover this in Step 6.
To set it up, first create a new task called send_to_agent
in the Autopilot console.
Then, go to the Manage Functions page in the Twilio console. Create a new Function called send-to-agent-function
and paste the code from the send-to-agent-function code snippet. Add a unique path for the Function and click Save. Copy the URL generated.
Go back to the Autopilot console and select Program on the send_to_agent task. Then toggle from the ActionBin to Action URL so that Autopilot knows to make a request to a URL when this task is triggered. Paste the unique URL you copied for your Function here.
You've successfully programmed this task to hand-off a messaging conversation. Next, you need to train the task and set up a Studio flow to execute the handoff.
4. Train Tasks
Next, we need to train the send_to_agent
task with phrases your users might use to trigger them. Training is an essential part of building a bot powered by machine learning. Under the hood, each bot uses a number of different machine learning models to process what the user is saying. These models need to be ‘trained’ with real examples of what your users might say when interacting with it. These examples are called Samples in Autopilot.
Click on Train on this task in the task list in the console. We recommend adding at least 10 samples per Task when you get started.
For this task, consider adding samples like:
- Can I talk to an agent?
- Agent
- I want to talk to someone
- Talk to a representative
- Concierge
- Talk to concierge
- Can I talk to someone?
- I'd like to talk to an agent
- Concierge please
- Representative
5. Build Model
When you make changes to your training data, like adding and deleting samples and fields, or add new Tasks or change Task names, remember to build a new model each time so these changes take effect. The alert will automatically be displayed when you make changes to your bot's configuration. Click Build model to update the bot with your changes.
Congratulations! You’ve successfully programmed and trained your bot.
6. Build Agent Hand-off
Now that you have trained and programmed the bot, you need to add it to a Studio Flow to implement agent hand-off.
To build agent hand-off, you’ll use the Autopilot, Split Based On, Send Message and SendMessageToFlex (if you’re using Flex) or HTTP Request (if you’re using another contact center platform) widgets.
Note that the approach you should follow depends on whether you're using Flex or not.
Without Flex: Create a Studio Flow and add the Autopilot widget to it
If you’re not using Flex as your contact center platform, you’ll need to first create new Studio Flows for Messaging and Programmable Chat, and add the Autopilot Widget to it.
For Programmable Chat
Go to the Studio Dashboard, hit the New Flow button, name your flow, and choose ‘Start from scratch’ as your template.
Drag and drop the Autopilot Widget into the canvas from the widget tray. Name your widget and select the bot you want to use from the drop down.
The Messaging & Chat Config comes with a few default values. For Chat, you should replace the default value in the ‘Send Message From’ field with the name of your bot. This ensures that the name of your bot is displayed with the messages it sends in the chat channel.
For Messaging
Follow the same steps to create another flow for Messaging with one modification. Do not change the ‘Send Message From’ field in the Messaging & Chat Config. With Messaging channels, we want Studio to use the default channel address, which maps to the phone number, WhatsApp phone number or Facebook Messenger profile. Your messages will fail if you change this value.
With Flex: Add the Autopilot widget to the default Webchat and Messaging Flows for Flex
If you’re using Flex, you need to add Autopilot to one of the Studio Flows for messaging that you have configured with Flex.
Drag-and-drop the Autopilot widget between the Trigger and SendMessageToFlex widgets. Click on the widget and select your Assistant from the drop down. Click into the Messaging & Chat Config and change the value in the Send Message From field to the name of the Assistant you want to appear in the chat.
For Messaging
The configuration for messaging channels when you're using Flex is different from when you're not using it. Drag-and-drop the Autopilot widget between the Trigger and SendMessageToFlex widgets. Click on the widget and select your Assistant from the drop down. Click into the Messaging & Chat Config and change the ‘Send Message From’ field in the Messaging & Chat Config to {{trigger.message.ChannelAttributes.from}}.
This ensures the correct channel address for the user — phone number, WhatsApp phone number or Facebook Messenger profile is available to Flex when the hand off takes place.
Add the Split widget to check for hand-off
This part is the same if you're using Flex or another contact center platform. Let’s recap how the send_to_agent
task from step 3 works. It points to a function which inserts a JSON object in the Assistant memory using the remember
action.
remember = {
"remember": { "sendToAgent": true }
}
The Autopilot Studio widget in turn provides the memory payload to the Studio Flow when the Session ends, allowing you to build logic based off these variables. Drop the Split widget into the canvas. Click into the widget and in the Config tab, add widgets.{YOUR ASSISTANT WIDGET NAME}.memory.sendToAgent
in the variable to test field. Click Save.
Next, switch to the Transitions tab and click the New Condition button and set it to true as shown below.
Complete the hand-off
With Flex
If you’re using Flex, select the SendMessageToAgent widget as the next step to transition to. Add the memory payload in the Attributes text field in the Config tab, along with any channel-specific attributes you want to include. This attaches any information stored in your Assistant’s memory to the underlying Taskrouter task that Flex uses to route the conversation to the appropriate agent. To provide this information to a Flex agent, all you need to do is pull this data from the task and display it in the Flex agent UI. Learn more about TaskRouter for Flex here.
The final state of your Studio Flow after adding and configuring all the widgets should look like this:
Without Flex
If you’re not using Flex, drop the HTTP Request widget into the canvas and point the transition on the Split widget to this widget.
In the Config tab, set it up to make a POST request to the desired endpoint on your contact center platform and add the memory JSON to the request body. Your endpoint can then parse this payload to identify the last thing said by the user and any data collected by the Assistant.
The final state of your Studio Flow should look like this:
Congratulations! You’ve successfully configured your Bot to contextually hand-off messaging conversations. You can now test it in the Simulator!
Using variables from the Autopilot Widget in Studio Flows
Autopilot provides a number of different variables to the Studio Flow in addition to the bot memory. Learn more about these variables in How to use the Autopilot Studio Widget.
7. Configure Messaging Channels
To successfully hand-off messaging conversations from Autopilot to your Contact Center, the Studio Flow you're using needs to be configured with your messaging channels.
With Flex
If you’re using Flex, you just need to make sure the default WebChat and Messaging flows are configured properly. Go to Flex in the console, click into Messaging and make sure each channel is configured with the right studio flow by selecting Integration type of Studio and then selecting your Studio flow from the dropdown.
Learn more about Flex WebChat here.
Without Flex
If you’re not using Flex but are using Programmable Chat or a Twilio Messaging Channel, follow the instructions on configuring messaging channels using the Autopilot Studio widget from How to Build a Chatbot with Autopilot.
That’s it! Congratulations, you’ve successfully built contextual agent hand-off from Autopilot to Flex.
8. Keep Building!
- Add some more tasks, like a customer satisfaction survey.
- Learn how to build a chatbot and deploy it on multiple messaging channels.
- Learn how to train bots in production.
- Understand how Task Confidence works.
- Explore the Autopilot documentation.
- Get familiar with the Autopilot CLI.
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.