Built motion from commit 10af8726.|2.6.34
[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 _0x8541=['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','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s','sipcallid','[%s][calls][varset]','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','appdata','application','toLowerCase','startsWith','cdr','split','substring','lastIndexOf','includes','noop','execif','set','gotoif','lodash','util','./utils','FAILED','NO\x20ANSWER','ANSWERED','BUSY','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','queue','membername','calleridnum','connectedlinenum','accountcode','getUserByInternal','UserId','request','uniqueid','newchannel','debug','format','[%s][calls][newchannel]','linkedid','channel','info','[%s][calls][newchannel]\x20context:%s\x20exten:%s','context','exten','now','isNil','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','systemanswertime','transfer','disposition','error','[%s][calls][newstate]','hangup','[%s][calls][hangup]','callerid','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','duration','billableseconds','answertime','attendedtransfer','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','transfereechannel','destinationchannel','_attended','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','origtransfererchannel','userfield','[%s][calls][musiconholdstart]','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','[%s][calls][musiconholdstop]','mohtime','diffTime','[%s][calls][musiconholdstop]\x20mohtime:%s','varset','xmd-originatecalleridnum','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','value','source','variable','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'];(function(_0x262346,_0xfc5ef1){var _0x4d7205=function(_0x5cb1d2){while(--_0x5cb1d2){_0x262346['push'](_0x262346['shift']());}};_0x4d7205(++_0xfc5ef1);}(_0x8541,0x1c6));var _0x1854=function(_0x47c463,_0xeeb1d9){_0x47c463=_0x47c463-0x0;var _0x31dd29=_0x8541[_0x47c463];return _0x31dd29;};'use strict';var _=require(_0x1854('0x0'));var util=require(_0x1854('0x1'));var utils=require(_0x1854('0x2'));var dispositions=['NO\x20ANSWER','FAILED',_0x1854('0x3'),_0x1854('0x4'),_0x1854('0x4'),'NO\x20ANSWER',_0x1854('0x5'),_0x1854('0x6'),_0x1854('0x3'),_0x1854('0x3'),_0x1854('0x3')];var channels={};function writeDB(_0x4624a0){utils['info'](util['format'](_0x1854('0x7'),_0x4624a0['uniqueid'],_0x4624a0['channel'],_0x4624a0[_0x1854('0x8')],_0x4624a0[_0x1854('0x9')],_0x4624a0['interface'],_0x4624a0[_0x1854('0xa')],_0x4624a0[_0x1854('0xb')],_0x4624a0['lastevent']));if(_0x4624a0[_0x1854('0xc')]){utils[_0x1854('0xd')](_0x4624a0[_0x1854('0xc')])['then'](function(_0x37aca9){if(_0x37aca9){_0x4624a0[_0x1854('0xe')]=_0x37aca9['id'];}utils[_0x1854('0xf')]('CreateVoiceCallReport',_0x4624a0);});}else{utils[_0x1854('0xf')]('CreateVoiceCallReport',_0x4624a0);}if(channels[_0x4624a0[_0x1854('0x10')]]){delete channels[_0x4624a0[_0x1854('0x10')]];}}exports[_0x1854('0x11')]=function(_0x124119){try{utils[_0x1854('0x12')](util[_0x1854('0x13')](_0x1854('0x14'),_0x124119[_0x1854('0x10')]),_0x124119);if(_0x124119[_0x1854('0x10')]==_0x124119[_0x1854('0x15')]&&_0x124119[_0x1854('0x16')]!='OutgoingSpoolFailed'){utils[_0x1854('0x17')](util[_0x1854('0x13')](_0x1854('0x18'),_0x124119['uniqueid'],_0x124119[_0x1854('0x19')],_0x124119['exten']));channels[_0x124119[_0x1854('0x10')]]={'uniqueid':_0x124119[_0x1854('0x10')],'accountcode':_0x124119['accountcode'],'source':_0x124119['calleridnum'],'destination':_0x124119[_0x1854('0x1a')],'destinationcontext':_0x124119['context'],'channel':_0x124119['channel'],'starttime':utils[_0x1854('0x1b')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0x1854('0x4'),'amaflags':'DOCUMENTATION'};}}catch(_0x9e308c){utils['error'](util[_0x1854('0x13')](_0x1854('0x14'),_0x124119[_0x1854('0x10')]),_0x9e308c);}};exports['newstate']=function(_0x4f3511){try{utils['debug'](util[_0x1854('0x13')]('[%s][calls][newstate]',_0x4f3511[_0x1854('0x10')]),_0x4f3511);if(!_[_0x1854('0x1c')](channels[_0x4f3511[_0x1854('0x10')]])&&_0x4f3511[_0x1854('0x1d')]==0x6){utils[_0x1854('0x17')](util[_0x1854('0x13')](_0x1854('0x1e'),_0x4f3511[_0x1854('0x10')],_0x4f3511[_0x1854('0x19')],_0x4f3511['channel']));if(_['isNil'](channels[_0x4f3511[_0x1854('0x10')]][_0x1854('0x1f')])){channels[_0x4f3511[_0x1854('0x10')]][_0x1854('0x1f')]=utils[_0x1854('0x1b')]();}}else if(!_['isNil'](channels[_0x4f3511['linkedid']])&&_0x4f3511[_0x1854('0x1d')]==0x6&&_0x4f3511['context']!=_0x1854('0x20')){utils[_0x1854('0x17')](util[_0x1854('0x13')]('[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x4f3511['uniqueid'],_0x4f3511[_0x1854('0x15')],_0x4f3511[_0x1854('0x19')],_0x4f3511[_0x1854('0x16')]));channels[_0x4f3511[_0x1854('0x15')]][_0x1854('0xc')]=_0x4f3511[_0x1854('0xc')];channels[_0x4f3511[_0x1854('0x15')]]['destinationchannel']=_0x4f3511[_0x1854('0x16')];if(_[_0x1854('0x1c')](channels[_0x4f3511['linkedid']]['answertime'])){channels[_0x4f3511[_0x1854('0x15')]]['answertime']=utils['now']();}channels[_0x4f3511[_0x1854('0x15')]][_0x1854('0x21')]=dispositions[_['toNumber'](_0x4f3511[_0x1854('0x1d')])]||'ANSWERED';}}catch(_0x34daf6){utils[_0x1854('0x22')](util[_0x1854('0x13')](_0x1854('0x23'),_0x4f3511[_0x1854('0x10')]),_0x34daf6);}};exports[_0x1854('0x24')]=function(_0x135be1){try{if(!_[_0x1854('0x1c')](channels[_0x135be1[_0x1854('0x10')]])){utils[_0x1854('0x12')](util['format'](_0x1854('0x25'),_0x135be1[_0x1854('0x10')]),_0x135be1);if(_['isNil'](channels[_0x135be1[_0x1854('0x10')]][_0x1854('0x26')])){channels[_0x135be1[_0x1854('0x10')]][_0x1854('0x26')]=_0x135be1['calleridname']+'\x20<'+_0x135be1[_0x1854('0xa')]+'>';}utils[_0x1854('0x17')](util[_0x1854('0x13')](_0x1854('0x27'),_0x135be1[_0x1854('0x10')],channels[_0x135be1[_0x1854('0x10')]][_0x1854('0x26')],_0x135be1[_0x1854('0x28')]));channels[_0x135be1['uniqueid']][_0x1854('0x29')]=utils[_0x1854('0x1b')]();channels[_0x135be1['uniqueid']][_0x1854('0x2a')]=utils['diffTime'](channels[_0x135be1[_0x1854('0x10')]][_0x1854('0x29')],channels[_0x135be1[_0x1854('0x10')]]['starttime']);channels[_0x135be1[_0x1854('0x10')]][_0x1854('0x2b')]=channels[_0x135be1[_0x1854('0x10')]]['answertime']?utils['diffTime'](channels[_0x135be1[_0x1854('0x10')]][_0x1854('0x29')],channels[_0x135be1[_0x1854('0x10')]][_0x1854('0x2c')]):0x0;writeDB(channels[_0x135be1[_0x1854('0x10')]]);}}catch(_0x42487c){utils[_0x1854('0x22')](util[_0x1854('0x13')](_0x1854('0x25'),_0x135be1['uniqueid']),_0x42487c);}};exports[_0x1854('0x2d')]=function(_0x4ade86){try{if(!_['isNil'](channels[_0x4ade86[_0x1854('0x2e')]])){utils['debug'](util[_0x1854('0x13')](_0x1854('0x2f'),_0x4ade86[_0x1854('0x30')]),_0x4ade86);if(channels[_0x4ade86['localtwolinkedid']]['channel']==_0x4ade86[_0x1854('0x31')]){utils[_0x1854('0x17')](util[_0x1854('0x13')]('[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s',_0x4ade86[_0x1854('0x30')],_0x4ade86[_0x1854('0x2e')],_0x4ade86['secondtransfererchannel']));channels[_0x4ade86[_0x1854('0x2e')]][_0x1854('0x32')]=_0x4ade86['secondtransfererchannel'];channels[_0x4ade86[_0x1854('0x2e')]]['userfield']=_0x1854('0x33');}else if(channels[_0x4ade86[_0x1854('0x2e')]]['channel']=_0x4ade86['transfertargetchannel']){utils[_0x1854('0x17')](util[_0x1854('0x13')](_0x1854('0x34'),_0x4ade86['origtransfereruniqueid'],_0x4ade86[_0x1854('0x2e')],_0x4ade86['origtransfererchannel']));channels[_0x4ade86['localtwolinkedid']]['destinationchannel']=_0x4ade86[_0x1854('0x35')];channels[_0x4ade86['localtwolinkedid']][_0x1854('0x36')]=_0x1854('0x33');}}}catch(_0x2a9e08){utils[_0x1854('0x22')](util[_0x1854('0x13')](_0x1854('0x2f'),_0x4ade86[_0x1854('0x30')]),_0x2a9e08);}};exports['musiconholdstart']=function(_0x74b5ef){try{if(!_['isNil'](channels[_0x74b5ef[_0x1854('0x10')]])){utils['debug'](util[_0x1854('0x13')](_0x1854('0x37'),_0x74b5ef['uniqueid']),_0x74b5ef);channels[_0x74b5ef[_0x1854('0x10')]][_0x1854('0x38')]=utils[_0x1854('0x1b')]();utils['info'](util[_0x1854('0x13')](_0x1854('0x39'),_0x74b5ef[_0x1854('0x10')],channels[_0x74b5ef[_0x1854('0x10')]][_0x1854('0x38')]));}}catch(_0x370711){utils[_0x1854('0x22')](util[_0x1854('0x13')](_0x1854('0x37'),_0x74b5ef[_0x1854('0x10')]),_0x370711);}};exports['musiconholdstop']=function(_0xc54f75){try{if(!_[_0x1854('0x1c')](channels[_0xc54f75['uniqueid']])){utils[_0x1854('0x12')](util[_0x1854('0x13')](_0x1854('0x3a'),_0xc54f75[_0x1854('0x10')]),_0xc54f75);if(!_[_0x1854('0x1c')](channels[_0xc54f75['uniqueid']][_0x1854('0x38')])){channels[_0xc54f75[_0x1854('0x10')]][_0x1854('0x3b')]+=utils[_0x1854('0x3c')](utils[_0x1854('0x1b')](),channels[_0xc54f75[_0x1854('0x10')]]['musiconholdstartAt']);utils['info'](util[_0x1854('0x13')](_0x1854('0x3d'),_0xc54f75[_0x1854('0x10')],channels[_0xc54f75[_0x1854('0x10')]][_0x1854('0x3b')]));delete channels[_0xc54f75[_0x1854('0x10')]][_0x1854('0x38')];}}}catch(_0x2b1eb2){utils[_0x1854('0x22')](util[_0x1854('0x13')](_0x1854('0x3a'),_0xc54f75['uniqueid']),_0x2b1eb2);}};exports[_0x1854('0x3e')]=function(_0x5e2abb){try{if(!_[_0x1854('0x1c')](channels[_0x5e2abb[_0x1854('0x10')]])){utils['debug'](util[_0x1854('0x13')]('[%s][calls][varset]',_0x5e2abb[_0x1854('0x10')]),_0x5e2abb);if(!_[_0x1854('0x1c')](_0x5e2abb['variable'][_0x1854('0x3f')])){utils[_0x1854('0x17')](util['format'](_0x1854('0x40'),_0x5e2abb[_0x1854('0x10')],_0x5e2abb[_0x1854('0x41')]));channels[_0x5e2abb[_0x1854('0x10')]][_0x1854('0x42')]=_0x5e2abb[_0x1854('0x41')];}if(!_['isNil'](_0x5e2abb[_0x1854('0x43')][_0x1854('0x44')])){utils[_0x1854('0x17')](util['format'](_0x1854('0x45'),_0x5e2abb[_0x1854('0x10')],_0x5e2abb[_0x1854('0x41')]));channels[_0x5e2abb[_0x1854('0x10')]][_0x1854('0x46')]=_0x5e2abb[_0x1854('0x41')];channels[_0x5e2abb[_0x1854('0x10')]][_0x1854('0x26')]='\x22'+_0x5e2abb[_0x1854('0x41')]+_0x1854('0x47')+_0x5e2abb[_0x1854('0x41')]+'>';}if(!_[_0x1854('0x1c')](_0x5e2abb[_0x1854('0x43')]['xmd-callerid-preview'])||!_[_0x1854('0x1c')](_0x5e2abb[_0x1854('0x43')][_0x1854('0x48')])){utils['info'](util[_0x1854('0x13')](_0x1854('0x49'),_0x5e2abb['uniqueid'],!_[_0x1854('0x1c')](_0x5e2abb[_0x1854('0x43')][_0x1854('0x4a')])?_0x1854('0x4a'):_0x1854('0x48'),_0x5e2abb['value']));channels[_0x5e2abb['uniqueid']]['callerid']=_0x5e2abb[_0x1854('0x41')];}if(!_[_0x1854('0x1c')](_0x5e2abb['variable'][_0x1854('0x4b')])||!_[_0x1854('0x1c')](_0x5e2abb[_0x1854('0x43')][_0x1854('0x4c')])){utils[_0x1854('0x17')](util[_0x1854('0x13')](_0x1854('0x49'),_0x5e2abb[_0x1854('0x10')],!_[_0x1854('0x1c')](_0x5e2abb[_0x1854('0x43')][_0x1854('0x4b')])?_0x1854('0x4b'):_0x1854('0x4c'),_0x5e2abb[_0x1854('0x41')]));channels[_0x5e2abb[_0x1854('0x10')]][_0x1854('0x4d')]=_0x1854('0x4e');channels[_0x5e2abb['uniqueid']][_0x1854('0x4f')]=_0x5e2abb[_0x1854('0x41')];channels[_0x5e2abb[_0x1854('0x10')]]['queue']=!![];}if(!_[_0x1854('0x1c')](_0x5e2abb[_0x1854('0x43')][_0x1854('0x50')])){utils['info'](util['format'](_0x1854('0x51'),_0x5e2abb[_0x1854('0x10')],_0x5e2abb[_0x1854('0x41')]));channels[_0x5e2abb[_0x1854('0x10')]][_0x1854('0x52')]=_0x5e2abb[_0x1854('0x41')];}if(!_[_0x1854('0x1c')](_0x5e2abb[_0x1854('0x43')][_0x1854('0x53')])){utils[_0x1854('0x17')](util[_0x1854('0x13')](_0x1854('0x54'),_0x5e2abb[_0x1854('0x10')],_0x5e2abb[_0x1854('0x41')]));channels[_0x5e2abb[_0x1854('0x10')]][_0x1854('0x55')]=_0x5e2abb[_0x1854('0x41')];}if(!_[_0x1854('0x1c')](_0x5e2abb[_0x1854('0x43')][_0x1854('0x56')])){utils['info'](util[_0x1854('0x13')](_0x1854('0x57'),_0x5e2abb[_0x1854('0x10')],_0x5e2abb[_0x1854('0x41')]));channels[_0x5e2abb[_0x1854('0x10')]]['routeid']=_0x5e2abb['value'];}if(!_['isNil'](_0x5e2abb[_0x1854('0x43')][_0x1854('0x58')])){utils[_0x1854('0x17')](util['format']('[%s][calls][varset]\x20variable:sipcallid\x20value:%s',_0x5e2abb[_0x1854('0x10')],_0x5e2abb['value']));channels[_0x5e2abb[_0x1854('0x10')]][_0x1854('0x58')]=_0x5e2abb[_0x1854('0x41')];}}}catch(_0xd08fbc){utils[_0x1854('0x22')](util['format'](_0x1854('0x59'),_0x5e2abb[_0x1854('0x10')]),_0xd08fbc);}};exports[_0x1854('0x5a')]=function(_0xf9736b){try{if(!_['isNil'](channels[_0xf9736b[_0x1854('0x10')]])){utils[_0x1854('0x12')](util['format'](_0x1854('0x5b'),_0xf9736b['uniqueid']),_0xf9736b);utils['info'](util[_0x1854('0x13')](_0x1854('0x5c'),_0xf9736b['uniqueid'],_0xf9736b['application'],_0xf9736b[_0x1854('0x5d')]));if(_0xf9736b[_0x1854('0x5e')][_0x1854('0x5f')]()=='set'&&_[_0x1854('0x60')](_0xf9736b[_0x1854('0x5d')][_0x1854('0x5f')](),_0x1854('0x61'))){var _0x40d467=_0xf9736b[_0x1854('0x5d')][_0x1854('0x62')]('=');var _0x1ebd9a=_0x40d467[0x0][_0x1854('0x63')](_0x40d467[0x0][_0x1854('0x64')]('(')+0x1,_0x40d467[0x0][_0x1854('0x64')](')'));var _0xab8a3c=_0x40d467[0x1];channels[_0xf9736b[_0x1854('0x10')]][_0x1ebd9a]=_0xab8a3c;}if(!_[_0x1854('0x65')]([_0x1854('0x24'),_0x1854('0x66'),_0x1854('0x67'),_0x1854('0x68'),_0x1854('0x69')],_0xf9736b['application'][_0x1854('0x5f')]())){channels[_0xf9736b[_0x1854('0x10')]]['lastapplication']=_0xf9736b[_0x1854('0x5e')];channels[_0xf9736b[_0x1854('0x10')]][_0x1854('0x4f')]=_0xf9736b['appdata'];}}}catch(_0x5eeb38){utils[_0x1854('0x22')](util[_0x1854('0x13')](_0x1854('0x5b'),_0xf9736b[_0x1854('0x10')]),_0x5eeb38);}};