Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this pageProducts used

Use Twilio Conversations as a Channel


(warning)

Twilio Alpha - Developer Preview

AI Assistants is a Twilio Alpha(link takes you to an external page) project that's in Developer Preview. To request access, please join the waitlist(link takes you to an external page).

View the current limitations for details about feature limits during developer preview.

By connecting your AI Assistant to Twilio Conversations, you can have your AI Assistant available across the variety of channels that Twilio Conversations supports.

This connection also enables:

In this guide, you will connect your AI Assistant to Twilio Conversations. Your Assistant will then listen and respond in any conversation with only one participant.


Prerequisites

prerequisites page anchor

If you don't have a Twilio Conversations service yet, start by creating a new service(link takes you to an external page).

You will also need the Twilio CLI and Serverless Toolkit installed on your machine for this guide.


Deploy Conversations webhook code

deploy-conversations-webhook-code page anchor

To trigger your AI Assistant based on incoming messages to your Twilio Conversations service, you will need to configure Twilio Conversation webhooks. The AI Assistants Samples GitHub repository(link takes you to an external page) contains a sample webhook service that you can deploy for your Twilio account.

You only have to deploy this webhook into your Twilio account once, regardless of how many AI Assistants or Conversations services you intend to use.

To deploy the webhooks, clone the AI Assistants Samples repository(link takes you to an external page) and deploy the Twilio Functions from the repository into your Twilio account.

Install and deploy the webhooks

install-and-deploy-the-webhooks page anchor

_10
git clone git@github.com:twilio-labs/ai-assistants-samples.git
_10
cd ai-assistants-samples
_10
npm install
_10
cp .env.example .env
_10
# you can ignore editing the .env if you don't intend to use other tools in the project
_10
_10
twilio serverless:deploy

After running the commands above, your output should look similar to this:

Example deployment output

example-deployment-output page anchor

_22
Deployment Details
_22
Domain: ai-assistants-samples-1111-dev.twil.io
_22
Service:
_22
ai-assistants-samples (ZSf3510841424c854e3f3b282550211111)
_22
Environment:
_22
dev (ZE94900e7f2a2c330b15cf6e1c9fd11111)
_22
Build SID:
_22
ZB2743d62d52d42ccd55873a0bcd511111
_22
Runtime:
_22
node18
_22
View Live Logs:
_22
https://www.twilio.com/console/functions/editor/ZSf3510841424c854e3f3b282550211111/environment/ZE94900e7f2a2c330b15cf6e1c9fd11111
_22
Functions:
_22
[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/conversations/messageAdded
_22
[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/messaging/incoming
_22
[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/conversations/response
_22
[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/messaging/response
_22
https://ai-assistants-samples-1111-dev.twil.io/tools/flex-handover
_22
https://ai-assistants-samples-1111-dev.twil.io/tools/google-maps
_22
https://ai-assistants-samples-1111-dev.twil.io/tools/internet-search
_22
https://ai-assistants-samples-1111-dev.twil.io/tools/studio-handover
_22
Assets:

Make sure you take note of the output behind Domain, which is your Functions URL.


Next, configure your deployed webhook as an onMessageAdded webhook on your Twilio Conversations service. You can do this either by opening your Conversations service in the Twilio Console(link takes you to an external page) and selecting Webhooks in the menu to define a service-wide webhook, or by running the following command using the Twilio CLI:

Set a Conversations webhook

set-a-conversations-webhook page anchor

_10
twilio api:conversations:v1:services:configuration:webhooks:update \
_10
--post-webhook-url=https://<your-functions-domain>.twil.io/channels/conversations/messageAdded?AssistantSid=<your-assistant-sid>
_10
--chat-service-sid=<your-conversations-service-sid>
_10
--filter=onMessageAdded

Make sure you replace <your-functions-domain>, <your-assistant-sid>, and <your-conversations-service-sid> with the respective values from the steps above. You can find your AI Assistant's SID in the Twilio Console under your Assistant's configuration(link takes you to an external page).


If you've already been using Twilio Conversations with an existing application, you can test this configuration right away with that application. Your AI Assistant will respond in any conversation that has only one participant in it. Once another participant joins the conversation, your Assistant will automatically stop listening.

If you don't have an application yet, you can follow the instructions in the Conversations Quickstart(link takes you to an external page) to get started or check out the guide for using AI Assistants with React.



Rate this page: