Asterisk REST API module
#
#
A simple module for Asterisk PBX that provides two main features:
It is easily customizable and can serve as a base for integration of existing Asterisk installations with external data sources, like CRMs, databases or any other application with REST interface.
salara.conf - module configuration file
Makefile - make file (module compilation scenario)
salara.c - source (module source code)
Module name - salara.so
Required headers:
- asterisk headers files (asterisk package)
- libcurl headers files (libcurl-devel)
- libjansson headers files (libjansson-devel)
Required libraries:
- libcurl.so.4 or high (https://curl.haxx.se/download.html)
- libjansson.so.4 or high (http://www.digip.org/jansson/)
make
Copy files :
salara.so to directory /usr/lib/asterisk/modules/ (or other asterisk module directory)
salara.conf to directory /etc/asterisk/ (asterisk confifuration directory)
Load module via asterisk CLI:
module load salara.so
The following message will be shown in the console:
Loaded salara.so
== Registered application 'salara'
Loaded salara.so => (Features: transfer call; make call; get status: exten.,peer,channel; send: command,message,post)
[salara 14:13:56.141] SEND_BY_EVENT Thread started (tid:2886441792).
Get available module commands:
core show help salara
{
"operator": "8003",
"phone": "0000",
"context": "alnik"
}
where,
Module algorithm :
Example of module response to this request:
{"result":0,"text":"Idle"}
where,
{
"operator": "8003",
"phone": "8002",
"msg": "Message text",
"context": "general"
}
where,
Module algorithm :
Example of module response to this request :
{"result":0,"text":"Idle"}
where,
{
"exten": "8003",
"context": "alnik"
}
where,
Example of module response to this request :
{"result":0,"text":"Idle"} - available
{"result":4,"text":"Unavailable"} - unavailable
{"result":-1,"text":"Unknown"} - error in numbering plan
{
"peer": "8003",
"context": "alnik"
}
where,
Example of module response to this request :
{"result":0,"text":"Reachable"} - available
{"result":0,"text":"Unknown"} - unavailable
{"result":-1,"text":"Error"} - error in numbering plan
{
"chan": "SIP/8003-00000020"
}
where,
Example of module response to this request :
{"result":-1,"text":"Channel not present"} - the channel is not present
{"result":0,"text":"Up (6)"} - the channel is present (live)
Requests are created on the following events (events) :
Example of (CRM) request :
{"event":"Newchannel","chan":"SIP/8003-00000022","caller":"8003","exten":"0000","state":"DOWN"}
Example of HTTP response to this request :
{"result":0}
Example of (CRM) request :
{"event":"Hangup","chan":"SIP/8003-00000022","caller":"8003","exten":"0000","state":"UP"}
Example of HTTP response to this request :
{"result":0}
Example of HTTP request :
{"event":"Newexten","chan":"SIP/8003-00000023","caller":"8003","exten":"0000","state":"RING"} - call the number "0000"
or
{"event":"Newexten","chan":"SIP/8003-00000023","caller":"8003","exten":"0000","state":"UP","app":"Playback"} - connect the number "0000"
Example of HTTP response to this request :
{"result":0}
Example of HTTP request :
{"event":"AgentConnect","chan":"SIP/8003-00000025","caller":"8003","queue":"710","state":"UP","agent":"2222"} - connect the number "2222"
Example of HTTP response to this request :
{"result":0}