Thursday, April 5, 2012

Making or Originating a Call on Asterisk using Asterisk.Net Library.


Hi there folks, Today I'm going to start creating tutorials on how to use the Asterisk.Net library to interact with Asterisk or your phone systems.

When I was still learning how to use Asterisk.Net library to talk with Asterisk servers, I had a very very hard time. I don't have knowledge on Asterisk and also I definitely don't know much of the Asterisk.Net library. Mr. Google didn't help me much either, there was no tutorial available online for Asterisk.Net or even a documentation. And that makes it even more difficult. So today, I decided to create a tutorial for Asterisk.Net library. Forgive my english by the way.



My first tutorial is about how to tell Asterisk to make a Call to a Number or Extension using Asterisk.Net Library. First off, you should have all the requirements before you do this tutorial. Like Asterisk server, PBX systems and of course Asterisk.Net library. Now, I don't want to discuss about how to install Asterisk server, how to configure it and all that kind of stuff. By the way all of these are open source so you should not be having problem working with it (Hopefully!!!). Let's start. Shall we?

Okay, Provided that you have all the requirements running. Let's start by understanding on how to send Action to Asterisk. To do that, the command is:

Action: Originate
Channel: SIP/101test
Context: default
Exten: 8135551212
Priority: 1
Callerid: 3125551212
Timeout: 30000
Variable: var1=23|var2=24|var3=25
ActionID: ABC45678901234567890

Remeber the Action is Originate. This is the Action that we are sending to Asterisk to tell it to Originate the call to "SIP/101test" and when "SIP/101test" picks up the call Asterisk will then dial the Extension which is "8135551212". Extension here can be a local or an outbound number. For full explanation please refer to here. http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Originate.

Now that we have an idea on how to Originate a Call to Asterisk, let's move on to Asterisk.Net library. I will be using C# Language to demonstarte my examples.
To send a request to Asterisk using the Asterisk.net Libary we do this:

First make a Reference of Asterisk.Net library to your program. Then import the following namespace:

using Asterisk.NET.Manager;
using Asterisk.NET.Manager.Action;

Next, Copy and Paste the following codes:

OriginateAction o = new OriginateAction();
o.Channel = " SIP/101test ";
o.Context = "default"
o.Exten = "8135551212";
o.CallerId =  "3125551212 ";
o.Priority = 1;
o.Timeout = 30000;
o.ActionId = "ABC321";
ManagerResponse response = SendAction(o);

That's it. Basically what it does is it sends the Originate Action request to Asterisk. It is identical to the codes above, Asterisk.Net did all the formatting for you. The SendAction(o) is the one that actually sends the request to Asterisk and it will return ManagerResponse class whenever the SendAction() method is called. ManagerResponse is where you can see if your request is successful or failed.

Please note that before you can send a request to Asterisk you need to be logged in to your Asterisk Server. So pretty much, that's it. Stay tuned for the next Asterisk.Net tutorial. Should you have any questions or suggestion please leave a comment. Thanks for dropping by.