# Use Twilio Conversations as a Channel

> \[!WARNING]
>
> AI Assistants is a [Twilio Alpha](https://twilioalpha.com) project that's in **Developer Preview**.
>
> View the [current limitations](/docs/alpha/ai-assistants/pricing-and-limits) for details about feature limits during developer preview.

By connecting your AI Assistant to [Twilio Conversations](/docs/conversations), you can have your AI Assistant available across the variety of channels that Twilio Conversations supports.

This connection also enables:

* [AI Assistant handoff to a Twilio Flex agent](/docs/alpha/ai-assistants/code-samples/transition-flex)
* [Transitioning a conversation from an AI Assistant to a Twilio Studio Flow](/docs/alpha/ai-assistants/code-samples/transition-studio)
* [The AI Assistant React SDK](/docs/alpha/ai-assistants/code-samples/react)

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

If you don't have a Twilio Conversations service yet, start by [creating a new service](https://www.twilio.com/console/conversations/services).

You will also need the [Twilio CLI](/docs/twilio-cli/quickstart) and [Serverless Toolkit](/docs/labs/serverless-toolkit) installed on your machine for this guide.

## Deploy Conversations webhook code

To trigger your AI Assistant based on incoming messages to your Twilio Conversations service, you will need to configure [Twilio Conversation webhooks](/docs/conversations/conversations-webhooks). The [AI Assistants Samples GitHub repository](https://github.com/twilio-labs/ai-assistants-samples) 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](https://github.com/twilio-labs/ai-assistants-samples) and deploy the [Twilio Functions](/docs/serverless/functions-assets) from the repository into your Twilio account.

```bash {title="Install and deploy the webhooks"}
git clone git@github.com:twilio-labs/ai-assistants-samples.git
cd ai-assistants-samples
npm install
cp .env.example .env
# you can ignore editing the .env if you don't intend to use other tools in the project

twilio serverless:deploy
```

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

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

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

## Configure your webhook

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](https://twilio.com/console/conversations/services) and selecting **Webhooks** in the menu to define a service-wide webhook, or by running the following command using the Twilio CLI:

```bash {title="Set a Conversations webhook"}
twilio api:conversations:v1:services:configuration:webhooks:update \
    --post-webhook-url=https://<your-functions-domain>.twil.io/channels/conversations/messageAdded?AssistantSid=<your-assistant-sid>
    --chat-service-sid=<your-conversations-service-sid>
    --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](https://console.twilio.com/us1/develop/ai-assistants/assistants).

## Test your configuration

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](/docs/conversations/quickstart) to get started or check out the guide for using [AI Assistants with React](/docs/alpha/ai-assistants/code-samples/react).

## Learn more

* [Learn how to add an AI Assistant to your React application](/docs/alpha/ai-assistants/code-samples/react)
* [Learn how to have your AI Assistant transition a conversation to a Flex agent](/docs/alpha/ai-assistants/code-samples/transition-flex)
* [Learn how to have your AI Assistant transition a conversation to a Studio flow](/docs/alpha/ai-assistants/code-samples/transition-studio)
