Built motion from commit (unavailable).|2.5.21
[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 _0xb910=['lastdata','xmd-contactid','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','ContactId','xmd-cdrtype','[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s','outboundrouteid','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s','routeid','sipcallid','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','appdata','toLowerCase','startsWith','cdr','split','substring','lastIndexOf','hangup','execif','set','gotoif','lodash','util','./utils','NO\x20ANSWER','FAILED','ANSWERED','BUSY','info','format','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','channel','queue','membername','calleridnum','connectedlinenum','accountcode','getUserByInternal','UserId','CreateVoiceCallReport','request','uniqueid','newchannel','[%s][calls][newchannel]','linkedid','OutgoingSpoolFailed','context','exten','now','DOCUMENTATION','newstate','[%s][calls][newstate]','isNil','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','systemanswertime','transfer','destinationchannel','answertime','error','debug','callerid','calleridname','cause-txt','endtime','duration','starttime','billableseconds','diffTime','[%s][calls][hangup]','attendedtransfer','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','transfereechannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','secondtransfererchannel','_attended','transfertargetchannel','origtransfererchannel','userfield','musiconholdstartAt','[%s][calls][musiconholdstart]','musiconholdstop','[%s][calls][musiconholdstop]','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','varset','[%s][calls][varset]','xmd-originatecalleridnum','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','value','source','xmd-phone','\x22\x20<','variable','xmd-callerid-preview','xmd-callerid','xmd-queue','xmcs-queue','[%s][calls][varset]\x20variable:%s\x20value:%s','lastapplication','Queue'];(function(_0x11892e,_0xfb253c){var _0x2d0134=function(_0x2ef1bb){while(--_0x2ef1bb){_0x11892e['push'](_0x11892e['shift']());}};_0x2d0134(++_0xfb253c);}(_0xb910,0x1c5));var _0x0b91=function(_0x2f1762,_0xab43df){_0x2f1762=_0x2f1762-0x0;var _0x8ab21=_0xb910[_0x2f1762];return _0x8ab21;};'use strict';var _=require(_0x0b91('0x0'));var util=require(_0x0b91('0x1'));var utils=require(_0x0b91('0x2'));var dispositions=[_0x0b91('0x3'),_0x0b91('0x4'),_0x0b91('0x4'),'NO\x20ANSWER',_0x0b91('0x3'),_0x0b91('0x3'),_0x0b91('0x5'),_0x0b91('0x6'),'FAILED','FAILED','FAILED'];var channels={};function writeDB(_0x257f4b){utils[_0x0b91('0x7')](util[_0x0b91('0x8')](_0x0b91('0x9'),_0x257f4b['uniqueid'],_0x257f4b[_0x0b91('0xa')],_0x257f4b[_0x0b91('0xb')],_0x257f4b[_0x0b91('0xc')],_0x257f4b['interface'],_0x257f4b[_0x0b91('0xd')],_0x257f4b[_0x0b91('0xe')],_0x257f4b['lastevent']));if(_0x257f4b[_0x0b91('0xf')]){utils[_0x0b91('0x10')](_0x257f4b['accountcode'])['then'](function(_0x5df9ce){if(_0x5df9ce){_0x257f4b[_0x0b91('0x11')]=_0x5df9ce['id'];}utils['request'](_0x0b91('0x12'),_0x257f4b);});}else{utils[_0x0b91('0x13')]('CreateVoiceCallReport',_0x257f4b);}if(channels[_0x257f4b['uniqueid']]){delete channels[_0x257f4b[_0x0b91('0x14')]];}}exports[_0x0b91('0x15')]=function(_0x4a15ba){try{utils['debug'](util[_0x0b91('0x8')](_0x0b91('0x16'),_0x4a15ba[_0x0b91('0x14')]),_0x4a15ba);if(_0x4a15ba['uniqueid']==_0x4a15ba[_0x0b91('0x17')]&&_0x4a15ba['channel']!=_0x0b91('0x18')){utils[_0x0b91('0x7')](util[_0x0b91('0x8')]('[%s][calls][newchannel]\x20context:%s\x20exten:%s',_0x4a15ba[_0x0b91('0x14')],_0x4a15ba[_0x0b91('0x19')],_0x4a15ba[_0x0b91('0x1a')]));channels[_0x4a15ba[_0x0b91('0x14')]]={'uniqueid':_0x4a15ba[_0x0b91('0x14')],'accountcode':_0x4a15ba[_0x0b91('0xf')],'source':_0x4a15ba[_0x0b91('0xd')],'destination':_0x4a15ba[_0x0b91('0x1a')],'destinationcontext':_0x4a15ba['context'],'channel':_0x4a15ba['channel'],'starttime':utils[_0x0b91('0x1b')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':_0x0b91('0x1c')};}}catch(_0xe2cd7f){utils['error'](util[_0x0b91('0x8')]('[%s][calls][newchannel]',_0x4a15ba[_0x0b91('0x14')]),_0xe2cd7f);}};exports[_0x0b91('0x1d')]=function(_0x12c38c){try{utils['debug'](util[_0x0b91('0x8')](_0x0b91('0x1e'),_0x12c38c[_0x0b91('0x14')]),_0x12c38c);if(!_[_0x0b91('0x1f')](channels[_0x12c38c[_0x0b91('0x14')]])&&_0x12c38c[_0x0b91('0x20')]==0x6){utils[_0x0b91('0x7')](util[_0x0b91('0x8')](_0x0b91('0x21'),_0x12c38c['uniqueid'],_0x12c38c[_0x0b91('0x19')],_0x12c38c[_0x0b91('0xa')]));if(_[_0x0b91('0x1f')](channels[_0x12c38c['uniqueid']]['systemanswertime'])){channels[_0x12c38c[_0x0b91('0x14')]][_0x0b91('0x22')]=utils[_0x0b91('0x1b')]();}}else if(!_[_0x0b91('0x1f')](channels[_0x12c38c[_0x0b91('0x17')]])&&_0x12c38c[_0x0b91('0x20')]==0x6&&_0x12c38c[_0x0b91('0x19')]!=_0x0b91('0x23')){utils[_0x0b91('0x7')](util[_0x0b91('0x8')]('[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x12c38c[_0x0b91('0x14')],_0x12c38c[_0x0b91('0x17')],_0x12c38c['context'],_0x12c38c['channel']));channels[_0x12c38c[_0x0b91('0x17')]]['accountcode']=_0x12c38c['accountcode'];channels[_0x12c38c[_0x0b91('0x17')]][_0x0b91('0x24')]=_0x12c38c[_0x0b91('0xa')];if(_[_0x0b91('0x1f')](channels[_0x12c38c[_0x0b91('0x17')]]['answertime'])){channels[_0x12c38c[_0x0b91('0x17')]][_0x0b91('0x25')]=utils['now']();}channels[_0x12c38c['linkedid']]['disposition']=dispositions[_['toNumber'](_0x12c38c[_0x0b91('0x20')])]||_0x0b91('0x5');}}catch(_0x4612b3){utils[_0x0b91('0x26')](util['format'](_0x0b91('0x1e'),_0x12c38c['uniqueid']),_0x4612b3);}};exports['hangup']=function(_0x40074d){try{if(!_[_0x0b91('0x1f')](channels[_0x40074d['uniqueid']])){utils[_0x0b91('0x27')](util[_0x0b91('0x8')]('[%s][calls][hangup]',_0x40074d[_0x0b91('0x14')]),_0x40074d);if(_[_0x0b91('0x1f')](channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x28')])){channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x28')]=_0x40074d[_0x0b91('0x29')]+'\x20<'+_0x40074d['calleridnum']+'>';}utils[_0x0b91('0x7')](util[_0x0b91('0x8')]('[%s][calls][hangup]\x20callerid:%s\x20reason:%s',_0x40074d[_0x0b91('0x14')],channels[_0x40074d['uniqueid']][_0x0b91('0x28')],_0x40074d[_0x0b91('0x2a')]));channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x2b')]=utils[_0x0b91('0x1b')]();channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x2c')]=utils['diffTime'](channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x2b')],channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x2d')]);channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x2e')]=channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x25')]?utils[_0x0b91('0x2f')](channels[_0x40074d[_0x0b91('0x14')]][_0x0b91('0x2b')],channels[_0x40074d['uniqueid']][_0x0b91('0x25')]):0x0;writeDB(channels[_0x40074d['uniqueid']]);}}catch(_0x54757e){utils[_0x0b91('0x26')](util[_0x0b91('0x8')](_0x0b91('0x30'),_0x40074d[_0x0b91('0x14')]),_0x54757e);}};exports[_0x0b91('0x31')]=function(_0x17f22b){try{if(!_[_0x0b91('0x1f')](channels[_0x17f22b[_0x0b91('0x32')]])){utils[_0x0b91('0x27')](util[_0x0b91('0x8')](_0x0b91('0x33'),_0x17f22b[_0x0b91('0x34')]),_0x17f22b);if(channels[_0x17f22b[_0x0b91('0x32')]][_0x0b91('0xa')]==_0x17f22b[_0x0b91('0x35')]){utils[_0x0b91('0x7')](util[_0x0b91('0x8')](_0x0b91('0x36'),_0x17f22b[_0x0b91('0x34')],_0x17f22b[_0x0b91('0x32')],_0x17f22b[_0x0b91('0x37')]));channels[_0x17f22b[_0x0b91('0x32')]][_0x0b91('0x24')]=_0x17f22b[_0x0b91('0x37')];channels[_0x17f22b['localtwolinkedid']]['userfield']=_0x0b91('0x38');}else if(channels[_0x17f22b[_0x0b91('0x32')]][_0x0b91('0xa')]=_0x17f22b[_0x0b91('0x39')]){utils[_0x0b91('0x7')](util[_0x0b91('0x8')](_0x0b91('0x36'),_0x17f22b[_0x0b91('0x34')],_0x17f22b[_0x0b91('0x32')],_0x17f22b['origtransfererchannel']));channels[_0x17f22b[_0x0b91('0x32')]][_0x0b91('0x24')]=_0x17f22b[_0x0b91('0x3a')];channels[_0x17f22b['localtwolinkedid']][_0x0b91('0x3b')]=_0x0b91('0x38');}}}catch(_0xd901b8){utils['error'](util[_0x0b91('0x8')](_0x0b91('0x33'),_0x17f22b[_0x0b91('0x34')]),_0xd901b8);}};exports['musiconholdstart']=function(_0x23714e){try{if(!_[_0x0b91('0x1f')](channels[_0x23714e[_0x0b91('0x14')]])){utils[_0x0b91('0x27')](util[_0x0b91('0x8')]('[%s][calls][musiconholdstart]',_0x23714e[_0x0b91('0x14')]),_0x23714e);channels[_0x23714e[_0x0b91('0x14')]]['musiconholdstartAt']=utils[_0x0b91('0x1b')]();utils['info'](util['format']('[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s',_0x23714e[_0x0b91('0x14')],channels[_0x23714e[_0x0b91('0x14')]][_0x0b91('0x3c')]));}}catch(_0x5a773b){utils['error'](util['format'](_0x0b91('0x3d'),_0x23714e[_0x0b91('0x14')]),_0x5a773b);}};exports[_0x0b91('0x3e')]=function(_0x4b9e25){try{if(!_[_0x0b91('0x1f')](channels[_0x4b9e25[_0x0b91('0x14')]])){utils['debug'](util['format'](_0x0b91('0x3f'),_0x4b9e25[_0x0b91('0x14')]),_0x4b9e25);if(!_['isNil'](channels[_0x4b9e25['uniqueid']][_0x0b91('0x3c')])){channels[_0x4b9e25[_0x0b91('0x14')]][_0x0b91('0x40')]+=utils[_0x0b91('0x2f')](utils[_0x0b91('0x1b')](),channels[_0x4b9e25[_0x0b91('0x14')]]['musiconholdstartAt']);utils['info'](util['format'](_0x0b91('0x41'),_0x4b9e25[_0x0b91('0x14')],channels[_0x4b9e25[_0x0b91('0x14')]][_0x0b91('0x40')]));delete channels[_0x4b9e25[_0x0b91('0x14')]][_0x0b91('0x3c')];}}}catch(_0x3f3fe9){utils[_0x0b91('0x26')](util[_0x0b91('0x8')]('[%s][calls][musiconholdstop]',_0x4b9e25[_0x0b91('0x14')]),_0x3f3fe9);}};exports[_0x0b91('0x42')]=function(_0xdc75a7){try{if(!_['isNil'](channels[_0xdc75a7[_0x0b91('0x14')]])){utils[_0x0b91('0x27')](util[_0x0b91('0x8')](_0x0b91('0x43'),_0xdc75a7[_0x0b91('0x14')]),_0xdc75a7);if(!_['isNil'](_0xdc75a7['variable'][_0x0b91('0x44')])){utils['info'](util[_0x0b91('0x8')](_0x0b91('0x45'),_0xdc75a7['uniqueid'],_0xdc75a7[_0x0b91('0x46')]));channels[_0xdc75a7['uniqueid']][_0x0b91('0x47')]=_0xdc75a7[_0x0b91('0x46')];}if(!_[_0x0b91('0x1f')](_0xdc75a7['variable'][_0x0b91('0x48')])){utils[_0x0b91('0x7')](util[_0x0b91('0x8')]('[%s][calls][varset]\x20variable:xmd-phone\x20value:%s',_0xdc75a7[_0x0b91('0x14')],_0xdc75a7[_0x0b91('0x46')]));channels[_0xdc75a7[_0x0b91('0x14')]]['destination']=_0xdc75a7[_0x0b91('0x46')];channels[_0xdc75a7['uniqueid']][_0x0b91('0x28')]='\x22'+_0xdc75a7[_0x0b91('0x46')]+_0x0b91('0x49')+_0xdc75a7[_0x0b91('0x46')]+'>';}if(!_['isNil'](_0xdc75a7[_0x0b91('0x4a')][_0x0b91('0x4b')])||!_['isNil'](_0xdc75a7['variable'][_0x0b91('0x4c')])){utils['info'](util[_0x0b91('0x8')]('[%s][calls][varset]\x20variable:%s\x20value:%s',_0xdc75a7[_0x0b91('0x14')],!_[_0x0b91('0x1f')](_0xdc75a7['variable'][_0x0b91('0x4b')])?'xmd-callerid-preview':_0x0b91('0x4c'),_0xdc75a7[_0x0b91('0x46')]));channels[_0xdc75a7[_0x0b91('0x14')]][_0x0b91('0x28')]=_0xdc75a7[_0x0b91('0x46')];}if(!_[_0x0b91('0x1f')](_0xdc75a7[_0x0b91('0x4a')][_0x0b91('0x4d')])||!_[_0x0b91('0x1f')](_0xdc75a7['variable'][_0x0b91('0x4e')])){utils[_0x0b91('0x7')](util[_0x0b91('0x8')](_0x0b91('0x4f'),_0xdc75a7['uniqueid'],!_['isNil'](_0xdc75a7[_0x0b91('0x4a')]['xmd-queue'])?_0x0b91('0x4d'):_0x0b91('0x4e'),_0xdc75a7[_0x0b91('0x46')]));channels[_0xdc75a7['uniqueid']][_0x0b91('0x50')]=_0x0b91('0x51');channels[_0xdc75a7[_0x0b91('0x14')]][_0x0b91('0x52')]=_0xdc75a7['value'];channels[_0xdc75a7[_0x0b91('0x14')]][_0x0b91('0xb')]=!![];}if(!_[_0x0b91('0x1f')](_0xdc75a7['variable'][_0x0b91('0x53')])){utils['info'](util[_0x0b91('0x8')](_0x0b91('0x54'),_0xdc75a7['uniqueid'],_0xdc75a7[_0x0b91('0x46')]));channels[_0xdc75a7['uniqueid']][_0x0b91('0x55')]=_0xdc75a7[_0x0b91('0x46')];}if(!_[_0x0b91('0x1f')](_0xdc75a7[_0x0b91('0x4a')][_0x0b91('0x56')])){utils[_0x0b91('0x7')](util[_0x0b91('0x8')](_0x0b91('0x57'),_0xdc75a7[_0x0b91('0x14')],_0xdc75a7[_0x0b91('0x46')]));channels[_0xdc75a7[_0x0b91('0x14')]]['type']=_0xdc75a7['value'];}if(!_['isNil'](_0xdc75a7[_0x0b91('0x4a')][_0x0b91('0x58')])){utils[_0x0b91('0x7')](util[_0x0b91('0x8')](_0x0b91('0x59'),_0xdc75a7[_0x0b91('0x14')],_0xdc75a7[_0x0b91('0x46')]));channels[_0xdc75a7[_0x0b91('0x14')]][_0x0b91('0x5a')]=_0xdc75a7[_0x0b91('0x46')];}if(!_[_0x0b91('0x1f')](_0xdc75a7[_0x0b91('0x4a')][_0x0b91('0x5b')])){utils['info'](util[_0x0b91('0x8')]('[%s][calls][varset]\x20variable:sipcallid\x20value:%s',_0xdc75a7[_0x0b91('0x14')],_0xdc75a7['value']));channels[_0xdc75a7['uniqueid']]['sipcallid']=_0xdc75a7[_0x0b91('0x46')];}}}catch(_0x5e9a8e){utils['error'](util[_0x0b91('0x8')](_0x0b91('0x43'),_0xdc75a7['uniqueid']),_0x5e9a8e);}};exports[_0x0b91('0x5c')]=function(_0x88a53){try{if(!_[_0x0b91('0x1f')](channels[_0x88a53[_0x0b91('0x14')]])){utils['debug'](util['format'](_0x0b91('0x5d'),_0x88a53['uniqueid']),_0x88a53);utils[_0x0b91('0x7')](util[_0x0b91('0x8')](_0x0b91('0x5e'),_0x88a53[_0x0b91('0x14')],_0x88a53[_0x0b91('0x5f')],_0x88a53[_0x0b91('0x60')]));if(_0x88a53[_0x0b91('0x5f')][_0x0b91('0x61')]()=='set'&&_[_0x0b91('0x62')](_0x88a53[_0x0b91('0x60')]['toLowerCase'](),_0x0b91('0x63'))){var _0x44d03b=_0x88a53['appdata'][_0x0b91('0x64')]('=');var _0x2bada8=_0x44d03b[0x0][_0x0b91('0x65')](_0x44d03b[0x0][_0x0b91('0x66')]('(')+0x1,_0x44d03b[0x0][_0x0b91('0x66')](')'));var _0x1cee86=_0x44d03b[0x1];channels[_0x88a53[_0x0b91('0x14')]][_0x2bada8]=_0x1cee86;}if(!_['includes']([_0x0b91('0x67'),'noop',_0x0b91('0x68'),_0x0b91('0x69'),_0x0b91('0x6a')],_0x88a53[_0x0b91('0x5f')][_0x0b91('0x61')]())){channels[_0x88a53['uniqueid']]['lastapplication']=_0x88a53['application'];channels[_0x88a53['uniqueid']][_0x0b91('0x52')]=_0x88a53[_0x0b91('0x60')];}}}catch(_0x5b8945){utils[_0x0b91('0x26')](util[_0x0b91('0x8')](_0x0b91('0x5d'),_0x88a53[_0x0b91('0x14')]),_0x5b8945);}};