Built motion from commit ae138b72.|2.6.28
[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 _0x0afd=['destinationchannel','toNumber','[%s][calls][newstate]','hangup','[%s][calls][hangup]','callerid','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','duration','diffTime','starttime','billableseconds','answertime','attendedtransfer','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','transfereechannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','secondtransfererchannel','userfield','_attended','origtransfererchannel','[%s][calls][musiconholdstart]','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','musiconholdstop','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','[%s][calls][musiconholdstop]','varset','[%s][calls][varset]','xmd-originatecalleridnum','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','source','variable','xmd-phone','[%s][calls][varset]\x20variable:xmd-phone\x20value:%s','value','\x22\x20<','xmd-callerid-preview','xmd-callerid','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-queue','xmcs-queue','Queue','lastdata','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','ContactId','xmd-cdrtype','type','outboundrouteid','routeid','sipcallid','[%s][calls][varset]\x20variable:sipcallid\x20value:%s','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','appdata','application','toLowerCase','set','startsWith','cdr','split','substring','lastIndexOf','includes','execif','lastapplication','lodash','util','./utils','NO\x20ANSWER','FAILED','ANSWERED','info','format','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','uniqueid','queue','interface','calleridnum','accountcode','getUserByInternal','then','UserId','request','CreateVoiceCallReport','newchannel','[%s][calls][newchannel]','linkedid','channel','context','exten','DOCUMENTATION','error','debug','channelstate','systemanswertime','now','isNil','transfer','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s'];(function(_0x2455e4,_0x3c81a8){var _0x316e40=function(_0x165c01){while(--_0x165c01){_0x2455e4['push'](_0x2455e4['shift']());}};_0x316e40(++_0x3c81a8);}(_0x0afd,0xac));var _0xd0af=function(_0x5c6109,_0x4ec78a){_0x5c6109=_0x5c6109-0x0;var _0xeaeaa2=_0x0afd[_0x5c6109];return _0xeaeaa2;};'use strict';var _=require(_0xd0af('0x0'));var util=require(_0xd0af('0x1'));var utils=require(_0xd0af('0x2'));var dispositions=[_0xd0af('0x3'),_0xd0af('0x4'),'FAILED','NO\x20ANSWER',_0xd0af('0x3'),_0xd0af('0x3'),_0xd0af('0x5'),'BUSY','FAILED',_0xd0af('0x4'),'FAILED'];var channels={};function writeDB(_0x30eed7){utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x8'),_0x30eed7[_0xd0af('0x9')],_0x30eed7['channel'],_0x30eed7[_0xd0af('0xa')],_0x30eed7['membername'],_0x30eed7[_0xd0af('0xb')],_0x30eed7[_0xd0af('0xc')],_0x30eed7['connectedlinenum'],_0x30eed7['lastevent']));if(_0x30eed7[_0xd0af('0xd')]){utils[_0xd0af('0xe')](_0x30eed7[_0xd0af('0xd')])[_0xd0af('0xf')](function(_0x2d2354){if(_0x2d2354){_0x30eed7[_0xd0af('0x10')]=_0x2d2354['id'];}utils[_0xd0af('0x11')]('CreateVoiceCallReport',_0x30eed7);});}else{utils['request'](_0xd0af('0x12'),_0x30eed7);}if(channels[_0x30eed7[_0xd0af('0x9')]]){delete channels[_0x30eed7[_0xd0af('0x9')]];}}exports[_0xd0af('0x13')]=function(_0x5b0798){try{utils['debug'](util[_0xd0af('0x7')](_0xd0af('0x14'),_0x5b0798[_0xd0af('0x9')]),_0x5b0798);if(_0x5b0798[_0xd0af('0x9')]==_0x5b0798[_0xd0af('0x15')]&&_0x5b0798[_0xd0af('0x16')]!='OutgoingSpoolFailed'){utils[_0xd0af('0x6')](util[_0xd0af('0x7')]('[%s][calls][newchannel]\x20context:%s\x20exten:%s',_0x5b0798[_0xd0af('0x9')],_0x5b0798[_0xd0af('0x17')],_0x5b0798[_0xd0af('0x18')]));channels[_0x5b0798['uniqueid']]={'uniqueid':_0x5b0798[_0xd0af('0x9')],'accountcode':_0x5b0798['accountcode'],'source':_0x5b0798[_0xd0af('0xc')],'destination':_0x5b0798[_0xd0af('0x18')],'destinationcontext':_0x5b0798[_0xd0af('0x17')],'channel':_0x5b0798[_0xd0af('0x16')],'starttime':utils['now'](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':_0xd0af('0x19')};}}catch(_0x4ea73f){utils[_0xd0af('0x1a')](util[_0xd0af('0x7')](_0xd0af('0x14'),_0x5b0798[_0xd0af('0x9')]),_0x4ea73f);}};exports['newstate']=function(_0x3cb29b){try{utils[_0xd0af('0x1b')](util[_0xd0af('0x7')]('[%s][calls][newstate]',_0x3cb29b['uniqueid']),_0x3cb29b);if(!_['isNil'](channels[_0x3cb29b[_0xd0af('0x9')]])&&_0x3cb29b[_0xd0af('0x1c')]==0x6){utils[_0xd0af('0x6')](util[_0xd0af('0x7')]('[%s][calls][newstate]\x20context:%s\x20channel:%s',_0x3cb29b['uniqueid'],_0x3cb29b[_0xd0af('0x17')],_0x3cb29b['channel']));if(_['isNil'](channels[_0x3cb29b[_0xd0af('0x9')]][_0xd0af('0x1d')])){channels[_0x3cb29b[_0xd0af('0x9')]][_0xd0af('0x1d')]=utils[_0xd0af('0x1e')]();}}else if(!_[_0xd0af('0x1f')](channels[_0x3cb29b['linkedid']])&&_0x3cb29b[_0xd0af('0x1c')]==0x6&&_0x3cb29b[_0xd0af('0x17')]!=_0xd0af('0x20')){utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x21'),_0x3cb29b[_0xd0af('0x9')],_0x3cb29b[_0xd0af('0x15')],_0x3cb29b[_0xd0af('0x17')],_0x3cb29b[_0xd0af('0x16')]));channels[_0x3cb29b[_0xd0af('0x15')]][_0xd0af('0xd')]=_0x3cb29b[_0xd0af('0xd')];channels[_0x3cb29b['linkedid']][_0xd0af('0x22')]=_0x3cb29b['channel'];if(_[_0xd0af('0x1f')](channels[_0x3cb29b[_0xd0af('0x15')]]['answertime'])){channels[_0x3cb29b[_0xd0af('0x15')]]['answertime']=utils[_0xd0af('0x1e')]();}channels[_0x3cb29b[_0xd0af('0x15')]]['disposition']=dispositions[_[_0xd0af('0x23')](_0x3cb29b[_0xd0af('0x1c')])]||'ANSWERED';}}catch(_0x1903dc){utils['error'](util['format'](_0xd0af('0x24'),_0x3cb29b[_0xd0af('0x9')]),_0x1903dc);}};exports[_0xd0af('0x25')]=function(_0x2f7ec6){try{if(!_[_0xd0af('0x1f')](channels[_0x2f7ec6['uniqueid']])){utils[_0xd0af('0x1b')](util[_0xd0af('0x7')](_0xd0af('0x26'),_0x2f7ec6[_0xd0af('0x9')]),_0x2f7ec6);if(_[_0xd0af('0x1f')](channels[_0x2f7ec6[_0xd0af('0x9')]][_0xd0af('0x27')])){channels[_0x2f7ec6[_0xd0af('0x9')]][_0xd0af('0x27')]=_0x2f7ec6['calleridname']+'\x20<'+_0x2f7ec6[_0xd0af('0xc')]+'>';}utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x28'),_0x2f7ec6['uniqueid'],channels[_0x2f7ec6[_0xd0af('0x9')]][_0xd0af('0x27')],_0x2f7ec6['cause-txt']));channels[_0x2f7ec6[_0xd0af('0x9')]]['endtime']=utils[_0xd0af('0x1e')]();channels[_0x2f7ec6[_0xd0af('0x9')]][_0xd0af('0x29')]=utils[_0xd0af('0x2a')](channels[_0x2f7ec6[_0xd0af('0x9')]]['endtime'],channels[_0x2f7ec6[_0xd0af('0x9')]][_0xd0af('0x2b')]);channels[_0x2f7ec6[_0xd0af('0x9')]][_0xd0af('0x2c')]=channels[_0x2f7ec6['uniqueid']][_0xd0af('0x2d')]?utils['diffTime'](channels[_0x2f7ec6[_0xd0af('0x9')]]['endtime'],channels[_0x2f7ec6[_0xd0af('0x9')]][_0xd0af('0x2d')]):0x0;writeDB(channels[_0x2f7ec6[_0xd0af('0x9')]]);}}catch(_0x1ebd16){utils[_0xd0af('0x1a')](util[_0xd0af('0x7')](_0xd0af('0x26'),_0x2f7ec6[_0xd0af('0x9')]),_0x1ebd16);}};exports[_0xd0af('0x2e')]=function(_0x33464e){try{if(!_[_0xd0af('0x1f')](channels[_0x33464e[_0xd0af('0x2f')]])){utils[_0xd0af('0x1b')](util[_0xd0af('0x7')](_0xd0af('0x30'),_0x33464e[_0xd0af('0x31')]),_0x33464e);if(channels[_0x33464e[_0xd0af('0x2f')]]['channel']==_0x33464e[_0xd0af('0x32')]){utils['info'](util[_0xd0af('0x7')](_0xd0af('0x33'),_0x33464e[_0xd0af('0x31')],_0x33464e[_0xd0af('0x2f')],_0x33464e['secondtransfererchannel']));channels[_0x33464e[_0xd0af('0x2f')]][_0xd0af('0x22')]=_0x33464e[_0xd0af('0x34')];channels[_0x33464e[_0xd0af('0x2f')]][_0xd0af('0x35')]=_0xd0af('0x36');}else if(channels[_0x33464e[_0xd0af('0x2f')]][_0xd0af('0x16')]=_0x33464e['transfertargetchannel']){utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x33'),_0x33464e['origtransfereruniqueid'],_0x33464e[_0xd0af('0x2f')],_0x33464e[_0xd0af('0x37')]));channels[_0x33464e['localtwolinkedid']]['destinationchannel']=_0x33464e[_0xd0af('0x37')];channels[_0x33464e['localtwolinkedid']][_0xd0af('0x35')]=_0xd0af('0x36');}}}catch(_0x16ad75){utils[_0xd0af('0x1a')](util[_0xd0af('0x7')]('[%s][calls][attendedtransfer]',_0x33464e[_0xd0af('0x31')]),_0x16ad75);}};exports['musiconholdstart']=function(_0x4bc150){try{if(!_[_0xd0af('0x1f')](channels[_0x4bc150[_0xd0af('0x9')]])){utils[_0xd0af('0x1b')](util['format'](_0xd0af('0x38'),_0x4bc150[_0xd0af('0x9')]),_0x4bc150);channels[_0x4bc150['uniqueid']][_0xd0af('0x39')]=utils[_0xd0af('0x1e')]();utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x3a'),_0x4bc150[_0xd0af('0x9')],channels[_0x4bc150['uniqueid']][_0xd0af('0x39')]));}}catch(_0x25a0b1){utils[_0xd0af('0x1a')](util[_0xd0af('0x7')]('[%s][calls][musiconholdstart]',_0x4bc150[_0xd0af('0x9')]),_0x25a0b1);}};exports[_0xd0af('0x3b')]=function(_0x53972c){try{if(!_[_0xd0af('0x1f')](channels[_0x53972c[_0xd0af('0x9')]])){utils[_0xd0af('0x1b')](util[_0xd0af('0x7')]('[%s][calls][musiconholdstop]',_0x53972c[_0xd0af('0x9')]),_0x53972c);if(!_[_0xd0af('0x1f')](channels[_0x53972c[_0xd0af('0x9')]][_0xd0af('0x39')])){channels[_0x53972c[_0xd0af('0x9')]][_0xd0af('0x3c')]+=utils['diffTime'](utils[_0xd0af('0x1e')](),channels[_0x53972c[_0xd0af('0x9')]]['musiconholdstartAt']);utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x3d'),_0x53972c[_0xd0af('0x9')],channels[_0x53972c[_0xd0af('0x9')]][_0xd0af('0x3c')]));delete channels[_0x53972c[_0xd0af('0x9')]]['musiconholdstartAt'];}}}catch(_0x3c80ee){utils[_0xd0af('0x1a')](util['format'](_0xd0af('0x3e'),_0x53972c[_0xd0af('0x9')]),_0x3c80ee);}};exports[_0xd0af('0x3f')]=function(_0x4f02aa){try{if(!_[_0xd0af('0x1f')](channels[_0x4f02aa['uniqueid']])){utils[_0xd0af('0x1b')](util[_0xd0af('0x7')](_0xd0af('0x40'),_0x4f02aa[_0xd0af('0x9')]),_0x4f02aa);if(!_[_0xd0af('0x1f')](_0x4f02aa['variable'][_0xd0af('0x41')])){utils[_0xd0af('0x6')](util['format'](_0xd0af('0x42'),_0x4f02aa['uniqueid'],_0x4f02aa['value']));channels[_0x4f02aa[_0xd0af('0x9')]][_0xd0af('0x43')]=_0x4f02aa['value'];}if(!_[_0xd0af('0x1f')](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x45')])){utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x46'),_0x4f02aa[_0xd0af('0x9')],_0x4f02aa[_0xd0af('0x47')]));channels[_0x4f02aa[_0xd0af('0x9')]]['destination']=_0x4f02aa[_0xd0af('0x47')];channels[_0x4f02aa['uniqueid']][_0xd0af('0x27')]='\x22'+_0x4f02aa[_0xd0af('0x47')]+_0xd0af('0x48')+_0x4f02aa[_0xd0af('0x47')]+'>';}if(!_['isNil'](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x49')])||!_[_0xd0af('0x1f')](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x4a')])){utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x4b'),_0x4f02aa[_0xd0af('0x9')],!_[_0xd0af('0x1f')](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x49')])?'xmd-callerid-preview':_0xd0af('0x4a'),_0x4f02aa[_0xd0af('0x47')]));channels[_0x4f02aa[_0xd0af('0x9')]][_0xd0af('0x27')]=_0x4f02aa['value'];}if(!_[_0xd0af('0x1f')](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x4c')])||!_[_0xd0af('0x1f')](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x4d')])){utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x4b'),_0x4f02aa[_0xd0af('0x9')],!_['isNil'](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x4c')])?'xmd-queue':_0xd0af('0x4d'),_0x4f02aa['value']));channels[_0x4f02aa[_0xd0af('0x9')]]['lastapplication']=_0xd0af('0x4e');channels[_0x4f02aa[_0xd0af('0x9')]][_0xd0af('0x4f')]=_0x4f02aa[_0xd0af('0x47')];channels[_0x4f02aa[_0xd0af('0x9')]]['queue']=!![];}if(!_[_0xd0af('0x1f')](_0x4f02aa[_0xd0af('0x44')]['xmd-contactid'])){utils[_0xd0af('0x6')](util['format'](_0xd0af('0x50'),_0x4f02aa[_0xd0af('0x9')],_0x4f02aa[_0xd0af('0x47')]));channels[_0x4f02aa[_0xd0af('0x9')]][_0xd0af('0x51')]=_0x4f02aa[_0xd0af('0x47')];}if(!_[_0xd0af('0x1f')](_0x4f02aa['variable'][_0xd0af('0x52')])){utils[_0xd0af('0x6')](util[_0xd0af('0x7')]('[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s',_0x4f02aa['uniqueid'],_0x4f02aa[_0xd0af('0x47')]));channels[_0x4f02aa['uniqueid']][_0xd0af('0x53')]=_0x4f02aa[_0xd0af('0x47')];}if(!_[_0xd0af('0x1f')](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x54')])){utils[_0xd0af('0x6')](util[_0xd0af('0x7')]('[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s',_0x4f02aa[_0xd0af('0x9')],_0x4f02aa[_0xd0af('0x47')]));channels[_0x4f02aa[_0xd0af('0x9')]][_0xd0af('0x55')]=_0x4f02aa['value'];}if(!_[_0xd0af('0x1f')](_0x4f02aa[_0xd0af('0x44')][_0xd0af('0x56')])){utils[_0xd0af('0x6')](util[_0xd0af('0x7')](_0xd0af('0x57'),_0x4f02aa['uniqueid'],_0x4f02aa[_0xd0af('0x47')]));channels[_0x4f02aa['uniqueid']][_0xd0af('0x56')]=_0x4f02aa[_0xd0af('0x47')];}}}catch(_0x318a2e){utils[_0xd0af('0x1a')](util[_0xd0af('0x7')]('[%s][calls][varset]',_0x4f02aa['uniqueid']),_0x318a2e);}};exports[_0xd0af('0x58')]=function(_0x2e738f){try{if(!_[_0xd0af('0x1f')](channels[_0x2e738f[_0xd0af('0x9')]])){utils['debug'](util['format'](_0xd0af('0x59'),_0x2e738f[_0xd0af('0x9')]),_0x2e738f);utils['info'](util[_0xd0af('0x7')](_0xd0af('0x5a'),_0x2e738f[_0xd0af('0x9')],_0x2e738f['application'],_0x2e738f[_0xd0af('0x5b')]));if(_0x2e738f[_0xd0af('0x5c')][_0xd0af('0x5d')]()==_0xd0af('0x5e')&&_[_0xd0af('0x5f')](_0x2e738f[_0xd0af('0x5b')][_0xd0af('0x5d')](),_0xd0af('0x60'))){var _0xeb89d=_0x2e738f[_0xd0af('0x5b')][_0xd0af('0x61')]('=');var _0x1cd219=_0xeb89d[0x0][_0xd0af('0x62')](_0xeb89d[0x0][_0xd0af('0x63')]('(')+0x1,_0xeb89d[0x0][_0xd0af('0x63')](')'));var _0x3aa929=_0xeb89d[0x1];channels[_0x2e738f[_0xd0af('0x9')]][_0x1cd219]=_0x3aa929;}if(!_[_0xd0af('0x64')]([_0xd0af('0x25'),'noop',_0xd0af('0x65'),'set','gotoif'],_0x2e738f[_0xd0af('0x5c')][_0xd0af('0x5d')]())){channels[_0x2e738f['uniqueid']][_0xd0af('0x66')]=_0x2e738f[_0xd0af('0x5c')];channels[_0x2e738f['uniqueid']][_0xd0af('0x4f')]=_0x2e738f[_0xd0af('0x5b')];}}}catch(_0x5f8837){utils[_0xd0af('0x1a')](util['format'](_0xd0af('0x59'),_0x2e738f[_0xd0af('0x9')]),_0x5f8837);}};