This Function in forward-call.js
will complete 3 steps:
- Look up the incoming call number using the Twilio Lookup API
- Send an SMS to the forwarding number with Caller ID information
- Forward the incoming call to a number that is set in the environment variables.
Note: caller-name
lookup is currently only available in the US.
This Function expects one environment variable to be set.
Variable | Meaning |
---|---|
MY_PHONE_NUMBER |
The number you want to forward incoming messages to in E.164 format |
This Function expects the incoming request to be a voice webhook. The parameter used is From
.
- Install the Twilio CLI
- Install the serverless toolkit
twilio plugins:install @twilio-labs/plugin-serverless
- Initiate a new project
twilio serverless:init caller-id-forwarding --template=caller-id-forwarding
cd caller-id-forwarding
- Add your environment variables to
.env
:
Make sure variables are populated in your .env
file. See Environment variables.
- Deploy
Deploy your functions and assets with the following commands. Note: you must run the command from inside your project folder. More details in the docs.
With the Twilio CLI:
twilio serverless:deploy
- Connect your Twilio phone number to your callback URL:
Replace the phone number with your Twilio Number and the voice-url
with your deployed URL. You can also do this in the console settings page for the phone number.
twilio api:core:phone-numbers:update +11111111111 --voice-url https://YOUR_URL_HERE/twil.io/forward-call