05e84a8271e7bd2c253e259431328feb631d827c
[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 _0x643f=['varset','[%s][index][varset]','newexten','[%s][index][newexten]','newchannel','[%s][index][newchannel]','[%s][index][dialbegin]','dialbegin','dialend','[%s][index][dialend]','asterisk-manager','../../config/environment','./utils','xdr','disabled','env','production','local','asterisk','username','password','keepConnected','info','XDR\x20DISABLED','Asterisk\x20disabled\x20on\x20localhost','./calls.controller','./recordings.controller','./members.controller','./dials.controller','./transfers.controller','./core.controller','shutdown','fullybooted','error','close','managerevent','devicestatechange','debug','device','[%s][index][devicestatechange]','format','[%s][index][agentcalled]','uniqueid','[%s][index][agentringnoanswer]','agentconnect','[%s][index][agentconnect]','agentcomplete','queuecallerabandon','[%s][index][queuecallerabandon]','queuecallerjoin','[%s][index][queuecallerjoin]','queuecallerleave','[%s][index][queuecallerleave]','[%s][index][musiconholdstart]','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]'];(function(_0x34843e,_0x4c4224){var _0x598f7f=function(_0x12a44c){while(--_0x12a44c){_0x34843e['push'](_0x34843e['shift']());}};_0x598f7f(++_0x4c4224);}(_0x643f,0x11a));var _0xf643=function(_0x33c02a,_0x45a1e4){_0x33c02a=_0x33c02a-0x0;var _0xce3d6e=_0x643f[_0x33c02a];return _0xce3d6e;};var AsteriskManager=require(_0xf643('0x0'));var config=require(_0xf643('0x1'));var utils=require(_0xf643('0x2'));var util=require('util');var isXDREnabled=config[_0xf643('0x3')]&&config[_0xf643('0x3')][_0xf643('0x4')]?!config[_0xf643('0x3')]['disabled']:!![];var isProduction=config[_0xf643('0x5')]===_0xf643('0x6')||![];var isLocalAsterisk=config[_0xf643('0x3')]&&config[_0xf643('0x3')][_0xf643('0x7')]===!![]||![];var ami=new AsteriskManager(config[_0xf643('0x8')]['port'],config['asterisk']['ip'],config['asterisk'][_0xf643('0x9')],config['asterisk'][_0xf643('0xa')],!![]);ami[_0xf643('0xb')]();if(!isXDREnabled){utils[_0xf643('0xc')](_0xf643('0xd'));}else if(!isProduction&&!isLocalAsterisk){utils[_0xf643('0xc')](_0xf643('0xe'));}else{var agents=require('./agents.controller');var calls=require(_0xf643('0xf'));var queues=require('./queues.controller');var recordings=require(_0xf643('0x10'));var members=require(_0xf643('0x11'));var dials=require(_0xf643('0x12'));var transfers=require(_0xf643('0x13'));var core=require(_0xf643('0x14'));ami['on']('connect',core['connect']);ami['on'](_0xf643('0x15'),core[_0xf643('0x15')]);ami['on'](_0xf643('0x16'),core[_0xf643('0x16')]);ami['on'](_0xf643('0x17'),core[_0xf643('0x17')]);ami['on'](_0xf643('0x18'),core[_0xf643('0x18')]);ami['on']('managerevent',core[_0xf643('0x19')]);ami['on'](_0xf643('0x1a'),function(_0xbbafd8){try{utils[_0xf643('0x1b')](util['format']('[%s][index][devicestatechange]',_0xbbafd8[_0xf643('0x1c')]),_0xbbafd8);members[_0xf643('0x1a')](_0xbbafd8);}catch(_0x558711){utils['error'](util['format'](_0xf643('0x1d'),_0xbbafd8['device']),_0x558711);}});ami['on']('agentcalled',function(_0x1fdfc1){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')](_0xf643('0x1f'),_0x1fdfc1[_0xf643('0x20')]),_0x1fdfc1);agents['agentcalled'](_0x1fdfc1);}catch(_0x2b8ab1){utils[_0xf643('0x17')](util[_0xf643('0x1e')](_0xf643('0x1f'),_0x1fdfc1['uniqueid']),_0x2b8ab1);}});ami['on']('agentringnoanswer',function(_0x325fd2){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')](_0xf643('0x21'),_0x325fd2['uniqueid']),_0x325fd2);agents['agentringnoanswer'](_0x325fd2);}catch(_0x9e4535){utils['error'](util[_0xf643('0x1e')](_0xf643('0x21'),_0x325fd2[_0xf643('0x20')]),_0x9e4535);}});ami['on'](_0xf643('0x22'),function(_0x400d8a){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')](_0xf643('0x23'),_0x400d8a[_0xf643('0x20')]),_0x400d8a);agents['agentconnect'](_0x400d8a);queues[_0xf643('0x22')](_0x400d8a);}catch(_0xd366ea){utils[_0xf643('0x17')](util[_0xf643('0x1e')](_0xf643('0x23'),_0x400d8a[_0xf643('0x20')]),_0xd366ea);}});ami['on'](_0xf643('0x24'),function(_0x3a1be3){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')]('[%s][index][agentcomplete]',_0x3a1be3[_0xf643('0x20')]),_0x3a1be3);agents[_0xf643('0x24')](_0x3a1be3);queues['agentcomplete'](_0x3a1be3);members[_0xf643('0x24')](_0x3a1be3);}catch(_0x115290){utils[_0xf643('0x17')](util['format']('[%s][index][agentcomplete]',_0x3a1be3[_0xf643('0x20')]),_0x115290);}});ami['on'](_0xf643('0x25'),function(_0xf2134f){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')]('[%s][index][queuecallerabandon]',_0xf2134f[_0xf643('0x20')]),_0xf2134f);agents['queuecallerabandon'](_0xf2134f);queues[_0xf643('0x25')](_0xf2134f);}catch(_0x103cd3){utils['error'](util['format'](_0xf643('0x26'),_0xf2134f[_0xf643('0x20')]),_0x103cd3);}});ami['on'](_0xf643('0x27'),function(_0x1c82ca){try{utils['debug'](util[_0xf643('0x1e')](_0xf643('0x28'),_0x1c82ca[_0xf643('0x20')]),_0x1c82ca);queues[_0xf643('0x27')](_0x1c82ca);recordings[_0xf643('0x27')](_0x1c82ca);}catch(_0x4921f0){utils[_0xf643('0x17')](util[_0xf643('0x1e')](_0xf643('0x28'),_0x1c82ca[_0xf643('0x20')]),_0x4921f0);}});ami['on'](_0xf643('0x29'),function(_0x4a02e1){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')]('[%s][index][queuecallerleave]',_0x4a02e1['uniqueid']),_0x4a02e1);queues[_0xf643('0x29')](_0x4a02e1);}catch(_0xa4faa1){utils['error'](util[_0xf643('0x1e')](_0xf643('0x2a'),_0x4a02e1[_0xf643('0x20')]),_0xa4faa1);}});ami['on']('musiconholdstart',function(_0x13d08f){try{utils['debug'](util['format'](_0xf643('0x2b'),_0x13d08f[_0xf643('0x20')]),_0x13d08f);queues[_0xf643('0x2c')](_0x13d08f);calls[_0xf643('0x2c')](_0x13d08f);}catch(_0x3a16c9){utils[_0xf643('0x17')](util[_0xf643('0x1e')](_0xf643('0x2b'),_0x13d08f['uniqueid']),_0x3a16c9);}});ami['on'](_0xf643('0x2d'),function(_0x2a9599){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')](_0xf643('0x2e'),_0x2a9599['uniqueid']),_0x2a9599);queues[_0xf643('0x2d')](_0x2a9599);calls[_0xf643('0x2d')](_0x2a9599);}catch(_0x4738a9){utils[_0xf643('0x17')](util[_0xf643('0x1e')]('[%s][index][musiconholdstop]',_0x2a9599['uniqueid']),_0x4738a9);}});ami['on'](_0xf643('0x2f'),function(_0xae850d){try{utils[_0xf643('0x1b')](util['format'](_0xf643('0x30'),_0xae850d['uniqueid']),_0xae850d);calls[_0xf643('0x2f')](_0xae850d);recordings[_0xf643('0x2f')](_0xae850d);}catch(_0x499f3a){utils['error'](util['format'](_0xf643('0x30'),_0xae850d[_0xf643('0x20')]),_0x499f3a);}});ami['on']('hangup',function(_0x2f15d3){try{utils[_0xf643('0x1b')](util['format'](_0xf643('0x31'),_0x2f15d3['uniqueid']),_0x2f15d3);calls[_0xf643('0x32')](_0x2f15d3);recordings[_0xf643('0x32')](_0x2f15d3);dials[_0xf643('0x32')](_0x2f15d3);agents[_0xf643('0x32')](_0x2f15d3);queues[_0xf643('0x32')](_0x2f15d3);}catch(_0x4f5cdb){utils['error'](util[_0xf643('0x1e')](_0xf643('0x31'),_0x2f15d3[_0xf643('0x20')]),_0x4f5cdb);}});ami['on'](_0xf643('0x33'),function(_0x1cd136){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')](_0xf643('0x34'),_0x1cd136[_0xf643('0x20')]),_0x1cd136);members['cdr'](_0x1cd136);}catch(_0x1443c6){utils[_0xf643('0x17')](util['format'](_0xf643('0x34'),_0x1cd136[_0xf643('0x20')]),_0x1443c6);}});ami['on'](_0xf643('0x35'),function(_0x3b66a9){try{utils['debug'](util['format']('[%s][index][blindtransfer]',_0x3b66a9[_0xf643('0x20')]),_0x3b66a9);queues[_0xf643('0x35')](_0x3b66a9);agents[_0xf643('0x35')](_0x3b66a9);transfers[_0xf643('0x35')](_0x3b66a9);recordings[_0xf643('0x35')](_0x3b66a9);}catch(_0x4fd551){utils[_0xf643('0x17')](util[_0xf643('0x1e')](_0xf643('0x36'),_0x3b66a9['uniqueid']),_0x4fd551);}});ami['on'](_0xf643('0x37'),function(_0x3e305a){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')]('[%s][index][attendedtransfer]',_0x3e305a[_0xf643('0x38')]),_0x3e305a);queues[_0xf643('0x37')](_0x3e305a);transfers[_0xf643('0x37')](_0x3e305a);agents[_0xf643('0x37')](_0x3e305a);calls[_0xf643('0x37')](_0x3e305a);}catch(_0x53eed7){utils['error'](util[_0xf643('0x1e')](_0xf643('0x39'),_0x3e305a[_0xf643('0x38')]),_0x53eed7);}});ami['on'](_0xf643('0x3a'),function(_0x1c627b){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')](_0xf643('0x3b'),_0x1c627b['uniqueid']),_0x1c627b);queues[_0xf643('0x3a')](_0x1c627b);recordings[_0xf643('0x3a')](_0x1c627b);calls['varset'](_0x1c627b);dials[_0xf643('0x3a')](_0x1c627b);}catch(_0x461972){utils[_0xf643('0x17')](util[_0xf643('0x1e')](_0xf643('0x3b'),_0x1c627b[_0xf643('0x20')]),_0x461972);}});ami['on'](_0xf643('0x3c'),function(_0x1b81ee){try{utils['debug'](util[_0xf643('0x1e')]('[%s][index][newexten]',_0x1b81ee[_0xf643('0x20')]),_0x1b81ee);calls['newexten'](_0x1b81ee);recordings[_0xf643('0x3c')](_0x1b81ee);dials['newexten'](_0x1b81ee);}catch(_0x2ee5d0){utils[_0xf643('0x17')](util['format'](_0xf643('0x3d'),_0x1b81ee['uniqueid']),_0x2ee5d0);}});ami['on'](_0xf643('0x3e'),function(_0x3c3ade){try{utils['debug'](util[_0xf643('0x1e')]('[%s][index][newchannel]',_0x3c3ade[_0xf643('0x20')]),_0x3c3ade);calls[_0xf643('0x3e')](_0x3c3ade);recordings[_0xf643('0x3e')](_0x3c3ade);}catch(_0x5c149d){utils[_0xf643('0x17')](util[_0xf643('0x1e')](_0xf643('0x3f'),_0x3c3ade['uniqueid']),_0x5c149d);}});ami['on']('dialbegin',function(_0x4efbb0){try{utils[_0xf643('0x1b')](util[_0xf643('0x1e')](_0xf643('0x40'),_0x4efbb0[_0xf643('0x20')]),_0x4efbb0);dials[_0xf643('0x41')](_0x4efbb0);}catch(_0x236f9d){utils['error'](util['format']('[%s]dialbegin',_0x4efbb0[_0xf643('0x20')]),_0x236f9d);}});ami['on'](_0xf643('0x42'),function(_0x35dff3){try{utils[_0xf643('0x1b')](util['format'](_0xf643('0x43'),_0x35dff3[_0xf643('0x20')]),_0x35dff3);dials[_0xf643('0x42')](_0x35dff3);}catch(_0x1ab410){utils[_0xf643('0x17')](util[_0xf643('0x1e')](_0xf643('0x43'),_0x35dff3[_0xf643('0x20')]),_0x1ab410);}});}