This is a small PHP app built using the Slim Framework that shows how to build a call forwarding app that forwards calls during a specific time window, and records voicemails if calls are unanswered or outside that time window.
Find out more on Twilio Code Exchange.
The application forwards incoming calls to a specified number during business hours; by default, these are Monday to Friday 8:00-18:00 UTC. Otherwise, it directs the call to voicemail. If the call is directed to voicemail, a message can be recorded and a link of the recording sent via SMS to the configured phone number.
To use the application, you'll need the following:
- PHP 8.3
- Composer installed globally
- A Twilio account (free or paid) with a phone number. Click here to create one, if you don't have already.
- ngrok
- Two phone numbers; one to call the service and another to redirect your call to, if it's between business hours.
After cloning the code to wherever you store your PHP projects, and change into the project directory. Then, copy .env.example as .env, by running the following command:
cp -v .env.example .env
After that, set values for TWILIO_ACCOUNT_SID
, TWILIO_AUTH_TOKEN
, TWILIO_PHONE_NUMBER
.
You can retrieve these details from the Account Info panel of your Twilio Console dashboard.
Then, set MY_PHONE_NUMBER
to the phone number that you want to receive SMS notifications to.
Ideally, also set as many of the commented out configuration details as possible.
When that's done, run the following command to launch the application:
composer serve
Then, use ngrok to create a secure tunnel between port 8080 on your local development machine and the public internet, making the application publicly accessible, by running the following command.
ngrok http 8080
With the application ready to go, make a call to your Twilio phone number.