How to: Process Twilio voice transcriptions with AI
Oct 27, 2021 by Automation Hero
Goal
Classify, route and further process transcribed voice calls by integrating a Twilio-enabled telephone number into a processing workflow.
Combining the power of Twilio’s built-in transcriptions of voice messages and the Hero Platform_’s connectivity and automation capabilities will help you achieve great results.
In this how-to article, we’ll be creating a simple processing flow that uses Twilio as an input, processes the information available through the Twilio REST API, and then makes a decision based on the content of a call. This example can be the basis for more powerful automations that integrate AI models and other complex decision making.
Requirements
Get Set Up
We will create a Twilio trial account and provide a basic set up for a telephone number that can receive voice messages and transcribe them. We’ll set up a Hero Platfom_ trial account and connect this to our newly created Twilio trial account. Finally, we’ll set up a processing flow to analyze transcribed voice messages and use an AI model to extract appointment dates.
Create a Twilio trial account
- Login to the Twilio console and select Create New Account
- Provide an account name
- Verify your email and phone number
- Provide the requested information around what you are looking to build and which tools you’ll be using.
- From the dashboard click on Get a Trial Number
- Twilio will suggest a trial number for receiving voice, sms and mms messages.
- Select a number that is able to receive voice messages, we won’t be using SMS, MMS or Fax functionalities below.
- Click on Explore products and find TwiML Bins
- create a new TwiML Bin to say “goodbye”, so the user knows that the call has been recorded.
<?xml version="1.0" encoding="UTF-8"?> <Response> <Say>Thanks, Goodbye!</Say> </Response>
- Collect the
SID
of the above TwiML Bin (click on the name from the list) - Create a TwiML Bin called call handler referencing the SID at the end of the action (line 4):
<?xml version="1.0" encoding="UTF-8"?> <Response> <Say>Please leave a message after the beep then wait 3 seconds.</Say> <Record transcribe="true" playBeep="true" timeout="3" action="https://handler.twilio.com/twiml/EHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/> <Say>We didn't record any input. Goodbye!</Say> </Response>
- create a new TwiML Bin to say “goodbye”, so the user knows that the call has been recorded.
- Under 1
Phone Numbers > Manage > Active Numbers
select your trial number - Under Voice where it says A CALL COMES IN, select TwiML Bin, and then select your
call handler
TwiML Bin - Save your changes and test out the transcription functionality by calling the number and leaving a message, requesting an appointment on a certain date.
1Phone numbers for a Twilio trial account are all US based.
As we now have a working Twilio phone number, let’s dive into Automation Hero’s Hero Platform_ and start bringing in data from Twilio’s REST API.
Create a REST connection to your Twilio account
We’ll create two connections. One to the Hero Platform_’s internal Data Store
to save results, and one to Twilio.
- Create a trial account and log in to Hero Platform_.
- Under
Integration > Connections
click Create New Connection - Provide a name for the internal Data Store connection, e.g.
twilio_appointments
- Under
Connection Type
chooseTuple Store
- Click Create New Connection again
- Provide a name e.g.
twilio_connection
- Choose REST as the Connection Type
- We are using Basic Auth in this example
- The user name is the ACCOUNT SID (this can be found in the Twilio console account page.)
- Use the AUTH TOKEN instead of a password
- The Base URL is built up from the standard Twilio Base URL
https://api.twilio.com/2010-04-01 + /Accounts/ + <your ACCOUNT SID> + / e.g.
- Under
Test endpoint
useRecordings.json
and click on Test connection to verify that the end point is properly set up. - Press OK, and we have a connection to connect the Hero Platform_ to Twilio
Create a Flow
After getting data into the Hero Platform_ we can use a Flow to start automating how we route or use the data.
- Under
Automations > Flows
click Create New Flow - Give the flow a name e.g.
twilio flow
- In the element browser on the right, hit the plus button to create a new input
- Give it a name e.g.
twilio input
and choose thetwilio_connection
created previously - Under Endpoint enter
Recordings.json
- Our Root path is
recordings
- Click on the button to fetch the Fields mapping table
- Finally open the
Input
section in the element browser on the right hand side of the screen, and drag-and-drop your input onto the flow canvas.
We now have one element in our flow. We can click on the preview icon (square with a magnifying glass) to see what kind of data is returned by this connection. Clicking on chevron will show us information around which outputs this connection provides (e.g. column names and data types).
For this example we’re really only interested in sid
column, a unique identifier for the various call recordings.
- Double click on the Input node, and choose Edit output fields
- At the top, use the toggle to deselect all columns and select
sid
- Run the preview, by clicking on the preview icon (square with a magnifying glass), and copy one of the returned
sid
values.
RE0183922e9348ec1befc658a9f9991200
Add a REST API lookup
We want to get the actual transcripts of the calls. For this we need to create another REST lookup. In the element browser, we can see various categories of operators that we can add to our flow. There is also an option to search for a particular operator.
- In the search bar on the right search for REST to bring up a REST Lookup.
- Drag the REST operator onto the canvas and pull a cable from the REST input to the new node.
- Enter
sid
as the argument. - We’ll reuse the
twilio_connection
- Select
GET
as the HTTP method. As the endpoint varies according to thesid
, we can parameterize the endpoint, and use a different endpoint per record in Twilio. EnterRecordings/${sid}/Transcriptions.json
as the endpoint. - The root path of the the returned JSON is
transcriptions
- Click on the Fields mapping table button, paste in the
sid
value from above when prompted.- This pulls in all fields from the REST API
- Notice that
sid
is also a field pulled in and is marked as red, as there is already a column namedsid
- As we already have the sid of every recording, we’ll hit the
x
, to delete this column.
- Click ok, and the node is added and finalized on the canvas.
Analyze the Transcribed Text and Further Automate
Hero Platform_ provides many options for how to analyze the text contained within the transcriptions from Twilio – from simple contains
functions to advanced AI models for classification or extraction of important information. For this example, we want to use a simple AI model to obtain appointment dates from a call.
- From the element browser, under Output drag and drop an Automatic Output onto the canvas
- Connect this node by dragging a cable from the REST Lookup
- Provide a name for this output, e.g.
twilio_transcriptions_output
- Choose
twilio_tuple_store
as the connection
We have just brought data in from Twilio and pushed it to the Hero Platform_’s Data Store. This is where processed data can be stored before being processed further.
Create a Simple AI Model
We need to configure an input to pull data from the Data Store and provide it to an AI model.
- In the element browser, click the plus button to create a new input
- Provide a name, e.g.
twilio_transcriptions_input
- Choose
twilio_tuple_store
as the connection - On the left hand side, navigate to
AI > AI Models
- Click on Create Text Extractor
- Give the new AI model a name, e.g.
twilio_appointment_date
- Click Next
- We can use the newly created
twilio_transcriptions_input
as our source - Select
transcription_text
from the list of possible fieldnames. - Click Save
- While the Extraction Engine warms up, browse the transcribed text from Twilio.
- Click on Add Field and provide a name of what you want to extract, e.g. “appointment_date”
- Write a question in standard language, “On which date is the suggested appointment?”
- Select the check box, “Always answer”
- Click OK
The extraction engine will start to process, and provide an answer to the question. Beside the answer is a small bar that shows how much confidence the model has in its answer. The more full the bar is, the more confident the model is.
Finally click Save and return to the flow that we have created.
Add the AI Model to a Flow & Route Information According to a Confidence Score
We have all the pieces in place to start making decisions based on what information is in a transcribed voice message.
- From the element browser under AI text extraction function, drag your text extraction to the canvas
- As before, connect by dragging a cable to the new node
- Verify that we are using the
transcription_text
field as an argument, and click OK
The text extractor returns a tuple of data with two elements
- The extracted text
- A confidence value from 0 (not confident) to 1 (extremely confident)
We can use the confidence values to route only answers above a certain confidence value automatically, and send the lower values for further processing (either automated or by a human).
- In the element browser, drag the IsGreaterThanOrEqual operator to the canvas
- Connect with a cable
- Choose the field
appointment_date.confidence
as the argument - Enter
0.5
as the right side argument, and click ok
In this example, we’ll route answers with a confidence of 50% to another automatic output.
- From the element browser under output, drag an automatic output to the canvas
- Provide a name, e.g.
twilio_appointments
- Save the Flow and click Run Now
We see the Flow overview screen, listing all flows and other flow-related information. When the flow has stopped running, navigate to Storage > Data Store
and click on twilio_appointments
. Here we will see all of the calls that were transcribed along with the appointment dates which were extracted at above 50% confidence.
This is Just the Beginning
In our example, we connected the Hero Platform_ to another service, brought data into the platform, ran an AI model against the data, and used a confidence score to route our data. Connections in Hero Platform_ operate both ways. Instead of finishing with our data in the platform, we could easily push this to another system, like a CRM or a calendar. Flows can be simple or extremely complex.
To see the results in action, check out our short demo video.
How did it go? Do you have any feedback? Send it to hi@automationhero.ai with the subject line: Automation Hero and Twilio Integration Feedback.
Close Window
Automation Hero will track how you use the emails (e.g., at what time you open which part of the emails) sent by Automation Hero. If you have provided a separate declaration of consent that cookies for tracking your usage of the website and/or apps may be placed on your device, Automation Hero will also connect the information about your use of Automation Hero’s websites and apps (e.g., which information you open) collected by the tracking cookie to such information in so far as possible. Automation Hero will analyze such information, to identify your interests and preferences and to communicate with you in a more personalized and effective way, e.g. by providing information that you are likely interested in, like information on new technologies or products of the Automation Hero group that are likely relevant to you.