This project is read-only.

Consuming the Twilio Service with TwilioClient

Now that you've seen the API conventions, let's write some code.

string caller = "8505551212";     // The number to display on CallerId. Must be pre-validated as an OutgoingCallerId
string called = "8505552121";     // The number to call
string url = "";    // The Url to post to once the call is placed

CallManager callManager = new CallManager(_yourAccountSid, _yourApiKey);
PhoneCall call = callManager.PlaceCall(caller, called, url);

As you can see, the code is pretty straightforward. The Twilio API returns a new Call instance on a successful call, so you can manipulate that object however you want. You can also place a call by passing in an instance of a Call object. This is useful if you need to set additional options on the Call, for example, that you want it to hang up if it reaches an answering machine or voicemail.

PhoneCall call = new PhoneCall();
call.Caller =  "8505551212";
call.Called = "8505552121";
call.PostArguments.Add("Url", "");    //This is my personal test url. Please don't hammer it too hard.
call.PostArguments.Add("Method", "GET");

CallManager callManager = new CallManager(_yourAccountSid, _yourApiKey);
call = callManager.PlaceCall(call);

Last edited Jun 21, 2009 at 7:26 AM by interscape, version 2


No comments yet.