You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document provides AI assistants with essential information for working with the Voice IVR project.
4
+
5
+
## Project Overview
6
+
7
+
The Voice IVR project implements an interactive voice response system using Twilio. The system allows callers to navigate a phone tree using keypad digits or speech recognition. When users call the Twilio number, they can choose between: talking to sales, hearing business hours, or receiving an SMS with the company address.
8
+
9
+
## Documentation Links
10
+
11
+
All Twilio documentation URLs in this guide can be accessed in markdown format by adding `.md` to the end of the URL.
12
+
13
+
## Do-Not-Touch Areas
14
+
15
+
### 1. Webhook Signature Verification
16
+
17
+
The `.protected.js` suffix on function files indicates they require valid Twilio signatures. Never remove this protection or modify the validation logic. Twilio's serverless toolkit handles this automatically.
18
+
19
+
### 2. Critical Parameters
20
+
21
+
Never modify these critical parameters without explicit instructions:
22
+
23
+
-`numDigits: 1` in voice-ivr.js - This ensures the system expects a single digit input
24
+
-`input: 'speech dtmf'` in voice-ivr.js - This enables both speech and touch-tone input
25
+
- Webhook paths (`voice-ivr` and `handle-user-input`) - These must match Twilio configurations
26
+
27
+
### 3. Sensitive Data
28
+
29
+
Never expose or hardcode these sensitive details:
30
+
31
+
- Phone numbers (use environment variables)
32
+
- Twilio account credentials
33
+
- Customer information received during calls
34
+
35
+
## Coding Conventions
36
+
37
+
**TwiML must be returned via callback**: All functions must call `callback(null, twiml)` to return TwiML responses. Never use `return twiml` directly.
38
+
39
+
```javascript
40
+
consttwiml=newTwilio.twiml.VoiceResponse();
41
+
twiml.say('Message to speak');
42
+
callback(null, twiml); // Required pattern
43
+
```
44
+
45
+
## Tests
46
+
47
+
Run `npm test` from the repository root. Comprehensive test coverage exists in `tests/` for both functions, covering DTMF inputs, speech recognition, error handling, and SMS delivery.
48
+
49
+
## Common Tasks
50
+
51
+
### Adding a New Menu Option
52
+
53
+
To add a new menu option (e.g., "Support"):
54
+
55
+
1. Add new option in `voice-ivr.protected.js`:
56
+
```javascript
57
+
gather.say('Press 4 or say Support to get technical help');
58
+
```
59
+
60
+
2. Add speech recognition and handler in `handle-user-input.protected.js`:
61
+
```javascript
62
+
// In speech normalization section
63
+
if (UserInput.toLowerCase().includes('support')) {
64
+
UserInput ='4';
65
+
}
66
+
67
+
// In switch statement
68
+
case '4':
69
+
twiml.say('Connecting you to our support team');
70
+
twiml.dial(context.SUPPORT_PHONE_NUMBER);
71
+
break;
72
+
```
73
+
74
+
3. Add any necessary environment variable to `.env`:
This application allows users to navigate an IVR (phone tree) using keys or speech-to-text via a Twilio number. When a user calls the number, they are presented with three options: Talk to Sales, Hours of Operation, or Address. Selecting the first option forwards the call to a given phone number. The second provides an immediate voice response with relevant information. Choosing the third option triggers an SMS with the requested details. The application is fully customizable, allowing you to edit the available options and responses.
3
+
This application allows users to navigate an IVR (phone tree) using keys or speech-to-text via a Twilio number. When a user calls the number, they are presented with three options:
4
4
5
-
## Pre-requisites
5
+
1. Talk to Sales: Forwards the call to a given phone number (set in `.env`)
6
+
2. Hours of Operation: Provides an immediate voice response with opening hours information
7
+
3. Address: Triggers an SMS with address details to the caller's phone number
6
8
7
-
- A Twilio account - [sign up here](https://www.twilio.com/try-twilio)
8
-
- A Twilio phone number
9
+
The user can select an option by dialing or saying the appropriate number.
9
10
10
-
### Environment variables
11
+
The application is fully customizable, allowing you to edit the available options and responses.
11
12
12
-
This project requires some environment variables to be set. To keep your tokens and secrets secure, make sure to not commit the `.env` file in git. When setting up the project with `twilio serverless:init ...` the Twilio CLI will create a `.gitignore` file that excludes `.env` from the version history.
13
+
**For AI coding assistants:** See [AGENTS.md](./AGENTS.md) for implementation guidelines, do-not-touch areas, coding conventions, and common task recipes.
|`MY_PHONE_NUMBER`| The phone number that you want calls to be forwarded to. | yes |
17
+
- An [ngrok][ngrok_url] account
18
+
- A [Twilio account](try_twilio_url) with an active phone number that can send SMS
19
19
20
-
### Function Parameters
20
+
### Environment variables
21
21
22
-
`/voice-ivr` is protected and requires a valid Twilio signature.
22
+
This project requires some environment variables to be set. To keep any tokens and secrets secure, make sure to not commit the `.env` file in git. When setting up the project with `twilio serverless:init ...` the Twilio CLI will create a `.gitignore` file that excludes `.env` from the version history.
23
23
24
-
`/handle-user-input` is protected and requires a valid Twilio signature and expects the following parameters:
24
+
Copy `.env.example`, and set the following values:
Now when you call your Twilio number, it will trigger the `/voice-ivr` function.
57
94
58
95
## Deploying
59
96
60
-
Deploy your functions and assets with either of the following commands. Note: you must run these commands from inside your project folder. [More details in the docs.](https://www.twilio.com/docs/labs/serverless-toolkit)
97
+
Deploy your functions and assets with the following command. Note: you must run these commands from inside your project folder. [More information about the serverless toolkit in the docs.](https://www.twilio.com/docs/labs/serverless-toolkit)
61
98
62
99
With the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart):
0 commit comments