Skip to content

Commit d4d1f2f

Browse files
authored
Merge pull request #648 from dylanfrankcom/update-voice-ivr-agents
Refresh Voice IVR readme and agent guidance
2 parents 726bd99 + ca6f1a3 commit d4d1f2f

4 files changed

Lines changed: 57 additions & 78 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refer to [AGENTS.md](../AGENTS.md) for all repo instructions.

voice-ivr/AGENTS.md

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,74 @@
1-
# Voice IVR - Agent Guidelines
1+
# Voice IVR
22

3-
This document provides AI assistants with essential information for working with the Voice IVR project.
3+
This sample demonstrates a phone tree (IVR) using Twilio Voice and Programmable SMS, where callers navigate options by keypad or speech-to-text to reach sales, hear hours, or receive an address by SMS.
44

5-
## Project Overview
5+
## Environment Variables
66

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.
7+
Copy `.env.example` to `.env`. Never commit `.env`.
88

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.
9+
```bash
10+
cp .env.example .env
11+
```
1812

19-
### 2. Critical Parameters
13+
| Variable | Where to find | Format |
14+
| -------- | ------------- | ------ |
15+
| `MY_PHONE_NUMBER` | The phone number you want the Sales option to forward calls to — use your own mobile during development | E.164 format: `+15551234567` |
2016

21-
Never modify these critical parameters without explicit instructions:
17+
> Note: `ACCOUNT_SID` and `AUTH_TOKEN` are injected automatically by Twilio Serverless and do not need to be set in `.env`.
2218
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
19+
## Commands
2620

27-
### 3. Sensitive Data
21+
```bash
22+
# Install Twilio CLI serverless plugin (once)
23+
twilio plugins:install @twilio-labs/plugin-serverless
2824

29-
Never expose or hardcode these sensitive details:
25+
# Initialize a new project from this template
26+
twilio serverless:init example --template=voice-ivr && cd example
3027

31-
- Phone numbers (use environment variables)
32-
- Twilio account credentials
33-
- Customer information received during calls
28+
# Run locally
29+
twilio serverless:start
3430

35-
## Coding Conventions
31+
# Expose webhooks locally
32+
# Requires ngrok — install and authenticate at https://ngrok.com before running
33+
ngrok http 3000
34+
# Set the resulting HTTPS URL + /voice-ivr as the webhook in Twilio Console (Voice → A Call Comes In → POST)
3635

37-
**TwiML must be returned via callback**: All functions must call `callback(null, twiml)` to return TwiML responses. Never use `return twiml` directly.
36+
# Deploy to Twilio Serverless
37+
twilio serverless:deploy
3838

39-
```javascript
40-
const twiml = new Twilio.twiml.VoiceResponse();
41-
twiml.say('Message to speak');
42-
callback(null, twiml); // Required pattern
39+
# Test
40+
npm test
4341
```
4442

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.
43+
## Project Structure
4844

49-
## Common Tasks
45+
- `functions/voice-ivr.protected.js` — entry point; presents the IVR menu via TwiML `<Gather>`
46+
- `functions/handle-user-input.protected.js` — handles digit/speech input; forwards call, reads hours, or sends SMS
47+
- `.env.example` — environment variable template
48+
- `tests/` — Jest test suite
5049

51-
### Adding a New Menu Option
50+
## Agent Boundaries
5251

53-
To add a new menu option (e.g., "Support"):
52+
**Always:**
5453

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-
```
54+
- Confirm `.env` is configured before running any command
55+
- Use the Environment Variables section to guide the user to each credential — don't ask them to find values without direction
56+
- Confirm the app is running before asking the user to test it
5957

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-
}
58+
**Never:**
6659

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-
```
60+
- Run the app with missing or placeholder credentials
61+
- Hardcode credentials or phone numbers in source files
62+
- Skip the `cp .env.example .env` step
7363

74-
3. Add any necessary environment variable to `.env`:
75-
```
76-
SUPPORT_PHONE_NUMBER=+15551234567
77-
```
64+
## Verify It's Working
7865

79-
4. Add any required unit tests
66+
1. Call your Twilio phone number. You should hear the IVR prompt offering three options.
67+
2. Press `1` (or say "Sales") — the call should forward to the number set in `MY_PHONE_NUMBER`. Press `3` (or say "Address") — you should receive an SMS with the address to the caller's number within a few seconds.
8068

81-
## Further Resources
69+
## Twilio Resources
8270

83-
- [Twilio TwiML Voice Documentation](https://www.twilio.com/docs/voice/twiml)
84-
- [Twilio Speech Recognition](https://www.twilio.com/docs/voice/twiml/gather#speechmodel)
85-
- [Twilio SMS Documentation](https://www.twilio.com/docs/sms)
86-
- [Twilio Serverless Functions](https://www.twilio.com/docs/runtime/functions)
71+
- [Twilio Console](https://console.twilio.com) — credentials, phone numbers, webhook configuration
72+
- [Twilio Voice TwiML](https://www.twilio.com/docs/voice/twiml) — TwiML verb reference
73+
- [Twilio Serverless Toolkit](https://www.twilio.com/docs/labs/serverless-toolkit) — deploy and manage Twilio Functions
74+
- [Programmable SMS](https://www.twilio.com/docs/sms) — SMS API reference

voice-ivr/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md

voice-ivr/README.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
# Voice IVR
22

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:
3+
This application implements a phone tree (IVR) using Twilio Voice and Programmable SMS. When a caller dials your Twilio number they hear three options — Talk to Sales, Hours of Operation, or Address — and can select one by pressing a digit or speaking the option name. Sales calls are forwarded to a configurable phone number, hours are read back via text-to-speech, and the address is delivered as an SMS to the caller.
44

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
8-
9-
The user can select an option by dialing or saying the appropriate number.
10-
11-
The application is fully customizable, allowing you to edit the available options and responses.
12-
13-
**For AI coding assistants:** See [AGENTS.md](./AGENTS.md) for implementation guidelines, do-not-touch areas, coding conventions, and common task recipes.
5+
**For AI coding assistants:** See [AGENTS.md](./AGENTS.md) for setup and implementation guidelines.
146

157
## Prerequisites
168

17-
- An [ngrok][ngrok_url] account
18-
- A [Twilio account](try_twilio_url) with an active phone number that can send SMS
9+
- An [ngrok](https://ngrok.com) account
10+
- A [Twilio account](https://www.twilio.com/try-twilio) with an active phone number that can send SMS
1911

20-
### Environment variables
12+
## Environment variables
2113

2214
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.
2315

@@ -58,7 +50,7 @@ Check the developer console and terminal for any errors, and make sure you've se
5850

5951
### Exposing your local server
6052

61-
To test with a real Twilio phone number, you need to expose your local server to the internet. You can use [ngrok](ngrok_url):
53+
To test with a real Twilio phone number, you need to expose your local server to the internet. You can use [ngrok](https://ngrok.com):
6254

6355
```bash
6456
ngrok http 3000
@@ -101,6 +93,3 @@ With the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart):
10193
```
10294
twilio serverless:deploy
10395
```
104-
105-
[ngrok_url]: https://ngrok.com/
106-
[try_twilio_url]: https://www.twilio.com/try-twilio

0 commit comments

Comments
 (0)