Not getting Any Events From Asternet.Ari On FreePbx - asterisk

I have set up FreePbx and it is working I can make calls into the pbx and out of the pbx. I have enabled the REST API and added a user and password. I cloned the Asternet.Ari https://github.com/skrusty/AsterNET.ARI.
The program runs and I get the connected event:
// Create a new Ari Connection
ActionClient = new AriClient(
new StasisEndpoint("192.168.1.14", 8088, "userId", "password"),
"HelloWorld");
// Hook into required events
ActionClient.OnStasisStartEvent += c_OnStasisStartEvent;
ActionClient.OnChannelDtmfReceivedEvent += ActionClientOnChannelDtmfReceivedEvent;
ActionClient.OnConnectionStateChanged += ActionClientOnConnectionStateChanged;
ActionClient.OnChannelCallerIdEvent += ActionClient_OnChannelCallerIdEvent;
ActionClient.Connect();
........
private static void ActionClientOnConnectionStateChanged(object sender)
{
Console.WriteLine("Connection state is now {0}", ActionClient.Connected);
}
The ActionClient is connected.
I then call in to a extension but nothing happens. I do not get any other events. Should an event fire when any extension is called? Not sure if I have set the pbx up correctly. I do not get any calling events when I call in from soft phone or from outside Lan on a cell phone.

Long time have passed but maybe useful yet.
Just set subscribeAllEvents argument to true.
ActionClient = new AriClient(
new StasisEndpoint("voip", 8088, "root", "password"),
"HelloWorld",
true);

Well your Asterisk Ari is connecting, but to get anything in it, you have to create Extension so your call go to Stasis application.
Please edit your extensions.conf file with following information
exten => _1XX,1,NoOp()
same => n,Stasis(HelloWorld,PJSIP/${EXTEN}, 45)
same => n,Hangup()
This script first check any incoming number which starts with 1 will be forawarded to your ARI script. HelloWorld is name of app so you alread have it in your script. Now any call come it will show whole information on your socket. Now you have to handle this information to any specific task.
\

Related

Asterisk AsterNET How to move from parking to queue?

Im using C# AsterNET to manage my Asterisk commands and events, and now I do have a new feature to work on.
This is simple (I think) but I'm stucked right now.
Scenario
I do have two queues, 8100 and 8300, and 2 extensions being 8101 and 8301. When I do have a call from PSTN it is driven to 8100 queue. When the 8101 extension become available I do add this extension to the 8100 queue, so the calling PSTN device will be redirected to this 8101 extension.
Everything is working fine till here.
Sometimes I do park the calling device and let 8301 knows it using my app, so 8301 user using the same app can send a command asking for that parked channel to be redirect to his SIP Phone. Also working fine.
Scope
Now I want to have some feature to let 8101 transfer this calling device to my other queue, the 8300. So I just tried to reuse my parked method and redirect method
internal void Park(string channel, int parkTimeout)
{
ParkAction pa = new ParkAction(channel, channel, parkTimeout.ToString());
ManagerResponse mr = manager.SendAction(pa);
}
internal void RedirectFromParking(string channel, string exten)
{
RedirectAction ra = new RedirectAction
{
Priority = 1,
Context = "default",
Channel = channel,
Exten = exten
};
ManagerResponse mr = manager.SendAction(ra);
}
Park("abc123456", 10000);
RedirectFromParking("abc123456", "8300")
Issue
I'm parking fine but when I try to redirect from parking to my queue the calling device is just disconnected and the connection is lost.
How can I transfer a parked call to my queue or transfer it directly to the queue (would be better) without needing to originate?
Just do hold instead of parking and make your own list of such calls.
To transfer to a queue I can do a blind transfer as documented on Asterisk website. Links below:
ManagerAction_BlindTransfer
ManagerEvent_BlindTransfer
To achieve this using AsterNET, I can use the same RedirectAction I was using but I do need to change the context. It can't be default for context, as default we are letting Asterisk manage it and somehow it can't handle as I expetected. So it need to be clearly specified as internar transfer. The event raised after this context transfer is the Manager_BlindTransfer.
Manager_Action_RedirectAction
So using my SIP Phone I manage to transfer a call while I was debugging that raised event method, so I could catch the context used in. Using the correct context
ManagerConnection manager = new ManagerConnection(address, port, user, password);
manager.BlindTransfer += Manager_BlindTransfer;
private void Manager_BlindTransfer(object sender, BlindTransferEvent e)
{
}
After this I created another method to transfer to directly to a queue using the correct context.
internal void TransferToQueue(string channel, string queue)
{
RedirectAction ma = new RedirectAction
{
Priority = priority,
Context = "from-internal-xfer",
Channel = channel,
Exten = queue
};
ManagerResponse mr = manager.SendAction(ma);
}
TransferToQueue("abc123456", "8300")
Summary
Was just a matter of the correct context to be used in.
from-internal-xfer

