Research

Repurposing Twilio

Initially, it seemed that Twilio didn’t have the capability to run our SMS chatbots. However, after we dove deeper into its feature set, we found a way to repurpose them to achieve what we need.

How Twilio Works

There are two main features that Twilio provide when it comes to their platform being feasible for the system we want to design.

Twilio Autopilot

Twilio Autopilot allows users to create custom bots, IVRs and home assistant apps[1], giving developers access through their API.

Chatbots that you create with Autopilot are made up of what Twilio calls “Tasks”.

A Task can be described as a single item of work waiting to be processed[2].

You can think of these Tasks in a similar way to how we have blocks in Voiceflow. Each Task defines an action such as returning a message to the user, and you can have many of these Tasks to create a chatbot.

However, after a Task completes and a message is returned to the user, there is no logic that starts another Task based on the user’s response.

Only one task can redirect to another specific task, and no branching is supported.

This is why we need to utilise another feature that Twilio offers.

Twilio Services

Twilio enables developers to create a serverless environment on their platform[3].

With this serverless environment, you can upload your own custom code and files that Twilio will host for you.

This custom code can be used to create event-driven scripts, such as when a user responds to a chatbot[4].

In a Task, you can redirect to this custom code.

How Can We Use These Twilio Features?

This is an example of how a Task is constructed under one of these chatbots.

{
	"actions": [
		{
			"say": "Are you feeling ill?"
		},
		{
			"redirect": "task://next-question"
		}
	]
}

Previously I likened Twilio Tasks to blocks in Voiceflow and that gave us the idea to try converting each Voiceflow block into a Twilio Task.

Within each Task, you can define a set of actions, and the thing most important to us is defining what text you want to be displayed to the user. You can also define which Task you want to redirect to from your current Task.

For a Yes or No question, you will have one Task holding the answer to a question if a user responds “Yes”, and you will have another Task holding the answer to a question if a user responds “No”.

You can only redirect to one specific Task[5], but a Yes or No question would require redirecting to one or the other Task, which you don’t know until the user responds.

This is where Twilio Services are useful to us. When a user responds and a task finishes, we can then redirect the Task to a handling script that knows the current Task and user input and, using that, pursues to the next Task Twilio needs to route to continue the conversation.

By combining Twilio Autopilot and Twilio Services, we are able to support conversational branching where we can dynamically change which question a user gets routed to based on their input.


[1] “Twilio Autopilot - An AI Platform to build artificially intelligent assistants, bots, IVRs, and Alexa apps.”, Twilio, 2021. [Online]. Available: https://www.twilio.com/autopilot. [Accessed: 21 Mar 2021].
[2] “Twilio TaskRouter Task Resource”, Twilio.com. [Online]. Available: https://www.twilio.com/docs/taskrouter/api/task. [Accessed: 21 Mar 2021].
[3] C. RABASA, “Introducing Twilio Functions — Public Beta Now Open”, Twilio Blog, 2017. [Online]. Available: https://www.twilio.com/blog/2017/05/introducing-twilio-functions.html. [Accessed: 21 Mar 2021].
[4] Twilio.com. Functions. [online] Available at: https://www.twilio.com/docs/runtime/functions [Accessed 21 March 2021].
[5] Twilio.com. Redirect. [online] Available at: https://www.twilio.com/docs/autopilot/actions/redirect [Accessed 21 March 2021].