views:

330

answers:

2

Hi Everyone,

I'm currently writing a windows service that uses the Asterisk AMI to detect when a call is coming in and then perform a web request based on who the call is from and who it is going to. Does anyone know of an event in Asterisk that I could listen for the includes both of these details? I need the number of the person outside the system who is calling but anything that I could use to identify the internal phone number being called would be fine, as long as it can be used outside of asterisk.

I was looking at the events and they all have the number of the external caller on them however none of them link to the internal caller other than with the uniqueid which unless I build a Dictionary of these in the service I wont be able to use.

Has anyone got any ideas?

A: 

I do have an idea but you will probably not like the answer :)

We tried to do this and failed so we did something evil :)

What we did were to write agi scripts and them call them using the Manager interface and then scrape the command line.

Stuff like core show channels concise etc, its ikky but it works.. we used regex to parse the string output and then grabbed the info from there, the only issue with doing stuff like that is that you have to watch every time you patch as the output from the command line tends to change patch to patch.

If you do discover a way doing this using the c# api and not using agi i'd be very interested but we just couldn't do what we wanted with the api without resorting to agi scripts in the end.

krystan honour
Thanks, I'm looking into a few other options at the moment and I'll let you know if I can get something working.
Ryan French
+3  A: 

So in the end I managed to do this through using only the AMI and listening for call events. With what we wanted access to I listened for the Newchannel events, Dial events and Hangup events, although if all you are after is the number of who is calling and the number of who they are calling I am pretty sure you could get away with monitoring just the Dial events.

Each time a Newchannel event was received I created a Channel object and added it to a list of Channels that were currently on the Asterisk server. Then, by listening to the Dial events with the Subevent of Begin I was able to extract the unique channel id's of both parties involved in the call and then get the numbers involved. When a Hangup event was received I removed the channel that was being destroyed. This seems to be working great for now although we havent had full time to test it so hopefully it's correct.

Ryan French