Please excuse our look. We're just getting started here.

Want to learn more about Twilio Forums? Check out our FAQ page here.

Forward calls based on twilio number called?

What's the right way to forward calls to different phone numbers based on which twilio number that was called?

In the examples, they use an environmental variable to keep the numbers out of the code. How would you do this properly when you need to send calls to multiple numbers based on the twillio number called?



  • Hi @davebailey , Developer Educator here.

    Are you looking at a specific tutorial/quickstart? What programming language/framework are you using? This may help me answer your question a bit better.

    The request body of the webhook for an incoming call will contain which of your Twilio numbers was dialed (request.body.Called and request.body.To are the specific properties that will contain your Twilio number.)

    How are you handling incoming calls to Twilio phone numbers right now? Are all of your Twilio numbers configured with the same application/TwiML Bin/endpoint/whatever?

    If all of your Twilio numbers that handle incoming calls are configured to point to the same TwiML application (some sort of endpoint that returns TwiML to Twilio), you can check the value of the request.body.To or request.body.Called and then forward a call based on that value. (And you could store the forwarding phone numbers in environmental variables, as well.)

  • davebailey
    edited January 8

    I'm a Twilio newbie trying to test a Service Function that does forwards calls to numbers based on the Twilio number called. e.g. Call comes to Twilio number 1 and is forwarded to real number 1. Call comes to Twilio number 2 and is forwarded to real number 2.

    I know how to do it with two Services. I'm trying to find the right way to do it with one.

    I can handle Node.js or Python.

If this is an emergency, please contact Twilio Support. This is not an official Support channel.
Have an urgent question?
Please contact Twilio Support. This is not an official Support channel.
Contact Support