8ecaec32c46b8b45dde896927831814ae0a7f501
[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 _0xba1e=['util','xdr','disabled','local','asterisk','port','username','password','keepConnected','info','XDR\x20DISABLED','./agents.controller','./calls.controller','./queues.controller','./dials.controller','./core.controller','connect','shutdown','fullybooted','error','close','managerevent','devicestatechange','debug','format','device','[%s][index][devicestatechange]','agentcalled','[%s][index][agentcalled]','uniqueid','agentringnoanswer','[%s][index][agentringnoanswer]','agentconnect','agentcomplete','queuecallerabandon','[%s][index][queuecallerabandon]','queuecallerjoin','[%s][index][queuecallerjoin]','[%s][index][queuecallerleave]','musiconholdstart','[%s][index][musiconholdstart]','musiconholdstop','[%s][index][musiconholdstop]','newstate','[%s][index][newstate]','hangup','[%s][index][hangup]','[%s][index][cdr]','blindtransfer','[%s][index][blindtransfer]','attendedtransfer','[%s][index][attendedtransfer]','origtransfereruniqueid','varset','[%s][index][varset]','newexten','[%s][index][newexten]','newchannel','[%s][index][newchannel]','dialbegin','[%s][index][dialbegin]','[%s][index][dialend]','dialend','asterisk-manager','./utils'];(function(_0x303c30,_0x16edcb){var _0x43161b=function(_0x3330ff){while(--_0x3330ff){_0x303c30['push'](_0x303c30['shift']());}};_0x43161b(++_0x16edcb);}(_0xba1e,0x1c5));var _0xeba1=function(_0x333159,_0x68262e){_0x333159=_0x333159-0x0;var _0x2e29ac=_0xba1e[_0x333159];return _0x2e29ac;};var AsteriskManager=require(_0xeba1('0x0'));var config=require('../../config/environment');var utils=require(_0xeba1('0x1'));var util=require(_0xeba1('0x2'));var isXDREnabled=config[_0xeba1('0x3')]&&config[_0xeba1('0x3')][_0xeba1('0x4')]?!config[_0xeba1('0x3')]['disabled']:!![];var isProduction=config['env']==='production'||![];var isLocalAsterisk=config[_0xeba1('0x3')]&&config[_0xeba1('0x3')][_0xeba1('0x5')]===!![]||![];var ami=new AsteriskManager(config[_0xeba1('0x6')][_0xeba1('0x7')],config[_0xeba1('0x6')]['ip'],config['asterisk'][_0xeba1('0x8')],config[_0xeba1('0x6')][_0xeba1('0x9')],!![]);ami[_0xeba1('0xa')]();if(!isXDREnabled){utils[_0xeba1('0xb')](_0xeba1('0xc'));}else if(!isProduction&&!isLocalAsterisk){utils['info']('Asterisk\x20disabled\x20on\x20localhost');}else{var agents=require(_0xeba1('0xd'));var calls=require(_0xeba1('0xe'));var queues=require(_0xeba1('0xf'));var recordings=require('./recordings.controller');var members=require('./members.controller');var dials=require(_0xeba1('0x10'));var transfers=require('./transfers.controller');var core=require(_0xeba1('0x11'));ami['on']('connect',core[_0xeba1('0x12')]);ami['on']('shutdown',core[_0xeba1('0x13')]);ami['on'](_0xeba1('0x14'),core[_0xeba1('0x14')]);ami['on'](_0xeba1('0x15'),core[_0xeba1('0x15')]);ami['on'](_0xeba1('0x16'),core[_0xeba1('0x16')]);ami['on'](_0xeba1('0x17'),core[_0xeba1('0x17')]);ami['on'](_0xeba1('0x18'),function(_0x47ca39){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')]('[%s][index][devicestatechange]',_0x47ca39[_0xeba1('0x1b')]),_0x47ca39);members[_0xeba1('0x18')](_0x47ca39);}catch(_0x1f8810){utils[_0xeba1('0x15')](util['format'](_0xeba1('0x1c'),_0x47ca39[_0xeba1('0x1b')]),_0x1f8810);}});ami['on'](_0xeba1('0x1d'),function(_0x1b41fb){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')](_0xeba1('0x1e'),_0x1b41fb[_0xeba1('0x1f')]),_0x1b41fb);agents[_0xeba1('0x1d')](_0x1b41fb);}catch(_0x31dbfc){utils['error'](util[_0xeba1('0x1a')](_0xeba1('0x1e'),_0x1b41fb[_0xeba1('0x1f')]),_0x31dbfc);}});ami['on'](_0xeba1('0x20'),function(_0x45aea7){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')]('[%s][index][agentringnoanswer]',_0x45aea7[_0xeba1('0x1f')]),_0x45aea7);agents[_0xeba1('0x20')](_0x45aea7);}catch(_0x3b2eb3){utils['error'](util['format'](_0xeba1('0x21'),_0x45aea7[_0xeba1('0x1f')]),_0x3b2eb3);}});ami['on'](_0xeba1('0x22'),function(_0x35dfca){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')]('[%s][index][agentconnect]',_0x35dfca[_0xeba1('0x1f')]),_0x35dfca);agents[_0xeba1('0x22')](_0x35dfca);queues[_0xeba1('0x22')](_0x35dfca);}catch(_0x2a8c59){utils['error'](util[_0xeba1('0x1a')]('[%s][index][agentconnect]',_0x35dfca['uniqueid']),_0x2a8c59);}});ami['on'](_0xeba1('0x23'),function(_0x5bc49c){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')]('[%s][index][agentcomplete]',_0x5bc49c[_0xeba1('0x1f')]),_0x5bc49c);agents[_0xeba1('0x23')](_0x5bc49c);queues[_0xeba1('0x23')](_0x5bc49c);members[_0xeba1('0x23')](_0x5bc49c);}catch(_0x585d0e){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')]('[%s][index][agentcomplete]',_0x5bc49c[_0xeba1('0x1f')]),_0x585d0e);}});ami['on'](_0xeba1('0x24'),function(_0x32fb3a){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')](_0xeba1('0x25'),_0x32fb3a['uniqueid']),_0x32fb3a);agents[_0xeba1('0x24')](_0x32fb3a);queues['queuecallerabandon'](_0x32fb3a);}catch(_0x45f813){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')]('[%s][index][queuecallerabandon]',_0x32fb3a['uniqueid']),_0x45f813);}});ami['on'](_0xeba1('0x26'),function(_0x3f3ae6){try{utils['debug'](util[_0xeba1('0x1a')](_0xeba1('0x27'),_0x3f3ae6[_0xeba1('0x1f')]),_0x3f3ae6);queues['queuecallerjoin'](_0x3f3ae6);recordings[_0xeba1('0x26')](_0x3f3ae6);}catch(_0x262368){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')]('[%s][index][queuecallerjoin]',_0x3f3ae6[_0xeba1('0x1f')]),_0x262368);}});ami['on']('queuecallerleave',function(_0x18fd6f){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')](_0xeba1('0x28'),_0x18fd6f[_0xeba1('0x1f')]),_0x18fd6f);queues['queuecallerleave'](_0x18fd6f);}catch(_0x420d54){utils['error'](util['format'](_0xeba1('0x28'),_0x18fd6f[_0xeba1('0x1f')]),_0x420d54);}});ami['on'](_0xeba1('0x29'),function(_0x4d4c69){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')](_0xeba1('0x2a'),_0x4d4c69['uniqueid']),_0x4d4c69);queues[_0xeba1('0x29')](_0x4d4c69);calls[_0xeba1('0x29')](_0x4d4c69);}catch(_0xb68517){utils['error'](util['format'](_0xeba1('0x2a'),_0x4d4c69['uniqueid']),_0xb68517);}});ami['on']('musiconholdstop',function(_0x4cc237){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')]('[%s][index][musiconholdstop]',_0x4cc237['uniqueid']),_0x4cc237);queues[_0xeba1('0x2b')](_0x4cc237);calls[_0xeba1('0x2b')](_0x4cc237);}catch(_0x292c54){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')](_0xeba1('0x2c'),_0x4cc237[_0xeba1('0x1f')]),_0x292c54);}});ami['on'](_0xeba1('0x2d'),function(_0x483265){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')](_0xeba1('0x2e'),_0x483265[_0xeba1('0x1f')]),_0x483265);calls[_0xeba1('0x2d')](_0x483265);recordings[_0xeba1('0x2d')](_0x483265);}catch(_0x2dea97){utils[_0xeba1('0x15')](util['format']('[%s][index][newstate]',_0x483265[_0xeba1('0x1f')]),_0x2dea97);}});ami['on'](_0xeba1('0x2f'),function(_0x2c8268){try{utils[_0xeba1('0x19')](util['format'](_0xeba1('0x30'),_0x2c8268['uniqueid']),_0x2c8268);calls['hangup'](_0x2c8268);recordings[_0xeba1('0x2f')](_0x2c8268);dials[_0xeba1('0x2f')](_0x2c8268);agents['hangup'](_0x2c8268);queues[_0xeba1('0x2f')](_0x2c8268);}catch(_0x2a7b21){utils[_0xeba1('0x15')](util['format'](_0xeba1('0x30'),_0x2c8268['uniqueid']),_0x2a7b21);}});ami['on']('cdr',function(_0x58800a){try{utils['debug'](util[_0xeba1('0x1a')](_0xeba1('0x31'),_0x58800a['uniqueid']),_0x58800a);members['cdr'](_0x58800a);}catch(_0x276ee0){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')]('[%s][index][cdr]',_0x58800a[_0xeba1('0x1f')]),_0x276ee0);}});ami['on'](_0xeba1('0x32'),function(_0x18cc46){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')](_0xeba1('0x33'),_0x18cc46['uniqueid']),_0x18cc46);queues[_0xeba1('0x32')](_0x18cc46);agents[_0xeba1('0x32')](_0x18cc46);transfers[_0xeba1('0x32')](_0x18cc46);}catch(_0x4d4d86){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')](_0xeba1('0x33'),_0x18cc46[_0xeba1('0x1f')]),_0x4d4d86);}});ami['on'](_0xeba1('0x34'),function(_0x153b38){try{utils['debug'](util[_0xeba1('0x1a')](_0xeba1('0x35'),_0x153b38[_0xeba1('0x36')]),_0x153b38);queues[_0xeba1('0x34')](_0x153b38);transfers[_0xeba1('0x34')](_0x153b38);agents['attendedtransfer'](_0x153b38);calls[_0xeba1('0x34')](_0x153b38);}catch(_0x2ca372){utils['error'](util[_0xeba1('0x1a')](_0xeba1('0x35'),_0x153b38[_0xeba1('0x36')]),_0x2ca372);}});ami['on'](_0xeba1('0x37'),function(_0x106363){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')]('[%s][index][varset]',_0x106363[_0xeba1('0x1f')]),_0x106363);queues[_0xeba1('0x37')](_0x106363);recordings[_0xeba1('0x37')](_0x106363);calls[_0xeba1('0x37')](_0x106363);dials[_0xeba1('0x37')](_0x106363);}catch(_0x25613d){utils['error'](util['format'](_0xeba1('0x38'),_0x106363[_0xeba1('0x1f')]),_0x25613d);}});ami['on'](_0xeba1('0x39'),function(_0x35db38){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')](_0xeba1('0x3a'),_0x35db38['uniqueid']),_0x35db38);calls[_0xeba1('0x39')](_0x35db38);recordings['newexten'](_0x35db38);dials[_0xeba1('0x39')](_0x35db38);}catch(_0x12aae2){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')]('[%s][index][newexten]',_0x35db38['uniqueid']),_0x12aae2);}});ami['on'](_0xeba1('0x3b'),function(_0xbf1551){try{utils[_0xeba1('0x19')](util['format'](_0xeba1('0x3c'),_0xbf1551['uniqueid']),_0xbf1551);calls[_0xeba1('0x3b')](_0xbf1551);recordings[_0xeba1('0x3b')](_0xbf1551);}catch(_0x30d1d2){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')](_0xeba1('0x3c'),_0xbf1551[_0xeba1('0x1f')]),_0x30d1d2);}});ami['on'](_0xeba1('0x3d'),function(_0x4338ac){try{utils[_0xeba1('0x19')](util[_0xeba1('0x1a')](_0xeba1('0x3e'),_0x4338ac[_0xeba1('0x1f')]),_0x4338ac);dials[_0xeba1('0x3d')](_0x4338ac);}catch(_0x351590){utils[_0xeba1('0x15')](util[_0xeba1('0x1a')]('[%s]dialbegin',_0x4338ac[_0xeba1('0x1f')]),_0x351590);}});ami['on']('dialend',function(_0x130048){try{utils['debug'](util['format'](_0xeba1('0x3f'),_0x130048[_0xeba1('0x1f')]),_0x130048);dials[_0xeba1('0x40')](_0x130048);}catch(_0x4e4dba){utils['error'](util[_0xeba1('0x1a')](_0xeba1('0x3f'),_0x130048[_0xeba1('0x1f')]),_0x4e4dba);}});}