Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / services / xdr / calls.controller.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 _0x7ce6=['disposition','toNumber','[%s][calls][newstate]','[%s][calls][hangup]','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','duration','starttime','billableseconds','diffTime','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','transfereechannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','secondtransfererchannel','destinationchannel','userfield','_attended','transfertargetchannel','origtransfererchannel','musiconholdstart','musiconholdstartAt','musiconholdstop','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','varset','variable','xmd-originatecalleridnum','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','value','source','xmd-phone','[%s][calls][varset]\x20variable:xmd-phone\x20value:%s','destination','\x22\x20<','xmd-callerid-preview','xmd-callerid','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-queue','xmcs-queue','lastapplication','Queue','lastdata','xmd-contactid','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','ContactId','type','outboundrouteid','routeid','sipcallid','[%s][calls][varset]\x20variable:sipcallid\x20value:%s','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','appdata','toLowerCase','cdr','split','substring','lastIndexOf','hangup','gotoif','lodash','util','./utils','NO\x20ANSWER','FAILED','info','format','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','uniqueid','channel','membername','connectedlinenum','lastevent','accountcode','getUserByInternal','then','request','CreateVoiceCallReport','newchannel','debug','linkedid','OutgoingSpoolFailed','[%s][calls][newchannel]\x20context:%s\x20exten:%s','context','exten','calleridnum','now','DOCUMENTATION','error','[%s][calls][newchannel]','newstate','systemanswertime','channelstate','transfer','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','isNil','answertime'];(function(_0x4fc425,_0x5cfc14){var _0x4a50a9=function(_0x3875a1){while(--_0x3875a1){_0x4fc425['push'](_0x4fc425['shift']());}};_0x4a50a9(++_0x5cfc14);}(_0x7ce6,0x17b));var _0x67ce=function(_0x939db2,_0x58e90c){_0x939db2=_0x939db2-0x0;var _0x5f18a4=_0x7ce6[_0x939db2];return _0x5f18a4;};'use strict';var _=require(_0x67ce('0x0'));var util=require(_0x67ce('0x1'));var utils=require(_0x67ce('0x2'));var dispositions=[_0x67ce('0x3'),_0x67ce('0x4'),'FAILED',_0x67ce('0x3'),_0x67ce('0x3'),_0x67ce('0x3'),'ANSWERED','BUSY',_0x67ce('0x4'),'FAILED',_0x67ce('0x4')];var channels={};function writeDB(_0x50ab0b){utils[_0x67ce('0x5')](util[_0x67ce('0x6')](_0x67ce('0x7'),_0x50ab0b[_0x67ce('0x8')],_0x50ab0b[_0x67ce('0x9')],_0x50ab0b['queue'],_0x50ab0b[_0x67ce('0xa')],_0x50ab0b['interface'],_0x50ab0b['calleridnum'],_0x50ab0b[_0x67ce('0xb')],_0x50ab0b[_0x67ce('0xc')]));if(_0x50ab0b[_0x67ce('0xd')]){utils[_0x67ce('0xe')](_0x50ab0b[_0x67ce('0xd')])[_0x67ce('0xf')](function(_0x1da455){if(_0x1da455){_0x50ab0b['UserId']=_0x1da455['id'];}utils[_0x67ce('0x10')](_0x67ce('0x11'),_0x50ab0b);});}else{utils[_0x67ce('0x10')](_0x67ce('0x11'),_0x50ab0b);}if(channels[_0x50ab0b[_0x67ce('0x8')]]){delete channels[_0x50ab0b[_0x67ce('0x8')]];}}exports[_0x67ce('0x12')]=function(_0x94c21){try{utils[_0x67ce('0x13')](util[_0x67ce('0x6')]('[%s][calls][newchannel]',_0x94c21[_0x67ce('0x8')]),_0x94c21);if(_0x94c21[_0x67ce('0x8')]==_0x94c21[_0x67ce('0x14')]&&_0x94c21[_0x67ce('0x9')]!=_0x67ce('0x15')){utils[_0x67ce('0x5')](util[_0x67ce('0x6')](_0x67ce('0x16'),_0x94c21['uniqueid'],_0x94c21[_0x67ce('0x17')],_0x94c21[_0x67ce('0x18')]));channels[_0x94c21['uniqueid']]={'uniqueid':_0x94c21[_0x67ce('0x8')],'accountcode':_0x94c21[_0x67ce('0xd')],'source':_0x94c21[_0x67ce('0x19')],'destination':_0x94c21['exten'],'destinationcontext':_0x94c21[_0x67ce('0x17')],'channel':_0x94c21[_0x67ce('0x9')],'starttime':utils[_0x67ce('0x1a')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x67ce('0x3'),'amaflags':_0x67ce('0x1b')};}}catch(_0x225ce2){utils[_0x67ce('0x1c')](util[_0x67ce('0x6')](_0x67ce('0x1d'),_0x94c21['uniqueid']),_0x225ce2);}};exports[_0x67ce('0x1e')]=function(_0x384d35){try{utils['debug'](util[_0x67ce('0x6')]('[%s][calls][newstate]',_0x384d35['uniqueid']),_0x384d35);if(!_['isNil'](channels[_0x384d35[_0x67ce('0x8')]])&&_0x384d35['channelstate']==0x6){utils[_0x67ce('0x5')](util[_0x67ce('0x6')]('[%s][calls][newstate]\x20context:%s\x20channel:%s',_0x384d35[_0x67ce('0x8')],_0x384d35['context'],_0x384d35[_0x67ce('0x9')]));if(_['isNil'](channels[_0x384d35[_0x67ce('0x8')]]['systemanswertime'])){channels[_0x384d35[_0x67ce('0x8')]][_0x67ce('0x1f')]=utils['now']();}}else if(!_['isNil'](channels[_0x384d35[_0x67ce('0x14')]])&&_0x384d35[_0x67ce('0x20')]==0x6&&_0x384d35[_0x67ce('0x17')]!=_0x67ce('0x21')){utils['info'](util['format'](_0x67ce('0x22'),_0x384d35[_0x67ce('0x8')],_0x384d35[_0x67ce('0x14')],_0x384d35['context'],_0x384d35['channel']));channels[_0x384d35['linkedid']][_0x67ce('0xd')]=_0x384d35[_0x67ce('0xd')];channels[_0x384d35['linkedid']]['destinationchannel']=_0x384d35[_0x67ce('0x9')];if(_[_0x67ce('0x23')](channels[_0x384d35['linkedid']][_0x67ce('0x24')])){channels[_0x384d35['linkedid']][_0x67ce('0x24')]=utils[_0x67ce('0x1a')]();}channels[_0x384d35['linkedid']][_0x67ce('0x25')]=dispositions[_[_0x67ce('0x26')](_0x384d35['channelstate'])]||'ANSWERED';}}catch(_0x1c22c5){utils[_0x67ce('0x1c')](util['format'](_0x67ce('0x27'),_0x384d35['uniqueid']),_0x1c22c5);}};exports['hangup']=function(_0x27f4a1){try{if(!_[_0x67ce('0x23')](channels[_0x27f4a1[_0x67ce('0x8')]])){utils[_0x67ce('0x13')](util[_0x67ce('0x6')](_0x67ce('0x28'),_0x27f4a1[_0x67ce('0x8')]),_0x27f4a1);if(_[_0x67ce('0x23')](channels[_0x27f4a1['uniqueid']][_0x67ce('0x29')])){channels[_0x27f4a1['uniqueid']]['callerid']=_0x27f4a1[_0x67ce('0x2a')]+'\x20<'+_0x27f4a1[_0x67ce('0x19')]+'>';}utils[_0x67ce('0x5')](util['format'](_0x67ce('0x2b'),_0x27f4a1[_0x67ce('0x8')],channels[_0x27f4a1[_0x67ce('0x8')]][_0x67ce('0x29')],_0x27f4a1[_0x67ce('0x2c')]));channels[_0x27f4a1[_0x67ce('0x8')]][_0x67ce('0x2d')]=utils['now']();channels[_0x27f4a1[_0x67ce('0x8')]][_0x67ce('0x2e')]=utils['diffTime'](channels[_0x27f4a1[_0x67ce('0x8')]][_0x67ce('0x2d')],channels[_0x27f4a1[_0x67ce('0x8')]][_0x67ce('0x2f')]);channels[_0x27f4a1[_0x67ce('0x8')]][_0x67ce('0x30')]=channels[_0x27f4a1[_0x67ce('0x8')]]['answertime']?utils[_0x67ce('0x31')](channels[_0x27f4a1['uniqueid']][_0x67ce('0x2d')],channels[_0x27f4a1[_0x67ce('0x8')]]['answertime']):0x0;writeDB(channels[_0x27f4a1[_0x67ce('0x8')]]);}}catch(_0x516af0){utils[_0x67ce('0x1c')](util[_0x67ce('0x6')](_0x67ce('0x28'),_0x27f4a1[_0x67ce('0x8')]),_0x516af0);}};exports['attendedtransfer']=function(_0x512bbf){try{if(!_[_0x67ce('0x23')](channels[_0x512bbf[_0x67ce('0x32')]])){utils[_0x67ce('0x13')](util[_0x67ce('0x6')](_0x67ce('0x33'),_0x512bbf[_0x67ce('0x34')]),_0x512bbf);if(channels[_0x512bbf[_0x67ce('0x32')]][_0x67ce('0x9')]==_0x512bbf[_0x67ce('0x35')]){utils[_0x67ce('0x5')](util[_0x67ce('0x6')](_0x67ce('0x36'),_0x512bbf[_0x67ce('0x34')],_0x512bbf['localtwolinkedid'],_0x512bbf[_0x67ce('0x37')]));channels[_0x512bbf['localtwolinkedid']][_0x67ce('0x38')]=_0x512bbf[_0x67ce('0x37')];channels[_0x512bbf[_0x67ce('0x32')]][_0x67ce('0x39')]=_0x67ce('0x3a');}else if(channels[_0x512bbf['localtwolinkedid']][_0x67ce('0x9')]=_0x512bbf[_0x67ce('0x3b')]){utils['info'](util[_0x67ce('0x6')](_0x67ce('0x36'),_0x512bbf[_0x67ce('0x34')],_0x512bbf['localtwolinkedid'],_0x512bbf[_0x67ce('0x3c')]));channels[_0x512bbf['localtwolinkedid']][_0x67ce('0x38')]=_0x512bbf['origtransfererchannel'];channels[_0x512bbf[_0x67ce('0x32')]]['userfield']=_0x67ce('0x3a');}}}catch(_0x53240e){utils[_0x67ce('0x1c')](util[_0x67ce('0x6')](_0x67ce('0x33'),_0x512bbf[_0x67ce('0x34')]),_0x53240e);}};exports[_0x67ce('0x3d')]=function(_0x5de4e2){try{if(!_[_0x67ce('0x23')](channels[_0x5de4e2[_0x67ce('0x8')]])){utils[_0x67ce('0x13')](util['format']('[%s][calls][musiconholdstart]',_0x5de4e2[_0x67ce('0x8')]),_0x5de4e2);channels[_0x5de4e2[_0x67ce('0x8')]][_0x67ce('0x3e')]=utils[_0x67ce('0x1a')]();utils[_0x67ce('0x5')](util[_0x67ce('0x6')]('[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s',_0x5de4e2['uniqueid'],channels[_0x5de4e2['uniqueid']]['musiconholdstartAt']));}}catch(_0x4d850b){utils[_0x67ce('0x1c')](util[_0x67ce('0x6')]('[%s][calls][musiconholdstart]',_0x5de4e2[_0x67ce('0x8')]),_0x4d850b);}};exports[_0x67ce('0x3f')]=function(_0x15ed3b){try{if(!_[_0x67ce('0x23')](channels[_0x15ed3b[_0x67ce('0x8')]])){utils[_0x67ce('0x13')](util[_0x67ce('0x6')]('[%s][calls][musiconholdstop]',_0x15ed3b[_0x67ce('0x8')]),_0x15ed3b);if(!_[_0x67ce('0x23')](channels[_0x15ed3b['uniqueid']][_0x67ce('0x3e')])){channels[_0x15ed3b[_0x67ce('0x8')]][_0x67ce('0x40')]+=utils[_0x67ce('0x31')](utils[_0x67ce('0x1a')](),channels[_0x15ed3b['uniqueid']][_0x67ce('0x3e')]);utils[_0x67ce('0x5')](util[_0x67ce('0x6')](_0x67ce('0x41'),_0x15ed3b[_0x67ce('0x8')],channels[_0x15ed3b[_0x67ce('0x8')]][_0x67ce('0x40')]));delete channels[_0x15ed3b[_0x67ce('0x8')]][_0x67ce('0x3e')];}}}catch(_0x19b1da){utils[_0x67ce('0x1c')](util[_0x67ce('0x6')]('[%s][calls][musiconholdstop]',_0x15ed3b['uniqueid']),_0x19b1da);}};exports[_0x67ce('0x42')]=function(_0xaddb32){try{if(!_['isNil'](channels[_0xaddb32[_0x67ce('0x8')]])){utils[_0x67ce('0x13')](util[_0x67ce('0x6')]('[%s][calls][varset]',_0xaddb32['uniqueid']),_0xaddb32);if(!_['isNil'](_0xaddb32[_0x67ce('0x43')][_0x67ce('0x44')])){utils[_0x67ce('0x5')](util[_0x67ce('0x6')](_0x67ce('0x45'),_0xaddb32['uniqueid'],_0xaddb32[_0x67ce('0x46')]));channels[_0xaddb32[_0x67ce('0x8')]][_0x67ce('0x47')]=_0xaddb32[_0x67ce('0x46')];}if(!_[_0x67ce('0x23')](_0xaddb32['variable'][_0x67ce('0x48')])){utils[_0x67ce('0x5')](util['format'](_0x67ce('0x49'),_0xaddb32['uniqueid'],_0xaddb32['value']));channels[_0xaddb32['uniqueid']][_0x67ce('0x4a')]=_0xaddb32[_0x67ce('0x46')];channels[_0xaddb32[_0x67ce('0x8')]][_0x67ce('0x29')]='\x22'+_0xaddb32[_0x67ce('0x46')]+_0x67ce('0x4b')+_0xaddb32[_0x67ce('0x46')]+'>';}if(!_['isNil'](_0xaddb32[_0x67ce('0x43')][_0x67ce('0x4c')])||!_['isNil'](_0xaddb32[_0x67ce('0x43')][_0x67ce('0x4d')])){utils[_0x67ce('0x5')](util['format'](_0x67ce('0x4e'),_0xaddb32[_0x67ce('0x8')],!_[_0x67ce('0x23')](_0xaddb32['variable'][_0x67ce('0x4c')])?_0x67ce('0x4c'):'xmd-callerid',_0xaddb32[_0x67ce('0x46')]));channels[_0xaddb32[_0x67ce('0x8')]]['callerid']=_0xaddb32[_0x67ce('0x46')];}if(!_[_0x67ce('0x23')](_0xaddb32['variable'][_0x67ce('0x4f')])||!_[_0x67ce('0x23')](_0xaddb32[_0x67ce('0x43')][_0x67ce('0x50')])){utils[_0x67ce('0x5')](util[_0x67ce('0x6')](_0x67ce('0x4e'),_0xaddb32['uniqueid'],!_[_0x67ce('0x23')](_0xaddb32['variable'][_0x67ce('0x4f')])?_0x67ce('0x4f'):_0x67ce('0x50'),_0xaddb32[_0x67ce('0x46')]));channels[_0xaddb32[_0x67ce('0x8')]][_0x67ce('0x51')]=_0x67ce('0x52');channels[_0xaddb32[_0x67ce('0x8')]][_0x67ce('0x53')]=_0xaddb32[_0x67ce('0x46')];channels[_0xaddb32['uniqueid']]['queue']=!![];}if(!_[_0x67ce('0x23')](_0xaddb32[_0x67ce('0x43')][_0x67ce('0x54')])){utils['info'](util['format'](_0x67ce('0x55'),_0xaddb32[_0x67ce('0x8')],_0xaddb32[_0x67ce('0x46')]));channels[_0xaddb32['uniqueid']][_0x67ce('0x56')]=_0xaddb32['value'];}if(!_[_0x67ce('0x23')](_0xaddb32[_0x67ce('0x43')]['xmd-cdrtype'])){utils[_0x67ce('0x5')](util['format']('[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s',_0xaddb32['uniqueid'],_0xaddb32['value']));channels[_0xaddb32['uniqueid']][_0x67ce('0x57')]=_0xaddb32[_0x67ce('0x46')];}if(!_[_0x67ce('0x23')](_0xaddb32['variable'][_0x67ce('0x58')])){utils[_0x67ce('0x5')](util[_0x67ce('0x6')]('[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s',_0xaddb32[_0x67ce('0x8')],_0xaddb32['value']));channels[_0xaddb32[_0x67ce('0x8')]][_0x67ce('0x59')]=_0xaddb32['value'];}if(!_[_0x67ce('0x23')](_0xaddb32[_0x67ce('0x43')][_0x67ce('0x5a')])){utils[_0x67ce('0x5')](util[_0x67ce('0x6')](_0x67ce('0x5b'),_0xaddb32[_0x67ce('0x8')],_0xaddb32[_0x67ce('0x46')]));channels[_0xaddb32[_0x67ce('0x8')]][_0x67ce('0x5a')]=_0xaddb32[_0x67ce('0x46')];}}}catch(_0x1dacc8){utils[_0x67ce('0x1c')](util[_0x67ce('0x6')]('[%s][calls][varset]',_0xaddb32['uniqueid']),_0x1dacc8);}};exports[_0x67ce('0x5c')]=function(_0x3048e3){try{if(!_[_0x67ce('0x23')](channels[_0x3048e3['uniqueid']])){utils[_0x67ce('0x13')](util[_0x67ce('0x6')](_0x67ce('0x5d'),_0x3048e3[_0x67ce('0x8')]),_0x3048e3);utils[_0x67ce('0x5')](util['format'](_0x67ce('0x5e'),_0x3048e3['uniqueid'],_0x3048e3[_0x67ce('0x5f')],_0x3048e3[_0x67ce('0x60')]));if(_0x3048e3['application']['toLowerCase']()=='set'&&_['startsWith'](_0x3048e3[_0x67ce('0x60')][_0x67ce('0x61')](),_0x67ce('0x62'))){var _0x383edc=_0x3048e3[_0x67ce('0x60')][_0x67ce('0x63')]('=');var _0x291c74=_0x383edc[0x0][_0x67ce('0x64')](_0x383edc[0x0][_0x67ce('0x65')]('(')+0x1,_0x383edc[0x0][_0x67ce('0x65')](')'));var _0x83809e=_0x383edc[0x1];channels[_0x3048e3['uniqueid']][_0x291c74]=_0x83809e;}if(!_['includes']([_0x67ce('0x66'),'noop','execif','set',_0x67ce('0x67')],_0x3048e3[_0x67ce('0x5f')]['toLowerCase']())){channels[_0x3048e3['uniqueid']]['lastapplication']=_0x3048e3[_0x67ce('0x5f')];channels[_0x3048e3[_0x67ce('0x8')]][_0x67ce('0x53')]=_0x3048e3[_0x67ce('0x60')];}}}catch(_0x269edd){utils[_0x67ce('0x1c')](util['format']('[%s][calls][newexten]',_0x3048e3[_0x67ce('0x8')]),_0x269edd);}};