77b0d04da348bc88926b5cf5461897f44d9dd839
[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 _0x9401=['xmd-contactid','ContactId','xmd-cdrtype','outboundrouteid','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s','routeid','sipcallid','[%s][calls][varset]','newexten','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','appdata','toLowerCase','set','cdr','split','lastIndexOf','includes','noop','execif','gotoif','lastapplication','[%s][calls][newexten]','lodash','util','./utils','FAILED','NO\x20ANSWER','BUSY','uniqueid','channel','queue','membername','interface','calleridnum','connectedlinenum','accountcode','getUserByInternal','then','request','CreateVoiceCallReport','newchannel','debug','[%s][calls][newchannel]','info','format','[%s][calls][newchannel]\x20context:%s\x20exten:%s','context','now','error','newstate','[%s][calls][newstate]','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','isNil','systemanswertime','linkedid','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','destinationchannel','answertime','disposition','toNumber','ANSWERED','hangup','[%s][calls][hangup]','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','duration','diffTime','starttime','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','secondtransfererchannel','_attended','transfertargetchannel','origtransfererchannel','userfield','[%s][calls][musiconholdstart]','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','[%s][calls][musiconholdstop]','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','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','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-callerid','xmd-queue','xmcs-queue','Queue','lastdata'];(function(_0x456fee,_0x56510c){var _0x398bc8=function(_0x119738){while(--_0x119738){_0x456fee['push'](_0x456fee['shift']());}};_0x398bc8(++_0x56510c);}(_0x9401,0xe7));var _0x1940=function(_0x4ff09b,_0x53f67d){_0x4ff09b=_0x4ff09b-0x0;var _0x3f5c2e=_0x9401[_0x4ff09b];return _0x3f5c2e;};'use strict';var _=require(_0x1940('0x0'));var util=require(_0x1940('0x1'));var utils=require(_0x1940('0x2'));var dispositions=['NO\x20ANSWER',_0x1940('0x3'),'FAILED',_0x1940('0x4'),'NO\x20ANSWER',_0x1940('0x4'),'ANSWERED',_0x1940('0x5'),_0x1940('0x3'),'FAILED',_0x1940('0x3')];var channels={};function writeDB(_0x335a2e){utils['info'](util['format']('[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s',_0x335a2e[_0x1940('0x6')],_0x335a2e[_0x1940('0x7')],_0x335a2e[_0x1940('0x8')],_0x335a2e[_0x1940('0x9')],_0x335a2e[_0x1940('0xa')],_0x335a2e[_0x1940('0xb')],_0x335a2e[_0x1940('0xc')],_0x335a2e['lastevent']));if(_0x335a2e[_0x1940('0xd')]){utils[_0x1940('0xe')](_0x335a2e[_0x1940('0xd')])[_0x1940('0xf')](function(_0x313a06){if(_0x313a06){_0x335a2e['UserId']=_0x313a06['id'];}utils[_0x1940('0x10')](_0x1940('0x11'),_0x335a2e);});}else{utils[_0x1940('0x10')]('CreateVoiceCallReport',_0x335a2e);}if(channels[_0x335a2e[_0x1940('0x6')]]){delete channels[_0x335a2e[_0x1940('0x6')]];}}exports[_0x1940('0x12')]=function(_0x36efbe){try{utils[_0x1940('0x13')](util['format'](_0x1940('0x14'),_0x36efbe[_0x1940('0x6')]),_0x36efbe);if(_0x36efbe[_0x1940('0x6')]==_0x36efbe['linkedid']&&_0x36efbe['channel']!='OutgoingSpoolFailed'){utils[_0x1940('0x15')](util[_0x1940('0x16')](_0x1940('0x17'),_0x36efbe['uniqueid'],_0x36efbe[_0x1940('0x18')],_0x36efbe['exten']));channels[_0x36efbe[_0x1940('0x6')]]={'uniqueid':_0x36efbe[_0x1940('0x6')],'accountcode':_0x36efbe['accountcode'],'source':_0x36efbe[_0x1940('0xb')],'destination':_0x36efbe['exten'],'destinationcontext':_0x36efbe['context'],'channel':_0x36efbe['channel'],'starttime':utils[_0x1940('0x19')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x1940('0x4'),'amaflags':'DOCUMENTATION'};}}catch(_0x3d77bf){utils[_0x1940('0x1a')](util[_0x1940('0x16')]('[%s][calls][newchannel]',_0x36efbe['uniqueid']),_0x3d77bf);}};exports[_0x1940('0x1b')]=function(_0x472df6){try{utils[_0x1940('0x13')](util[_0x1940('0x16')](_0x1940('0x1c'),_0x472df6[_0x1940('0x6')]),_0x472df6);if(!_['isNil'](channels[_0x472df6[_0x1940('0x6')]])&&_0x472df6[_0x1940('0x1d')]==0x6){utils[_0x1940('0x15')](util[_0x1940('0x16')](_0x1940('0x1e'),_0x472df6[_0x1940('0x6')],_0x472df6[_0x1940('0x18')],_0x472df6[_0x1940('0x7')]));if(_[_0x1940('0x1f')](channels[_0x472df6[_0x1940('0x6')]][_0x1940('0x20')])){channels[_0x472df6[_0x1940('0x6')]][_0x1940('0x20')]=utils[_0x1940('0x19')]();}}else if(!_[_0x1940('0x1f')](channels[_0x472df6[_0x1940('0x21')]])&&_0x472df6[_0x1940('0x1d')]==0x6&&_0x472df6['context']!='transfer'){utils[_0x1940('0x15')](util[_0x1940('0x16')](_0x1940('0x22'),_0x472df6[_0x1940('0x6')],_0x472df6[_0x1940('0x21')],_0x472df6[_0x1940('0x18')],_0x472df6[_0x1940('0x7')]));channels[_0x472df6['linkedid']]['accountcode']=_0x472df6[_0x1940('0xd')];channels[_0x472df6['linkedid']][_0x1940('0x23')]=_0x472df6[_0x1940('0x7')];if(_[_0x1940('0x1f')](channels[_0x472df6[_0x1940('0x21')]][_0x1940('0x24')])){channels[_0x472df6[_0x1940('0x21')]][_0x1940('0x24')]=utils['now']();}channels[_0x472df6['linkedid']][_0x1940('0x25')]=dispositions[_[_0x1940('0x26')](_0x472df6[_0x1940('0x1d')])]||_0x1940('0x27');}}catch(_0x32dbb1){utils[_0x1940('0x1a')](util[_0x1940('0x16')](_0x1940('0x1c'),_0x472df6[_0x1940('0x6')]),_0x32dbb1);}};exports[_0x1940('0x28')]=function(_0xb586da){try{if(!_['isNil'](channels[_0xb586da[_0x1940('0x6')]])){utils[_0x1940('0x13')](util[_0x1940('0x16')](_0x1940('0x29'),_0xb586da[_0x1940('0x6')]),_0xb586da);if(_[_0x1940('0x1f')](channels[_0xb586da[_0x1940('0x6')]]['callerid'])){channels[_0xb586da[_0x1940('0x6')]][_0x1940('0x2a')]=_0xb586da[_0x1940('0x2b')]+'\x20<'+_0xb586da[_0x1940('0xb')]+'>';}utils[_0x1940('0x15')](util[_0x1940('0x16')](_0x1940('0x2c'),_0xb586da[_0x1940('0x6')],channels[_0xb586da['uniqueid']][_0x1940('0x2a')],_0xb586da[_0x1940('0x2d')]));channels[_0xb586da[_0x1940('0x6')]][_0x1940('0x2e')]=utils[_0x1940('0x19')]();channels[_0xb586da[_0x1940('0x6')]][_0x1940('0x2f')]=utils[_0x1940('0x30')](channels[_0xb586da[_0x1940('0x6')]][_0x1940('0x2e')],channels[_0xb586da[_0x1940('0x6')]][_0x1940('0x31')]);channels[_0xb586da[_0x1940('0x6')]]['billableseconds']=channels[_0xb586da[_0x1940('0x6')]][_0x1940('0x24')]?utils['diffTime'](channels[_0xb586da[_0x1940('0x6')]]['endtime'],channels[_0xb586da[_0x1940('0x6')]]['answertime']):0x0;writeDB(channels[_0xb586da[_0x1940('0x6')]]);}}catch(_0x3108f7){utils[_0x1940('0x1a')](util[_0x1940('0x16')](_0x1940('0x29'),_0xb586da[_0x1940('0x6')]),_0x3108f7);}};exports['attendedtransfer']=function(_0x3bd514){try{if(!_['isNil'](channels[_0x3bd514[_0x1940('0x32')]])){utils[_0x1940('0x13')](util[_0x1940('0x16')](_0x1940('0x33'),_0x3bd514[_0x1940('0x34')]),_0x3bd514);if(channels[_0x3bd514[_0x1940('0x32')]][_0x1940('0x7')]==_0x3bd514['transfereechannel']){utils['info'](util['format'](_0x1940('0x35'),_0x3bd514[_0x1940('0x34')],_0x3bd514[_0x1940('0x32')],_0x3bd514[_0x1940('0x36')]));channels[_0x3bd514['localtwolinkedid']]['destinationchannel']=_0x3bd514['secondtransfererchannel'];channels[_0x3bd514['localtwolinkedid']]['userfield']=_0x1940('0x37');}else if(channels[_0x3bd514[_0x1940('0x32')]][_0x1940('0x7')]=_0x3bd514[_0x1940('0x38')]){utils['info'](util[_0x1940('0x16')](_0x1940('0x35'),_0x3bd514[_0x1940('0x34')],_0x3bd514[_0x1940('0x32')],_0x3bd514[_0x1940('0x39')]));channels[_0x3bd514['localtwolinkedid']][_0x1940('0x23')]=_0x3bd514['origtransfererchannel'];channels[_0x3bd514[_0x1940('0x32')]][_0x1940('0x3a')]='_attended';}}}catch(_0x51d0e0){utils['error'](util['format'](_0x1940('0x33'),_0x3bd514[_0x1940('0x34')]),_0x51d0e0);}};exports['musiconholdstart']=function(_0x17af8e){try{if(!_[_0x1940('0x1f')](channels[_0x17af8e[_0x1940('0x6')]])){utils[_0x1940('0x13')](util['format'](_0x1940('0x3b'),_0x17af8e[_0x1940('0x6')]),_0x17af8e);channels[_0x17af8e[_0x1940('0x6')]][_0x1940('0x3c')]=utils[_0x1940('0x19')]();utils[_0x1940('0x15')](util['format'](_0x1940('0x3d'),_0x17af8e[_0x1940('0x6')],channels[_0x17af8e[_0x1940('0x6')]][_0x1940('0x3c')]));}}catch(_0x4f10da){utils['error'](util[_0x1940('0x16')](_0x1940('0x3b'),_0x17af8e[_0x1940('0x6')]),_0x4f10da);}};exports['musiconholdstop']=function(_0x9d94be){try{if(!_['isNil'](channels[_0x9d94be[_0x1940('0x6')]])){utils['debug'](util[_0x1940('0x16')](_0x1940('0x3e'),_0x9d94be[_0x1940('0x6')]),_0x9d94be);if(!_[_0x1940('0x1f')](channels[_0x9d94be[_0x1940('0x6')]][_0x1940('0x3c')])){channels[_0x9d94be[_0x1940('0x6')]][_0x1940('0x3f')]+=utils[_0x1940('0x30')](utils[_0x1940('0x19')](),channels[_0x9d94be[_0x1940('0x6')]][_0x1940('0x3c')]);utils[_0x1940('0x15')](util[_0x1940('0x16')](_0x1940('0x40'),_0x9d94be[_0x1940('0x6')],channels[_0x9d94be['uniqueid']][_0x1940('0x3f')]));delete channels[_0x9d94be[_0x1940('0x6')]][_0x1940('0x3c')];}}}catch(_0x45d59b){utils[_0x1940('0x1a')](util[_0x1940('0x16')](_0x1940('0x3e'),_0x9d94be[_0x1940('0x6')]),_0x45d59b);}};exports['varset']=function(_0x5db63d){try{if(!_[_0x1940('0x1f')](channels[_0x5db63d[_0x1940('0x6')]])){utils['debug'](util[_0x1940('0x16')]('[%s][calls][varset]',_0x5db63d[_0x1940('0x6')]),_0x5db63d);if(!_[_0x1940('0x1f')](_0x5db63d[_0x1940('0x41')][_0x1940('0x42')])){utils[_0x1940('0x15')](util[_0x1940('0x16')](_0x1940('0x43'),_0x5db63d[_0x1940('0x6')],_0x5db63d[_0x1940('0x44')]));channels[_0x5db63d['uniqueid']][_0x1940('0x45')]=_0x5db63d['value'];}if(!_[_0x1940('0x1f')](_0x5db63d['variable'][_0x1940('0x46')])){utils[_0x1940('0x15')](util[_0x1940('0x16')](_0x1940('0x47'),_0x5db63d[_0x1940('0x6')],_0x5db63d[_0x1940('0x44')]));channels[_0x5db63d[_0x1940('0x6')]][_0x1940('0x48')]=_0x5db63d['value'];channels[_0x5db63d[_0x1940('0x6')]][_0x1940('0x2a')]='\x22'+_0x5db63d[_0x1940('0x44')]+_0x1940('0x49')+_0x5db63d[_0x1940('0x44')]+'>';}if(!_[_0x1940('0x1f')](_0x5db63d[_0x1940('0x41')][_0x1940('0x4a')])||!_[_0x1940('0x1f')](_0x5db63d[_0x1940('0x41')]['xmd-callerid'])){utils[_0x1940('0x15')](util[_0x1940('0x16')](_0x1940('0x4b'),_0x5db63d[_0x1940('0x6')],!_[_0x1940('0x1f')](_0x5db63d[_0x1940('0x41')][_0x1940('0x4a')])?_0x1940('0x4a'):_0x1940('0x4c'),_0x5db63d['value']));channels[_0x5db63d[_0x1940('0x6')]]['callerid']=_0x5db63d[_0x1940('0x44')];}if(!_[_0x1940('0x1f')](_0x5db63d[_0x1940('0x41')][_0x1940('0x4d')])||!_['isNil'](_0x5db63d['variable'][_0x1940('0x4e')])){utils['info'](util[_0x1940('0x16')]('[%s][calls][varset]\x20variable:%s\x20value:%s',_0x5db63d['uniqueid'],!_[_0x1940('0x1f')](_0x5db63d[_0x1940('0x41')][_0x1940('0x4d')])?'xmd-queue':_0x1940('0x4e'),_0x5db63d[_0x1940('0x44')]));channels[_0x5db63d[_0x1940('0x6')]]['lastapplication']=_0x1940('0x4f');channels[_0x5db63d['uniqueid']][_0x1940('0x50')]=_0x5db63d[_0x1940('0x44')];channels[_0x5db63d[_0x1940('0x6')]][_0x1940('0x8')]=!![];}if(!_['isNil'](_0x5db63d['variable'][_0x1940('0x51')])){utils[_0x1940('0x15')](util[_0x1940('0x16')]('[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s',_0x5db63d[_0x1940('0x6')],_0x5db63d['value']));channels[_0x5db63d[_0x1940('0x6')]][_0x1940('0x52')]=_0x5db63d[_0x1940('0x44')];}if(!_[_0x1940('0x1f')](_0x5db63d[_0x1940('0x41')][_0x1940('0x53')])){utils[_0x1940('0x15')](util[_0x1940('0x16')]('[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s',_0x5db63d[_0x1940('0x6')],_0x5db63d[_0x1940('0x44')]));channels[_0x5db63d[_0x1940('0x6')]]['type']=_0x5db63d[_0x1940('0x44')];}if(!_['isNil'](_0x5db63d[_0x1940('0x41')][_0x1940('0x54')])){utils['info'](util[_0x1940('0x16')](_0x1940('0x55'),_0x5db63d[_0x1940('0x6')],_0x5db63d['value']));channels[_0x5db63d['uniqueid']][_0x1940('0x56')]=_0x5db63d[_0x1940('0x44')];}if(!_[_0x1940('0x1f')](_0x5db63d[_0x1940('0x41')][_0x1940('0x57')])){utils[_0x1940('0x15')](util[_0x1940('0x16')]('[%s][calls][varset]\x20variable:sipcallid\x20value:%s',_0x5db63d['uniqueid'],_0x5db63d[_0x1940('0x44')]));channels[_0x5db63d[_0x1940('0x6')]][_0x1940('0x57')]=_0x5db63d[_0x1940('0x44')];}}}catch(_0x32a7fd){utils[_0x1940('0x1a')](util[_0x1940('0x16')](_0x1940('0x58'),_0x5db63d['uniqueid']),_0x32a7fd);}};exports[_0x1940('0x59')]=function(_0x8a65a3){try{if(!_[_0x1940('0x1f')](channels[_0x8a65a3[_0x1940('0x6')]])){utils[_0x1940('0x13')](util[_0x1940('0x16')]('[%s][calls][newexten]',_0x8a65a3['uniqueid']),_0x8a65a3);utils[_0x1940('0x15')](util['format'](_0x1940('0x5a'),_0x8a65a3[_0x1940('0x6')],_0x8a65a3[_0x1940('0x5b')],_0x8a65a3[_0x1940('0x5c')]));if(_0x8a65a3[_0x1940('0x5b')][_0x1940('0x5d')]()==_0x1940('0x5e')&&_['startsWith'](_0x8a65a3[_0x1940('0x5c')]['toLowerCase'](),_0x1940('0x5f'))){var _0x339d29=_0x8a65a3['appdata'][_0x1940('0x60')]('=');var _0x324377=_0x339d29[0x0]['substring'](_0x339d29[0x0]['lastIndexOf']('(')+0x1,_0x339d29[0x0][_0x1940('0x61')](')'));var _0x32da90=_0x339d29[0x1];channels[_0x8a65a3[_0x1940('0x6')]][_0x324377]=_0x32da90;}if(!_[_0x1940('0x62')]([_0x1940('0x28'),_0x1940('0x63'),_0x1940('0x64'),_0x1940('0x5e'),_0x1940('0x65')],_0x8a65a3['application'][_0x1940('0x5d')]())){channels[_0x8a65a3['uniqueid']][_0x1940('0x66')]=_0x8a65a3[_0x1940('0x5b')];channels[_0x8a65a3['uniqueid']]['lastdata']=_0x8a65a3[_0x1940('0x5c')];}}}catch(_0x18c630){utils['error'](util[_0x1940('0x16')](_0x1940('0x67'),_0x8a65a3[_0x1940('0x6')]),_0x18c630);}};