Skip to contentSkip to navigationSkip to topbar
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.

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
1
git clone git@github.com:twilio-labs/ai-assistants-samples.git
2
cd ai-assistants-samples
3
npm install
4
cp .env.example .env
5
# you can ignore editing the .env if you don't intend to use other tools in the project
6
7
twilio serverless:deploy

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

Example deployment output

example-deployment-output page anchor
1
Deployment Details
2
Domain: ai-assistants-samples-1111-dev.twil.io
3
Service:
4
ai-assistants-samples (ZSf3510841424c854e3f3b282550211111)
5
Environment:
6
dev (ZE94900e7f2a2c330b15cf6e1c9fd11111)
7
Build SID:
8
ZB2743d62d52d42ccd55873a0bcd511111
9
Runtime:
10
node18
11
View Live Logs:
12
https://www.twilio.com/console/functions/editor/ZSf3510841424c854e3f3b282550211111/environment/ZE94900e7f2a2c330b15cf6e1c9fd11111
13
Functions:
14
[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/conversations/messageAdded
15
[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/messaging/incoming
16
[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/conversations/response
17
[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/messaging/response
18
https://ai-assistants-samples-1111-dev.twil.io/tools/flex-handover
19
https://ai-assistants-samples-1111-dev.twil.io/tools/google-maps
20
https://ai-assistants-samples-1111-dev.twil.io/tools/internet-search
21
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
1
twilio api:conversations:v1:services:configuration:webhooks:update \
2
--post-webhook-url=https://<your-functions-domain>.twil.io/channels/conversations/messageAdded?AssistantSid=<your-assistant-sid>
3
--chat-service-sid=<your-conversations-service-sid>
4
--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.


Need some help?

Terms of service

Copyright © 2024 Twilio Inc.