What is the best way to <Dial> multiple phone numbers simultaneously using the Twilio C# Library?

StackOverflow https://stackoverflow.com/questions/20223599

  •  05-08-2022
  •  | 
  •  

Question

I'm using the twilio-csharp helper library. I have a Twilio number, and when someone calls that number, I want to call multiple phones or endpoints like a Twilio Client endpoint and a few phone numbers all at the same time. What is the best way to accomplish this?

Was it helpful?

Solution

The workflow for this functionality looks like this: caller calls a Twilio phone number, Twilio looks up the Voice Request URL associated with that phone number, Twilio sends a TwiML request to the resource at that URL, the resource responds with TwiML instructing Twilio to <Dial> out to several phone numbers, Twilio then calls the phone numbers and connects the caller with the first person to pick up. Note that if you simultaneously <Dial> numbers, when the first phone picks up, the rest of the calls are cancelled.

There are a couple ways to simultaneously <Dial> phone numbers using the twilio-csharp library . The first way to simultaneously <Dial> is to use the DialNumbers method. As the name suggests, DialNumbers will only dial phone numbers, and will only take an array of strings.

The second way to simultaneously <Dial> numbers is to use the Twilio.TwiML.TwilioResponse.Dial(params, Twilio.TwiML.IDialNoun[] dialTargets) method. One of the benefits of using this method is that one can call phone numbers, sip addresses, and/or Twilio Client instances. One can also modify the call attributes, setting the the action URL, timeout limit, or any other dial attribute. Here's a usage example:

public ActionResult SimulDial()
{
    var response = new TwilioResponse();
    var dialAttributes = new { timeout = 10 };
    var dialTargets = new IDialNoun[]
    {
        new Number("8021111111"),
        new Number("8022222222"),
        new Client("clientName")
    };
    response.Dial(dialAttributes, dialTargets);

    return TwiML(response);
}

When Twilio receives this TwiML, Twilio will dial out to the three specified endpoints (the two numbers and one client). If no one picks up within 10 seconds, all dialing will be cancelled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top