This app shows you how to build a basic interactive voice response (IVR) system with PHP and Twilio.
This sample app provides the following functionality:
- A customer calls your Twilio phone number
- Your app answers the call using text-to-speech and asks the caller to choose from one of three options:
- Talk to sales
- Get the company's hours of operation
- Get the company's address
- The caller dials an option. Your app tells them the information that they requested or it sends an SMS to the caller with the company's address.
To run the app locally, you need the following:
- PHP 8.3 or later
- Composer
- An ngrok account
- A Twilio account with an active phone number that can send SMS
- Clone or download this repository.
- Install the dependencies:
composer install
- Rename the
.env.examplefile to.env - Go to the Twilio Console and find your Account SID, Auth Token, and Twilio phone number.
- Copy and paste those values into the placeholders in the
.envfile. Save the file. - Start the app:
composer run-script serve
- Start your ngrok server:
ngrok http 8080
- Go to the Active numbers page in the Twilio Console.
- Click your Twilio phone number.
- Go to the Configure tab and find the Voice Configuration section.
- In the A call comes in row, select the Webhook option.
- Paste your ngrok public URL in the URL field. For example, if your ngrok console shows Forwarding
https://1aaa-123-45-678-910.ngrok-free.app, enterhttps://1aaa-123-45-678-910.ngrok-free.app. - Click Save configuration.
- With the PHP server and ngrok running, call your Twilio phone number. You hear the IVR greeting defined in
public/index.php.
This project uses PHPUnit for testing. To run tests:
composer test