This directory contains Twilio Functions that handle voice calls and conference management for an automated customer service system with AI assistant and human escalation capabilities.
Handles the AI assistant's participation in conference calls:
- Manages the AI assistant's connection to conferences
- Configures voice settings and behavior
- Handles assistant-specific conference parameters
Manages conference call setup when a customer dials in:
- Creates a new conference using the CallSid as identifier
- Sets appropriate time limits
- Configures conference parameters:
- Records from start
- Ends when initiator leaves
- Labels participant as 'customer'
- Monitors conference events through status callbacks
Handles conference status events and participant management:
- Processes conference event callbacks (start, join, leave)
- Manages participant labels ('customer', 'agent')
- Handles dynamic addition of AI assistant
- Tracks call details and participant information
- Manages conference state and routing
Manages the escalation process from AI to human agent:
- Extracts session information from call headers
- Identifies active customer conferences
- Manages the transition from AI to human agent
- Handles conference participant updates
- Ensures smooth handover process
- Customer initiates call
- Call is placed into conference via
customer-dial-conference.js
- AI assistant joins via
assistant-call-conference.js
- Conference events managed by
conference-status-callback.js
- Optional escalation to human agent via
escalate-to-human-conference.js
Required environment variables:
TWILIO_ACCOUNT_SID
: Your Twilio Account SIDTWILIO_AUTH_TOKEN
: Your Twilio Auth TokenASSISTANT_ID
: Your AI Assistant IDFUNCTIONS_DOMAIN
: Your Twilio Functions domainAI_ASSISTANT_PHONE_NUMBER
: Phone number for AI assistant
- Node.js >= 14.0.0
- A Twilio account with access to Functions
- Environment variables configured (see below)
- Copy the
.env.example
file to create a new.env
file:cp .env.example .env
- Fill in your environment variables in the
.env
file with the required values listed above
Install the required dependencies by running:
npm install
There are two ways to deploy the functions:
-
Initial deployment:
npm run deploy
This will create a new service and deploy all functions.
-
Redeploy existing service:
npm run redeploy
Use this for subsequent deployments to update existing functions.
After successful deployment, the Functions domain URL will be displayed in the console. Use this URL to configure your Twilio phone numbers or other services that need to interact with these functions.