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

Use Twilio Messaging 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.

This guide will show you how to trigger your AI Assistant with incoming messages from end users by connecting your Assistant with Twilio Conversations. To get started, you will need the following:


Setup

setup page anchor

To trigger your AI Assistant via incoming messages, you will configure an incoming message webhook on your Twilio phone number to forward messages to your AI Assistant.

Deploy the webhook code

deploy-the-webhook-code page anchor

You only have to deploy this webhook into your Twilio account once, regardless of how many AI Assistants or phone numbers 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 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 above commands, 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
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
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; this is your Functions URL.

Configure your webhook for SMS

configure-your-webhook-for-sms page anchor

If you use the Twilio Console, open your SMS-capable phone number(link takes you to an external page) of choice or Messaging Service(link takes you to an external page) in the Twilio Console and configure the When a message comes in webhook to point to: https://<your-functions-domain>.twil.io/channels/messaging/incoming?AssistantSid=<your-assistant-sid>. You can find your Assistant's SID in the Twilio Console under your Assistant's configuration.

Alternatively, you can use the Twilio CLI to configure the webhook by running the following command:

Set an Incoming Message webhook

set-an-incoming-message-webhook page anchor

_10
twilio phone_number <your-twilio-number> \
_10
--sms-url=https://<your-functions-domain>.twil.io/channels/messaging/incoming?AssistantSid=<your-assistant-sid>

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

Configure your webhook for the Sandbox for WhatsApp

configure-your-webhook-for-the-sandbox-for-whatsapp page anchor

If you are using the WhatsApp Sandbox for this guide, configure your When a message comes in webhook in the WhatsApp Sandbox Settings(link takes you to an external page) to point to https://<your-functions-domain>.twil.io/channels/messaging/incoming?AssistantSid=<your-assistant-sid>

Make sure you replace <your-functions-domain> and <your-assistant-sid> with the respective values from the steps above.

Send a message to your Twilio phone number or WhatsApp sandbox, and you should receive a response from your AI Assistant.



Rate this page: