0

we are in early stage review of Twilio and have a bit of a snag. The examples show something like this

      string accountSid = mySid;
      string authToken = myToken;
      TwilioClient.Init(accountSid, authToken);
      var call = CallResource.Create(
                 from: new Twilio.Types.PhoneNumber("+4411112222"),
                 to: new Twilio.Types.PhoneNumber("+44999988888"),
                 twiml: new Twilio.Types.Twiml("<Response></Response>")
                );

While I can get the call to "say" I cannot see how to:

  1. Get the originator to "hear" the call - does this need a softphone like Zoiper?
  2. How should the Twiml be constructed to allow the from to talk to the to?

There is loads of documents and I have looked at a lot - but its not gelling with me yet :(

Any guidance really appreciated !

1 Answers1

0

Twilio developer evangelist here.

In that code example, you are creating a single leg of a call from Twilio using the Twilio number provided as the from number to the number you pass as the to parameter. The originator of the call is Twilio and the call is only between Twilio and the person you called.

In the example code you added above you also only include an empty <Response> as the TwiML parameter. TwiML is intended to tell Twilio what to do with the call and you gave Twilio no instructions so the call likely hangs up straight away.

If you want to connect two callers then you need to provide TwiML that will <Dial> the next leg once the first leg has connected. You could do this like:

string accountSid = mySid;
string authToken = myToken;
TwilioClient.Init(accountSid, authToken);
var call = CallResource.Create(
    from: new Twilio.Types.PhoneNumber(YOUR_TWILIO_NUMBER),
    to: new Twilio.Types.PhoneNumber(FIRST_OUTBOUND_NUMBER),
    twiml: new Twilio.Types.Twiml("<Response><Dial>SECOND_OUTBOUND_NUMBER</Dial></Response>")
);

For an example application that implements this, I recommend you check out the Click to Call example on the Twilio CodeExchange.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • So to connect the Twilo number to the "client" shouldnt it be from: new Twilio.Types.PhoneNumber(YOUR_TWILIO_NUMBER), to: new Twilio.Types.PhoneNumber(FIRST_OUTBOUND_NUMBER), twiml: new Twilio.Types.Twiml("YOUR_TWILIO_NUMBER") What I am trying to do is use Twilo with a softphone to call a number by "clicking" a link – Peter Bannister Nov 10 '21 at 16:26
  • Oh, then you are looking for the [Twilio Voice SDK](https://www.twilio.com/docs/voice/sdks/javascript). Check out [the quick start application here](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-csharp). – philnash Nov 11 '21 at 00:23