The plugin provides integration with Asterisk PBX. The application’s users can occupy numbers as operators of a call-center and process incoming calls.
Asterisk configuration files are typically located in /etc/asterisk
directory. The instruction below was produced for version 21.5.0.
To apply any changes run the CLI:
asterisk -RvvvvvvvvvvT
And reload affected modules:
asterisk*CLI> pjsip reload
Or the whole PBX:
asterisk*CLI> core reload
Use the command to obtain help:
asterisk*CLI> help
SIP endpoints are defined in pjsip.conf
file. Here is the sample of minimal configuration for number 100
[100](endpoint) callerid=100 auth=100-auth aors=100 [100-auth] type=auth auth_type=userpass username=100 password=123456 [100] type=aor max_contacts=2
After adding endpoints it should be possible register SIP clients.
SIP trunks are used for receiving on calls to an external phone number and making outgoing calls from it. They are configured in pjsip_wizard.conf
file. Here is the sample of adding such a connection to server sip.bgerp.org
[trunk] type = wizard sends_auth = yes sends_registrations = yes transport = transport-udp remote_hosts = sip.bgerp.org:5060 outbound_auth/username = username outbound_auth/password = password endpoint/allow = alaw,ulaw endpoint/context = from-external endpoint/from_domain = sip.bgerp.org endpoint/direct_media = no identify/match = sip.bgerp.org
A Dialplan configuration made in extensions.conf
file defines processing rules for calls.
[general] static=yes writeprotect=no [globals] [outgoing_calls] exten => _[78]XXXXXXXXX,1,Set(CALLERID(num)=79996669966) same => n,Dial(PJSIP/${EXTEN}@trunk) exten => _XXXXXXX,1,Dial(PJSIP/${EXTEN}@trunk) same => n,HangUp() [incoming_calls] exten => ,1,Answer same => n,Set(CALLERID(name)=trunk same => n,Dial(PJSIP/100) same => n,HangUp() [local_calls] exten => _1XX,1,Dial(PJSIP/${EXTEN}) exten => s,1,Dial(PJSIP/100&PJSIP/101) same => n,HangUp()
In file manager.conf
define AMI settings for connection from the Plugin side.
[general] enabled = yes port = 5038 bindaddr = 0.0.0.0 [crm] secret = <amiSecret> deny=0.0.0.0/0.0.0.0 ; allowed networks with masks permit=192.168.0.0/255.255.0.0 permit=127.0.0.1/255.255.255.0 read = call writetimeout = 5000
The clients connect to Asterisk server and used as phone devices.
Client and Platforms | Configuration |
---|---|
https://www.linphone.org/en/getting-started iOS, Android, GNU/Linux, macOS, Windows |
|
https://www.microsip.org/ Windows |
Popup menu Edit Account |
Add to Plugin Configuration.
asterisk:amiManager.{@inc:cnt}.messageTypeId=<typeId> asterisk:amiManager.{@cnt}.host=<host> asterisk:amiManager.{@cnt}.login=crm asterisk:amiManager.{@cnt}.pswd=<amiSecret> # optional # change default AMI port #asterisk:amiManager.{@cnt}.port=5038 # speeds connection process up or solves problem with undetectable version #asterisk:amiManager.{@cnt}.version=<version> # redefinition of listener, the custom class has to extend the defined below #asterisk:amiManager.{@cnt}.listenerClass=<listenerClass>
Where:
<typeId> - ID of message type Call, used for persisting calls into the system;
<host> - host where Asterisk with AMI is running;
<amiSecret> - AMI password;
<version> - version string, may be: 'Asterisk 13.0', 'Asterisk 16.0', see: https://github.com/asterisk-java/asterisk-java/blob/master/src/main/java/org/asteriskjava/AsteriskVersion.java;
<listenerClass> - custom listener Java class, extending ru.bgcrm.plugin.asterisk.AmiEventListener
Example:
asterisk:amiManager.{@inc:cnt}.messageTypeId=1 asterisk:amiManager.{@cnt}.host=192.168.0.10 asterisk:amiManager.{@cnt}.login=crm asterisk:amiManager.{@cnt}.pswd=234567
After occupation by a user his number, all the accepted calls there must be registered as messages and opened for processing.
Incoming API events are written down to log/bgerp.debug.log
file. The plugin catches NewStateEvent like this:
01-24/15:16:49 DEBUG [Asterisk-Java ManagerConnection-216-Reader-0:AsyncEventPump] AmiEventListener - AMI event: org.asteriskjava.manager.event.NewStateEvent[dateReceived='Fri Jan 24 15:16:49 ALMT 2025',privilege='call,all',linkedid='1737713805.909',server=null,calleridname=null,channel='PJSIP/114-000001ec',language='ru',exten='s',calleridnum='114',context='external-context',state='Up',callerid='114',connectedlinenum='8707xxxxxxxx',uniqueid='1737713805.923',timestamp=null,channelstatedesc='Up',systemname=null,connectedlinename=null,sequencenumber=null,priority='1',channelstate='6',accountcode='',systemHashcode=1996251948]
Fields connectedlinenum is treated as FROM and callerid as TO number respectively.
Output of asterisk-java can be enabled in logger configuration.
# for debugging library log4j.logger.org.asteriskjava=DEBUG, filed