This project shows how to use two Twilio Add-ons (Marchex Clean Call and Nomorobo Spam Score.) from the Twilio Add-ons Marketplace to block unwanted voice calls.
The application is a small web application built around the Slim Framework. When your Twilio number receives an inbound call, this code will check the spam rating of the phone number using both of the spam Add-ons. If both of them deem the number to be spam, then the number will be blocked. Otherwise, if the number is not deemed to be spam, the call will be forwarded to the customer
The application is a simple example of how to integrate Add-ons from the Twilio Marketplace into your application to help you determine if inbound phone calls are spam or not, i.e., telemarketers, auto-dialers, accidental hang ups, and outright spam callers. By using these Add-ons, you can save wasting your time answering unnecessary calls.
To use this application, you're going to need:
- A Twilio account (either free or paid) with a Twilio phone number that can handle phone calls. If you are new to Twilio, create a free account.
- PHP 8.3
- Composer installed globally
- ngrok
The following guide will help you to install Add-ons. You can access the Add-ons in the Twilio console. The Spam Filtering Add-ons that are used on this application are (as mentioned earlier):
Once you've selected the Add-on, click on the Install button. Then, you will see a pop-up window where you should read and agree the terms. After that, click the Agree & Install button. For this application, you just need to handle the incoming voice calls, so make sure that the Incoming Voice Call box for Use In is checked, then click Save.
After the above requirements have been met, clone this repository and change into the cloned directory with the following commands:
git clone [email protected]:settermjd/block-spam-calls-php.git
cd block-spam-calls-php
Then, install PHP's dependencies:
composer install
After that, you need to set the environment variables which the application requires. These are your Twilio Account SID, Auth Token, and phone number. To do that, first copy .env.example (which has the variables defined but not set) as .env.
cp .env.example .env
Then, you need to retrieve your Twilio from the Account Info panel in the Twilio Console Dashboard. After you've retrieved them, update .env as required.
Now, start the application using the following command:
composer serve
To forward incoming calls, your development server will need to be publicly accessible. We recommend using ngrok to do this, by running the following command:
ngrok http 8080
Once ngrok's started, copy the Forwarding URL from the output it writes to the terminal.
Now, it's time to update your Twilio phone number's configuration. Under Phone Numbers > Manage > Active numbers click the phone number that you're using. Then, under Voice Configuration set:
- Configure with to "Webhook, TwiML Bin, Function, Studio Flow, Proxy Service"
- A call comes in to "Webhook"
- The URL field next to A call comes in to the ngrok Forwarding URL that you copied from the ngrok terminal output
- HTTP next to the URL field to "HTTP POST"
After that's done, click Save configuration. That's it for the configuration.
To test the application, make a phone call to your Twilio phone number. You should hear "Welcome to the jungle" in a female, British voice.
If you want to contribute to the project, whether you have found issues with it or just want to improve it, here's how:
- Issues: ask questions and submit your feature requests, bug reports, etc
- Pull requests: send your improvements
- The CodeExchange repository can be found here.
If the project was useful and you want to say thank you and/or support its active development, here's how:
- Add a GitHub Star to the project
- Write an interesting article about the project wherever you blog
No warranty expressed or implied. Software is as is.