Built motion from commit 013e4bb4.|2.6.18
[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 _0x39e3=['Queue','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','sipcallid','[%s][calls][varset]\x20variable:sipcallid\x20value:%s','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','toLowerCase','startsWith','appdata','cdr','split','substring','lastIndexOf','includes','noop','execif','gotoif','lodash','util','./utils','NO\x20ANSWER','FAILED','ANSWERED','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','uniqueid','channel','queue','interface','calleridnum','connectedlinenum','lastevent','accountcode','getUserByInternal','UserId','request','CreateVoiceCallReport','newchannel','format','[%s][calls][newchannel]','linkedid','OutgoingSpoolFailed','info','[%s][calls][newchannel]\x20context:%s\x20exten:%s','context','now','DOCUMENTATION','newstate','debug','isNil','[%s][calls][newstate]\x20context:%s\x20channel:%s','systemanswertime','channelstate','transfer','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','answertime','toNumber','error','[%s][calls][hangup]','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','duration','diffTime','billableseconds','localtwolinkedid','[%s][calls][attendedtransfer]','transfereechannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','origtransfereruniqueid','secondtransfererchannel','destinationchannel','userfield','_attended','origtransfererchannel','musiconholdstart','[%s][calls][musiconholdstart]','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','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','[%s][calls][varset]\x20variable:xmd-phone\x20value:%s','\x22\x20<','variable','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-callerid-preview','xmd-callerid','xmd-queue','xmcs-queue','lastapplication'];(function(_0x4d6554,_0x24a2bf){var _0xd9f05b=function(_0x679c5e){while(--_0x679c5e){_0x4d6554['push'](_0x4d6554['shift']());}};_0xd9f05b(++_0x24a2bf);}(_0x39e3,0x1ce));var _0x339e=function(_0x2e7c85,_0x3fed1c){_0x2e7c85=_0x2e7c85-0x0;var _0x425b1a=_0x39e3[_0x2e7c85];return _0x425b1a;};'use strict';var _=require(_0x339e('0x0'));var util=require(_0x339e('0x1'));var utils=require(_0x339e('0x2'));var dispositions=[_0x339e('0x3'),_0x339e('0x4'),_0x339e('0x4'),_0x339e('0x3'),'NO\x20ANSWER','NO\x20ANSWER',_0x339e('0x5'),'BUSY',_0x339e('0x4'),_0x339e('0x4'),_0x339e('0x4')];var channels={};function writeDB(_0x1f4985){utils['info'](util['format'](_0x339e('0x6'),_0x1f4985[_0x339e('0x7')],_0x1f4985[_0x339e('0x8')],_0x1f4985[_0x339e('0x9')],_0x1f4985['membername'],_0x1f4985[_0x339e('0xa')],_0x1f4985[_0x339e('0xb')],_0x1f4985[_0x339e('0xc')],_0x1f4985[_0x339e('0xd')]));if(_0x1f4985[_0x339e('0xe')]){utils[_0x339e('0xf')](_0x1f4985[_0x339e('0xe')])['then'](function(_0x3e7c63){if(_0x3e7c63){_0x1f4985[_0x339e('0x10')]=_0x3e7c63['id'];}utils[_0x339e('0x11')](_0x339e('0x12'),_0x1f4985);});}else{utils[_0x339e('0x11')](_0x339e('0x12'),_0x1f4985);}if(channels[_0x1f4985[_0x339e('0x7')]]){delete channels[_0x1f4985[_0x339e('0x7')]];}}exports[_0x339e('0x13')]=function(_0x4751ea){try{utils['debug'](util[_0x339e('0x14')](_0x339e('0x15'),_0x4751ea[_0x339e('0x7')]),_0x4751ea);if(_0x4751ea[_0x339e('0x7')]==_0x4751ea[_0x339e('0x16')]&&_0x4751ea[_0x339e('0x8')]!=_0x339e('0x17')){utils[_0x339e('0x18')](util['format'](_0x339e('0x19'),_0x4751ea[_0x339e('0x7')],_0x4751ea[_0x339e('0x1a')],_0x4751ea['exten']));channels[_0x4751ea[_0x339e('0x7')]]={'uniqueid':_0x4751ea[_0x339e('0x7')],'accountcode':_0x4751ea[_0x339e('0xe')],'source':_0x4751ea[_0x339e('0xb')],'destination':_0x4751ea['exten'],'destinationcontext':_0x4751ea[_0x339e('0x1a')],'channel':_0x4751ea[_0x339e('0x8')],'starttime':utils[_0x339e('0x1b')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x339e('0x3'),'amaflags':_0x339e('0x1c')};}}catch(_0x58484e){utils['error'](util[_0x339e('0x14')](_0x339e('0x15'),_0x4751ea[_0x339e('0x7')]),_0x58484e);}};exports[_0x339e('0x1d')]=function(_0x21a2e1){try{utils[_0x339e('0x1e')](util[_0x339e('0x14')]('[%s][calls][newstate]',_0x21a2e1[_0x339e('0x7')]),_0x21a2e1);if(!_[_0x339e('0x1f')](channels[_0x21a2e1[_0x339e('0x7')]])&&_0x21a2e1['channelstate']==0x6){utils['info'](util['format'](_0x339e('0x20'),_0x21a2e1[_0x339e('0x7')],_0x21a2e1[_0x339e('0x1a')],_0x21a2e1[_0x339e('0x8')]));if(_[_0x339e('0x1f')](channels[_0x21a2e1[_0x339e('0x7')]][_0x339e('0x21')])){channels[_0x21a2e1[_0x339e('0x7')]][_0x339e('0x21')]=utils[_0x339e('0x1b')]();}}else if(!_[_0x339e('0x1f')](channels[_0x21a2e1[_0x339e('0x16')]])&&_0x21a2e1[_0x339e('0x22')]==0x6&&_0x21a2e1['context']!=_0x339e('0x23')){utils['info'](util['format'](_0x339e('0x24'),_0x21a2e1[_0x339e('0x7')],_0x21a2e1['linkedid'],_0x21a2e1[_0x339e('0x1a')],_0x21a2e1['channel']));channels[_0x21a2e1[_0x339e('0x16')]][_0x339e('0xe')]=_0x21a2e1[_0x339e('0xe')];channels[_0x21a2e1['linkedid']]['destinationchannel']=_0x21a2e1[_0x339e('0x8')];if(_[_0x339e('0x1f')](channels[_0x21a2e1['linkedid']][_0x339e('0x25')])){channels[_0x21a2e1['linkedid']][_0x339e('0x25')]=utils[_0x339e('0x1b')]();}channels[_0x21a2e1[_0x339e('0x16')]]['disposition']=dispositions[_[_0x339e('0x26')](_0x21a2e1[_0x339e('0x22')])]||_0x339e('0x5');}}catch(_0x23d459){utils[_0x339e('0x27')](util[_0x339e('0x14')]('[%s][calls][newstate]',_0x21a2e1[_0x339e('0x7')]),_0x23d459);}};exports['hangup']=function(_0x5124c6){try{if(!_[_0x339e('0x1f')](channels[_0x5124c6[_0x339e('0x7')]])){utils['debug'](util[_0x339e('0x14')](_0x339e('0x28'),_0x5124c6[_0x339e('0x7')]),_0x5124c6);if(_['isNil'](channels[_0x5124c6['uniqueid']][_0x339e('0x29')])){channels[_0x5124c6['uniqueid']][_0x339e('0x29')]=_0x5124c6[_0x339e('0x2a')]+'\x20<'+_0x5124c6[_0x339e('0xb')]+'>';}utils['info'](util[_0x339e('0x14')](_0x339e('0x2b'),_0x5124c6[_0x339e('0x7')],channels[_0x5124c6[_0x339e('0x7')]][_0x339e('0x29')],_0x5124c6[_0x339e('0x2c')]));channels[_0x5124c6['uniqueid']][_0x339e('0x2d')]=utils[_0x339e('0x1b')]();channels[_0x5124c6[_0x339e('0x7')]][_0x339e('0x2e')]=utils[_0x339e('0x2f')](channels[_0x5124c6[_0x339e('0x7')]]['endtime'],channels[_0x5124c6[_0x339e('0x7')]]['starttime']);channels[_0x5124c6['uniqueid']][_0x339e('0x30')]=channels[_0x5124c6[_0x339e('0x7')]]['answertime']?utils[_0x339e('0x2f')](channels[_0x5124c6[_0x339e('0x7')]][_0x339e('0x2d')],channels[_0x5124c6['uniqueid']][_0x339e('0x25')]):0x0;writeDB(channels[_0x5124c6['uniqueid']]);}}catch(_0x9fe626){utils[_0x339e('0x27')](util[_0x339e('0x14')](_0x339e('0x28'),_0x5124c6[_0x339e('0x7')]),_0x9fe626);}};exports['attendedtransfer']=function(_0x2eb1ac){try{if(!_['isNil'](channels[_0x2eb1ac[_0x339e('0x31')]])){utils[_0x339e('0x1e')](util[_0x339e('0x14')](_0x339e('0x32'),_0x2eb1ac['origtransfereruniqueid']),_0x2eb1ac);if(channels[_0x2eb1ac[_0x339e('0x31')]][_0x339e('0x8')]==_0x2eb1ac[_0x339e('0x33')]){utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x34'),_0x2eb1ac[_0x339e('0x35')],_0x2eb1ac['localtwolinkedid'],_0x2eb1ac[_0x339e('0x36')]));channels[_0x2eb1ac['localtwolinkedid']][_0x339e('0x37')]=_0x2eb1ac[_0x339e('0x36')];channels[_0x2eb1ac[_0x339e('0x31')]][_0x339e('0x38')]=_0x339e('0x39');}else if(channels[_0x2eb1ac[_0x339e('0x31')]][_0x339e('0x8')]=_0x2eb1ac['transfertargetchannel']){utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x34'),_0x2eb1ac[_0x339e('0x35')],_0x2eb1ac['localtwolinkedid'],_0x2eb1ac['origtransfererchannel']));channels[_0x2eb1ac['localtwolinkedid']][_0x339e('0x37')]=_0x2eb1ac[_0x339e('0x3a')];channels[_0x2eb1ac[_0x339e('0x31')]][_0x339e('0x38')]=_0x339e('0x39');}}}catch(_0x3cef7){utils[_0x339e('0x27')](util[_0x339e('0x14')]('[%s][calls][attendedtransfer]',_0x2eb1ac['origtransfereruniqueid']),_0x3cef7);}};exports[_0x339e('0x3b')]=function(_0x1b7725){try{if(!_[_0x339e('0x1f')](channels[_0x1b7725[_0x339e('0x7')]])){utils['debug'](util[_0x339e('0x14')](_0x339e('0x3c'),_0x1b7725[_0x339e('0x7')]),_0x1b7725);channels[_0x1b7725['uniqueid']][_0x339e('0x3d')]=utils[_0x339e('0x1b')]();utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x3e'),_0x1b7725['uniqueid'],channels[_0x1b7725['uniqueid']][_0x339e('0x3d')]));}}catch(_0x1e4f25){utils[_0x339e('0x27')](util[_0x339e('0x14')](_0x339e('0x3c'),_0x1b7725[_0x339e('0x7')]),_0x1e4f25);}};exports[_0x339e('0x3f')]=function(_0x10bffa){try{if(!_[_0x339e('0x1f')](channels[_0x10bffa[_0x339e('0x7')]])){utils['debug'](util['format'](_0x339e('0x40'),_0x10bffa[_0x339e('0x7')]),_0x10bffa);if(!_[_0x339e('0x1f')](channels[_0x10bffa[_0x339e('0x7')]]['musiconholdstartAt'])){channels[_0x10bffa['uniqueid']][_0x339e('0x41')]+=utils[_0x339e('0x2f')](utils[_0x339e('0x1b')](),channels[_0x10bffa[_0x339e('0x7')]][_0x339e('0x3d')]);utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x42'),_0x10bffa[_0x339e('0x7')],channels[_0x10bffa['uniqueid']]['mohtime']));delete channels[_0x10bffa['uniqueid']][_0x339e('0x3d')];}}}catch(_0x644669){utils['error'](util[_0x339e('0x14')](_0x339e('0x40'),_0x10bffa[_0x339e('0x7')]),_0x644669);}};exports[_0x339e('0x43')]=function(_0x1ed628){try{if(!_['isNil'](channels[_0x1ed628[_0x339e('0x7')]])){utils[_0x339e('0x1e')](util[_0x339e('0x14')](_0x339e('0x44'),_0x1ed628[_0x339e('0x7')]),_0x1ed628);if(!_['isNil'](_0x1ed628['variable'][_0x339e('0x45')])){utils[_0x339e('0x18')](util['format'](_0x339e('0x46'),_0x1ed628['uniqueid'],_0x1ed628[_0x339e('0x47')]));channels[_0x1ed628['uniqueid']][_0x339e('0x48')]=_0x1ed628['value'];}if(!_['isNil'](_0x1ed628['variable'][_0x339e('0x49')])){utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x4a'),_0x1ed628[_0x339e('0x7')],_0x1ed628[_0x339e('0x47')]));channels[_0x1ed628['uniqueid']]['destination']=_0x1ed628['value'];channels[_0x1ed628[_0x339e('0x7')]][_0x339e('0x29')]='\x22'+_0x1ed628[_0x339e('0x47')]+_0x339e('0x4b')+_0x1ed628['value']+'>';}if(!_['isNil'](_0x1ed628[_0x339e('0x4c')]['xmd-callerid-preview'])||!_[_0x339e('0x1f')](_0x1ed628[_0x339e('0x4c')]['xmd-callerid'])){utils['info'](util[_0x339e('0x14')](_0x339e('0x4d'),_0x1ed628[_0x339e('0x7')],!_[_0x339e('0x1f')](_0x1ed628[_0x339e('0x4c')][_0x339e('0x4e')])?'xmd-callerid-preview':_0x339e('0x4f'),_0x1ed628[_0x339e('0x47')]));channels[_0x1ed628['uniqueid']]['callerid']=_0x1ed628[_0x339e('0x47')];}if(!_['isNil'](_0x1ed628['variable'][_0x339e('0x50')])||!_[_0x339e('0x1f')](_0x1ed628[_0x339e('0x4c')]['xmcs-queue'])){utils['info'](util[_0x339e('0x14')]('[%s][calls][varset]\x20variable:%s\x20value:%s',_0x1ed628['uniqueid'],!_['isNil'](_0x1ed628['variable'][_0x339e('0x50')])?'xmd-queue':_0x339e('0x51'),_0x1ed628[_0x339e('0x47')]));channels[_0x1ed628[_0x339e('0x7')]][_0x339e('0x52')]=_0x339e('0x53');channels[_0x1ed628[_0x339e('0x7')]][_0x339e('0x54')]=_0x1ed628[_0x339e('0x47')];channels[_0x1ed628[_0x339e('0x7')]][_0x339e('0x9')]=!![];}if(!_[_0x339e('0x1f')](_0x1ed628[_0x339e('0x4c')][_0x339e('0x55')])){utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x56'),_0x1ed628[_0x339e('0x7')],_0x1ed628[_0x339e('0x47')]));channels[_0x1ed628[_0x339e('0x7')]][_0x339e('0x57')]=_0x1ed628['value'];}if(!_[_0x339e('0x1f')](_0x1ed628[_0x339e('0x4c')][_0x339e('0x58')])){utils['info'](util[_0x339e('0x14')](_0x339e('0x59'),_0x1ed628['uniqueid'],_0x1ed628[_0x339e('0x47')]));channels[_0x1ed628[_0x339e('0x7')]]['type']=_0x1ed628[_0x339e('0x47')];}if(!_[_0x339e('0x1f')](_0x1ed628[_0x339e('0x4c')][_0x339e('0x5a')])){utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x5b'),_0x1ed628[_0x339e('0x7')],_0x1ed628[_0x339e('0x47')]));channels[_0x1ed628[_0x339e('0x7')]]['routeid']=_0x1ed628[_0x339e('0x47')];}if(!_[_0x339e('0x1f')](_0x1ed628[_0x339e('0x4c')][_0x339e('0x5c')])){utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x5d'),_0x1ed628['uniqueid'],_0x1ed628[_0x339e('0x47')]));channels[_0x1ed628[_0x339e('0x7')]][_0x339e('0x5c')]=_0x1ed628[_0x339e('0x47')];}}}catch(_0x27e677){utils['error'](util[_0x339e('0x14')]('[%s][calls][varset]',_0x1ed628[_0x339e('0x7')]),_0x27e677);}};exports[_0x339e('0x5e')]=function(_0xfea42){try{if(!_[_0x339e('0x1f')](channels[_0xfea42[_0x339e('0x7')]])){utils[_0x339e('0x1e')](util['format'](_0x339e('0x5f'),_0xfea42[_0x339e('0x7')]),_0xfea42);utils[_0x339e('0x18')](util[_0x339e('0x14')](_0x339e('0x60'),_0xfea42[_0x339e('0x7')],_0xfea42[_0x339e('0x61')],_0xfea42['appdata']));if(_0xfea42[_0x339e('0x61')][_0x339e('0x62')]()=='set'&&_[_0x339e('0x63')](_0xfea42[_0x339e('0x64')]['toLowerCase'](),_0x339e('0x65'))){var _0x46001b=_0xfea42['appdata'][_0x339e('0x66')]('=');var _0x1e00f9=_0x46001b[0x0][_0x339e('0x67')](_0x46001b[0x0][_0x339e('0x68')]('(')+0x1,_0x46001b[0x0]['lastIndexOf'](')'));var _0x42afb7=_0x46001b[0x1];channels[_0xfea42[_0x339e('0x7')]][_0x1e00f9]=_0x42afb7;}if(!_[_0x339e('0x69')](['hangup',_0x339e('0x6a'),_0x339e('0x6b'),'set',_0x339e('0x6c')],_0xfea42[_0x339e('0x61')][_0x339e('0x62')]())){channels[_0xfea42[_0x339e('0x7')]]['lastapplication']=_0xfea42['application'];channels[_0xfea42[_0x339e('0x7')]][_0x339e('0x54')]=_0xfea42[_0x339e('0x64')];}}}catch(_0x40fdd0){utils['error'](util[_0x339e('0x14')](_0x339e('0x5f'),_0xfea42[_0x339e('0x7')]),_0x40fdd0);}};