4c66444ed0f24a948e80b71efe728d76715aeb92
[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 _0xf9e7=['routeid','[%s][calls][varset]\x20variable:sipcallid\x20value:%s','sipcallid','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','toLowerCase','set','startsWith','appdata','cdr','split','lastIndexOf','noop','execif','gotoif','application','lodash','./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','uniqueid','channel','queue','membername','interface','calleridnum','lastevent','accountcode','then','UserId','newchannel','debug','[%s][calls][newchannel]','linkedid','OutgoingSpoolFailed','[%s][calls][newchannel]\x20context:%s\x20exten:%s','context','exten','now','error','newstate','[%s][calls][newstate]','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','isNil','systemanswertime','transfer','destinationchannel','answertime','disposition','toNumber','hangup','callerid','calleridname','cause-txt','endtime','diffTime','starttime','billableseconds','[%s][calls][hangup]','attendedtransfer','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','secondtransfererchannel','userfield','_attended','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','origtransfererchannel','[%s][calls][musiconholdstart]','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','musiconholdstop','[%s][calls][musiconholdstop]','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','varset','[%s][calls][varset]','variable','[%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','xmcs-queue','xmd-queue','lastapplication','Queue','lastdata','xmd-contactid','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','xmd-cdrtype','[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s','type','outboundrouteid','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s'];(function(_0x44bc27,_0x2999be){var _0xb97599=function(_0x23755d){while(--_0x23755d){_0x44bc27['push'](_0x44bc27['shift']());}};_0xb97599(++_0x2999be);}(_0xf9e7,0x14f));var _0x7f9e=function(_0x367c8e,_0x3a6502){_0x367c8e=_0x367c8e-0x0;var _0x1c2789=_0xf9e7[_0x367c8e];return _0x1c2789;};'use strict';var _=require(_0x7f9e('0x0'));var util=require('util');var utils=require(_0x7f9e('0x1'));var dispositions=[_0x7f9e('0x2'),_0x7f9e('0x3'),_0x7f9e('0x3'),_0x7f9e('0x2'),_0x7f9e('0x2'),'NO\x20ANSWER',_0x7f9e('0x4'),_0x7f9e('0x5'),_0x7f9e('0x3'),'FAILED','FAILED'];var channels={};function writeDB(_0x5eebf4){utils[_0x7f9e('0x6')](util[_0x7f9e('0x7')](_0x7f9e('0x8'),_0x5eebf4[_0x7f9e('0x9')],_0x5eebf4[_0x7f9e('0xa')],_0x5eebf4[_0x7f9e('0xb')],_0x5eebf4[_0x7f9e('0xc')],_0x5eebf4[_0x7f9e('0xd')],_0x5eebf4[_0x7f9e('0xe')],_0x5eebf4['connectedlinenum'],_0x5eebf4[_0x7f9e('0xf')]));if(_0x5eebf4[_0x7f9e('0x10')]){utils['getUserByInternal'](_0x5eebf4[_0x7f9e('0x10')])[_0x7f9e('0x11')](function(_0x56f1e7){if(_0x56f1e7){_0x5eebf4[_0x7f9e('0x12')]=_0x56f1e7['id'];}utils['request']('CreateVoiceCallReport',_0x5eebf4);});}else{utils['request']('CreateVoiceCallReport',_0x5eebf4);}if(channels[_0x5eebf4['uniqueid']]){delete channels[_0x5eebf4['uniqueid']];}}exports[_0x7f9e('0x13')]=function(_0x39a6b3){try{utils[_0x7f9e('0x14')](util[_0x7f9e('0x7')](_0x7f9e('0x15'),_0x39a6b3[_0x7f9e('0x9')]),_0x39a6b3);if(_0x39a6b3[_0x7f9e('0x9')]==_0x39a6b3[_0x7f9e('0x16')]&&_0x39a6b3[_0x7f9e('0xa')]!=_0x7f9e('0x17')){utils[_0x7f9e('0x6')](util[_0x7f9e('0x7')](_0x7f9e('0x18'),_0x39a6b3['uniqueid'],_0x39a6b3[_0x7f9e('0x19')],_0x39a6b3[_0x7f9e('0x1a')]));channels[_0x39a6b3[_0x7f9e('0x9')]]={'uniqueid':_0x39a6b3[_0x7f9e('0x9')],'accountcode':_0x39a6b3[_0x7f9e('0x10')],'source':_0x39a6b3[_0x7f9e('0xe')],'destination':_0x39a6b3['exten'],'destinationcontext':_0x39a6b3['context'],'channel':_0x39a6b3[_0x7f9e('0xa')],'starttime':utils[_0x7f9e('0x1b')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x7f9e('0x2'),'amaflags':'DOCUMENTATION'};}}catch(_0x5c1574){utils[_0x7f9e('0x1c')](util[_0x7f9e('0x7')](_0x7f9e('0x15'),_0x39a6b3[_0x7f9e('0x9')]),_0x5c1574);}};exports[_0x7f9e('0x1d')]=function(_0x543bf4){try{utils[_0x7f9e('0x14')](util['format'](_0x7f9e('0x1e'),_0x543bf4[_0x7f9e('0x9')]),_0x543bf4);if(!_['isNil'](channels[_0x543bf4[_0x7f9e('0x9')]])&&_0x543bf4[_0x7f9e('0x1f')]==0x6){utils[_0x7f9e('0x6')](util['format'](_0x7f9e('0x20'),_0x543bf4['uniqueid'],_0x543bf4[_0x7f9e('0x19')],_0x543bf4[_0x7f9e('0xa')]));if(_[_0x7f9e('0x21')](channels[_0x543bf4[_0x7f9e('0x9')]][_0x7f9e('0x22')])){channels[_0x543bf4['uniqueid']]['systemanswertime']=utils['now']();}}else if(!_[_0x7f9e('0x21')](channels[_0x543bf4['linkedid']])&&_0x543bf4[_0x7f9e('0x1f')]==0x6&&_0x543bf4[_0x7f9e('0x19')]!=_0x7f9e('0x23')){utils[_0x7f9e('0x6')](util['format']('[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x543bf4[_0x7f9e('0x9')],_0x543bf4[_0x7f9e('0x16')],_0x543bf4[_0x7f9e('0x19')],_0x543bf4['channel']));channels[_0x543bf4[_0x7f9e('0x16')]]['accountcode']=_0x543bf4[_0x7f9e('0x10')];channels[_0x543bf4['linkedid']][_0x7f9e('0x24')]=_0x543bf4[_0x7f9e('0xa')];if(_[_0x7f9e('0x21')](channels[_0x543bf4['linkedid']]['answertime'])){channels[_0x543bf4[_0x7f9e('0x16')]][_0x7f9e('0x25')]=utils[_0x7f9e('0x1b')]();}channels[_0x543bf4[_0x7f9e('0x16')]][_0x7f9e('0x26')]=dispositions[_[_0x7f9e('0x27')](_0x543bf4[_0x7f9e('0x1f')])]||_0x7f9e('0x4');}}catch(_0x2b3bcc){utils[_0x7f9e('0x1c')](util[_0x7f9e('0x7')](_0x7f9e('0x1e'),_0x543bf4[_0x7f9e('0x9')]),_0x2b3bcc);}};exports[_0x7f9e('0x28')]=function(_0x3a345b){try{if(!_[_0x7f9e('0x21')](channels[_0x3a345b[_0x7f9e('0x9')]])){utils[_0x7f9e('0x14')](util[_0x7f9e('0x7')]('[%s][calls][hangup]',_0x3a345b[_0x7f9e('0x9')]),_0x3a345b);if(_[_0x7f9e('0x21')](channels[_0x3a345b[_0x7f9e('0x9')]]['callerid'])){channels[_0x3a345b[_0x7f9e('0x9')]][_0x7f9e('0x29')]=_0x3a345b[_0x7f9e('0x2a')]+'\x20<'+_0x3a345b[_0x7f9e('0xe')]+'>';}utils[_0x7f9e('0x6')](util[_0x7f9e('0x7')]('[%s][calls][hangup]\x20callerid:%s\x20reason:%s',_0x3a345b[_0x7f9e('0x9')],channels[_0x3a345b[_0x7f9e('0x9')]]['callerid'],_0x3a345b[_0x7f9e('0x2b')]));channels[_0x3a345b['uniqueid']][_0x7f9e('0x2c')]=utils[_0x7f9e('0x1b')]();channels[_0x3a345b[_0x7f9e('0x9')]]['duration']=utils[_0x7f9e('0x2d')](channels[_0x3a345b[_0x7f9e('0x9')]]['endtime'],channels[_0x3a345b[_0x7f9e('0x9')]][_0x7f9e('0x2e')]);channels[_0x3a345b[_0x7f9e('0x9')]][_0x7f9e('0x2f')]=channels[_0x3a345b[_0x7f9e('0x9')]][_0x7f9e('0x25')]?utils[_0x7f9e('0x2d')](channels[_0x3a345b[_0x7f9e('0x9')]]['endtime'],channels[_0x3a345b[_0x7f9e('0x9')]][_0x7f9e('0x25')]):0x0;writeDB(channels[_0x3a345b['uniqueid']]);}}catch(_0x27a479){utils[_0x7f9e('0x1c')](util[_0x7f9e('0x7')](_0x7f9e('0x30'),_0x3a345b['uniqueid']),_0x27a479);}};exports[_0x7f9e('0x31')]=function(_0x422c6e){try{if(!_[_0x7f9e('0x21')](channels[_0x422c6e[_0x7f9e('0x32')]])){utils[_0x7f9e('0x14')](util[_0x7f9e('0x7')](_0x7f9e('0x33'),_0x422c6e[_0x7f9e('0x34')]),_0x422c6e);if(channels[_0x422c6e[_0x7f9e('0x32')]]['channel']==_0x422c6e['transfereechannel']){utils[_0x7f9e('0x6')](util[_0x7f9e('0x7')]('[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s',_0x422c6e[_0x7f9e('0x34')],_0x422c6e['localtwolinkedid'],_0x422c6e[_0x7f9e('0x35')]));channels[_0x422c6e['localtwolinkedid']]['destinationchannel']=_0x422c6e[_0x7f9e('0x35')];channels[_0x422c6e[_0x7f9e('0x32')]][_0x7f9e('0x36')]=_0x7f9e('0x37');}else if(channels[_0x422c6e[_0x7f9e('0x32')]][_0x7f9e('0xa')]=_0x422c6e['transfertargetchannel']){utils['info'](util[_0x7f9e('0x7')](_0x7f9e('0x38'),_0x422c6e['origtransfereruniqueid'],_0x422c6e[_0x7f9e('0x32')],_0x422c6e[_0x7f9e('0x39')]));channels[_0x422c6e[_0x7f9e('0x32')]][_0x7f9e('0x24')]=_0x422c6e[_0x7f9e('0x39')];channels[_0x422c6e[_0x7f9e('0x32')]]['userfield']=_0x7f9e('0x37');}}}catch(_0x5a1d62){utils[_0x7f9e('0x1c')](util[_0x7f9e('0x7')](_0x7f9e('0x33'),_0x422c6e['origtransfereruniqueid']),_0x5a1d62);}};exports['musiconholdstart']=function(_0x2d30a5){try{if(!_[_0x7f9e('0x21')](channels[_0x2d30a5[_0x7f9e('0x9')]])){utils[_0x7f9e('0x14')](util[_0x7f9e('0x7')](_0x7f9e('0x3a'),_0x2d30a5[_0x7f9e('0x9')]),_0x2d30a5);channels[_0x2d30a5[_0x7f9e('0x9')]][_0x7f9e('0x3b')]=utils[_0x7f9e('0x1b')]();utils[_0x7f9e('0x6')](util[_0x7f9e('0x7')](_0x7f9e('0x3c'),_0x2d30a5[_0x7f9e('0x9')],channels[_0x2d30a5[_0x7f9e('0x9')]][_0x7f9e('0x3b')]));}}catch(_0x1975bc){utils[_0x7f9e('0x1c')](util[_0x7f9e('0x7')](_0x7f9e('0x3a'),_0x2d30a5[_0x7f9e('0x9')]),_0x1975bc);}};exports[_0x7f9e('0x3d')]=function(_0x4930a5){try{if(!_[_0x7f9e('0x21')](channels[_0x4930a5[_0x7f9e('0x9')]])){utils[_0x7f9e('0x14')](util[_0x7f9e('0x7')](_0x7f9e('0x3e'),_0x4930a5[_0x7f9e('0x9')]),_0x4930a5);if(!_[_0x7f9e('0x21')](channels[_0x4930a5[_0x7f9e('0x9')]]['musiconholdstartAt'])){channels[_0x4930a5[_0x7f9e('0x9')]][_0x7f9e('0x3f')]+=utils[_0x7f9e('0x2d')](utils['now'](),channels[_0x4930a5[_0x7f9e('0x9')]][_0x7f9e('0x3b')]);utils['info'](util['format'](_0x7f9e('0x40'),_0x4930a5[_0x7f9e('0x9')],channels[_0x4930a5[_0x7f9e('0x9')]]['mohtime']));delete channels[_0x4930a5[_0x7f9e('0x9')]][_0x7f9e('0x3b')];}}}catch(_0x2c9b3a){utils[_0x7f9e('0x1c')](util[_0x7f9e('0x7')](_0x7f9e('0x3e'),_0x4930a5[_0x7f9e('0x9')]),_0x2c9b3a);}};exports[_0x7f9e('0x41')]=function(_0x3f6dad){try{if(!_[_0x7f9e('0x21')](channels[_0x3f6dad['uniqueid']])){utils[_0x7f9e('0x14')](util[_0x7f9e('0x7')](_0x7f9e('0x42'),_0x3f6dad[_0x7f9e('0x9')]),_0x3f6dad);if(!_['isNil'](_0x3f6dad[_0x7f9e('0x43')]['xmd-originatecalleridnum'])){utils[_0x7f9e('0x6')](util[_0x7f9e('0x7')](_0x7f9e('0x44'),_0x3f6dad[_0x7f9e('0x9')],_0x3f6dad[_0x7f9e('0x45')]));channels[_0x3f6dad[_0x7f9e('0x9')]][_0x7f9e('0x46')]=_0x3f6dad[_0x7f9e('0x45')];}if(!_[_0x7f9e('0x21')](_0x3f6dad[_0x7f9e('0x43')][_0x7f9e('0x47')])){utils[_0x7f9e('0x6')](util[_0x7f9e('0x7')](_0x7f9e('0x48'),_0x3f6dad[_0x7f9e('0x9')],_0x3f6dad[_0x7f9e('0x45')]));channels[_0x3f6dad[_0x7f9e('0x9')]][_0x7f9e('0x49')]=_0x3f6dad['value'];channels[_0x3f6dad['uniqueid']][_0x7f9e('0x29')]='\x22'+_0x3f6dad[_0x7f9e('0x45')]+_0x7f9e('0x4a')+_0x3f6dad[_0x7f9e('0x45')]+'>';}if(!_[_0x7f9e('0x21')](_0x3f6dad[_0x7f9e('0x43')][_0x7f9e('0x4b')])||!_[_0x7f9e('0x21')](_0x3f6dad['variable']['xmd-callerid'])){utils[_0x7f9e('0x6')](util['format']('[%s][calls][varset]\x20variable:%s\x20value:%s',_0x3f6dad['uniqueid'],!_['isNil'](_0x3f6dad['variable'][_0x7f9e('0x4b')])?_0x7f9e('0x4b'):_0x7f9e('0x4c'),_0x3f6dad[_0x7f9e('0x45')]));channels[_0x3f6dad[_0x7f9e('0x9')]][_0x7f9e('0x29')]=_0x3f6dad[_0x7f9e('0x45')];}if(!_[_0x7f9e('0x21')](_0x3f6dad['variable']['xmd-queue'])||!_['isNil'](_0x3f6dad[_0x7f9e('0x43')][_0x7f9e('0x4d')])){utils['info'](util[_0x7f9e('0x7')]('[%s][calls][varset]\x20variable:%s\x20value:%s',_0x3f6dad[_0x7f9e('0x9')],!_['isNil'](_0x3f6dad[_0x7f9e('0x43')][_0x7f9e('0x4e')])?_0x7f9e('0x4e'):_0x7f9e('0x4d'),_0x3f6dad[_0x7f9e('0x45')]));channels[_0x3f6dad['uniqueid']][_0x7f9e('0x4f')]=_0x7f9e('0x50');channels[_0x3f6dad[_0x7f9e('0x9')]][_0x7f9e('0x51')]=_0x3f6dad[_0x7f9e('0x45')];channels[_0x3f6dad[_0x7f9e('0x9')]][_0x7f9e('0xb')]=!![];}if(!_[_0x7f9e('0x21')](_0x3f6dad[_0x7f9e('0x43')][_0x7f9e('0x52')])){utils[_0x7f9e('0x6')](util['format'](_0x7f9e('0x53'),_0x3f6dad['uniqueid'],_0x3f6dad['value']));channels[_0x3f6dad[_0x7f9e('0x9')]]['ContactId']=_0x3f6dad['value'];}if(!_[_0x7f9e('0x21')](_0x3f6dad[_0x7f9e('0x43')][_0x7f9e('0x54')])){utils[_0x7f9e('0x6')](util['format'](_0x7f9e('0x55'),_0x3f6dad['uniqueid'],_0x3f6dad[_0x7f9e('0x45')]));channels[_0x3f6dad[_0x7f9e('0x9')]][_0x7f9e('0x56')]=_0x3f6dad[_0x7f9e('0x45')];}if(!_[_0x7f9e('0x21')](_0x3f6dad[_0x7f9e('0x43')][_0x7f9e('0x57')])){utils['info'](util[_0x7f9e('0x7')](_0x7f9e('0x58'),_0x3f6dad[_0x7f9e('0x9')],_0x3f6dad[_0x7f9e('0x45')]));channels[_0x3f6dad[_0x7f9e('0x9')]][_0x7f9e('0x59')]=_0x3f6dad[_0x7f9e('0x45')];}if(!_[_0x7f9e('0x21')](_0x3f6dad[_0x7f9e('0x43')]['sipcallid'])){utils[_0x7f9e('0x6')](util[_0x7f9e('0x7')](_0x7f9e('0x5a'),_0x3f6dad[_0x7f9e('0x9')],_0x3f6dad['value']));channels[_0x3f6dad[_0x7f9e('0x9')]][_0x7f9e('0x5b')]=_0x3f6dad[_0x7f9e('0x45')];}}}catch(_0x57c8ce){utils['error'](util['format'](_0x7f9e('0x42'),_0x3f6dad[_0x7f9e('0x9')]),_0x57c8ce);}};exports[_0x7f9e('0x5c')]=function(_0x157f8d){try{if(!_[_0x7f9e('0x21')](channels[_0x157f8d[_0x7f9e('0x9')]])){utils[_0x7f9e('0x14')](util[_0x7f9e('0x7')](_0x7f9e('0x5d'),_0x157f8d[_0x7f9e('0x9')]),_0x157f8d);utils['info'](util[_0x7f9e('0x7')](_0x7f9e('0x5e'),_0x157f8d[_0x7f9e('0x9')],_0x157f8d['application'],_0x157f8d['appdata']));if(_0x157f8d['application'][_0x7f9e('0x5f')]()==_0x7f9e('0x60')&&_[_0x7f9e('0x61')](_0x157f8d[_0x7f9e('0x62')]['toLowerCase'](),_0x7f9e('0x63'))){var _0x29f1bb=_0x157f8d[_0x7f9e('0x62')][_0x7f9e('0x64')]('=');var _0x4a3d18=_0x29f1bb[0x0]['substring'](_0x29f1bb[0x0][_0x7f9e('0x65')]('(')+0x1,_0x29f1bb[0x0]['lastIndexOf'](')'));var _0x3379a2=_0x29f1bb[0x1];channels[_0x157f8d[_0x7f9e('0x9')]][_0x4a3d18]=_0x3379a2;}if(!_['includes']([_0x7f9e('0x28'),_0x7f9e('0x66'),_0x7f9e('0x67'),_0x7f9e('0x60'),_0x7f9e('0x68')],_0x157f8d[_0x7f9e('0x69')]['toLowerCase']())){channels[_0x157f8d[_0x7f9e('0x9')]][_0x7f9e('0x4f')]=_0x157f8d[_0x7f9e('0x69')];channels[_0x157f8d['uniqueid']][_0x7f9e('0x51')]=_0x157f8d[_0x7f9e('0x62')];}}}catch(_0x87a609){utils[_0x7f9e('0x1c')](util[_0x7f9e('0x7')](_0x7f9e('0x5d'),_0x157f8d[_0x7f9e('0x9')]),_0x87a609);}};