How to execute code before making a call on Asterisk - asterisk

I have an asterisk pbx server. I’m new to asterisk, I know there are dial plans extensions groups etc.
My goal is to handle a dial event do some checks then decide whether to let the call go through or not.
I read about ARI AGI AMI and dial plan but I got confused and don’t know how to proceed.
I just want to execute code (call an API for example) when any number is dialed, and drop the call or let it through according to that.
I know if I do more research I can get something working, but honestly I don’t have time. I just need to know where to look.

So I solved it. In case anyone needs this, here's what I did.
I used AsterNET fastAGI and created my service script, which does whatever checks I need and calls HangUp() when needed, else just returns and lets the call go through.
Then I called the fastAGI script in the dial plan and it's working perfectly.

Related

variables in extensions_custom.conf

I am using Queues to handle incoming calls which works pretty well.
What I would like to do now is to get the info which extensions has answered a call in "sub-queue-answer" context of extensions_custom.conf to hand over this information via CURL to another - e.g. CRM-server via:
exten => s,n,Set(foo=${CURL(https://hostname/voipcr.php?device=pbx1.xxx\&agent=${???}...)})
anyone any idea which variable can be set in the spaceholder of the three ??? to hand over the extension number of the agent who has answered that call?
i usually use ${CUT(DIALEDPEERNUMBER,#,1)}
You can not do that using extensions. Queues are sending calls to users without passing through the dialplan (a queue will call a agent directly).
To access data about who answered the call (and also when that happened) you need to listen for the AgentConnect event on Asterisk Manager Interface. As you can see in the documentation, the AgentConnect event will pass a lot of properties that you can parse, to extract the information you need. Probably you want to check MemberName and Interface properties, but that is subject to your particular setup.
Queue logs / CDR will help you only if you want to send the data after the call has been completed, but, to do that, you probably need to create a pooling system (an undesirable solution, from my point of view).

IIS request with quick response but continue to process

I'm working on an API (Pragmatic Rest API or very similar). I would like to know if it is possible to do an API request that will return a quick response (in JSON) and continue to process heavy code in background.
I suppose this is possible by using queue system but I have no idea where to start with this.
You can have your API delegate long running things to another process.
You mentioned queues, that's one way of doing things, all you need really is an application which can execute whatever long running tasks you have.
Let's imagine a simple system that can do this.
Your API receives a request to do something.
Instead of doing this something, the API writes one record into a database with the details of what needs to be done. Another app watches that table, sees a new record, runs the thing, updates the record with the status / result / whatever it needs.
On any requests from now on, the API can check the record and return whatever is there.
This is the simplest thing I can think of. You can easily do other things as well, talk to a queue system, send it data, let something else execute it.
Looking at your comments, what you are suggesting is not really a good way of building APIs. Why do I say this?
Well, let's say that you receive a request, the API starts a work thread and sends back a 200 to the client. Great the client knows work has started and how does it know when that process had ended and how does it receive whatever data it expects back?
Let's go a bit deeper next.
What happens when 1000 clients call that one endpoint and your API is attempting to start 1000 work threads? You've killed your API, no work gets done and no client gets anything.
This is why I suggest to delegate the work to something else, not the API. Let the API do what it does best, run quick things and return results and delegate other things to something else.

asterisk get credit card info

I`m trying to build a script that will capture the credit card info like card number,cvc and expiration date using asterisk 11.x and asterisk-java library for AMI/AGI integration.
Right now I am able to build a script that will acquire that info if it is called via dialplan but i have a different scenario:
1. A call enters a queue.
2. An agent from the specific queue answer the call
3. The caller wants to input the card details
4. After the caller has entered the card details is redirected back to agent to continue the call.
My specific problem is related to step 3 as I do not know how to route the caller to my AGI and then back to the same agent. (eventually the agents has to be still involved in (some) call to guarantee that when the caller returns from agi it is still available)
Any idea how can I achieve that ? I know that this is a common practice so I think that there has to be a way.
When the call is delivered to the agent, use a macro to set a custom channel variable with the agent ID or extension in it.
Then, when your credit-card authentication function is done, read the variable and use an AGI command to transfer the call back to the agent.
Further Reading
http://www.voip-info.org/wiki/view/Asterisk+variables
http://www.voip-info.org/wiki/view/Asterisk+manager+Example:+Transfer
Note if this solution solves your problem, please 'accept' it to make it easier for others with the same issue to find it. thanks!
There are no any common practice for business process like you have. That depend of you and your client only.
You can use features conf or transfer. Can transfer to special extension or to conference room.
No way say what suite you better.
For sure you need understand how asterisk work before write any AGI/AMI or dialplan application. I can recommend ORelly's "Asterisk the future of telephony" book as start point.

Oneway conference calling through asterisk

I am new to Asterisk and Voip. I wanted to accomplish a following small thing using Asterisk.
Description
Asterisk is used as server
Several Voip clients. (Two types of clients possible. One which can start a conference call, other can't call but can only hear.) Only caller client can start/end this call.
The call can't be longer then a particular time.
Is it possible through Asterisk. How does asterisk help to implement this scenario. What does I need to learn? Any web links will be very helpful.
Thanks
You can do all that with Asterisk and ConfBridge:
http://www.voip-info.org/wiki/view/Asterisk+cmd+ConfBridge
Use the following options to accomplish your objectives:
'A' — Set marked mode
'm' — Set initially muted.
'w' — Wait until the marked user enters the conference
You can use another dial plan function: TIMEOUT(absolute) to limit the conference duration.
To start I would look at the examples in the above link.

How to determine current PBX status (calls, ringing, etc. etc.) with asterisk-dotnet

I am using asterisk-dotnet, and I am looking for a way to get the current PBX "status".
What I need is to determine:
which extensions are busy in a call
which extensions are ringing
which number is calling the extension
which number is called by the extension
and the extension number itself.
I know that I can obtain part of these data by using the Status Action, the ExtensionState Action and the NewChannel Action. However these work when an event happens. For example, if an extension is busy on a call, I'll have a new ExtensionState only when the call ends (when the channels are dropped and the peer is available again).
Any help will be much appreciated.
Thanks in advance,
Gianluca
I've just checked Asterisk changelog. It appears that a CoreShowChannel action has been introduced in Asterisk 1.6. I still have to do my homeworks, but I guess that's all I need to get info about what's going on the server at my app startup time.
After this initialization, event tracking is easier as there are already many events that one can subscribe to in order to be notified about new calls, hangs up, etc.
Hope this can help someone else.
Cheers,
Gianluca.

Resources