5f043a45603cf89b5573758a82c5f125ad1b6822
[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 _0xef04=['[%s][calls][varset]','variable','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','source','value','xmd-phone','[%s][calls][varset]\x20variable:xmd-phone\x20value:%s','destination','\x22\x20<','xmd-callerid','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-callerid-preview','xmd-queue','xmcs-queue','lastapplication','Queue','lastdata','queue','[%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','newexten','application','appdata','toLowerCase','startsWith','split','substring','lastIndexOf','execif','gotoif','[%s][calls][newexten]','util','./utils','FAILED','NO\x20ANSWER','ANSWERED','BUSY','info','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','uniqueid','channel','calleridnum','lastevent','accountcode','getUserByInternal','UserId','request','CreateVoiceCallReport','newchannel','debug','format','[%s][calls][newchannel]','OutgoingSpoolFailed','[%s][calls][newchannel]\x20context:%s\x20exten:%s','context','exten','now','DOCUMENTATION','newstate','isNil','[%s][calls][newstate]\x20context:%s\x20channel:%s','systemanswertime','channelstate','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','linkedid','destinationchannel','answertime','disposition','toNumber','error','[%s][calls][newstate]','hangup','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','duration','diffTime','starttime','billableseconds','endtime','[%s][calls][hangup]','attendedtransfer','localtwolinkedid','[%s][calls][attendedtransfer]','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','origtransfereruniqueid','secondtransfererchannel','userfield','_attended','transfertargetchannel','origtransfererchannel','[%s][calls][musiconholdstart]','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','musiconholdstop','[%s][calls][musiconholdstop]','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','varset'];(function(_0x2bb18c,_0x44c34e){var _0x2fa5e8=function(_0x46912f){while(--_0x46912f){_0x2bb18c['push'](_0x2bb18c['shift']());}};_0x2fa5e8(++_0x44c34e);}(_0xef04,0x16b));var _0x4ef0=function(_0x3422cf,_0x3640fb){_0x3422cf=_0x3422cf-0x0;var _0x377b90=_0xef04[_0x3422cf];return _0x377b90;};'use strict';var _=require('lodash');var util=require(_0x4ef0('0x0'));var utils=require(_0x4ef0('0x1'));var dispositions=['NO\x20ANSWER',_0x4ef0('0x2'),'FAILED','NO\x20ANSWER',_0x4ef0('0x3'),_0x4ef0('0x3'),_0x4ef0('0x4'),_0x4ef0('0x5'),_0x4ef0('0x2'),_0x4ef0('0x2'),'FAILED'];var channels={};function writeDB(_0x4fa117){utils[_0x4ef0('0x6')](util['format'](_0x4ef0('0x7'),_0x4fa117[_0x4ef0('0x8')],_0x4fa117[_0x4ef0('0x9')],_0x4fa117['queue'],_0x4fa117['membername'],_0x4fa117['interface'],_0x4fa117[_0x4ef0('0xa')],_0x4fa117['connectedlinenum'],_0x4fa117[_0x4ef0('0xb')]));if(_0x4fa117[_0x4ef0('0xc')]){utils[_0x4ef0('0xd')](_0x4fa117['accountcode'])['then'](function(_0x4eed17){if(_0x4eed17){_0x4fa117[_0x4ef0('0xe')]=_0x4eed17['id'];}utils[_0x4ef0('0xf')](_0x4ef0('0x10'),_0x4fa117);});}else{utils[_0x4ef0('0xf')]('CreateVoiceCallReport',_0x4fa117);}if(channels[_0x4fa117[_0x4ef0('0x8')]]){delete channels[_0x4fa117[_0x4ef0('0x8')]];}}exports[_0x4ef0('0x11')]=function(_0x38ed86){try{utils[_0x4ef0('0x12')](util[_0x4ef0('0x13')](_0x4ef0('0x14'),_0x38ed86[_0x4ef0('0x8')]),_0x38ed86);if(_0x38ed86['uniqueid']==_0x38ed86['linkedid']&&_0x38ed86['channel']!=_0x4ef0('0x15')){utils[_0x4ef0('0x6')](util[_0x4ef0('0x13')](_0x4ef0('0x16'),_0x38ed86[_0x4ef0('0x8')],_0x38ed86[_0x4ef0('0x17')],_0x38ed86[_0x4ef0('0x18')]));channels[_0x38ed86[_0x4ef0('0x8')]]={'uniqueid':_0x38ed86[_0x4ef0('0x8')],'accountcode':_0x38ed86[_0x4ef0('0xc')],'source':_0x38ed86[_0x4ef0('0xa')],'destination':_0x38ed86[_0x4ef0('0x18')],'destinationcontext':_0x38ed86[_0x4ef0('0x17')],'channel':_0x38ed86[_0x4ef0('0x9')],'starttime':utils[_0x4ef0('0x19')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x4ef0('0x3'),'amaflags':_0x4ef0('0x1a')};}}catch(_0x6f8ce9){utils['error'](util['format'](_0x4ef0('0x14'),_0x38ed86['uniqueid']),_0x6f8ce9);}};exports[_0x4ef0('0x1b')]=function(_0x17e001){try{utils['debug'](util[_0x4ef0('0x13')]('[%s][calls][newstate]',_0x17e001[_0x4ef0('0x8')]),_0x17e001);if(!_[_0x4ef0('0x1c')](channels[_0x17e001[_0x4ef0('0x8')]])&&_0x17e001['channelstate']==0x6){utils[_0x4ef0('0x6')](util[_0x4ef0('0x13')](_0x4ef0('0x1d'),_0x17e001[_0x4ef0('0x8')],_0x17e001[_0x4ef0('0x17')],_0x17e001[_0x4ef0('0x9')]));if(_[_0x4ef0('0x1c')](channels[_0x17e001[_0x4ef0('0x8')]][_0x4ef0('0x1e')])){channels[_0x17e001[_0x4ef0('0x8')]][_0x4ef0('0x1e')]=utils[_0x4ef0('0x19')]();}}else if(!_[_0x4ef0('0x1c')](channels[_0x17e001['linkedid']])&&_0x17e001[_0x4ef0('0x1f')]==0x6&&_0x17e001[_0x4ef0('0x17')]!='transfer'){utils['info'](util[_0x4ef0('0x13')](_0x4ef0('0x20'),_0x17e001['uniqueid'],_0x17e001['linkedid'],_0x17e001[_0x4ef0('0x17')],_0x17e001[_0x4ef0('0x9')]));channels[_0x17e001['linkedid']][_0x4ef0('0xc')]=_0x17e001[_0x4ef0('0xc')];channels[_0x17e001[_0x4ef0('0x21')]][_0x4ef0('0x22')]=_0x17e001[_0x4ef0('0x9')];if(_[_0x4ef0('0x1c')](channels[_0x17e001['linkedid']][_0x4ef0('0x23')])){channels[_0x17e001[_0x4ef0('0x21')]][_0x4ef0('0x23')]=utils[_0x4ef0('0x19')]();}channels[_0x17e001[_0x4ef0('0x21')]][_0x4ef0('0x24')]=dispositions[_[_0x4ef0('0x25')](_0x17e001[_0x4ef0('0x1f')])]||_0x4ef0('0x4');}}catch(_0x4b924e){utils[_0x4ef0('0x26')](util[_0x4ef0('0x13')](_0x4ef0('0x27'),_0x17e001[_0x4ef0('0x8')]),_0x4b924e);}};exports[_0x4ef0('0x28')]=function(_0x3263bd){try{if(!_[_0x4ef0('0x1c')](channels[_0x3263bd['uniqueid']])){utils['debug'](util['format']('[%s][calls][hangup]',_0x3263bd[_0x4ef0('0x8')]),_0x3263bd);if(_['isNil'](channels[_0x3263bd[_0x4ef0('0x8')]]['callerid'])){channels[_0x3263bd[_0x4ef0('0x8')]][_0x4ef0('0x29')]=_0x3263bd[_0x4ef0('0x2a')]+'\x20<'+_0x3263bd['calleridnum']+'>';}utils['info'](util[_0x4ef0('0x13')](_0x4ef0('0x2b'),_0x3263bd[_0x4ef0('0x8')],channels[_0x3263bd['uniqueid']][_0x4ef0('0x29')],_0x3263bd[_0x4ef0('0x2c')]));channels[_0x3263bd['uniqueid']]['endtime']=utils[_0x4ef0('0x19')]();channels[_0x3263bd['uniqueid']][_0x4ef0('0x2d')]=utils[_0x4ef0('0x2e')](channels[_0x3263bd[_0x4ef0('0x8')]]['endtime'],channels[_0x3263bd[_0x4ef0('0x8')]][_0x4ef0('0x2f')]);channels[_0x3263bd['uniqueid']][_0x4ef0('0x30')]=channels[_0x3263bd['uniqueid']][_0x4ef0('0x23')]?utils['diffTime'](channels[_0x3263bd[_0x4ef0('0x8')]][_0x4ef0('0x31')],channels[_0x3263bd[_0x4ef0('0x8')]][_0x4ef0('0x23')]):0x0;writeDB(channels[_0x3263bd[_0x4ef0('0x8')]]);}}catch(_0xbd650b){utils['error'](util[_0x4ef0('0x13')](_0x4ef0('0x32'),_0x3263bd[_0x4ef0('0x8')]),_0xbd650b);}};exports[_0x4ef0('0x33')]=function(_0xe4d59){try{if(!_[_0x4ef0('0x1c')](channels[_0xe4d59[_0x4ef0('0x34')]])){utils['debug'](util[_0x4ef0('0x13')](_0x4ef0('0x35'),_0xe4d59['origtransfereruniqueid']),_0xe4d59);if(channels[_0xe4d59[_0x4ef0('0x34')]]['channel']==_0xe4d59['transfereechannel']){utils[_0x4ef0('0x6')](util[_0x4ef0('0x13')](_0x4ef0('0x36'),_0xe4d59[_0x4ef0('0x37')],_0xe4d59['localtwolinkedid'],_0xe4d59[_0x4ef0('0x38')]));channels[_0xe4d59[_0x4ef0('0x34')]]['destinationchannel']=_0xe4d59[_0x4ef0('0x38')];channels[_0xe4d59[_0x4ef0('0x34')]][_0x4ef0('0x39')]=_0x4ef0('0x3a');}else if(channels[_0xe4d59[_0x4ef0('0x34')]][_0x4ef0('0x9')]=_0xe4d59[_0x4ef0('0x3b')]){utils[_0x4ef0('0x6')](util['format'](_0x4ef0('0x36'),_0xe4d59[_0x4ef0('0x37')],_0xe4d59[_0x4ef0('0x34')],_0xe4d59[_0x4ef0('0x3c')]));channels[_0xe4d59['localtwolinkedid']]['destinationchannel']=_0xe4d59[_0x4ef0('0x3c')];channels[_0xe4d59[_0x4ef0('0x34')]]['userfield']='_attended';}}}catch(_0xe02e25){utils['error'](util['format']('[%s][calls][attendedtransfer]',_0xe4d59[_0x4ef0('0x37')]),_0xe02e25);}};exports['musiconholdstart']=function(_0x55140e){try{if(!_['isNil'](channels[_0x55140e[_0x4ef0('0x8')]])){utils[_0x4ef0('0x12')](util[_0x4ef0('0x13')](_0x4ef0('0x3d'),_0x55140e[_0x4ef0('0x8')]),_0x55140e);channels[_0x55140e[_0x4ef0('0x8')]][_0x4ef0('0x3e')]=utils['now']();utils['info'](util[_0x4ef0('0x13')](_0x4ef0('0x3f'),_0x55140e[_0x4ef0('0x8')],channels[_0x55140e['uniqueid']][_0x4ef0('0x3e')]));}}catch(_0x3f752d){utils[_0x4ef0('0x26')](util[_0x4ef0('0x13')](_0x4ef0('0x3d'),_0x55140e['uniqueid']),_0x3f752d);}};exports[_0x4ef0('0x40')]=function(_0xeb2e95){try{if(!_[_0x4ef0('0x1c')](channels[_0xeb2e95[_0x4ef0('0x8')]])){utils[_0x4ef0('0x12')](util[_0x4ef0('0x13')](_0x4ef0('0x41'),_0xeb2e95[_0x4ef0('0x8')]),_0xeb2e95);if(!_[_0x4ef0('0x1c')](channels[_0xeb2e95[_0x4ef0('0x8')]][_0x4ef0('0x3e')])){channels[_0xeb2e95[_0x4ef0('0x8')]][_0x4ef0('0x42')]+=utils[_0x4ef0('0x2e')](utils['now'](),channels[_0xeb2e95['uniqueid']][_0x4ef0('0x3e')]);utils[_0x4ef0('0x6')](util[_0x4ef0('0x13')](_0x4ef0('0x43'),_0xeb2e95[_0x4ef0('0x8')],channels[_0xeb2e95[_0x4ef0('0x8')]]['mohtime']));delete channels[_0xeb2e95[_0x4ef0('0x8')]]['musiconholdstartAt'];}}}catch(_0x145500){utils['error'](util['format'](_0x4ef0('0x41'),_0xeb2e95['uniqueid']),_0x145500);}};exports[_0x4ef0('0x44')]=function(_0x1c1b53){try{if(!_[_0x4ef0('0x1c')](channels[_0x1c1b53[_0x4ef0('0x8')]])){utils[_0x4ef0('0x12')](util[_0x4ef0('0x13')](_0x4ef0('0x45'),_0x1c1b53['uniqueid']),_0x1c1b53);if(!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')]['xmd-originatecalleridnum'])){utils[_0x4ef0('0x6')](util['format'](_0x4ef0('0x47'),_0x1c1b53[_0x4ef0('0x8')],_0x1c1b53['value']));channels[_0x1c1b53[_0x4ef0('0x8')]][_0x4ef0('0x48')]=_0x1c1b53[_0x4ef0('0x49')];}if(!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')][_0x4ef0('0x4a')])){utils[_0x4ef0('0x6')](util[_0x4ef0('0x13')](_0x4ef0('0x4b'),_0x1c1b53[_0x4ef0('0x8')],_0x1c1b53[_0x4ef0('0x49')]));channels[_0x1c1b53[_0x4ef0('0x8')]][_0x4ef0('0x4c')]=_0x1c1b53[_0x4ef0('0x49')];channels[_0x1c1b53[_0x4ef0('0x8')]]['callerid']='\x22'+_0x1c1b53[_0x4ef0('0x49')]+_0x4ef0('0x4d')+_0x1c1b53[_0x4ef0('0x49')]+'>';}if(!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')]['xmd-callerid-preview'])||!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')][_0x4ef0('0x4e')])){utils['info'](util[_0x4ef0('0x13')](_0x4ef0('0x4f'),_0x1c1b53[_0x4ef0('0x8')],!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')][_0x4ef0('0x50')])?'xmd-callerid-preview':_0x4ef0('0x4e'),_0x1c1b53[_0x4ef0('0x49')]));channels[_0x1c1b53['uniqueid']][_0x4ef0('0x29')]=_0x1c1b53[_0x4ef0('0x49')];}if(!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')][_0x4ef0('0x51')])||!_['isNil'](_0x1c1b53['variable'][_0x4ef0('0x52')])){utils[_0x4ef0('0x6')](util[_0x4ef0('0x13')](_0x4ef0('0x4f'),_0x1c1b53[_0x4ef0('0x8')],!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')][_0x4ef0('0x51')])?_0x4ef0('0x51'):_0x4ef0('0x52'),_0x1c1b53['value']));channels[_0x1c1b53['uniqueid']][_0x4ef0('0x53')]=_0x4ef0('0x54');channels[_0x1c1b53[_0x4ef0('0x8')]][_0x4ef0('0x55')]=_0x1c1b53[_0x4ef0('0x49')];channels[_0x1c1b53[_0x4ef0('0x8')]][_0x4ef0('0x56')]=!![];}if(!_[_0x4ef0('0x1c')](_0x1c1b53['variable']['xmd-contactid'])){utils[_0x4ef0('0x6')](util['format'](_0x4ef0('0x57'),_0x1c1b53[_0x4ef0('0x8')],_0x1c1b53[_0x4ef0('0x49')]));channels[_0x1c1b53[_0x4ef0('0x8')]][_0x4ef0('0x58')]=_0x1c1b53[_0x4ef0('0x49')];}if(!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')][_0x4ef0('0x59')])){utils['info'](util[_0x4ef0('0x13')](_0x4ef0('0x5a'),_0x1c1b53[_0x4ef0('0x8')],_0x1c1b53[_0x4ef0('0x49')]));channels[_0x1c1b53['uniqueid']][_0x4ef0('0x5b')]=_0x1c1b53['value'];}if(!_[_0x4ef0('0x1c')](_0x1c1b53['variable'][_0x4ef0('0x5c')])){utils[_0x4ef0('0x6')](util[_0x4ef0('0x13')](_0x4ef0('0x5d'),_0x1c1b53[_0x4ef0('0x8')],_0x1c1b53[_0x4ef0('0x49')]));channels[_0x1c1b53[_0x4ef0('0x8')]][_0x4ef0('0x5e')]=_0x1c1b53['value'];}if(!_[_0x4ef0('0x1c')](_0x1c1b53[_0x4ef0('0x46')][_0x4ef0('0x5f')])){utils[_0x4ef0('0x6')](util['format'](_0x4ef0('0x60'),_0x1c1b53['uniqueid'],_0x1c1b53[_0x4ef0('0x49')]));channels[_0x1c1b53[_0x4ef0('0x8')]][_0x4ef0('0x5f')]=_0x1c1b53[_0x4ef0('0x49')];}}}catch(_0x44e835){utils['error'](util['format'](_0x4ef0('0x45'),_0x1c1b53[_0x4ef0('0x8')]),_0x44e835);}};exports[_0x4ef0('0x61')]=function(_0x3dc060){try{if(!_[_0x4ef0('0x1c')](channels[_0x3dc060[_0x4ef0('0x8')]])){utils[_0x4ef0('0x12')](util['format']('[%s][calls][newexten]',_0x3dc060[_0x4ef0('0x8')]),_0x3dc060);utils['info'](util['format']('[%s][calls][newexten]\x20application:%s\x20appdata:%s',_0x3dc060[_0x4ef0('0x8')],_0x3dc060[_0x4ef0('0x62')],_0x3dc060[_0x4ef0('0x63')]));if(_0x3dc060[_0x4ef0('0x62')][_0x4ef0('0x64')]()=='set'&&_[_0x4ef0('0x65')](_0x3dc060[_0x4ef0('0x63')][_0x4ef0('0x64')](),'cdr')){var _0x37bb58=_0x3dc060[_0x4ef0('0x63')][_0x4ef0('0x66')]('=');var _0x3ea408=_0x37bb58[0x0][_0x4ef0('0x67')](_0x37bb58[0x0][_0x4ef0('0x68')]('(')+0x1,_0x37bb58[0x0][_0x4ef0('0x68')](')'));var _0x55ce69=_0x37bb58[0x1];channels[_0x3dc060[_0x4ef0('0x8')]][_0x3ea408]=_0x55ce69;}if(!_['includes']([_0x4ef0('0x28'),'noop',_0x4ef0('0x69'),'set',_0x4ef0('0x6a')],_0x3dc060[_0x4ef0('0x62')][_0x4ef0('0x64')]())){channels[_0x3dc060[_0x4ef0('0x8')]]['lastapplication']=_0x3dc060['application'];channels[_0x3dc060[_0x4ef0('0x8')]][_0x4ef0('0x55')]=_0x3dc060[_0x4ef0('0x63')];}}}catch(_0x430b18){utils[_0x4ef0('0x26')](util[_0x4ef0('0x13')](_0x4ef0('0x6b'),_0x3dc060[_0x4ef0('0x8')]),_0x430b18);}};