Example demonstrating ChatChannel integration with Twilio Agent Connect. Uses the Twilio Conversations JS SDK for web chat conversations.
-
From the repository root, install and build the SDK:
npm install npm run build
-
Configure environment variables. From the
getting_started/examples/directory, copy and fill in the template:cp .env.example .env # Edit .env with your credentialsRequired credentials:
- Standard TAC credentials (Account SID, Auth Token, API credentials, Conversation Orchestrator configuration ID:
TWILIO_CONVERSATION_CONFIGURATION_ID) TWILIO_CONVERSATIONS_SERVICE_SID- Conversations v1 Service SID (starts with IS, not the Conversation Orchestrator configuration ID)OPENAI_API_KEY- OpenAI API key
- Standard TAC credentials (Account SID, Auth Token, API credentials, Conversation Orchestrator configuration ID:
-
Install the example's dependencies:
cd getting_started/examples/chat npm install -
Start the server:
npm start
-
Open http://localhost:8000 in your browser
-
Frontend: Browser-based chat with Twilio Conversations SDK
- Select from predefined email identities (e.g.,
test1@example.com) for identity resolution - Fetches access token from
/tokenendpoint - Creates conversation lazily on first message
- Sends messages via Conversations SDK
- Displays AI responses in real-time
- Select from predefined email identities (e.g.,
-
Backend: Standalone Fastify server with TAC + ChatChannel + OpenAI
POST /token— generates Conversations SDK access tokenPOST /webhook— Conversation Orchestrator webhook endpoint- Routes webhook events to ChatChannel
- Calls OpenAI gpt-5.4-mini for responses
- Sends responses via Conversation Orchestrator Actions API
sequenceDiagram
participant Browser
participant Server
participant OpenAI
participant TC as Twilio Conversations
participant CO as Conversation Orchestrator
Browser->>Server: 1. POST /token
Server-->>Browser: Access Token
Browser->>TC: 2. Create Conversation & Send Message (SDK)
TC-->>CO: 3. Passive hydration
CO->>Server: 4. POST /webhook (COMMUNICATION_CREATED)
Server->>OpenAI: 5. Generate response
OpenAI-->>Server: AI response
Server->>CO: 6. POST /v2/Conversations/{id}/Actions (SEND_MESSAGE)
CO-->>TC: 7. Deliver message
TC->>Browser: 8. Message Added (SDK event)
- Start the server and open http://localhost:8000
- Type a message (conversation is created automatically)
- AI responds via OpenAI
- Check server logs to see:
- Token generation
- Webhook routing to ChatChannel
- Actions API calls with
channel='CHAT'
- Conversations are created client-side by the Conversations SDK
- The backend receives webhook events from Conversation Orchestrator
- Messages from the AI agent (
ai-agent) are filtered out to prevent echo