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"; } }
}
Twilio evangelist here.
If you want to place a phone call from your browser you'll need to look at using Twilio Client for JavaScript:
https://www.twilio.com/docs/quickstart/csharp/client
That will let you place a VoIP call from the browser into Twilio. Once the call reaches Twilio you can then bridge that call with another Twilio Client, SIP endpoint or PSTN phone:
https://www.twilio.com/docs/quickstart/csharp/client/outgoing-calls
Hope that helps.
The way to do this would be to use the Dial Twiml https://www.twilio.com/docs/api/twiml/dial Dial can take one of several options; either a phone number, a SIP URL or a Twilio Client identifier. An example of dial is the CallMe twimlet available at https://www.twilio.com/labs/twimlets/callme and would look something like the following
If you've already got a softphone installed on your notebook then you could dial that. If you've got Skype you could use your Skype phone number for example.
If you don't have a softphone installed, you could always use Twilio client https://www.twilio.com/client and have that running inside your web browser.