5515b227f4924d9795016db01c9195a350679843
[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 _0x1e3d=['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','xmcs-queue','lastapplication','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','routeid','sipcallid','[%s][calls][varset]','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','toLowerCase','set','startsWith','appdata','split','substring','lastIndexOf','includes','hangup','noop','execif','gotoif','application','util','NO\x20ANSWER','FAILED','ANSWERED','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','connectedlinenum','accountcode','getUserByInternal','then','UserId','request','CreateVoiceCallReport','newchannel','debug','[%s][calls][newchannel]','linkedid','OutgoingSpoolFailed','context','exten','now','error','newstate','[%s][calls][newstate]','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','isNil','systemanswertime','transfer','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','destinationchannel','answertime','toNumber','[%s][calls][hangup]','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','duration','diffTime','starttime','billableseconds','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','transfereechannel','secondtransfererchannel','userfield','origtransfererchannel','musiconholdstart','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','[%s][calls][musiconholdstart]','musiconholdstop','[%s][calls][musiconholdstop]'];(function(_0x3c9e30,_0x4db9f9){var _0xbddb66=function(_0x4c8ad1){while(--_0x4c8ad1){_0x3c9e30['push'](_0x3c9e30['shift']());}};_0xbddb66(++_0x4db9f9);}(_0x1e3d,0x171));var _0xd1e3=function(_0x4f9b18,_0x2cb5ca){_0x4f9b18=_0x4f9b18-0x0;var _0x29f20c=_0x1e3d[_0x4f9b18];return _0x29f20c;};'use strict';var _=require('lodash');var util=require(_0xd1e3('0x0'));var utils=require('./utils');var dispositions=[_0xd1e3('0x1'),_0xd1e3('0x2'),_0xd1e3('0x2'),_0xd1e3('0x1'),_0xd1e3('0x1'),'NO\x20ANSWER',_0xd1e3('0x3'),'BUSY',_0xd1e3('0x2'),_0xd1e3('0x2'),_0xd1e3('0x2')];var channels={};function writeDB(_0xfcdee6){utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')](_0xd1e3('0x6'),_0xfcdee6[_0xd1e3('0x7')],_0xfcdee6[_0xd1e3('0x8')],_0xfcdee6[_0xd1e3('0x9')],_0xfcdee6[_0xd1e3('0xa')],_0xfcdee6[_0xd1e3('0xb')],_0xfcdee6[_0xd1e3('0xc')],_0xfcdee6[_0xd1e3('0xd')],_0xfcdee6['lastevent']));if(_0xfcdee6[_0xd1e3('0xe')]){utils[_0xd1e3('0xf')](_0xfcdee6['accountcode'])[_0xd1e3('0x10')](function(_0x5004f7){if(_0x5004f7){_0xfcdee6[_0xd1e3('0x11')]=_0x5004f7['id'];}utils[_0xd1e3('0x12')](_0xd1e3('0x13'),_0xfcdee6);});}else{utils[_0xd1e3('0x12')](_0xd1e3('0x13'),_0xfcdee6);}if(channels[_0xfcdee6[_0xd1e3('0x7')]]){delete channels[_0xfcdee6['uniqueid']];}}exports[_0xd1e3('0x14')]=function(_0x3aa925){try{utils[_0xd1e3('0x15')](util[_0xd1e3('0x5')](_0xd1e3('0x16'),_0x3aa925[_0xd1e3('0x7')]),_0x3aa925);if(_0x3aa925[_0xd1e3('0x7')]==_0x3aa925[_0xd1e3('0x17')]&&_0x3aa925['channel']!=_0xd1e3('0x18')){utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')]('[%s][calls][newchannel]\x20context:%s\x20exten:%s',_0x3aa925[_0xd1e3('0x7')],_0x3aa925[_0xd1e3('0x19')],_0x3aa925[_0xd1e3('0x1a')]));channels[_0x3aa925[_0xd1e3('0x7')]]={'uniqueid':_0x3aa925[_0xd1e3('0x7')],'accountcode':_0x3aa925[_0xd1e3('0xe')],'source':_0x3aa925[_0xd1e3('0xc')],'destination':_0x3aa925['exten'],'destinationcontext':_0x3aa925['context'],'channel':_0x3aa925[_0xd1e3('0x8')],'starttime':utils[_0xd1e3('0x1b')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0xd1e3('0x1'),'amaflags':'DOCUMENTATION'};}}catch(_0x597989){utils[_0xd1e3('0x1c')](util[_0xd1e3('0x5')](_0xd1e3('0x16'),_0x3aa925['uniqueid']),_0x597989);}};exports[_0xd1e3('0x1d')]=function(_0x44b53e){try{utils[_0xd1e3('0x15')](util[_0xd1e3('0x5')](_0xd1e3('0x1e'),_0x44b53e[_0xd1e3('0x7')]),_0x44b53e);if(!_['isNil'](channels[_0x44b53e[_0xd1e3('0x7')]])&&_0x44b53e[_0xd1e3('0x1f')]==0x6){utils[_0xd1e3('0x4')](util['format'](_0xd1e3('0x20'),_0x44b53e['uniqueid'],_0x44b53e[_0xd1e3('0x19')],_0x44b53e['channel']));if(_[_0xd1e3('0x21')](channels[_0x44b53e[_0xd1e3('0x7')]][_0xd1e3('0x22')])){channels[_0x44b53e['uniqueid']]['systemanswertime']=utils[_0xd1e3('0x1b')]();}}else if(!_['isNil'](channels[_0x44b53e[_0xd1e3('0x17')]])&&_0x44b53e[_0xd1e3('0x1f')]==0x6&&_0x44b53e[_0xd1e3('0x19')]!=_0xd1e3('0x23')){utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')](_0xd1e3('0x24'),_0x44b53e[_0xd1e3('0x7')],_0x44b53e['linkedid'],_0x44b53e[_0xd1e3('0x19')],_0x44b53e[_0xd1e3('0x8')]));channels[_0x44b53e['linkedid']]['accountcode']=_0x44b53e['accountcode'];channels[_0x44b53e[_0xd1e3('0x17')]][_0xd1e3('0x25')]=_0x44b53e[_0xd1e3('0x8')];if(_[_0xd1e3('0x21')](channels[_0x44b53e[_0xd1e3('0x17')]][_0xd1e3('0x26')])){channels[_0x44b53e[_0xd1e3('0x17')]]['answertime']=utils['now']();}channels[_0x44b53e['linkedid']]['disposition']=dispositions[_[_0xd1e3('0x27')](_0x44b53e[_0xd1e3('0x1f')])]||'ANSWERED';}}catch(_0x359607){utils['error'](util[_0xd1e3('0x5')](_0xd1e3('0x1e'),_0x44b53e[_0xd1e3('0x7')]),_0x359607);}};exports['hangup']=function(_0x107f98){try{if(!_['isNil'](channels[_0x107f98[_0xd1e3('0x7')]])){utils[_0xd1e3('0x15')](util['format'](_0xd1e3('0x28'),_0x107f98[_0xd1e3('0x7')]),_0x107f98);if(_[_0xd1e3('0x21')](channels[_0x107f98[_0xd1e3('0x7')]][_0xd1e3('0x29')])){channels[_0x107f98['uniqueid']][_0xd1e3('0x29')]=_0x107f98[_0xd1e3('0x2a')]+'\x20<'+_0x107f98[_0xd1e3('0xc')]+'>';}utils['info'](util[_0xd1e3('0x5')](_0xd1e3('0x2b'),_0x107f98[_0xd1e3('0x7')],channels[_0x107f98[_0xd1e3('0x7')]][_0xd1e3('0x29')],_0x107f98[_0xd1e3('0x2c')]));channels[_0x107f98[_0xd1e3('0x7')]][_0xd1e3('0x2d')]=utils['now']();channels[_0x107f98['uniqueid']][_0xd1e3('0x2e')]=utils[_0xd1e3('0x2f')](channels[_0x107f98[_0xd1e3('0x7')]][_0xd1e3('0x2d')],channels[_0x107f98['uniqueid']][_0xd1e3('0x30')]);channels[_0x107f98[_0xd1e3('0x7')]][_0xd1e3('0x31')]=channels[_0x107f98['uniqueid']]['answertime']?utils['diffTime'](channels[_0x107f98['uniqueid']][_0xd1e3('0x2d')],channels[_0x107f98[_0xd1e3('0x7')]][_0xd1e3('0x26')]):0x0;writeDB(channels[_0x107f98[_0xd1e3('0x7')]]);}}catch(_0x3179e1){utils['error'](util['format']('[%s][calls][hangup]',_0x107f98[_0xd1e3('0x7')]),_0x3179e1);}};exports['attendedtransfer']=function(_0x561d17){try{if(!_[_0xd1e3('0x21')](channels[_0x561d17[_0xd1e3('0x32')]])){utils[_0xd1e3('0x15')](util[_0xd1e3('0x5')](_0xd1e3('0x33'),_0x561d17[_0xd1e3('0x34')]),_0x561d17);if(channels[_0x561d17[_0xd1e3('0x32')]]['channel']==_0x561d17[_0xd1e3('0x35')]){utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')]('[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s',_0x561d17[_0xd1e3('0x34')],_0x561d17[_0xd1e3('0x32')],_0x561d17[_0xd1e3('0x36')]));channels[_0x561d17[_0xd1e3('0x32')]][_0xd1e3('0x25')]=_0x561d17['secondtransfererchannel'];channels[_0x561d17[_0xd1e3('0x32')]][_0xd1e3('0x37')]='_attended';}else if(channels[_0x561d17[_0xd1e3('0x32')]][_0xd1e3('0x8')]=_0x561d17['transfertargetchannel']){utils['info'](util[_0xd1e3('0x5')]('[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s',_0x561d17[_0xd1e3('0x34')],_0x561d17[_0xd1e3('0x32')],_0x561d17[_0xd1e3('0x38')]));channels[_0x561d17[_0xd1e3('0x32')]][_0xd1e3('0x25')]=_0x561d17[_0xd1e3('0x38')];channels[_0x561d17[_0xd1e3('0x32')]][_0xd1e3('0x37')]='_attended';}}}catch(_0x5d8b34){utils[_0xd1e3('0x1c')](util[_0xd1e3('0x5')](_0xd1e3('0x33'),_0x561d17['origtransfereruniqueid']),_0x5d8b34);}};exports[_0xd1e3('0x39')]=function(_0x304ad0){try{if(!_['isNil'](channels[_0x304ad0['uniqueid']])){utils[_0xd1e3('0x15')](util['format']('[%s][calls][musiconholdstart]',_0x304ad0['uniqueid']),_0x304ad0);channels[_0x304ad0['uniqueid']][_0xd1e3('0x3a')]=utils[_0xd1e3('0x1b')]();utils['info'](util['format'](_0xd1e3('0x3b'),_0x304ad0[_0xd1e3('0x7')],channels[_0x304ad0['uniqueid']][_0xd1e3('0x3a')]));}}catch(_0x293b0d){utils[_0xd1e3('0x1c')](util['format'](_0xd1e3('0x3c'),_0x304ad0[_0xd1e3('0x7')]),_0x293b0d);}};exports[_0xd1e3('0x3d')]=function(_0x31a536){try{if(!_[_0xd1e3('0x21')](channels[_0x31a536['uniqueid']])){utils[_0xd1e3('0x15')](util[_0xd1e3('0x5')](_0xd1e3('0x3e'),_0x31a536[_0xd1e3('0x7')]),_0x31a536);if(!_[_0xd1e3('0x21')](channels[_0x31a536['uniqueid']][_0xd1e3('0x3a')])){channels[_0x31a536[_0xd1e3('0x7')]][_0xd1e3('0x3f')]+=utils[_0xd1e3('0x2f')](utils['now'](),channels[_0x31a536[_0xd1e3('0x7')]][_0xd1e3('0x3a')]);utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')](_0xd1e3('0x40'),_0x31a536['uniqueid'],channels[_0x31a536[_0xd1e3('0x7')]][_0xd1e3('0x3f')]));delete channels[_0x31a536[_0xd1e3('0x7')]][_0xd1e3('0x3a')];}}}catch(_0x57f1eb){utils[_0xd1e3('0x1c')](util['format'](_0xd1e3('0x3e'),_0x31a536[_0xd1e3('0x7')]),_0x57f1eb);}};exports[_0xd1e3('0x41')]=function(_0x196c5e){try{if(!_[_0xd1e3('0x21')](channels[_0x196c5e[_0xd1e3('0x7')]])){utils[_0xd1e3('0x15')](util[_0xd1e3('0x5')]('[%s][calls][varset]',_0x196c5e[_0xd1e3('0x7')]),_0x196c5e);if(!_['isNil'](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x43')])){utils['info'](util[_0xd1e3('0x5')](_0xd1e3('0x44'),_0x196c5e[_0xd1e3('0x7')],_0x196c5e[_0xd1e3('0x45')]));channels[_0x196c5e[_0xd1e3('0x7')]][_0xd1e3('0x46')]=_0x196c5e['value'];}if(!_[_0xd1e3('0x21')](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x47')])){utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')](_0xd1e3('0x48'),_0x196c5e[_0xd1e3('0x7')],_0x196c5e[_0xd1e3('0x45')]));channels[_0x196c5e['uniqueid']][_0xd1e3('0x49')]=_0x196c5e['value'];channels[_0x196c5e['uniqueid']][_0xd1e3('0x29')]='\x22'+_0x196c5e[_0xd1e3('0x45')]+_0xd1e3('0x4a')+_0x196c5e['value']+'>';}if(!_[_0xd1e3('0x21')](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x4b')])||!_['isNil'](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x4c')])){utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')](_0xd1e3('0x4d'),_0x196c5e[_0xd1e3('0x7')],!_['isNil'](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x4b')])?_0xd1e3('0x4b'):_0xd1e3('0x4c'),_0x196c5e['value']));channels[_0x196c5e['uniqueid']][_0xd1e3('0x29')]=_0x196c5e['value'];}if(!_[_0xd1e3('0x21')](_0x196c5e['variable']['xmd-queue'])||!_[_0xd1e3('0x21')](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x4e')])){utils['info'](util['format'](_0xd1e3('0x4d'),_0x196c5e[_0xd1e3('0x7')],!_['isNil'](_0x196c5e[_0xd1e3('0x42')]['xmd-queue'])?'xmd-queue':_0xd1e3('0x4e'),_0x196c5e[_0xd1e3('0x45')]));channels[_0x196c5e[_0xd1e3('0x7')]][_0xd1e3('0x4f')]=_0xd1e3('0x50');channels[_0x196c5e[_0xd1e3('0x7')]][_0xd1e3('0x51')]=_0x196c5e[_0xd1e3('0x45')];channels[_0x196c5e['uniqueid']][_0xd1e3('0x9')]=!![];}if(!_[_0xd1e3('0x21')](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x52')])){utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')](_0xd1e3('0x53'),_0x196c5e[_0xd1e3('0x7')],_0x196c5e[_0xd1e3('0x45')]));channels[_0x196c5e[_0xd1e3('0x7')]][_0xd1e3('0x54')]=_0x196c5e[_0xd1e3('0x45')];}if(!_[_0xd1e3('0x21')](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x55')])){utils[_0xd1e3('0x4')](util['format'](_0xd1e3('0x56'),_0x196c5e[_0xd1e3('0x7')],_0x196c5e[_0xd1e3('0x45')]));channels[_0x196c5e[_0xd1e3('0x7')]][_0xd1e3('0x57')]=_0x196c5e[_0xd1e3('0x45')];}if(!_['isNil'](_0x196c5e[_0xd1e3('0x42')][_0xd1e3('0x58')])){utils['info'](util[_0xd1e3('0x5')]('[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s',_0x196c5e['uniqueid'],_0x196c5e['value']));channels[_0x196c5e[_0xd1e3('0x7')]][_0xd1e3('0x59')]=_0x196c5e[_0xd1e3('0x45')];}if(!_['isNil'](_0x196c5e['variable'][_0xd1e3('0x5a')])){utils['info'](util[_0xd1e3('0x5')]('[%s][calls][varset]\x20variable:sipcallid\x20value:%s',_0x196c5e[_0xd1e3('0x7')],_0x196c5e[_0xd1e3('0x45')]));channels[_0x196c5e[_0xd1e3('0x7')]]['sipcallid']=_0x196c5e[_0xd1e3('0x45')];}}}catch(_0x47fce4){utils[_0xd1e3('0x1c')](util[_0xd1e3('0x5')](_0xd1e3('0x5b'),_0x196c5e['uniqueid']),_0x47fce4);}};exports[_0xd1e3('0x5c')]=function(_0x3c8a97){try{if(!_['isNil'](channels[_0x3c8a97['uniqueid']])){utils[_0xd1e3('0x15')](util['format'](_0xd1e3('0x5d'),_0x3c8a97[_0xd1e3('0x7')]),_0x3c8a97);utils[_0xd1e3('0x4')](util[_0xd1e3('0x5')](_0xd1e3('0x5e'),_0x3c8a97[_0xd1e3('0x7')],_0x3c8a97['application'],_0x3c8a97['appdata']));if(_0x3c8a97['application'][_0xd1e3('0x5f')]()==_0xd1e3('0x60')&&_[_0xd1e3('0x61')](_0x3c8a97[_0xd1e3('0x62')]['toLowerCase'](),'cdr')){var _0x42e9fe=_0x3c8a97[_0xd1e3('0x62')][_0xd1e3('0x63')]('=');var _0x19707d=_0x42e9fe[0x0][_0xd1e3('0x64')](_0x42e9fe[0x0][_0xd1e3('0x65')]('(')+0x1,_0x42e9fe[0x0][_0xd1e3('0x65')](')'));var _0x267637=_0x42e9fe[0x1];channels[_0x3c8a97[_0xd1e3('0x7')]][_0x19707d]=_0x267637;}if(!_[_0xd1e3('0x66')]([_0xd1e3('0x67'),_0xd1e3('0x68'),_0xd1e3('0x69'),_0xd1e3('0x60'),_0xd1e3('0x6a')],_0x3c8a97['application'][_0xd1e3('0x5f')]())){channels[_0x3c8a97[_0xd1e3('0x7')]][_0xd1e3('0x4f')]=_0x3c8a97[_0xd1e3('0x6b')];channels[_0x3c8a97[_0xd1e3('0x7')]][_0xd1e3('0x51')]=_0x3c8a97[_0xd1e3('0x62')];}}}catch(_0x335e16){utils[_0xd1e3('0x1c')](util[_0xd1e3('0x5')](_0xd1e3('0x5d'),_0x3c8a97[_0xd1e3('0x7')]),_0x335e16);}};