Built motion from commit 39adb707.|2.6.14
[motion2.git] / server / services / xdr / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x27f4=['blindtransfer','[%s][index][blindtransfer]','attendedtransfer','[%s][index][attendedtransfer]','origtransfereruniqueid','[%s][index][varset]','varset','newexten','[%s][index][newexten]','newchannel','[%s][index][newchannel]','dialbegin','[%s][index][dialbegin]','[%s]dialbegin','[%s][index][dialend]','asterisk-manager','util','xdr','disabled','production','local','asterisk','username','password','keepConnected','info','./agents.controller','./calls.controller','./recordings.controller','./members.controller','./dials.controller','./transfers.controller','./core.controller','connect','fullybooted','error','close','managerevent','devicestatechange','debug','format','[%s][index][devicestatechange]','device','agentcalled','[%s][index][agentcalled]','uniqueid','agentringnoanswer','[%s][index][agentringnoanswer]','agentconnect','[%s][index][agentconnect]','agentcomplete','[%s][index][agentcomplete]','queuecallerabandon','[%s][index][queuecallerabandon]','[%s][index][queuecallerjoin]','queuecallerjoin','queuecallerleave','[%s][index][queuecallerleave]','musiconholdstart','[%s][index][musiconholdstart]','musiconholdstop','[%s][index][musiconholdstop]','newstate','[%s][index][newstate]','hangup','[%s][index][hangup]','cdr','[%s][index][cdr]'];(function(_0x4b326e,_0x270c33){var _0x401814=function(_0x153baf){while(--_0x153baf){_0x4b326e['push'](_0x4b326e['shift']());}};_0x401814(++_0x270c33);}(_0x27f4,0x1a7));var _0x427f=function(_0x2c9f51,_0x2eec01){_0x2c9f51=_0x2c9f51-0x0;var _0x12abf9=_0x27f4[_0x2c9f51];return _0x12abf9;};var AsteriskManager=require(_0x427f('0x0'));var config=require('../../config/environment');var utils=require('./utils');var util=require(_0x427f('0x1'));var isXDREnabled=config[_0x427f('0x2')]&&config['xdr']['disabled']?!config[_0x427f('0x2')][_0x427f('0x3')]:!![];var isProduction=config['env']===_0x427f('0x4')||![];var isLocalAsterisk=config[_0x427f('0x2')]&&config[_0x427f('0x2')][_0x427f('0x5')]===!![]||![];var ami=new AsteriskManager(config[_0x427f('0x6')]['port'],config[_0x427f('0x6')]['ip'],config[_0x427f('0x6')][_0x427f('0x7')],config[_0x427f('0x6')][_0x427f('0x8')],!![]);ami[_0x427f('0x9')]();if(!isXDREnabled){utils[_0x427f('0xa')]('XDR\x20DISABLED');}else if(!isProduction&&!isLocalAsterisk){utils[_0x427f('0xa')]('Asterisk\x20disabled\x20on\x20localhost');}else{var agents=require(_0x427f('0xb'));var calls=require(_0x427f('0xc'));var queues=require('./queues.controller');var recordings=require(_0x427f('0xd'));var members=require(_0x427f('0xe'));var dials=require(_0x427f('0xf'));var transfers=require(_0x427f('0x10'));var core=require(_0x427f('0x11'));ami['on']('connect',core[_0x427f('0x12')]);ami['on']('shutdown',core['shutdown']);ami['on'](_0x427f('0x13'),core[_0x427f('0x13')]);ami['on'](_0x427f('0x14'),core[_0x427f('0x14')]);ami['on'](_0x427f('0x15'),core[_0x427f('0x15')]);ami['on'](_0x427f('0x16'),core[_0x427f('0x16')]);ami['on'](_0x427f('0x17'),function(_0x20e8e2){try{utils[_0x427f('0x18')](util[_0x427f('0x19')](_0x427f('0x1a'),_0x20e8e2[_0x427f('0x1b')]),_0x20e8e2);members['devicestatechange'](_0x20e8e2);}catch(_0x18f8e0){utils[_0x427f('0x14')](util['format'](_0x427f('0x1a'),_0x20e8e2[_0x427f('0x1b')]),_0x18f8e0);}});ami['on'](_0x427f('0x1c'),function(_0x5532e7){try{utils[_0x427f('0x18')](util['format'](_0x427f('0x1d'),_0x5532e7[_0x427f('0x1e')]),_0x5532e7);agents[_0x427f('0x1c')](_0x5532e7);}catch(_0x312e70){utils[_0x427f('0x14')](util['format']('[%s][index][agentcalled]',_0x5532e7[_0x427f('0x1e')]),_0x312e70);}});ami['on'](_0x427f('0x1f'),function(_0xe44fc4){try{utils[_0x427f('0x18')](util[_0x427f('0x19')]('[%s][index][agentringnoanswer]',_0xe44fc4['uniqueid']),_0xe44fc4);agents[_0x427f('0x1f')](_0xe44fc4);}catch(_0x3be8dd){utils[_0x427f('0x14')](util[_0x427f('0x19')](_0x427f('0x20'),_0xe44fc4[_0x427f('0x1e')]),_0x3be8dd);}});ami['on'](_0x427f('0x21'),function(_0x554e7b){try{utils[_0x427f('0x18')](util[_0x427f('0x19')](_0x427f('0x22'),_0x554e7b[_0x427f('0x1e')]),_0x554e7b);agents[_0x427f('0x21')](_0x554e7b);queues[_0x427f('0x21')](_0x554e7b);}catch(_0x1336bb){utils[_0x427f('0x14')](util[_0x427f('0x19')]('[%s][index][agentconnect]',_0x554e7b[_0x427f('0x1e')]),_0x1336bb);}});ami['on'](_0x427f('0x23'),function(_0x39ec9b){try{utils[_0x427f('0x18')](util[_0x427f('0x19')](_0x427f('0x24'),_0x39ec9b[_0x427f('0x1e')]),_0x39ec9b);agents[_0x427f('0x23')](_0x39ec9b);queues[_0x427f('0x23')](_0x39ec9b);members['agentcomplete'](_0x39ec9b);}catch(_0x132860){utils['error'](util['format']('[%s][index][agentcomplete]',_0x39ec9b[_0x427f('0x1e')]),_0x132860);}});ami['on'](_0x427f('0x25'),function(_0x287b28){try{utils[_0x427f('0x18')](util[_0x427f('0x19')](_0x427f('0x26'),_0x287b28[_0x427f('0x1e')]),_0x287b28);agents[_0x427f('0x25')](_0x287b28);queues[_0x427f('0x25')](_0x287b28);}catch(_0x94ff95){utils['error'](util[_0x427f('0x19')](_0x427f('0x26'),_0x287b28['uniqueid']),_0x94ff95);}});ami['on']('queuecallerjoin',function(_0x2e513b){try{utils['debug'](util[_0x427f('0x19')](_0x427f('0x27'),_0x2e513b[_0x427f('0x1e')]),_0x2e513b);queues[_0x427f('0x28')](_0x2e513b);recordings[_0x427f('0x28')](_0x2e513b);}catch(_0x6841a2){utils['error'](util[_0x427f('0x19')](_0x427f('0x27'),_0x2e513b[_0x427f('0x1e')]),_0x6841a2);}});ami['on'](_0x427f('0x29'),function(_0x107494){try{utils[_0x427f('0x18')](util['format'](_0x427f('0x2a'),_0x107494[_0x427f('0x1e')]),_0x107494);queues[_0x427f('0x29')](_0x107494);}catch(_0x3a3782){utils[_0x427f('0x14')](util['format'](_0x427f('0x2a'),_0x107494[_0x427f('0x1e')]),_0x3a3782);}});ami['on'](_0x427f('0x2b'),function(_0x379997){try{utils[_0x427f('0x18')](util[_0x427f('0x19')](_0x427f('0x2c'),_0x379997[_0x427f('0x1e')]),_0x379997);queues[_0x427f('0x2b')](_0x379997);calls[_0x427f('0x2b')](_0x379997);}catch(_0x5c8e51){utils[_0x427f('0x14')](util[_0x427f('0x19')](_0x427f('0x2c'),_0x379997[_0x427f('0x1e')]),_0x5c8e51);}});ami['on'](_0x427f('0x2d'),function(_0x5110b4){try{utils['debug'](util['format']('[%s][index][musiconholdstop]',_0x5110b4[_0x427f('0x1e')]),_0x5110b4);queues[_0x427f('0x2d')](_0x5110b4);calls[_0x427f('0x2d')](_0x5110b4);}catch(_0x12c11f){utils[_0x427f('0x14')](util['format'](_0x427f('0x2e'),_0x5110b4['uniqueid']),_0x12c11f);}});ami['on'](_0x427f('0x2f'),function(_0x21b2b6){try{utils['debug'](util[_0x427f('0x19')]('[%s][index][newstate]',_0x21b2b6[_0x427f('0x1e')]),_0x21b2b6);calls[_0x427f('0x2f')](_0x21b2b6);recordings['newstate'](_0x21b2b6);}catch(_0x27e4bc){utils[_0x427f('0x14')](util[_0x427f('0x19')](_0x427f('0x30'),_0x21b2b6[_0x427f('0x1e')]),_0x27e4bc);}});ami['on'](_0x427f('0x31'),function(_0x1c8656){try{utils[_0x427f('0x18')](util['format'](_0x427f('0x32'),_0x1c8656[_0x427f('0x1e')]),_0x1c8656);calls['hangup'](_0x1c8656);recordings[_0x427f('0x31')](_0x1c8656);dials[_0x427f('0x31')](_0x1c8656);agents[_0x427f('0x31')](_0x1c8656);queues[_0x427f('0x31')](_0x1c8656);}catch(_0x53da23){utils[_0x427f('0x14')](util[_0x427f('0x19')]('[%s][index][hangup]',_0x1c8656['uniqueid']),_0x53da23);}});ami['on'](_0x427f('0x33'),function(_0x486c71){try{utils['debug'](util[_0x427f('0x19')]('[%s][index][cdr]',_0x486c71['uniqueid']),_0x486c71);members['cdr'](_0x486c71);}catch(_0x20abe7){utils[_0x427f('0x14')](util[_0x427f('0x19')](_0x427f('0x34'),_0x486c71['uniqueid']),_0x20abe7);}});ami['on'](_0x427f('0x35'),function(_0x217876){try{utils['debug'](util[_0x427f('0x19')](_0x427f('0x36'),_0x217876['uniqueid']),_0x217876);queues[_0x427f('0x35')](_0x217876);agents[_0x427f('0x35')](_0x217876);transfers[_0x427f('0x35')](_0x217876);recordings[_0x427f('0x35')](_0x217876);}catch(_0xd70e65){utils[_0x427f('0x14')](util[_0x427f('0x19')](_0x427f('0x36'),_0x217876[_0x427f('0x1e')]),_0xd70e65);}});ami['on'](_0x427f('0x37'),function(_0x101830){try{utils[_0x427f('0x18')](util[_0x427f('0x19')](_0x427f('0x38'),_0x101830['origtransfereruniqueid']),_0x101830);queues[_0x427f('0x37')](_0x101830);transfers[_0x427f('0x37')](_0x101830);agents[_0x427f('0x37')](_0x101830);calls['attendedtransfer'](_0x101830);}catch(_0x4aa679){utils[_0x427f('0x14')](util[_0x427f('0x19')]('[%s][index][attendedtransfer]',_0x101830[_0x427f('0x39')]),_0x4aa679);}});ami['on']('varset',function(_0x48a24d){try{utils['debug'](util['format'](_0x427f('0x3a'),_0x48a24d['uniqueid']),_0x48a24d);queues[_0x427f('0x3b')](_0x48a24d);recordings[_0x427f('0x3b')](_0x48a24d);calls[_0x427f('0x3b')](_0x48a24d);dials[_0x427f('0x3b')](_0x48a24d);}catch(_0x3b3532){utils[_0x427f('0x14')](util[_0x427f('0x19')](_0x427f('0x3a'),_0x48a24d['uniqueid']),_0x3b3532);}});ami['on'](_0x427f('0x3c'),function(_0x550935){try{utils[_0x427f('0x18')](util['format'](_0x427f('0x3d'),_0x550935[_0x427f('0x1e')]),_0x550935);calls[_0x427f('0x3c')](_0x550935);recordings[_0x427f('0x3c')](_0x550935);dials[_0x427f('0x3c')](_0x550935);}catch(_0x105933){utils[_0x427f('0x14')](util[_0x427f('0x19')](_0x427f('0x3d'),_0x550935['uniqueid']),_0x105933);}});ami['on'](_0x427f('0x3e'),function(_0x3a6561){try{utils[_0x427f('0x18')](util['format']('[%s][index][newchannel]',_0x3a6561[_0x427f('0x1e')]),_0x3a6561);calls[_0x427f('0x3e')](_0x3a6561);recordings['newchannel'](_0x3a6561);}catch(_0x338f57){utils['error'](util[_0x427f('0x19')](_0x427f('0x3f'),_0x3a6561[_0x427f('0x1e')]),_0x338f57);}});ami['on'](_0x427f('0x40'),function(_0x165775){try{utils[_0x427f('0x18')](util[_0x427f('0x19')](_0x427f('0x41'),_0x165775[_0x427f('0x1e')]),_0x165775);dials[_0x427f('0x40')](_0x165775);}catch(_0x8e0145){utils[_0x427f('0x14')](util[_0x427f('0x19')](_0x427f('0x42'),_0x165775[_0x427f('0x1e')]),_0x8e0145);}});ami['on']('dialend',function(_0x9d2fbc){try{utils[_0x427f('0x18')](util[_0x427f('0x19')](_0x427f('0x43'),_0x9d2fbc[_0x427f('0x1e')]),_0x9d2fbc);dials['dialend'](_0x9d2fbc);}catch(_0x46d36){utils['error'](util['format'](_0x427f('0x43'),_0x9d2fbc[_0x427f('0x1e')]),_0x46d36);}});}