This is a function that Twilio admin users can implement in Twilio and in the Spoke Phone web portal to forward calls to an external number while retaining the original caller's phone number.
Requirements and Considerations
- Admin access to the Twilio account
- Admin access to the Spoke Phone web portal
- The function will only work for Twilio numbers. Using it on Non-Twilio numbers will result in errors.
Twilio Console
- Go to Functions and Assets
- Click on Services
- Click Create Service and give it a name
- Click Next
- Click Add and Add Function, and name your function
- Delete all text and replace it with the one below:
exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
const fromNumber = event.From;
const toNumber = event.phonetocall;
if (!fromNumber || !toNumber) {
return callback(null, 'Missing "from" or "to" number.');
}
const dial = twiml.dial({ callerId: fromNumber });
dial.number(toNumber);
console.log('Generated TwiML:', twiml.toString());
return callback(null, twiml);
};- Save and Deploy
- Copy URL
Spoke Phone Web Portal
- Log in to the Spoke Phone Portal
- Go to Teams
- Click Manage Teams
- Click the pencil icon to edit teams to forward calls from
- Scroll down to "What happens if no one picks up?"
- Choose Send to a Twilio Function
- Paste URL copied from Twilio service and add ?phonetocall=Phonenumbertoforwardcallsto
- Click Save