To call phone number from notebook through Twilio I created ASP.NET-MVC 5.2 application.
I can call a number and answer the phone but I don't know how to achieve live voice(to be able to talk) connection instead of just playing music.
I created an action method inside HomeController
:
public ActionResult Call(string to) {
client = new TwilioRestClient(Settings.AccountSid, Settings.AuthToken);
var result = client.InitiateOutboundCall(Settings.TwilioNumber, to, "http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3"); //it causes to play zelda theme when call is answered by callee
if (result.RestException != null) {
return new System.Web.Mvc.HttpStatusCodeResult(500, result.RestException.Message);
}
return Content("Call enroute!");
}
public ActionResult Index() {
return View();
}
This action method is invoked by Ajax call.
When I hit the button from Views\Home\Index.csthml
:
<form>
<p>Enter your mobile phone number:</p>
<input id="to" type="text"
placeholder="ex: +16518675309" />
<button>Send me a message</button>
</form>
The script below is invoked which passes the phone number from <input id="to">
to the action method public ActionResult Call(string to)
in the HomeController
:
$('form button').on('click', function(e) {
e.preventDefault();
// expect just a string of text back from the server
var url = '/call';
$.ajax(url, { //invokes call action method
method:'POST',
dataType:'text',
data:{
to:$('#to').val()//passes the number argument to the action method
},
success: function(data) {
showFlash(data);
},
error: function(jqxhr) {
alert('There was an error sending a request to the server');
}
})
});
This starts phone call to the specified number i.e. 48123456789
where 48
is the country code. When the call is answered by the callee, the zelda theme is played.( http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3 )
Instead of that I would like to talk through notebook(it has internal microphone) to the person I've called and let this person talk back. In few words I would like to have live voice.
Question: How to achieve live voice phone call using Twilio in ASP.NET-MVC 5.x?
Settings.AccountSid
and Settings.AuthToken
are my credentials:
public static class Settings
{
public static string AccountSid { get { return "A###############0"; } }
public static string AuthToken { get { return "e###############0"; } }
public static string TwilioNumber { get { return "4########1"; } }
}