Detect an incoming call using Asterisk and find out who the call is for

I am currently writing a Windows service that uses Asterisk AMI to determine when a call is arriving and then run a web request based on who the call came from and who it is being directed to. Does anyone know of an event at Asterisk that I could listen to include both of these details? I need a subscriber number outside the system that is calling, but everything that I could use to determine the internal phone number being called will be fine if it can be used outside of the asterisk.

I looked at events, and they all have an external caller number, however, none of them communicate with the internal caller, except with uniqueid, which, if I do not create their dictionary in the service, I can’t use it.

+4
source share
2 answers

So, in the end, I managed to do this using only AMI and listening for call events. With what we wanted to receive, I listened to Newchannel events, Dial events, and Hangup events, although if all you need is the number of people who are calling and the number of those who are calling. I'm sure you can get away with monitoring just dial events.

Each time a Newchannel event was received, I created a Channel object and added it to the list of channels that are currently on the Asterisk server. Then, listening to the Dial events with Subevent of Begin, I was able to extract a unique channel identifier for both parties involved in the call, and then get the numbers involved. When the Hangup event was received, I deleted the destroyed channel. This works fine for now, although we don’t have time to check it, I hope this is correct.

+6
source

I have an idea, but you probably won't like the answer :)

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

What we did was write agi scripts, and they call them using the dispatcher interface, and then clear the command line.

Things like the kernel show compressed channels, etc., its ikky, but it works. We used regex to parse the output of the line, and then grabbed the information from there, the only problem with this activity is that you have to watch every time you fix it, since the output from the command line tends to change the patch to fix it.

If you find a way to do this using C # api but not using agi, I would be very interested, but we just could not do what we wanted with api without resorting to agi scripts at the end.

0
source

Source: https://habr.com/ru/post/1303063/


All Articles