+
Skip to content

lmbelo/cr-demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Voice Assistant with Twilio and Open AI (Node.js)

This application demonstrates how to use Node.js, Twilio Voice and ConversationRelay, and the Open AI API to create a voice assistant that can engage in two-way conversations over a phone call. Other branches in this repository demonstrate how to add more advanced features such as streaming, interruption handling, and tool/function calling.

Prerequisites

To use the app, you will need:

  • Node.js 23.9.0: Download from here. Other versions may work, but I tested with this one.
  • A Twilio Account: Sign up for a free trial here.
  • A Twilio Number with Voice Capabilities: Instructions to purchase a number.
  • An Open AI Account and API Key: Visit Open AI's platform here for more information.

Setup

1. Run ngrok

You'll need to expose your local server to the internet for Twilio to access it. Use ngrok for tunneling:

ngrok http 8080

Copy the Forwarding URL and put it aside; it looks like https://[your-ngrok-subdomain].ngrok.app. You'll need it in a couple places.

2. Install dependencies

Run the following command to install necessary packages:

npm install

3. Configure Twilio

Update Your Twilio Phone Number: In the Twilio Console under Phone Numbers, set the Webhook for A call comes in to your ngrok URL followed by /twiml.

Example: https://[your-ngrok-subdomain].ngrok.app/twiml.

4. Configure Environment Variables

Copy the example environment file to .env:

cp .env.example .env

Edit the .env file and input your Open AI API key in OPENAI_API_KEY. Add your ngrok URL in NGROK_URL (do not include the scheme, "http://" or "https://")

Run the app

Start the development server:

node server.js

Run and test the app

Call your Twilio phone number. After connection, you should be able to converse with the Open AI-powered AI Assistant, integrated over ConversationRelay with Twilio Voice!

Note

Customize the initial greeting and response behavior by modifying the aiResponse function and constants like SYSTEM_PROMPT in index.js. Ensure that you update ngrok URLs each time you restart ngrok, as they change with each session.

About

Small demo project integrating Twilio Voice and Open AI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载