Communicating between AMI and AGI

Hii I am making a call from Manager AMI and in my dialPlan the caller will be connected to AGI.I want to send a variable var from AMI to AGI through channel variables
originateAction.setChannel("SIP/1000abc");
originateAction.setContext("outgoing-call");
originateAction.setExten("100");
originateAction.setVariable("var", "Say to the user that he sucks");
I tried all possible combination of outbound call but none of them working
[outgoing-call]
exten=>100,1,AGI(agi://127.0.0.1/hello.agi?user=${var})
[outgoing-call]
exten=>100,1,AGI(agi://127.0.0.1/hello.agi?var=${var})
[outgoing-call]
exten=>100,1,AGI(agi://127.0.0.1/hello.agi,${var})
AGI
public void service(AgiRequest request, AgiChannel channel)
throws AgiException
{
answer();
System.out.println("Inside");
String a=request.getParameter("var");
// String b=request.getParameter("user");
String c=channel.getVariable("var");
// String d=channel.getVariable("user");
System.out.println(a+"\n"+b+"\n"+c+"\n"+d+"\n");
hangup();
}
Output is null all the time.
The right way to pass argument to AGI in your dial plan is:
exten=>_0.,n,AGI(CALLyourAGI,${VARIABLE})
Before calling your AGI you can display in your CLI if the variable was really setted:
[outgoing-call]
exten=>100,1,NoOP(My Variable content ${var})
exten=>100,n,AGI(agi://127.0.0.1/hello.agi,${var})
Do not forget to set verbose in the CLI
ast*CLI> core set verbose 9999
Make a call and keep your eyes on it

Wait for async thrift requests to complete

I am invoking multiple async calls of thrift from my code. I would like to wait
for all of them to complete before going on with my next stage.
for (...) {
TNonblockingTransport transport = new TNonblockingSocket(host, port);
TAsyncClientManager clientManager = new TAsyncClientManager();
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
AsyncClient c = new AsyncClient(protocolFactory, clientManager, transport);
c.function(params, callback);
}
// I would like to wait for all the calls to be complete here.
I can have a countdown in the callback like wait/notify and get this done. But does the thrift system allow a way for me to wait on my async function call, preferably with a timeout ?
I didnt see any in the TAsyncClientManager or in the AsyncClient. Please help.
Given that it was not possible to do this, I used the sync api client and managed the launch and wait using executors and launchAll. I am leaving this as my answer for people to have an alternative.

Asterisk initiate call

can I initiate an outgoing call with Asterisk by an other way than using callfiles?
a friend called google told me that :
http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Originate
;)
you can also initiate originate command on asterisk cli. or can use dial-plan Dial application for making more interactive
using asterisk-manager node-js module then
var Ami = require('asterisk-manager');
var ami = Ami("5038", "127.0.0.1", "admin", "AMIpassword", true);
//call someone and move him to ivr-4
ami.action({
'action':'originate',
'channel':'SIP/trunk/0875421989',
'context':'ivr-4',
'CallerID': '0123456789',
'exten':'s',
'priority':1,
'async': true,
'Codecs': 'g729'
}, function(err, res) {
console.log(err);
console.log(res);
});
the number in channel going to be dialed
The CallerID is the number that should appear to the receiver
the context is where you are sending the receiver after call answered

Error #2126: NetConnection object must be connected

I want to count the online user,when each client login the system,it's connecting to the server and increase a variable stored in a remote shared object.
But when client connecting server,problems arises:Error #2126: NetConnection object must be connected
My web layout:
Website --- apps --- userLogin
Code snippets:
rtmpnc = new NetConnection();
rtmpnc.objectEncoding = ObjectEncoding.AMF0;
var uri:String = ServerConfig.getChannel("my-rtmp").endpoint + "/userLogin";
rtmpnc.connect("http://202.206.249.193:2367/userLogin");
rtmpnc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
The onNetStatusHander is defined as :
switch(event.info.code)
{
case "NetConnection.Connect.Success":onConnSuccess();break;
case "NetConnection.Connect.Failed":onConnError();break;
}
Could anyoue help me out?Much thanks!
Best,Shuo
Move the eventListener to the line above the connect() (just in case). Also add a SecurityErrorEvent.SECURITY_ERROR eventListener before your connect. I'm going to guess we're looking at a security sandbox problem.

Resources