Built motion from commit e02f907f.|2.6.14
[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 _0xd48e=['[%s][calls][musiconholdstop]','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','varset','variable','xmd-originatecalleridnum','source','value','xmd-phone','destination','xmd-callerid-preview','xmd-callerid','[%s][calls][varset]\x20variable:%s\x20value:%s','xmd-queue','xmcs-queue','lastapplication','Queue','lastdata','xmd-contactid','[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s','ContactId','xmd-cdrtype','routeid','sipcallid','[%s][calls][varset]\x20variable:sipcallid\x20value:%s','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','appdata','set','startsWith','toLowerCase','cdr','split','substring','hangup','execif','gotoif','util','./utils','./transfers.controller','NO\x20ANSWER','FAILED','BUSY','uniqueid','blinds','format','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','queue','membername','interface','calleridnum','connectedlinenum','lastevent','accountcode','getUserByInternal','then','UserId','request','recording','newchannel','debug','[%s][calls][newchannel]','channel','OutgoingSpoolFailed','info','context','exten','now','DOCUMENTATION','newstate','[%s][calls][newstate]','isNil','channelstate','systemanswertime','linkedid','transfer','destinationchannel','answertime','disposition','toNumber','ANSWERED','error','[%s][calls][hangup]','callerid','calleridname','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','diffTime','endtime','starttime','billableseconds','attendedtransfer','localtwolinkedid','[%s][calls][attendedtransfer]','origtransfereruniqueid','transfereechannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','secondtransfererchannel','_attended','transfertargetchannel','origtransfererchannel','userfield','musiconholdstart','[%s][calls][musiconholdstart]','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','musiconholdstartAt'];(function(_0xb76aa,_0x5b09f4){var _0x5c02d0=function(_0x224c48){while(--_0x224c48){_0xb76aa['push'](_0xb76aa['shift']());}};_0x5c02d0(++_0x5b09f4);}(_0xd48e,0x93));var _0xed48=function(_0x3c8e9a,_0x384306){_0x3c8e9a=_0x3c8e9a-0x0;var _0x2d4c57=_0xd48e[_0x3c8e9a];return _0x2d4c57;};'use strict';var _=require('lodash');var util=require(_0xed48('0x0'));var utils=require(_0xed48('0x1'));var transfers=require(_0xed48('0x2'));var dispositions=[_0xed48('0x3'),_0xed48('0x4'),'FAILED',_0xed48('0x3'),_0xed48('0x3'),_0xed48('0x3'),'ANSWERED',_0xed48('0x5'),_0xed48('0x4'),_0xed48('0x4'),'FAILED'];var channels={};function writeDB(_0x2cc522){var _0x1c9299;if(transfers['blinds'][_0x2cc522['uniqueid']]){_0x1c9299=_0x2cc522['uniqueid'];_0x2cc522[_0xed48('0x6')]=transfers[_0xed48('0x7')][_0x2cc522[_0xed48('0x6')]]['transfereeuniqueid'];}utils['info'](util[_0xed48('0x8')](_0xed48('0x9'),_0x2cc522[_0xed48('0x6')],_0x2cc522['channel'],_0x2cc522[_0xed48('0xa')],_0x2cc522[_0xed48('0xb')],_0x2cc522[_0xed48('0xc')],_0x2cc522[_0xed48('0xd')],_0x2cc522[_0xed48('0xe')],_0x2cc522[_0xed48('0xf')]));if(_0x2cc522[_0xed48('0x10')]){utils[_0xed48('0x11')](_0x2cc522[_0xed48('0x10')])[_0xed48('0x12')](function(_0x408ce8){if(_0x408ce8){_0x2cc522[_0xed48('0x13')]=_0x408ce8['id'];}utils[_0xed48('0x14')]('CreateVoiceCallReport',_0x2cc522);});}else{utils[_0xed48('0x14')]('CreateVoiceCallReport',_0x2cc522);}if(channels[_0x2cc522[_0xed48('0x6')]]){delete channels[_0x2cc522['uniqueid']];}else if(_0x1c9299&&channels[_0x1c9299]){if(!transfers['blinds'][_0x1c9299][_0xed48('0x15')])delete transfers[_0xed48('0x7')][_0x1c9299];delete channels[_0x1c9299];}}exports[_0xed48('0x16')]=function(_0x4cb521){try{utils[_0xed48('0x17')](util['format'](_0xed48('0x18'),_0x4cb521['uniqueid']),_0x4cb521);if(_0x4cb521[_0xed48('0x6')]==_0x4cb521['linkedid']&&_0x4cb521[_0xed48('0x19')]!=_0xed48('0x1a')){utils[_0xed48('0x1b')](util['format']('[%s][calls][newchannel]\x20context:%s\x20exten:%s',_0x4cb521[_0xed48('0x6')],_0x4cb521[_0xed48('0x1c')],_0x4cb521[_0xed48('0x1d')]));channels[_0x4cb521['uniqueid']]={'uniqueid':_0x4cb521[_0xed48('0x6')],'accountcode':_0x4cb521[_0xed48('0x10')],'source':_0x4cb521[_0xed48('0xd')],'destination':_0x4cb521['exten'],'destinationcontext':_0x4cb521[_0xed48('0x1c')],'channel':_0x4cb521[_0xed48('0x19')],'starttime':utils[_0xed48('0x1e')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':_0xed48('0x3'),'amaflags':_0xed48('0x1f')};}}catch(_0x17a39b){utils['error'](util[_0xed48('0x8')]('[%s][calls][newchannel]',_0x4cb521[_0xed48('0x6')]),_0x17a39b);}};exports[_0xed48('0x20')]=function(_0x14e642){try{utils['debug'](util['format'](_0xed48('0x21'),_0x14e642[_0xed48('0x6')]),_0x14e642);if(!_[_0xed48('0x22')](channels[_0x14e642[_0xed48('0x6')]])&&_0x14e642[_0xed48('0x23')]==0x6){utils[_0xed48('0x1b')](util[_0xed48('0x8')]('[%s][calls][newstate]\x20context:%s\x20channel:%s',_0x14e642[_0xed48('0x6')],_0x14e642[_0xed48('0x1c')],_0x14e642[_0xed48('0x19')]));if(_['isNil'](channels[_0x14e642[_0xed48('0x6')]][_0xed48('0x24')])){channels[_0x14e642['uniqueid']][_0xed48('0x24')]=utils['now']();}}else if(!_['isNil'](channels[_0x14e642[_0xed48('0x25')]])&&_0x14e642['channelstate']==0x6&&_0x14e642['context']!=_0xed48('0x26')){utils[_0xed48('0x1b')](util[_0xed48('0x8')]('[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x14e642[_0xed48('0x6')],_0x14e642[_0xed48('0x25')],_0x14e642[_0xed48('0x1c')],_0x14e642[_0xed48('0x19')]));channels[_0x14e642['linkedid']]['accountcode']=_0x14e642[_0xed48('0x10')];channels[_0x14e642['linkedid']][_0xed48('0x27')]=_0x14e642[_0xed48('0x19')];if(_[_0xed48('0x22')](channels[_0x14e642[_0xed48('0x25')]]['answertime'])){channels[_0x14e642['linkedid']][_0xed48('0x28')]=utils[_0xed48('0x1e')]();}channels[_0x14e642[_0xed48('0x25')]][_0xed48('0x29')]=dispositions[_[_0xed48('0x2a')](_0x14e642[_0xed48('0x23')])]||_0xed48('0x2b');}}catch(_0x3ce130){utils[_0xed48('0x2c')](util[_0xed48('0x8')](_0xed48('0x21'),_0x14e642[_0xed48('0x6')]),_0x3ce130);}};exports['hangup']=function(_0xdd9e08){try{if(!_[_0xed48('0x22')](channels[_0xdd9e08[_0xed48('0x6')]])){utils[_0xed48('0x17')](util[_0xed48('0x8')](_0xed48('0x2d'),_0xdd9e08[_0xed48('0x6')]),_0xdd9e08);if(_[_0xed48('0x22')](channels[_0xdd9e08[_0xed48('0x6')]][_0xed48('0x2e')])){channels[_0xdd9e08['uniqueid']][_0xed48('0x2e')]=_0xdd9e08[_0xed48('0x2f')]+'\x20<'+_0xdd9e08[_0xed48('0xd')]+'>';}utils[_0xed48('0x1b')](util['format'](_0xed48('0x30'),_0xdd9e08[_0xed48('0x6')],channels[_0xdd9e08['uniqueid']][_0xed48('0x2e')],_0xdd9e08[_0xed48('0x31')]));channels[_0xdd9e08[_0xed48('0x6')]]['endtime']=utils['now']();channels[_0xdd9e08[_0xed48('0x6')]]['duration']=utils[_0xed48('0x32')](channels[_0xdd9e08[_0xed48('0x6')]][_0xed48('0x33')],channels[_0xdd9e08[_0xed48('0x6')]][_0xed48('0x34')]);channels[_0xdd9e08[_0xed48('0x6')]][_0xed48('0x35')]=channels[_0xdd9e08[_0xed48('0x6')]][_0xed48('0x28')]?utils['diffTime'](channels[_0xdd9e08[_0xed48('0x6')]][_0xed48('0x33')],channels[_0xdd9e08[_0xed48('0x6')]][_0xed48('0x28')]):0x0;writeDB(channels[_0xdd9e08[_0xed48('0x6')]]);}}catch(_0x5b75b7){utils[_0xed48('0x2c')](util[_0xed48('0x8')](_0xed48('0x2d'),_0xdd9e08[_0xed48('0x6')]),_0x5b75b7);}};exports[_0xed48('0x36')]=function(_0x2563c8){try{if(!_[_0xed48('0x22')](channels[_0x2563c8[_0xed48('0x37')]])){utils[_0xed48('0x17')](util[_0xed48('0x8')](_0xed48('0x38'),_0x2563c8[_0xed48('0x39')]),_0x2563c8);if(channels[_0x2563c8[_0xed48('0x37')]][_0xed48('0x19')]==_0x2563c8[_0xed48('0x3a')]){utils[_0xed48('0x1b')](util[_0xed48('0x8')](_0xed48('0x3b'),_0x2563c8['origtransfereruniqueid'],_0x2563c8[_0xed48('0x37')],_0x2563c8[_0xed48('0x3c')]));channels[_0x2563c8[_0xed48('0x37')]][_0xed48('0x27')]=_0x2563c8[_0xed48('0x3c')];channels[_0x2563c8[_0xed48('0x37')]]['userfield']=_0xed48('0x3d');}else if(channels[_0x2563c8['localtwolinkedid']][_0xed48('0x19')]=_0x2563c8[_0xed48('0x3e')]){utils['info'](util['format'](_0xed48('0x3b'),_0x2563c8['origtransfereruniqueid'],_0x2563c8[_0xed48('0x37')],_0x2563c8['origtransfererchannel']));channels[_0x2563c8['localtwolinkedid']]['destinationchannel']=_0x2563c8[_0xed48('0x3f')];channels[_0x2563c8[_0xed48('0x37')]][_0xed48('0x40')]=_0xed48('0x3d');}}}catch(_0x283ab1){utils[_0xed48('0x2c')](util['format']('[%s][calls][attendedtransfer]',_0x2563c8[_0xed48('0x39')]),_0x283ab1);}};exports[_0xed48('0x41')]=function(_0xbab9c6){try{if(!_[_0xed48('0x22')](channels[_0xbab9c6[_0xed48('0x6')]])){utils[_0xed48('0x17')](util['format'](_0xed48('0x42'),_0xbab9c6['uniqueid']),_0xbab9c6);channels[_0xbab9c6['uniqueid']]['musiconholdstartAt']=utils[_0xed48('0x1e')]();utils[_0xed48('0x1b')](util[_0xed48('0x8')](_0xed48('0x43'),_0xbab9c6[_0xed48('0x6')],channels[_0xbab9c6[_0xed48('0x6')]][_0xed48('0x44')]));}}catch(_0x28924b){utils[_0xed48('0x2c')](util[_0xed48('0x8')](_0xed48('0x42'),_0xbab9c6[_0xed48('0x6')]),_0x28924b);}};exports['musiconholdstop']=function(_0x3f7deb){try{if(!_[_0xed48('0x22')](channels[_0x3f7deb[_0xed48('0x6')]])){utils[_0xed48('0x17')](util[_0xed48('0x8')](_0xed48('0x45'),_0x3f7deb[_0xed48('0x6')]),_0x3f7deb);if(!_[_0xed48('0x22')](channels[_0x3f7deb[_0xed48('0x6')]][_0xed48('0x44')])){channels[_0x3f7deb[_0xed48('0x6')]][_0xed48('0x46')]+=utils[_0xed48('0x32')](utils[_0xed48('0x1e')](),channels[_0x3f7deb['uniqueid']]['musiconholdstartAt']);utils['info'](util[_0xed48('0x8')](_0xed48('0x47'),_0x3f7deb[_0xed48('0x6')],channels[_0x3f7deb[_0xed48('0x6')]][_0xed48('0x46')]));delete channels[_0x3f7deb['uniqueid']]['musiconholdstartAt'];}}}catch(_0xbef0b0){utils[_0xed48('0x2c')](util[_0xed48('0x8')]('[%s][calls][musiconholdstop]',_0x3f7deb[_0xed48('0x6')]),_0xbef0b0);}};exports[_0xed48('0x48')]=function(_0x3f1943){try{if(!_[_0xed48('0x22')](channels[_0x3f1943[_0xed48('0x6')]])){utils['debug'](util[_0xed48('0x8')]('[%s][calls][varset]',_0x3f1943[_0xed48('0x6')]),_0x3f1943);if(!_[_0xed48('0x22')](_0x3f1943[_0xed48('0x49')][_0xed48('0x4a')])){utils[_0xed48('0x1b')](util[_0xed48('0x8')]('[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s',_0x3f1943[_0xed48('0x6')],_0x3f1943['value']));channels[_0x3f1943[_0xed48('0x6')]][_0xed48('0x4b')]=_0x3f1943[_0xed48('0x4c')];}if(!_['isNil'](_0x3f1943[_0xed48('0x49')][_0xed48('0x4d')])){utils['info'](util[_0xed48('0x8')]('[%s][calls][varset]\x20variable:xmd-phone\x20value:%s',_0x3f1943[_0xed48('0x6')],_0x3f1943['value']));channels[_0x3f1943[_0xed48('0x6')]][_0xed48('0x4e')]=_0x3f1943[_0xed48('0x4c')];channels[_0x3f1943[_0xed48('0x6')]]['callerid']='\x22'+_0x3f1943[_0xed48('0x4c')]+'\x22\x20<'+_0x3f1943[_0xed48('0x4c')]+'>';}if(!_[_0xed48('0x22')](_0x3f1943[_0xed48('0x49')][_0xed48('0x4f')])||!_[_0xed48('0x22')](_0x3f1943[_0xed48('0x49')][_0xed48('0x50')])){utils[_0xed48('0x1b')](util['format'](_0xed48('0x51'),_0x3f1943['uniqueid'],!_[_0xed48('0x22')](_0x3f1943['variable'][_0xed48('0x4f')])?_0xed48('0x4f'):_0xed48('0x50'),_0x3f1943[_0xed48('0x4c')]));channels[_0x3f1943[_0xed48('0x6')]][_0xed48('0x2e')]=_0x3f1943['value'];}if(!_['isNil'](_0x3f1943['variable'][_0xed48('0x52')])||!_['isNil'](_0x3f1943['variable'][_0xed48('0x53')])){utils['info'](util[_0xed48('0x8')](_0xed48('0x51'),_0x3f1943[_0xed48('0x6')],!_[_0xed48('0x22')](_0x3f1943['variable']['xmd-queue'])?_0xed48('0x52'):'xmcs-queue',_0x3f1943[_0xed48('0x4c')]));channels[_0x3f1943['uniqueid']][_0xed48('0x54')]=_0xed48('0x55');channels[_0x3f1943['uniqueid']][_0xed48('0x56')]=_0x3f1943['value'];channels[_0x3f1943[_0xed48('0x6')]][_0xed48('0xa')]=!![];}if(!_[_0xed48('0x22')](_0x3f1943[_0xed48('0x49')][_0xed48('0x57')])){utils[_0xed48('0x1b')](util[_0xed48('0x8')](_0xed48('0x58'),_0x3f1943['uniqueid'],_0x3f1943['value']));channels[_0x3f1943[_0xed48('0x6')]][_0xed48('0x59')]=_0x3f1943[_0xed48('0x4c')];}if(!_[_0xed48('0x22')](_0x3f1943['variable'][_0xed48('0x5a')])){utils[_0xed48('0x1b')](util[_0xed48('0x8')]('[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s',_0x3f1943[_0xed48('0x6')],_0x3f1943[_0xed48('0x4c')]));channels[_0x3f1943[_0xed48('0x6')]]['type']=_0x3f1943['value'];}if(!_[_0xed48('0x22')](_0x3f1943[_0xed48('0x49')]['outboundrouteid'])){utils[_0xed48('0x1b')](util['format']('[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s',_0x3f1943['uniqueid'],_0x3f1943['value']));channels[_0x3f1943[_0xed48('0x6')]][_0xed48('0x5b')]=_0x3f1943[_0xed48('0x4c')];}if(!_[_0xed48('0x22')](_0x3f1943['variable'][_0xed48('0x5c')])){utils['info'](util['format'](_0xed48('0x5d'),_0x3f1943[_0xed48('0x6')],_0x3f1943['value']));channels[_0x3f1943['uniqueid']][_0xed48('0x5c')]=_0x3f1943[_0xed48('0x4c')];}}}catch(_0x332812){utils['error'](util[_0xed48('0x8')]('[%s][calls][varset]',_0x3f1943[_0xed48('0x6')]),_0x332812);}};exports[_0xed48('0x5e')]=function(_0x147e19){try{if(!_[_0xed48('0x22')](channels[_0x147e19[_0xed48('0x6')]])){utils[_0xed48('0x17')](util['format'](_0xed48('0x5f'),_0x147e19[_0xed48('0x6')]),_0x147e19);utils[_0xed48('0x1b')](util[_0xed48('0x8')](_0xed48('0x60'),_0x147e19['uniqueid'],_0x147e19[_0xed48('0x61')],_0x147e19[_0xed48('0x62')]));if(_0x147e19['application']['toLowerCase']()==_0xed48('0x63')&&_[_0xed48('0x64')](_0x147e19[_0xed48('0x62')][_0xed48('0x65')](),_0xed48('0x66'))){var _0x412aa4=_0x147e19['appdata'][_0xed48('0x67')]('=');var _0x399eed=_0x412aa4[0x0][_0xed48('0x68')](_0x412aa4[0x0]['lastIndexOf']('(')+0x1,_0x412aa4[0x0]['lastIndexOf'](')'));var _0x5ebe8d=_0x412aa4[0x1];channels[_0x147e19[_0xed48('0x6')]][_0x399eed]=_0x5ebe8d;}if(!_['includes']([_0xed48('0x69'),'noop',_0xed48('0x6a'),_0xed48('0x63'),_0xed48('0x6b')],_0x147e19[_0xed48('0x61')][_0xed48('0x65')]())){channels[_0x147e19['uniqueid']]['lastapplication']=_0x147e19['application'];channels[_0x147e19['uniqueid']]['lastdata']=_0x147e19['appdata'];}}}catch(_0x3ba81c){utils['error'](util[_0xed48('0x8')](_0xed48('0x5f'),_0x147e19[_0xed48('0x6')]),_0x3ba81c);}};