-1

I have an ASP.Net Core website in which I want to start an outbound call on the number provided on the page. For this, first I generate a token from the backend controller as:

var accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"];
var authToken = ConfigurationManager.AppSettings["TwilioAuthToken"];
var appSid = ConfigurationManager.AppSettings["TwilioTwimlAppSid"];

var scopes = new HashSet<IScope>
{  
  { new OutgoingClientScope(appSid) }
};
var capability = new ClientCapability(accountSid, authToken, scopes: scopes);
return capability.ToJwt();

Now on the page, once anyone enters the phone number and clicks on call, I initiate the call with the javascript function Twilio.Device.connect().

The TwiML app whose AppSID I am using while generating token has the Request URL which provides following TwiML:

<Response>
 <Dial callerId="+1XXXYYY">+91XXXAAA</Dial>
</Response>

This works fine and I am able to receive call on the given hardcoded number in the TwiML. However I want to call on the number entered on the page.

So my question is how can I pass the numbered entered on the page(alongwith the CallerID as well) to this TwiML so that it dials to the specific entered number and not the hardcoded one?

If this is not possible then is there any other alternative available for my architecture?

Hemant Sisodia
  • 488
  • 6
  • 23

1 Answers1

1

Was able to finally start the call. For this, I used params in javascript method:

var params = {
    phoneToCall: document.getElementById('phone-number').value,
    callerIdToShow: document.getElementById('callerId').value
};
Twilio.Device.connect(params);

Then on the URL which returns the TwiML to dial, I received these params and used them in the xml as:

[HttpGet]
public HttpResponseMessage GetTwiML(string phoneToCall, string callerIdToShow)
{            
  string XML = $"<Response><Dial callerId=\"{callerIdToShow}\">{phoneToCall}</Dial></Response>";
  return new HttpResponseMessage()
  {
     Content = new StringContent(XML, Encoding.UTF8, "application/xml")
  };
}
Hemant Sisodia
  • 488
  • 6
  • 23