BACKGROUND
- First time using Twilio.
- Using ASP.NET MVC4
- Using official twilio-csharp library: https://www.twilio.com/docs/csharp/install
PROBLEM
I am trying to make a very simple example for working with phone calls. I think I have the main idea, but I am struggling with what to return in the TwiML, etc.. here is my code:
public ActionResult TestCall()
{
var twilio = new TwilioRestClient("accountSid", "authToken");
var call = twilio.InitiateOutboundCall("0123456789", "0123456789", "http://example.com/handleCall");
return new EmptyResult();// Is this correct?
}
public ActionResult HandleCall()// Do I need arguments here?
{
var response = new TwilioResponse();
// Do I need anythign in the response?
return TwiML(response);
}
I am not trying to provide any kind of automated service… I just want the user of my website to click Call button and he can speak with whoever he is calling… just like Skype, etc..
I just need a very basic example here. Believe me, I spent some time searching for this and there are plenty of examples, but none of them really answer this newbie question of mine in particular.
It sounds like what you want to do is use Twilio to lets a user make a phone call directly from their browser to another phone. To do this you can use Twilio Client.
http://www.twilio.com/client
Here is a link to a quickstart showing how to use the Twilio Client javascript SDK in a webpage to create an audio connect from the browser to Twilio:
http://www.twilio.com/docs/quickstart/csharp/client/outgoing-calls
Notice at the top there is some C# code. This uses a class called TwilioCapability to generate a token that tells Twilio what your account credentials are and what TwiML App sid you want to use to handle the connection once its made. TwilioCapability is included in the Twilio.Client nuget package.
http://nuget.org/packages/Twilio.Client
The TwiML App represents a URL that you can configure from your Twilio dashboard (click DevTools -> TwiML apps). Twilio will make an HTTP request to that URL once the audio connection from the browser is opened. This lets you provide TwiML instructions to Twilio that tell it what to do with that connection. You could for example tell Twilio to Dial out to another phone number.
If you wanted generate that TwiML dynamically using an MVC action method, you can use the Twilio.Mvc nuget package. I wrote a blog post a while ago that shows how to return TwiML from an MVC action method using the libraries installed by the nuget package:
http://www.twilio.com/blog/2012/02/twilio-for-net-developers-part-5-twilio-client-mvc-and-webmatrix-helper-libraries.html
Hope that helps. Let me know if you have any more questions.
Devin