Use Twilio Messaging as a Channel
Twilio Alpha - Developer Preview
AI Assistants is a Twilio Alpha project that's in Developer Preview.
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 Messaging. To get started, you will need the following:
- A configured AI Assistant. See the Quickstart guide to setting up an Assistant if you have not configured one yet.
- A Twilio phone number or WhatsApp business number. Alternatively, you can use the Twilio Sandbox for WhatsApp to get started.
- The Twilio CLI installed on your machine.
- The Serverless Toolkit installed on your machine.
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.
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 and deploy the Twilio Functions into your Twilio account.
1git clone git@github.com:twilio-labs/ai-assistants-samples.git2cd ai-assistants-samples3npm install4cp .env.example .env5# you can ignore editing the .env if you don't intend to use other tools in the project67twilio serverless:deploy
After running the above commands, your output should look similar to this:
1Deployment Details2Domain: ai-assistants-samples-1111-dev.twil.io3Service:4ai-assistants-samples (ZSf3510841424c854e3f3b282550211111)5Environment:6dev (ZE94900e7f2a2c330b15cf6e1c9fd11111)7Build SID:8ZB2743d62d52d42ccd55873a0bcd5111119Runtime:10node1811View Live Logs:12https://www.twilio.com/console/functions/editor/ZSf3510841424c854e3f3b282550211111/environment/ZE94900e7f2a2c330b15cf6e1c9fd1111113Functions:14[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/conversations/messageAdded15https://ai-assistants-samples-1111-dev.twil.io/channels/messaging/incoming16[protected] https://ai-assistants-samples-1111-dev.twil.io/channels/conversations/response17https://ai-assistants-samples-1111-dev.twil.io/channels/messaging/response18https://ai-assistants-samples-1111-dev.twil.io/tools/flex-handover19https://ai-assistants-samples-1111-dev.twil.io/tools/google-maps20https://ai-assistants-samples-1111-dev.twil.io/tools/internet-search21https://ai-assistants-samples-1111-dev.twil.io/tools/studio-handover22Assets:
Make sure you take note of the output behind Domain
; this is your Functions URL.
If you use the Twilio Console, open your SMS-capable phone number of choice or Messaging Service 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:
1twilio phone_number <your-twilio-number> \2--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.
If you are using the WhatsApp Sandbox for this guide, configure your When a message comes in webhook in the WhatsApp Sandbox Settings 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.