Twilio AI Assistant (AIA) Adapters is an open-source quick-start sample middleware for integrating Twilio AI Assistant with various communication channels. It provides a flexible and extensible way to connect AI-powered conversational experiences to Twilio Voice, SMS, WhatsApp, and Flex Webchat 3.0.
- Quick-Start: Simplifies AI Assistant deployment with sample ready-to-go configurations
- Performant: Optimizes the number of required API calls to ensure low overhead latency
- Multi-Channel Support: Integrates AI Assistant with Twilio Voice and Conversations (SMS, WhatsApp, and Flex Webchat 3.x)
- Extensible Middleware: Easily customize and extend adapter functionality.
- Enhanced Twilio Flex Handover: Ensures that all attributes from Tools input are passed as task attributes within Twilio Flex
Query Parameter(s) | Required | Default Value | Description |
---|---|---|---|
aiAssistantSid |
Required | N/A | Twilio AI Assistant SID (starts with aia_xxxxx ) |
language |
Optional | "default" | The language to be used by Twilio AI Assistant |
Supported languages with preset configurations:
default
en-US
en-AU
es-ES
hi-IN
ja-JP
ko-KR
pt-BR
th-TH
vi-VN
zh-CN
zh-HK
To use a different language, specify the supported language within the language
parameter.
Example: https://twilio-aia-adapters-XXXX-dev.twil.io/voice/incoming?aiAssistantSid=aia_xxxxx&language=zh-CN
Language configurations can be easily added or modified by updating the assets/voice-languages-config.private.json
file.
Query Parameter(s) | Required | Default Value | Description |
---|---|---|---|
aiAssistantSid |
Required | N/A | Twilio AI Assistant SID (starts with aia_xxxxx ) |
aiAssistantIsTyping |
Optional | false |
Injects the attribute assistantIsTyping into the conversation attribute. Setting this to true will increase the latency. |
aiAssistantIdentity |
Optional | AI Assistant |
The identity name of Twilio AI Assistant within the conversation |
Query Parameter(s) | Required | Default Value | Description |
---|---|---|---|
workspaceSid |
Required | N/A | Twilio TaskRouter's Workspace SID (starts with WSxxxxxx ) |
workflowSid |
Required | N/A | Twilio TaskRouter's Workflow SID (starts with WWxxxxxx ) |
All attributes provided in the Twilio AI Assistant's Tool - Input Schema will be transferred as task attributes in Twilio Flex.
Query Parameter(s) | Required | Default Value | Description |
---|---|---|---|
redirectNumber |
Required | N/A | E.164 Phone Number to Redirect the Call To |
Redirect voice call from AI Assistant to a user-input phone number
A lightweight Twilio Flex Plugin that showcases the Twilio AI Assistant's summary and sentiment, utilizing the task attributes conversationSummary
and conversationSentiment
passed from the AI Assistant's Tool execution during the Twilio Flex handover.
- Twilio Flex Account (Guide)
- Twilio AI Assistant configured (Guide)
- Node.js v18.x.x only (Guide)
- Twilio CLI v5.22.9 or above (Guide)
- Twilio CLI Serverless Toolkit v3.2.0 or above (Guide)
- Twilio CLI Flex Plugin v7.1.0 or above (Guide)
# Clone project
git clone https://github.com/leroychan/twilio-aia-adapters.git
# Change to working directory
cd twili-aia-adapters/serverless-functions
# Install NPM packages
npm install
# Build project as the source code is built using TypeScript
npm run build
# Verify Twilio account is selected correctly on Twilio CLI
twilio profiles:list
# Deploy to Twilio account
twilio serverless:deploy
# Take note of the webhook URL that is dislayed within the CLI
- Navigate to Twilio Console > Phone Numbers > Manage > Active Numbers
- Select your DESIRED VOICE-CAPABLE NUMBER
- Go to Configure > Voice Configuration > A Call Comes In
- Set the webhook URL to:
https://twilio-aia-adapters-XXXX-dev.twil.io/voice/incoming?aiAssistantSid=aia_xxxxx
withHTTP POST
- Click
Save configuration
- Navigate to Twilio Console > Conversations > Addresses > Configure addresses
- Under your DESIRED MESSAGING CHANNEL, click on the Pencil Icon
- Under
Step 1: Autocreate Conversations for new messages?
, EnableAutocreate a conversation
- Under
Step 2: Which Conversations Service should the Conversation be created in?
, selectFlex Chat Service
- Under
Step 3: Want to set up an integration?
, selectWebhook
- Webhook URL for incoming messages:
https://twilio-aia-adapters-XXXX-dev.twil.io/conversations/messageAdded?aiAssistantSid=aia_xxxxx
- Webhook method:
POST
- Webhook Filters:
onMessageAdded
only
- Click
Update
-
Ensure you have Twilio Flex Webchat 3.x configured (Guide)
-
Navigate to Twilio Console > Flex > Manage > Messaging
-
Under Filter by Address type, select Chat
-
Under your DESIRED FLEX WEBCHAT ADDRESS, click on the Pencil Icon
-
Under Flex Integration
- Integration Type:
Webhook
- Webhook URL:
https://twilio-aia-adapters-XXXX-dev.twil.io/conversations/messageAdded?aiAssistantSid=aia_xxxxx
- Integration Type:
-
Click Update Address
- Navigate to Twilio Console > TaskRouter > Workspaces to obtain both
workspaceSid
(i.e.WSxxxxx
) andworkflowSid
(WWxxxx
).workflowSid
can be retrieved after clicking into the default workspace namedFlex Task Assignment
and thenWorkflows
. - Once done, navigate to Twilio Console > AI Assistant > My Assistants
- Select your DESIRED AI ASSISTANT
- Go to **Tools* and click **Add Tool* button
- Name:
Twilio Flex Handover
- Description:
When the user requests to talk to a live agent or an actual human. This is meant to transfer call to a contact center
- Select HTTP Method:
POST
- Webhook URL:
https://twilio-aia-adapters-XXXX-dev.twil.io/tools/flex-handover?workfspaceSid=WSxxxxx&workflowSid=WWxxxxxx
- Input Schema:
export type Data = { conversationSummary: string, conversationSentiment: "positive" | "neutral" | "negative", };
- Authorization Provider:
None
- Name:
- Click Save Changes button
# Change to working directory
cd ..
cd plugin-aia-summary
# Install Dependencies
npm install
# Optional - Modify Environment Variables. You can also pass it via query parameters.
cp .env.example .env
# Optional - Local Development
twilio flex:plugins:start
# Verify Twilio account is selected correctly on Twilio CLI
twilio profiles:list
# Deploy to Twilio Flex Instance
twilio flex:plugins:deploy --changelog "Deploy AI Assistant Summary Plugin"
twilio flex:plugins:release --plugin plugin-aia-summary@0.0.1 --name "Deploy AIA Plugin" --description "Displays AI Assistant's Conversation Summary and Conversation Sentiment"