e665518d48abfbd46af9de374e2dc83de282ad4e
[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 _0x0a29=['[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','channel','queue','membername','interface','calleridnum','accountcode','getUserByInternal','then','UserId','request','CreateVoiceCallReport','newchannel','debug','info','[%s][calls][newchannel]\x20context:%s\x20exten:%s','exten','now','error','[%s][calls][newchannel]','[%s][calls][newstate]','isNil','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','systemanswertime','linkedid','context','transfer','destinationchannel','answertime','disposition','toNumber','hangup','[%s][calls][hangup]','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','duration','diffTime','starttime','billableseconds','attendedtransfer','localtwolinkedid','origtransfereruniqueid','transfereechannel','secondtransfererchannel','userfield','transfertargetchannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','origtransfererchannel','_attended','[%s][calls][attendedtransfer]','musiconholdstart','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','musiconholdstartAt','[%s][calls][musiconholdstart]','musiconholdstop','[%s][calls][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','lastdata','xmd-contactid','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','ContactId','xmd-cdrtype','[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s','type','outboundrouteid','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s','routeid','sipcallid','[%s][calls][varset]\x20variable:sipcallid\x20value:%s','[%s][calls][varset]','newexten','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','set','startsWith','appdata','split','substring','lastIndexOf','includes','noop','execif','gotoif','toLowerCase','lastapplication','[%s][calls][newexten]','lodash','util','./transfers.controller','NO\x20ANSWER','FAILED','ANSWERED','BUSY','blinds','uniqueid','format'];(function(_0x4b2693,_0x29f874){var _0x1957d7=function(_0x57a294){while(--_0x57a294){_0x4b2693['push'](_0x4b2693['shift']());}};_0x1957d7(++_0x29f874);}(_0x0a29,0x152));var _0x90a2=function(_0x42fb69,_0x351c80){_0x42fb69=_0x42fb69-0x0;var _0xf2f5c=_0x0a29[_0x42fb69];return _0xf2f5c;};'use strict';var _=require(_0x90a2('0x0'));var util=require(_0x90a2('0x1'));var utils=require('./utils');var transfers=require(_0x90a2('0x2'));var dispositions=[_0x90a2('0x3'),_0x90a2('0x4'),_0x90a2('0x4'),_0x90a2('0x3'),_0x90a2('0x3'),_0x90a2('0x3'),_0x90a2('0x5'),_0x90a2('0x6'),_0x90a2('0x4'),_0x90a2('0x4'),_0x90a2('0x4')];var channels={};function writeDB(_0x58702a){var _0x2e0af8;if(transfers[_0x90a2('0x7')][_0x58702a[_0x90a2('0x8')]]){_0x2e0af8=_0x58702a[_0x90a2('0x8')];_0x58702a[_0x90a2('0x8')]=transfers[_0x90a2('0x7')][_0x58702a[_0x90a2('0x8')]]['transfereeuniqueid'];}utils['info'](util[_0x90a2('0x9')](_0x90a2('0xa'),_0x58702a[_0x90a2('0x8')],_0x58702a[_0x90a2('0xb')],_0x58702a[_0x90a2('0xc')],_0x58702a[_0x90a2('0xd')],_0x58702a[_0x90a2('0xe')],_0x58702a[_0x90a2('0xf')],_0x58702a['connectedlinenum'],_0x58702a['lastevent']));if(_0x58702a[_0x90a2('0x10')]){utils[_0x90a2('0x11')](_0x58702a['accountcode'])[_0x90a2('0x12')](function(_0x3154d9){if(_0x3154d9){_0x58702a[_0x90a2('0x13')]=_0x3154d9['id'];}utils[_0x90a2('0x14')]('CreateVoiceCallReport',_0x58702a);});}else{utils[_0x90a2('0x14')](_0x90a2('0x15'),_0x58702a);}if(channels[_0x58702a[_0x90a2('0x8')]]){delete channels[_0x58702a[_0x90a2('0x8')]];}else if(_0x2e0af8&&channels[_0x2e0af8]){delete transfers[_0x90a2('0x7')][_0x2e0af8];delete channels[_0x2e0af8];}}exports[_0x90a2('0x16')]=function(_0x333383){try{utils[_0x90a2('0x17')](util[_0x90a2('0x9')]('[%s][calls][newchannel]',_0x333383['uniqueid']),_0x333383);if(_0x333383[_0x90a2('0x8')]==_0x333383['linkedid']&&_0x333383[_0x90a2('0xb')]!='OutgoingSpoolFailed'){utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x19'),_0x333383[_0x90a2('0x8')],_0x333383['context'],_0x333383[_0x90a2('0x1a')]));channels[_0x333383['uniqueid']]={'uniqueid':_0x333383[_0x90a2('0x8')],'accountcode':_0x333383['accountcode'],'source':_0x333383[_0x90a2('0xf')],'destination':_0x333383['exten'],'destinationcontext':_0x333383['context'],'channel':_0x333383[_0x90a2('0xb')],'starttime':utils[_0x90a2('0x1b')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':'DOCUMENTATION'};}}catch(_0x59eed4){utils[_0x90a2('0x1c')](util['format'](_0x90a2('0x1d'),_0x333383[_0x90a2('0x8')]),_0x59eed4);}};exports['newstate']=function(_0x49e895){try{utils[_0x90a2('0x17')](util['format'](_0x90a2('0x1e'),_0x49e895[_0x90a2('0x8')]),_0x49e895);if(!_[_0x90a2('0x1f')](channels[_0x49e895[_0x90a2('0x8')]])&&_0x49e895[_0x90a2('0x20')]==0x6){utils['info'](util['format'](_0x90a2('0x21'),_0x49e895['uniqueid'],_0x49e895['context'],_0x49e895['channel']));if(_[_0x90a2('0x1f')](channels[_0x49e895[_0x90a2('0x8')]][_0x90a2('0x22')])){channels[_0x49e895['uniqueid']]['systemanswertime']=utils['now']();}}else if(!_[_0x90a2('0x1f')](channels[_0x49e895[_0x90a2('0x23')]])&&_0x49e895[_0x90a2('0x20')]==0x6&&_0x49e895[_0x90a2('0x24')]!=_0x90a2('0x25')){utils[_0x90a2('0x18')](util[_0x90a2('0x9')]('[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x49e895[_0x90a2('0x8')],_0x49e895[_0x90a2('0x23')],_0x49e895[_0x90a2('0x24')],_0x49e895[_0x90a2('0xb')]));channels[_0x49e895[_0x90a2('0x23')]]['accountcode']=_0x49e895['accountcode'];channels[_0x49e895[_0x90a2('0x23')]][_0x90a2('0x26')]=_0x49e895[_0x90a2('0xb')];if(_[_0x90a2('0x1f')](channels[_0x49e895[_0x90a2('0x23')]][_0x90a2('0x27')])){channels[_0x49e895[_0x90a2('0x23')]][_0x90a2('0x27')]=utils[_0x90a2('0x1b')]();}channels[_0x49e895[_0x90a2('0x23')]][_0x90a2('0x28')]=dispositions[_[_0x90a2('0x29')](_0x49e895['channelstate'])]||_0x90a2('0x5');}}catch(_0xed6f18){utils[_0x90a2('0x1c')](util[_0x90a2('0x9')]('[%s][calls][newstate]',_0x49e895[_0x90a2('0x8')]),_0xed6f18);}};exports[_0x90a2('0x2a')]=function(_0x1159b9){try{if(!_[_0x90a2('0x1f')](channels[_0x1159b9['uniqueid']])){utils[_0x90a2('0x17')](util[_0x90a2('0x9')](_0x90a2('0x2b'),_0x1159b9[_0x90a2('0x8')]),_0x1159b9);if(_[_0x90a2('0x1f')](channels[_0x1159b9[_0x90a2('0x8')]]['callerid'])){channels[_0x1159b9[_0x90a2('0x8')]][_0x90a2('0x2c')]=_0x1159b9[_0x90a2('0x2d')]+'\x20<'+_0x1159b9['calleridnum']+'>';}utils['info'](util[_0x90a2('0x9')](_0x90a2('0x2e'),_0x1159b9[_0x90a2('0x8')],channels[_0x1159b9[_0x90a2('0x8')]]['callerid'],_0x1159b9[_0x90a2('0x2f')]));channels[_0x1159b9[_0x90a2('0x8')]][_0x90a2('0x30')]=utils['now']();channels[_0x1159b9[_0x90a2('0x8')]][_0x90a2('0x31')]=utils[_0x90a2('0x32')](channels[_0x1159b9['uniqueid']][_0x90a2('0x30')],channels[_0x1159b9[_0x90a2('0x8')]][_0x90a2('0x33')]);channels[_0x1159b9[_0x90a2('0x8')]][_0x90a2('0x34')]=channels[_0x1159b9[_0x90a2('0x8')]][_0x90a2('0x27')]?utils['diffTime'](channels[_0x1159b9[_0x90a2('0x8')]][_0x90a2('0x30')],channels[_0x1159b9[_0x90a2('0x8')]][_0x90a2('0x27')]):0x0;writeDB(channels[_0x1159b9['uniqueid']]);}}catch(_0x2fb581){utils[_0x90a2('0x1c')](util['format'](_0x90a2('0x2b'),_0x1159b9[_0x90a2('0x8')]),_0x2fb581);}};exports[_0x90a2('0x35')]=function(_0x23ae0a){try{if(!_['isNil'](channels[_0x23ae0a[_0x90a2('0x36')]])){utils['debug'](util['format']('[%s][calls][attendedtransfer]',_0x23ae0a[_0x90a2('0x37')]),_0x23ae0a);if(channels[_0x23ae0a[_0x90a2('0x36')]]['channel']==_0x23ae0a[_0x90a2('0x38')]){utils[_0x90a2('0x18')](util['format']('[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s',_0x23ae0a[_0x90a2('0x37')],_0x23ae0a['localtwolinkedid'],_0x23ae0a[_0x90a2('0x39')]));channels[_0x23ae0a[_0x90a2('0x36')]]['destinationchannel']=_0x23ae0a[_0x90a2('0x39')];channels[_0x23ae0a[_0x90a2('0x36')]][_0x90a2('0x3a')]='_attended';}else if(channels[_0x23ae0a[_0x90a2('0x36')]][_0x90a2('0xb')]=_0x23ae0a[_0x90a2('0x3b')]){utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x3c'),_0x23ae0a[_0x90a2('0x37')],_0x23ae0a[_0x90a2('0x36')],_0x23ae0a[_0x90a2('0x3d')]));channels[_0x23ae0a[_0x90a2('0x36')]]['destinationchannel']=_0x23ae0a[_0x90a2('0x3d')];channels[_0x23ae0a['localtwolinkedid']][_0x90a2('0x3a')]=_0x90a2('0x3e');}}}catch(_0x19311){utils['error'](util[_0x90a2('0x9')](_0x90a2('0x3f'),_0x23ae0a[_0x90a2('0x37')]),_0x19311);}};exports[_0x90a2('0x40')]=function(_0x44f82f){try{if(!_['isNil'](channels[_0x44f82f[_0x90a2('0x8')]])){utils[_0x90a2('0x17')](util['format']('[%s][calls][musiconholdstart]',_0x44f82f[_0x90a2('0x8')]),_0x44f82f);channels[_0x44f82f[_0x90a2('0x8')]]['musiconholdstartAt']=utils['now']();utils[_0x90a2('0x18')](util['format'](_0x90a2('0x41'),_0x44f82f[_0x90a2('0x8')],channels[_0x44f82f['uniqueid']][_0x90a2('0x42')]));}}catch(_0x149e5a){utils[_0x90a2('0x1c')](util[_0x90a2('0x9')](_0x90a2('0x43'),_0x44f82f[_0x90a2('0x8')]),_0x149e5a);}};exports[_0x90a2('0x44')]=function(_0x394c31){try{if(!_[_0x90a2('0x1f')](channels[_0x394c31['uniqueid']])){utils[_0x90a2('0x17')](util[_0x90a2('0x9')](_0x90a2('0x45'),_0x394c31[_0x90a2('0x8')]),_0x394c31);if(!_[_0x90a2('0x1f')](channels[_0x394c31[_0x90a2('0x8')]][_0x90a2('0x42')])){channels[_0x394c31['uniqueid']][_0x90a2('0x46')]+=utils['diffTime'](utils[_0x90a2('0x1b')](),channels[_0x394c31['uniqueid']][_0x90a2('0x42')]);utils['info'](util['format'](_0x90a2('0x47'),_0x394c31[_0x90a2('0x8')],channels[_0x394c31[_0x90a2('0x8')]][_0x90a2('0x46')]));delete channels[_0x394c31[_0x90a2('0x8')]][_0x90a2('0x42')];}}}catch(_0x2b5368){utils[_0x90a2('0x1c')](util[_0x90a2('0x9')](_0x90a2('0x45'),_0x394c31[_0x90a2('0x8')]),_0x2b5368);}};exports[_0x90a2('0x48')]=function(_0x590b38){try{if(!_['isNil'](channels[_0x590b38[_0x90a2('0x8')]])){utils[_0x90a2('0x17')](util[_0x90a2('0x9')]('[%s][calls][varset]',_0x590b38[_0x90a2('0x8')]),_0x590b38);if(!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x4a')])){utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x4b'),_0x590b38[_0x90a2('0x8')],_0x590b38[_0x90a2('0x4c')]));channels[_0x590b38[_0x90a2('0x8')]][_0x90a2('0x4d')]=_0x590b38[_0x90a2('0x4c')];}if(!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x4e')])){utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x4f'),_0x590b38[_0x90a2('0x8')],_0x590b38['value']));channels[_0x590b38[_0x90a2('0x8')]][_0x90a2('0x50')]=_0x590b38['value'];channels[_0x590b38[_0x90a2('0x8')]][_0x90a2('0x2c')]='\x22'+_0x590b38[_0x90a2('0x4c')]+_0x90a2('0x51')+_0x590b38[_0x90a2('0x4c')]+'>';}if(!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x52')])||!_['isNil'](_0x590b38['variable'][_0x90a2('0x53')])){utils['info'](util[_0x90a2('0x9')](_0x90a2('0x54'),_0x590b38['uniqueid'],!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x52')])?_0x90a2('0x52'):_0x90a2('0x53'),_0x590b38[_0x90a2('0x4c')]));channels[_0x590b38[_0x90a2('0x8')]][_0x90a2('0x2c')]=_0x590b38[_0x90a2('0x4c')];}if(!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x55')])||!_['isNil'](_0x590b38['variable'][_0x90a2('0x56')])){utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x54'),_0x590b38['uniqueid'],!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x55')])?_0x90a2('0x55'):'xmcs-queue',_0x590b38[_0x90a2('0x4c')]));channels[_0x590b38[_0x90a2('0x8')]]['lastapplication']='Queue';channels[_0x590b38['uniqueid']][_0x90a2('0x57')]=_0x590b38['value'];channels[_0x590b38[_0x90a2('0x8')]]['queue']=!![];}if(!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x58')])){utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x59'),_0x590b38['uniqueid'],_0x590b38['value']));channels[_0x590b38[_0x90a2('0x8')]][_0x90a2('0x5a')]=_0x590b38['value'];}if(!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x5b')])){utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x5c'),_0x590b38['uniqueid'],_0x590b38[_0x90a2('0x4c')]));channels[_0x590b38[_0x90a2('0x8')]][_0x90a2('0x5d')]=_0x590b38[_0x90a2('0x4c')];}if(!_[_0x90a2('0x1f')](_0x590b38['variable'][_0x90a2('0x5e')])){utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x5f'),_0x590b38[_0x90a2('0x8')],_0x590b38['value']));channels[_0x590b38[_0x90a2('0x8')]][_0x90a2('0x60')]=_0x590b38['value'];}if(!_[_0x90a2('0x1f')](_0x590b38[_0x90a2('0x49')][_0x90a2('0x61')])){utils[_0x90a2('0x18')](util['format'](_0x90a2('0x62'),_0x590b38[_0x90a2('0x8')],_0x590b38[_0x90a2('0x4c')]));channels[_0x590b38[_0x90a2('0x8')]][_0x90a2('0x61')]=_0x590b38[_0x90a2('0x4c')];}}}catch(_0x1cf48f){utils['error'](util[_0x90a2('0x9')](_0x90a2('0x63'),_0x590b38[_0x90a2('0x8')]),_0x1cf48f);}};exports[_0x90a2('0x64')]=function(_0x493a03){try{if(!_[_0x90a2('0x1f')](channels[_0x493a03[_0x90a2('0x8')]])){utils[_0x90a2('0x17')](util[_0x90a2('0x9')]('[%s][calls][newexten]',_0x493a03[_0x90a2('0x8')]),_0x493a03);utils[_0x90a2('0x18')](util[_0x90a2('0x9')](_0x90a2('0x65'),_0x493a03[_0x90a2('0x8')],_0x493a03[_0x90a2('0x66')],_0x493a03['appdata']));if(_0x493a03[_0x90a2('0x66')]['toLowerCase']()==_0x90a2('0x67')&&_[_0x90a2('0x68')](_0x493a03[_0x90a2('0x69')]['toLowerCase'](),'cdr')){var _0x525680=_0x493a03[_0x90a2('0x69')][_0x90a2('0x6a')]('=');var _0x568e14=_0x525680[0x0][_0x90a2('0x6b')](_0x525680[0x0][_0x90a2('0x6c')]('(')+0x1,_0x525680[0x0][_0x90a2('0x6c')](')'));var _0x55cb72=_0x525680[0x1];channels[_0x493a03[_0x90a2('0x8')]][_0x568e14]=_0x55cb72;}if(!_[_0x90a2('0x6d')]([_0x90a2('0x2a'),_0x90a2('0x6e'),_0x90a2('0x6f'),_0x90a2('0x67'),_0x90a2('0x70')],_0x493a03['application'][_0x90a2('0x71')]())){channels[_0x493a03[_0x90a2('0x8')]][_0x90a2('0x72')]=_0x493a03[_0x90a2('0x66')];channels[_0x493a03[_0x90a2('0x8')]]['lastdata']=_0x493a03[_0x90a2('0x69')];}}}catch(_0x39c974){utils[_0x90a2('0x1c')](util[_0x90a2('0x9')](_0x90a2('0x73'),_0x493a03['uniqueid']),_0x39c974);}};