I have multiple mobile numbers, and customers in various countries. I setup Twilio numbers in the various countries to allow customers to reach me using a local call, and change the forwarding number to whatever my local mobile number is.
The call forwarding service created here will be used by any number that needs to forward to my actual mobile number. As I travel, I change the forwarding number to whatever mobile number I'm using in that location.
- On the left pane, go to Functions and Assets > Services. Click Create Service, enter a name.
- If "Functions and Assets" is not visible, go to Explore Products, it's under Developer Tools.
- Click Create Service, enter a name (I used "forward-call").
- Create a function named forward call. Put this code in:
exports.handler = function (context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
twiml.dial(context.MY_PHONE_NUMBER);
callback(null, twiml);
};
- Add an environment variable called
MY_PHONE_NUMBER
, and set that to the number you want to forward the calls TO.
- Go to Phone Numbers > Manage > Active Numbers. Click the phone number. Go to the configure tab. Set "A call comes in" to "Function". For "Service", choose the service you created ("forward-call"), pick the environment ("forward-call"), and the function path ("/forward-call").
- On the left pane, go to Phone Numbers > Manage > Active Numbers.
- Click the /forward-call function for a number that has the function installed.
- Go to the Env.variables tab at the top.
- Set the
MY_PHONE_NUMBER
variable to the desired destination number.
TODO: Future expansion is to forward to multiple outgoing numbers, have a voice mail system, and add a way to make outgoing calls.
Google Voice can forward an incoming call to any number in the country where the Google Voice number is located (e.g. a US Google Voice number can only forward to a US number). One can mitigate this issue by setting up a Twilio number in the country with the GV account and using this forwarder.
This works, but if the first line goes to voicemail, the other phones won't be called.
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
twiml.say('Please wait while you are connected.');
const dial = twiml.dial();
const phoneNumbers = [context.MY_PHONE_NUMBER, context.MY_PHONE_NUMBER_2];
phoneNumbers.forEach(number => {
dial.number(number);
});
return callback(null, twiml);
};