cc838659a214e13aa239af8f2b4d09e14ba1a850
[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 _0xceee=['production','local','asterisk','port','password','info','Asterisk\x20disabled\x20on\x20localhost','./agents.controller','./members.controller','./transfers.controller','connect','shutdown','fullybooted','error','close','managerevent','devicestatechange','format','[%s][index][devicestatechange]','device','agentcalled','[%s][index][agentcalled]','uniqueid','agentringnoanswer','debug','[%s][index][agentringnoanswer]','agentconnect','[%s][index][agentconnect]','agentcomplete','[%s][index][agentcomplete]','queuecallerabandon','[%s][index][queuecallerabandon]','queuecallerjoin','[%s][index][queuecallerjoin]','queuecallerleave','musiconholdstart','[%s][index][musiconholdstart]','musiconholdstop','[%s][index][musiconholdstop]','newstate','[%s][index][newstate]','[%s][index][hangup]','hangup','cdr','[%s][index][cdr]','blindtransfer','[%s][index][blindtransfer]','attendedtransfer','origtransfereruniqueid','[%s][index][attendedtransfer]','varset','[%s][index][varset]','newexten','[%s][index][newexten]','newchannel','[%s][index][dialbegin]','dialbegin','dialend','[%s][index][dialend]','asterisk-manager','../../config/environment','xdr','disabled','env'];(function(_0x5c4444,_0x119726){var _0x20d93d=function(_0x326a33){while(--_0x326a33){_0x5c4444['push'](_0x5c4444['shift']());}};_0x20d93d(++_0x119726);}(_0xceee,0xbb));var _0xecee=function(_0x1d2c8b,_0x1fd2bf){_0x1d2c8b=_0x1d2c8b-0x0;var _0x22aa54=_0xceee[_0x1d2c8b];return _0x22aa54;};var AsteriskManager=require(_0xecee('0x0'));var config=require(_0xecee('0x1'));var utils=require('./utils');var util=require('util');var isXDREnabled=config[_0xecee('0x2')]&&!config[_0xecee('0x2')][_0xecee('0x3')];var isProduction=config[_0xecee('0x4')]===_0xecee('0x5')||![];var isLocalAsterisk=config[_0xecee('0x2')]&&config['xdr'][_0xecee('0x6')]===!![]||![];var ami=new AsteriskManager(config[_0xecee('0x7')][_0xecee('0x8')],config[_0xecee('0x7')]['ip'],config['asterisk']['username'],config[_0xecee('0x7')][_0xecee('0x9')],!![]);ami['keepConnected']();if(!isXDREnabled){utils[_0xecee('0xa')]('XDR\x20DISABLED');}else if(!isProduction&&!isLocalAsterisk){utils['info'](_0xecee('0xb'));}else{var agents=require(_0xecee('0xc'));var calls=require('./calls.controller');var queues=require('./queues.controller');var recordings=require('./recordings.controller');var members=require(_0xecee('0xd'));var dials=require('./dials.controller');var transfers=require(_0xecee('0xe'));var core=require('./core.controller');ami['on'](_0xecee('0xf'),core[_0xecee('0xf')]);ami['on'](_0xecee('0x10'),core[_0xecee('0x10')]);ami['on'](_0xecee('0x11'),core[_0xecee('0x11')]);ami['on'](_0xecee('0x12'),core[_0xecee('0x12')]);ami['on']('close',core[_0xecee('0x13')]);ami['on'](_0xecee('0x14'),core[_0xecee('0x14')]);ami['on'](_0xecee('0x15'),function(_0x3e04a0){try{utils['debug'](util[_0xecee('0x16')](_0xecee('0x17'),_0x3e04a0[_0xecee('0x18')]),_0x3e04a0);members[_0xecee('0x15')](_0x3e04a0);}catch(_0x4f40aa){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x17'),_0x3e04a0[_0xecee('0x18')]),_0x4f40aa);}});ami['on'](_0xecee('0x19'),function(_0x11d520){try{utils['debug'](util[_0xecee('0x16')](_0xecee('0x1a'),_0x11d520[_0xecee('0x1b')]),_0x11d520);agents[_0xecee('0x19')](_0x11d520);}catch(_0x318d33){utils[_0xecee('0x12')](util['format']('[%s][index][agentcalled]',_0x11d520['uniqueid']),_0x318d33);}});ami['on'](_0xecee('0x1c'),function(_0x378111){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')](_0xecee('0x1e'),_0x378111[_0xecee('0x1b')]),_0x378111);agents[_0xecee('0x1c')](_0x378111);}catch(_0x37d871){utils[_0xecee('0x12')](util['format'](_0xecee('0x1e'),_0x378111['uniqueid']),_0x37d871);}});ami['on'](_0xecee('0x1f'),function(_0x56f50d){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')](_0xecee('0x20'),_0x56f50d[_0xecee('0x1b')]),_0x56f50d);agents['agentconnect'](_0x56f50d);queues['agentconnect'](_0x56f50d);}catch(_0x25b7af){utils[_0xecee('0x12')](util[_0xecee('0x16')]('[%s][index][agentconnect]',_0x56f50d[_0xecee('0x1b')]),_0x25b7af);}});ami['on'](_0xecee('0x21'),function(_0x7b7db5){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')](_0xecee('0x22'),_0x7b7db5[_0xecee('0x1b')]),_0x7b7db5);agents[_0xecee('0x21')](_0x7b7db5);queues['agentcomplete'](_0x7b7db5);members['agentcomplete'](_0x7b7db5);}catch(_0x72ae5f){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x22'),_0x7b7db5['uniqueid']),_0x72ae5f);}});ami['on'](_0xecee('0x23'),function(_0x56fdb8){try{utils[_0xecee('0x1d')](util['format'](_0xecee('0x24'),_0x56fdb8[_0xecee('0x1b')]),_0x56fdb8);agents[_0xecee('0x23')](_0x56fdb8);queues[_0xecee('0x23')](_0x56fdb8);}catch(_0x213168){utils['error'](util[_0xecee('0x16')](_0xecee('0x24'),_0x56fdb8[_0xecee('0x1b')]),_0x213168);}});ami['on'](_0xecee('0x25'),function(_0xdb0546){try{utils[_0xecee('0x1d')](util['format'](_0xecee('0x26'),_0xdb0546[_0xecee('0x1b')]),_0xdb0546);queues['queuecallerjoin'](_0xdb0546);recordings[_0xecee('0x25')](_0xdb0546);}catch(_0x569da4){utils[_0xecee('0x12')](util['format']('[%s][index][queuecallerjoin]',_0xdb0546[_0xecee('0x1b')]),_0x569da4);}});ami['on'](_0xecee('0x27'),function(_0x1ec491){try{utils['debug'](util[_0xecee('0x16')]('[%s][index][queuecallerleave]',_0x1ec491[_0xecee('0x1b')]),_0x1ec491);queues[_0xecee('0x27')](_0x1ec491);}catch(_0x49b190){utils[_0xecee('0x12')](util['format']('[%s][index][queuecallerleave]',_0x1ec491[_0xecee('0x1b')]),_0x49b190);}});ami['on'](_0xecee('0x28'),function(_0x59ad53){try{utils['debug'](util['format'](_0xecee('0x29'),_0x59ad53[_0xecee('0x1b')]),_0x59ad53);queues[_0xecee('0x28')](_0x59ad53);calls[_0xecee('0x28')](_0x59ad53);}catch(_0x5e8e3d){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x29'),_0x59ad53[_0xecee('0x1b')]),_0x5e8e3d);}});ami['on'](_0xecee('0x2a'),function(_0x4289ab){try{utils[_0xecee('0x1d')](util['format'](_0xecee('0x2b'),_0x4289ab[_0xecee('0x1b')]),_0x4289ab);queues[_0xecee('0x2a')](_0x4289ab);calls[_0xecee('0x2a')](_0x4289ab);}catch(_0x3cecfa){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x2b'),_0x4289ab[_0xecee('0x1b')]),_0x3cecfa);}});ami['on'](_0xecee('0x2c'),function(_0x407d4e){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')]('[%s][index][newstate]',_0x407d4e['uniqueid']),_0x407d4e);calls[_0xecee('0x2c')](_0x407d4e);recordings[_0xecee('0x2c')](_0x407d4e);}catch(_0x33fcf4){utils[_0xecee('0x12')](util['format'](_0xecee('0x2d'),_0x407d4e[_0xecee('0x1b')]),_0x33fcf4);}});ami['on']('hangup',function(_0x33a6a5){try{utils[_0xecee('0x1d')](util['format'](_0xecee('0x2e'),_0x33a6a5['uniqueid']),_0x33a6a5);calls[_0xecee('0x2f')](_0x33a6a5);recordings['hangup'](_0x33a6a5);dials[_0xecee('0x2f')](_0x33a6a5);agents['hangup'](_0x33a6a5);queues[_0xecee('0x2f')](_0x33a6a5);}catch(_0x49a700){utils['error'](util[_0xecee('0x16')](_0xecee('0x2e'),_0x33a6a5[_0xecee('0x1b')]),_0x49a700);}});ami['on'](_0xecee('0x30'),function(_0x13635d){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')](_0xecee('0x31'),_0x13635d[_0xecee('0x1b')]),_0x13635d);members['cdr'](_0x13635d);}catch(_0x476794){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x31'),_0x13635d['uniqueid']),_0x476794);}});ami['on'](_0xecee('0x32'),function(_0x45c524){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')](_0xecee('0x33'),_0x45c524['uniqueid']),_0x45c524);queues[_0xecee('0x32')](_0x45c524);agents[_0xecee('0x32')](_0x45c524);transfers[_0xecee('0x32')](_0x45c524);recordings[_0xecee('0x32')](_0x45c524);}catch(_0xab1623){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x33'),_0x45c524['uniqueid']),_0xab1623);}});ami['on'](_0xecee('0x34'),function(_0x306b33){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')]('[%s][index][attendedtransfer]',_0x306b33[_0xecee('0x35')]),_0x306b33);queues[_0xecee('0x34')](_0x306b33);transfers[_0xecee('0x34')](_0x306b33);agents[_0xecee('0x34')](_0x306b33);calls['attendedtransfer'](_0x306b33);}catch(_0x5375b1){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x36'),_0x306b33[_0xecee('0x35')]),_0x5375b1);}});ami['on'](_0xecee('0x37'),function(_0x9261f9){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')](_0xecee('0x38'),_0x9261f9[_0xecee('0x1b')]),_0x9261f9);queues[_0xecee('0x37')](_0x9261f9);recordings[_0xecee('0x37')](_0x9261f9);calls[_0xecee('0x37')](_0x9261f9);dials[_0xecee('0x37')](_0x9261f9);}catch(_0x4ad92e){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x38'),_0x9261f9[_0xecee('0x1b')]),_0x4ad92e);}});ami['on'](_0xecee('0x39'),function(_0x4851f9){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')]('[%s][index][newexten]',_0x4851f9['uniqueid']),_0x4851f9);calls[_0xecee('0x39')](_0x4851f9);recordings[_0xecee('0x39')](_0x4851f9);dials[_0xecee('0x39')](_0x4851f9);}catch(_0x2fe4a8){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x3a'),_0x4851f9[_0xecee('0x1b')]),_0x2fe4a8);}});ami['on'](_0xecee('0x3b'),function(_0x17a50f){try{utils[_0xecee('0x1d')](util['format']('[%s][index][newchannel]',_0x17a50f[_0xecee('0x1b')]),_0x17a50f);calls[_0xecee('0x3b')](_0x17a50f);recordings[_0xecee('0x3b')](_0x17a50f);}catch(_0x495369){utils[_0xecee('0x12')](util[_0xecee('0x16')]('[%s][index][newchannel]',_0x17a50f[_0xecee('0x1b')]),_0x495369);}});ami['on']('dialbegin',function(_0x4f93a6){try{utils[_0xecee('0x1d')](util[_0xecee('0x16')](_0xecee('0x3c'),_0x4f93a6[_0xecee('0x1b')]),_0x4f93a6);dials[_0xecee('0x3d')](_0x4f93a6);}catch(_0x454532){utils[_0xecee('0x12')](util[_0xecee('0x16')]('[%s]dialbegin',_0x4f93a6[_0xecee('0x1b')]),_0x454532);}});ami['on'](_0xecee('0x3e'),function(_0x102faf){try{utils['debug'](util['format'](_0xecee('0x3f'),_0x102faf['uniqueid']),_0x102faf);dials[_0xecee('0x3e')](_0x102faf);}catch(_0x26768e){utils[_0xecee('0x12')](util[_0xecee('0x16')](_0xecee('0x3f'),_0x102faf['uniqueid']),_0x26768e);}});}