# Twilio Integration
The integration with Twilio can be facilitated using a combination of Twilio Studio (opens new window) and Twilio Functions (opens new window) or using some form of stateful external or on-prem lambda integration.
# Twilio (Studio + Functions)
The exact flow may contain states that are unique to the individual needs of the particular integration but the generic version of this process involves creating a Twilio Studio Flow that facilitates handling the following repeating steps. The JSON file for this flow and the Twilio Function that works in tandem is included below. While any part of this out of the box studio flow can be customized there is an included state whose entire purpose is to make it easier to configure. You can see this labeled in the JSON as “Set Variables”.
- TTS greeting message played to the user
- Start built-in speech recognition to grab the users query.
- Trigger Twilio Function with the user query and any previous dialog token if available.
- Save query response text and dialog token from the response.
- TTS query response played to the user
- Based on the conditional of the classified competency transferring to a live agent or ending the conversation here is possible.
- Repeat from step 2.
Download the JSON files here:
# Twilio Setup
# Setup Twilio Runtime Function for Voice
This section explains setting up the required functions used in an end to end Twilio voice integration with Clinc.
- Navigate to Twilio Console Functions Management Page (opens new window)
- Click Create a Function to add a new function.
- Select the template Blank and click Create.
- Give the function a desired name and path, you will need to remember this for step #6 in Setup Twilio Studio Flow.
- Uncheck Check for valid Twilio signature.
- Copy and paste the Javascript code from “ClincTwilioFunction_v1.3.js” above and click Save on the bottom of the screen.
# Setup Twilio Studio Flow
This section explains setting up the Twilio Studio Flow and its connections to the functions created in the previous sections.
- Navigate to Twilio Console Studio Flows Page (opens new window)
- Click Create new Flow to add a new flow.
- Enter the desired name and click next.
- Select template Import from JSON and click next.
- Copy and paste the JSON “ClincTwilioStudio_v1.3.json” from above and click next.
- Click the MakeQuery Widget in the canvas, then select the function you created in Setup Twilio Runtime Function, and click Save.
- Click the SetVariables Widget, then change any of the variables to fit your needs including authentication credentials, hostname and AI version.
- Optional steps
a. Change Voice used for Text to Speech in the WelcomeMessage, QueryResponse and EndCall widgets.
b. Change Region used for Speech Recognition in the FollowupAudioRequest and FirstAudioRequest widgets
c. Update greeting in the WelcomeMessage widget
d. Update the closing message in the EndCall widget
# Setup Twilio Phone Number
This section explains linking a rented or transferred phone number to the Twilio studio flow.
- Navigate to Twilio Console Phone Numbers Page (opens new window)
- If you have a voice capable phone number skip to step 4.
- Select Buy a Number, search for a phone number that is voice capable and in the desired region and purchase.
- Select the desired phone number.
- In the Voice section select Webhooks, TwiML Bins, Functions, Studio, or Proxy from the Configure With dropdown.
- Select Studio Flow from the A call comes in dropdown. Then select the studio flow created in Setup Twilio Studio Flow.
- If you don’t need to setup Twilio to support SMS messages then skip to step 10.
- In the Messaging section select Webhooks, TwiML Bins, Functions, Studio, or Proxy from the Configure With dropdown.
- Select Studio Flow from the A call comes in dropdown. Then select the studio flow created in Setup Twilio Studio Flow.
- Click Save.
# Live Agent Handoff
Twilio doesn't have a built-in live agent/contact center system, any live agent hand-off would be facilitated using the APIs of the "contact center system" being used. Twilio does allow to POST data using an HTTP request and can send any information received and retained during the user interaction.
Last Updated: 07/17/2020