I’m working on asterisk.
I managed to call an external api using dialplan.
Now I want to run a javascript inside that api function, because I need to notify a browser that someone is calling. What I’m thinking is that I can do that using node.js. I don’t want to use ajax polling cause it is bad.
The following are the process when someone is calling
Call -> Trigger dialplan -> Call external api via AGI method -> run javascript websocket event inside api -> notify browser.
Is that possible? or there is much better way.
Advertisement
Answer
The answer is “yes” – but it also depends on the API you want to use, and what you’re attempting to accomplish.
Asterisk has three “main” APIs: AMI, AGI, and ARI. AMI and AGI have existed for a long time; ARI – the Asterisk REST Interface – is relatively new. To quote from the Asterisk wiki:
Not long into the project, two application programming interfaces
(APIs) were added to Asterisk: the Asterisk Gateway Interface (AGI)
and the Asterisk Manager Interface (AMI). These interfaces have
distinct purposes:
- AGI is analogous to CGI in Apache. AGI provides an interface between the Asterisk dialplan and an external program that wants to
manipulate a channel in the dialplan. In general, the interface is
synchronous – actions taken on a channel from an AGI block and do not
return until the action is completed.- AMI provides a mechanism to control where channels execute in the dialplan. Unlike AGI, AMI is an asynchronous, event driven interface.
For the most part, AMI does not provide mechanisms to control channel
execution – rather, it provides information about the state of the
channels and controls about where the channels are executing
Unlike AMI and AGI, ARI is all about letting you write your own dialplan applications. If you’re interested in it, I highly suggest you check out the wiki page linked above.
The API you choose should be based on what you’re looking to accomplish. Since you’re looking to do a call pop, you really could do that either AMI (by listening for some event trigger) or through ARI (by having the channel enter the Stasis dialplan application, executing a custom node.js ARI application).
There are node.js libraries for both APIs:
AMI
ARI