2

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"; } }
    }
Yoda
  • 17,363
  • 67
  • 204
  • 344
  • I don't think it is possible unless you have VOIP software on your notebook. Otherwise you'd have to record what the person said, listen to it, record and inject your recording into the response to twilio, all before it times out. – Jacob Roberts May 18 '15 at 18:08
  • @JacobRoberts They directly say one can do it: https://www.twilio.com/docs/quickstart/php/client but I can't find example of that kind of usage. – Yoda May 18 '15 at 21:27
  • https://www.twilio.com/docs/quickstart/php/client/browser-to-browser-calls – Jacob Roberts May 19 '15 at 13:21

2 Answers2

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.

Devin Rader
  • 10,260
  • 1
  • 20
  • 32
  • Hello Devin, thank you for your help. I understood that I need Twilio client on a web browser side and few days later I came accross this problem: http://stackoverflow.com/questions/30382545/what-request-url-for-voice-in-twiml-app-setup-should-i-use-when-i-develop-on-loc could take a look, please? I just would like to have voice connection with telephone. – Yoda May 22 '15 at 19:11
  • The current answer is also my suggestion. – Devin Rader May 22 '15 at 19:12
  • Thanks, I've read those few times already (in past few days) and I came accross appSid problem. – Yoda May 22 '15 at 19:12
  • Could you please check that other subject, threre is no info on Twilio how tos what request link for voice should be. – Yoda May 28 '15 at 18:07
  • 2
    A Voice Request URL has to be a publicly accessible URL that Twilio can send an HTTP request to. You can either publish a web page or XML file to a publicly hosted website (eg A website running on Azure or AWS or Heroku or any other hosting provider), or you can use a tool like ngrok to expose the web server that is running on your own local machine out as a public URL. Does that help? – Devin Rader May 28 '15 at 18:18
  • Thank you Devin, I have finally deployed the ASP.NET-MVC app to the web and set the right URL but I get an error when I test the connection by Call button in TWIML App setup. Please help: http://stackoverflow.com/questions/30605151/twiml-app-unexpected-end-of-call-cannot-find-the-declaration-of-element-respon – Yoda Jun 02 '15 at 19:42
0

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

<Response>
    <Dial>
        <Number>+44.........</Number>
    </Dial>
</Response>

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.

bruinbrown
  • 1,006
  • 2
  • 8
  • 13
  • Isn't this Twilio client a `TwilioRestClient` which I initialize in the `Call` action method? I already can call. My program actually calls my cell phone number and plays Zelda.mp3 but I would like to be able to talk through that connection. – Yoda May 19 '15 at 13:30