Built motion from commit cb845558.|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 _0xe22d=['info','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','channel','queue','interface','calleridnum','connectedlinenum','accountcode','then','UserId','request','CreateVoiceCallReport','uniqueid','newchannel','format','[%s][calls][newchannel]','linkedid','OutgoingSpoolFailed','[%s][calls][newchannel]\x20context:%s\x20exten:%s','context','exten','now','DOCUMENTATION','error','isNil','channelstate','[%s][calls][newstate]\x20context:%s\x20channel:%s','systemanswertime','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','destinationchannel','answertime','disposition','[%s][calls][newstate]','hangup','debug','[%s][calls][hangup]','callerid','cause-txt','endtime','diffTime','starttime','billableseconds','attendedtransfer','localtwolinkedid','[%s][calls][attendedtransfer]','transfereechannel','origtransfereruniqueid','secondtransfererchannel','userfield','_attended','transfertargetchannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','origtransfererchannel','musiconholdstart','musiconholdstartAt','[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s','[%s][calls][musiconholdstart]','[%s][calls][musiconholdstop]','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','varset','[%s][calls][varset]','variable','xmd-originatecalleridnum','[%s][calls][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','value','source','xmd-phone','[%s][calls][varset]\x20variable:xmd-phone\x20value:%s','xmd-callerid-preview','xmd-callerid','xmd-queue','xmcs-queue','[%s][calls][varset]\x20variable:%s\x20value:%s','Queue','[%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]\x20variable:sipcallid\x20value:%s','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','appdata','toLowerCase','set','startsWith','cdr','split','substring','lastIndexOf','includes','noop','execif','application','lastapplication','lastdata','util','./utils','NO\x20ANSWER','FAILED','ANSWERED'];(function(_0xa464c9,_0x7c86d8){var _0x3d73c4=function(_0x5c2056){while(--_0x5c2056){_0xa464c9['push'](_0xa464c9['shift']());}};_0x3d73c4(++_0x7c86d8);}(_0xe22d,0x139));var _0xde22=function(_0x5b644e,_0x2e5e07){_0x5b644e=_0x5b644e-0x0;var _0x49c6bf=_0xe22d[_0x5b644e];return _0x49c6bf;};'use strict';var _=require('lodash');var util=require(_0xde22('0x0'));var utils=require(_0xde22('0x1'));var dispositions=[_0xde22('0x2'),_0xde22('0x3'),'FAILED',_0xde22('0x2'),_0xde22('0x2'),_0xde22('0x2'),_0xde22('0x4'),'BUSY',_0xde22('0x3'),_0xde22('0x3'),_0xde22('0x3')];var channels={};function writeDB(_0x408129){utils[_0xde22('0x5')](util['format'](_0xde22('0x6'),_0x408129['uniqueid'],_0x408129[_0xde22('0x7')],_0x408129[_0xde22('0x8')],_0x408129['membername'],_0x408129[_0xde22('0x9')],_0x408129[_0xde22('0xa')],_0x408129[_0xde22('0xb')],_0x408129['lastevent']));if(_0x408129[_0xde22('0xc')]){utils['getUserByInternal'](_0x408129[_0xde22('0xc')])[_0xde22('0xd')](function(_0x312a45){if(_0x312a45){_0x408129[_0xde22('0xe')]=_0x312a45['id'];}utils[_0xde22('0xf')](_0xde22('0x10'),_0x408129);});}else{utils[_0xde22('0xf')](_0xde22('0x10'),_0x408129);}if(channels[_0x408129[_0xde22('0x11')]]){delete channels[_0x408129[_0xde22('0x11')]];}}exports[_0xde22('0x12')]=function(_0x4252d7){try{utils['debug'](util[_0xde22('0x13')](_0xde22('0x14'),_0x4252d7[_0xde22('0x11')]),_0x4252d7);if(_0x4252d7['uniqueid']==_0x4252d7[_0xde22('0x15')]&&_0x4252d7[_0xde22('0x7')]!=_0xde22('0x16')){utils['info'](util['format'](_0xde22('0x17'),_0x4252d7['uniqueid'],_0x4252d7[_0xde22('0x18')],_0x4252d7[_0xde22('0x19')]));channels[_0x4252d7[_0xde22('0x11')]]={'uniqueid':_0x4252d7['uniqueid'],'accountcode':_0x4252d7[_0xde22('0xc')],'source':_0x4252d7[_0xde22('0xa')],'destination':_0x4252d7[_0xde22('0x19')],'destinationcontext':_0x4252d7[_0xde22('0x18')],'channel':_0x4252d7[_0xde22('0x7')],'starttime':utils[_0xde22('0x1a')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':_0xde22('0x1b')};}}catch(_0x222152){utils[_0xde22('0x1c')](util[_0xde22('0x13')](_0xde22('0x14'),_0x4252d7[_0xde22('0x11')]),_0x222152);}};exports['newstate']=function(_0x3aa012){try{utils['debug'](util['format']('[%s][calls][newstate]',_0x3aa012['uniqueid']),_0x3aa012);if(!_[_0xde22('0x1d')](channels[_0x3aa012[_0xde22('0x11')]])&&_0x3aa012[_0xde22('0x1e')]==0x6){utils[_0xde22('0x5')](util[_0xde22('0x13')](_0xde22('0x1f'),_0x3aa012[_0xde22('0x11')],_0x3aa012[_0xde22('0x18')],_0x3aa012[_0xde22('0x7')]));if(_[_0xde22('0x1d')](channels[_0x3aa012[_0xde22('0x11')]][_0xde22('0x20')])){channels[_0x3aa012[_0xde22('0x11')]][_0xde22('0x20')]=utils['now']();}}else if(!_[_0xde22('0x1d')](channels[_0x3aa012['linkedid']])&&_0x3aa012[_0xde22('0x1e')]==0x6&&_0x3aa012[_0xde22('0x18')]!='transfer'){utils[_0xde22('0x5')](util['format'](_0xde22('0x21'),_0x3aa012[_0xde22('0x11')],_0x3aa012['linkedid'],_0x3aa012[_0xde22('0x18')],_0x3aa012[_0xde22('0x7')]));channels[_0x3aa012[_0xde22('0x15')]][_0xde22('0xc')]=_0x3aa012[_0xde22('0xc')];channels[_0x3aa012[_0xde22('0x15')]][_0xde22('0x22')]=_0x3aa012[_0xde22('0x7')];if(_[_0xde22('0x1d')](channels[_0x3aa012[_0xde22('0x15')]][_0xde22('0x23')])){channels[_0x3aa012[_0xde22('0x15')]][_0xde22('0x23')]=utils[_0xde22('0x1a')]();}channels[_0x3aa012[_0xde22('0x15')]][_0xde22('0x24')]=dispositions[_['toNumber'](_0x3aa012[_0xde22('0x1e')])]||_0xde22('0x4');}}catch(_0x2bca75){utils[_0xde22('0x1c')](util['format'](_0xde22('0x25'),_0x3aa012[_0xde22('0x11')]),_0x2bca75);}};exports[_0xde22('0x26')]=function(_0x5c5680){try{if(!_['isNil'](channels[_0x5c5680[_0xde22('0x11')]])){utils[_0xde22('0x27')](util[_0xde22('0x13')](_0xde22('0x28'),_0x5c5680['uniqueid']),_0x5c5680);if(_[_0xde22('0x1d')](channels[_0x5c5680[_0xde22('0x11')]][_0xde22('0x29')])){channels[_0x5c5680[_0xde22('0x11')]]['callerid']=_0x5c5680['calleridname']+'\x20<'+_0x5c5680['calleridnum']+'>';}utils[_0xde22('0x5')](util[_0xde22('0x13')]('[%s][calls][hangup]\x20callerid:%s\x20reason:%s',_0x5c5680['uniqueid'],channels[_0x5c5680[_0xde22('0x11')]][_0xde22('0x29')],_0x5c5680[_0xde22('0x2a')]));channels[_0x5c5680[_0xde22('0x11')]][_0xde22('0x2b')]=utils[_0xde22('0x1a')]();channels[_0x5c5680[_0xde22('0x11')]]['duration']=utils[_0xde22('0x2c')](channels[_0x5c5680['uniqueid']][_0xde22('0x2b')],channels[_0x5c5680[_0xde22('0x11')]][_0xde22('0x2d')]);channels[_0x5c5680[_0xde22('0x11')]][_0xde22('0x2e')]=channels[_0x5c5680[_0xde22('0x11')]][_0xde22('0x23')]?utils[_0xde22('0x2c')](channels[_0x5c5680[_0xde22('0x11')]][_0xde22('0x2b')],channels[_0x5c5680[_0xde22('0x11')]]['answertime']):0x0;writeDB(channels[_0x5c5680['uniqueid']]);}}catch(_0x20c93d){utils['error'](util[_0xde22('0x13')](_0xde22('0x28'),_0x5c5680[_0xde22('0x11')]),_0x20c93d);}};exports[_0xde22('0x2f')]=function(_0x31806e){try{if(!_[_0xde22('0x1d')](channels[_0x31806e[_0xde22('0x30')]])){utils[_0xde22('0x27')](util[_0xde22('0x13')](_0xde22('0x31'),_0x31806e['origtransfereruniqueid']),_0x31806e);if(channels[_0x31806e[_0xde22('0x30')]][_0xde22('0x7')]==_0x31806e[_0xde22('0x32')]){utils['info'](util[_0xde22('0x13')]('[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s',_0x31806e[_0xde22('0x33')],_0x31806e[_0xde22('0x30')],_0x31806e[_0xde22('0x34')]));channels[_0x31806e[_0xde22('0x30')]][_0xde22('0x22')]=_0x31806e[_0xde22('0x34')];channels[_0x31806e[_0xde22('0x30')]][_0xde22('0x35')]=_0xde22('0x36');}else if(channels[_0x31806e[_0xde22('0x30')]]['channel']=_0x31806e[_0xde22('0x37')]){utils['info'](util[_0xde22('0x13')](_0xde22('0x38'),_0x31806e[_0xde22('0x33')],_0x31806e[_0xde22('0x30')],_0x31806e[_0xde22('0x39')]));channels[_0x31806e[_0xde22('0x30')]][_0xde22('0x22')]=_0x31806e[_0xde22('0x39')];channels[_0x31806e[_0xde22('0x30')]][_0xde22('0x35')]=_0xde22('0x36');}}}catch(_0x45d590){utils[_0xde22('0x1c')](util[_0xde22('0x13')]('[%s][calls][attendedtransfer]',_0x31806e['origtransfereruniqueid']),_0x45d590);}};exports[_0xde22('0x3a')]=function(_0x5ddc26){try{if(!_[_0xde22('0x1d')](channels[_0x5ddc26[_0xde22('0x11')]])){utils['debug'](util[_0xde22('0x13')]('[%s][calls][musiconholdstart]',_0x5ddc26[_0xde22('0x11')]),_0x5ddc26);channels[_0x5ddc26[_0xde22('0x11')]][_0xde22('0x3b')]=utils['now']();utils[_0xde22('0x5')](util['format'](_0xde22('0x3c'),_0x5ddc26[_0xde22('0x11')],channels[_0x5ddc26[_0xde22('0x11')]][_0xde22('0x3b')]));}}catch(_0x2b0142){utils[_0xde22('0x1c')](util[_0xde22('0x13')](_0xde22('0x3d'),_0x5ddc26['uniqueid']),_0x2b0142);}};exports['musiconholdstop']=function(_0xa230){try{if(!_[_0xde22('0x1d')](channels[_0xa230['uniqueid']])){utils['debug'](util[_0xde22('0x13')](_0xde22('0x3e'),_0xa230[_0xde22('0x11')]),_0xa230);if(!_[_0xde22('0x1d')](channels[_0xa230['uniqueid']][_0xde22('0x3b')])){channels[_0xa230['uniqueid']][_0xde22('0x3f')]+=utils['diffTime'](utils[_0xde22('0x1a')](),channels[_0xa230[_0xde22('0x11')]]['musiconholdstartAt']);utils['info'](util[_0xde22('0x13')](_0xde22('0x40'),_0xa230[_0xde22('0x11')],channels[_0xa230[_0xde22('0x11')]]['mohtime']));delete channels[_0xa230[_0xde22('0x11')]][_0xde22('0x3b')];}}}catch(_0xbf9824){utils['error'](util['format']('[%s][calls][musiconholdstop]',_0xa230['uniqueid']),_0xbf9824);}};exports[_0xde22('0x41')]=function(_0x27de7b){try{if(!_['isNil'](channels[_0x27de7b[_0xde22('0x11')]])){utils[_0xde22('0x27')](util[_0xde22('0x13')](_0xde22('0x42'),_0x27de7b['uniqueid']),_0x27de7b);if(!_[_0xde22('0x1d')](_0x27de7b[_0xde22('0x43')][_0xde22('0x44')])){utils[_0xde22('0x5')](util[_0xde22('0x13')](_0xde22('0x45'),_0x27de7b['uniqueid'],_0x27de7b[_0xde22('0x46')]));channels[_0x27de7b['uniqueid']][_0xde22('0x47')]=_0x27de7b['value'];}if(!_['isNil'](_0x27de7b[_0xde22('0x43')][_0xde22('0x48')])){utils[_0xde22('0x5')](util[_0xde22('0x13')](_0xde22('0x49'),_0x27de7b[_0xde22('0x11')],_0x27de7b['value']));channels[_0x27de7b[_0xde22('0x11')]]['destination']=_0x27de7b[_0xde22('0x46')];channels[_0x27de7b['uniqueid']]['callerid']='\x22'+_0x27de7b[_0xde22('0x46')]+'\x22\x20<'+_0x27de7b[_0xde22('0x46')]+'>';}if(!_[_0xde22('0x1d')](_0x27de7b['variable'][_0xde22('0x4a')])||!_[_0xde22('0x1d')](_0x27de7b[_0xde22('0x43')][_0xde22('0x4b')])){utils[_0xde22('0x5')](util['format']('[%s][calls][varset]\x20variable:%s\x20value:%s',_0x27de7b[_0xde22('0x11')],!_[_0xde22('0x1d')](_0x27de7b[_0xde22('0x43')][_0xde22('0x4a')])?_0xde22('0x4a'):_0xde22('0x4b'),_0x27de7b[_0xde22('0x46')]));channels[_0x27de7b[_0xde22('0x11')]][_0xde22('0x29')]=_0x27de7b[_0xde22('0x46')];}if(!_['isNil'](_0x27de7b[_0xde22('0x43')][_0xde22('0x4c')])||!_['isNil'](_0x27de7b[_0xde22('0x43')][_0xde22('0x4d')])){utils['info'](util['format'](_0xde22('0x4e'),_0x27de7b['uniqueid'],!_[_0xde22('0x1d')](_0x27de7b[_0xde22('0x43')][_0xde22('0x4c')])?'xmd-queue':_0xde22('0x4d'),_0x27de7b[_0xde22('0x46')]));channels[_0x27de7b['uniqueid']]['lastapplication']=_0xde22('0x4f');channels[_0x27de7b[_0xde22('0x11')]]['lastdata']=_0x27de7b['value'];channels[_0x27de7b[_0xde22('0x11')]]['queue']=!![];}if(!_[_0xde22('0x1d')](_0x27de7b['variable']['xmd-contactid'])){utils[_0xde22('0x5')](util[_0xde22('0x13')](_0xde22('0x50'),_0x27de7b['uniqueid'],_0x27de7b[_0xde22('0x46')]));channels[_0x27de7b[_0xde22('0x11')]][_0xde22('0x51')]=_0x27de7b[_0xde22('0x46')];}if(!_[_0xde22('0x1d')](_0x27de7b[_0xde22('0x43')][_0xde22('0x52')])){utils[_0xde22('0x5')](util[_0xde22('0x13')](_0xde22('0x53'),_0x27de7b[_0xde22('0x11')],_0x27de7b[_0xde22('0x46')]));channels[_0x27de7b[_0xde22('0x11')]][_0xde22('0x54')]=_0x27de7b[_0xde22('0x46')];}if(!_[_0xde22('0x1d')](_0x27de7b[_0xde22('0x43')][_0xde22('0x55')])){utils[_0xde22('0x5')](util['format']('[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s',_0x27de7b['uniqueid'],_0x27de7b[_0xde22('0x46')]));channels[_0x27de7b[_0xde22('0x11')]][_0xde22('0x56')]=_0x27de7b[_0xde22('0x46')];}if(!_['isNil'](_0x27de7b[_0xde22('0x43')][_0xde22('0x57')])){utils[_0xde22('0x5')](util[_0xde22('0x13')](_0xde22('0x58'),_0x27de7b[_0xde22('0x11')],_0x27de7b[_0xde22('0x46')]));channels[_0x27de7b[_0xde22('0x11')]][_0xde22('0x57')]=_0x27de7b[_0xde22('0x46')];}}}catch(_0x4f636d){utils[_0xde22('0x1c')](util[_0xde22('0x13')](_0xde22('0x42'),_0x27de7b[_0xde22('0x11')]),_0x4f636d);}};exports[_0xde22('0x59')]=function(_0x23a651){try{if(!_[_0xde22('0x1d')](channels[_0x23a651['uniqueid']])){utils['debug'](util['format'](_0xde22('0x5a'),_0x23a651['uniqueid']),_0x23a651);utils[_0xde22('0x5')](util['format'](_0xde22('0x5b'),_0x23a651[_0xde22('0x11')],_0x23a651['application'],_0x23a651[_0xde22('0x5c')]));if(_0x23a651['application'][_0xde22('0x5d')]()==_0xde22('0x5e')&&_[_0xde22('0x5f')](_0x23a651[_0xde22('0x5c')]['toLowerCase'](),_0xde22('0x60'))){var _0x56e562=_0x23a651['appdata'][_0xde22('0x61')]('=');var _0x422fc5=_0x56e562[0x0][_0xde22('0x62')](_0x56e562[0x0][_0xde22('0x63')]('(')+0x1,_0x56e562[0x0]['lastIndexOf'](')'));var _0x433c01=_0x56e562[0x1];channels[_0x23a651['uniqueid']][_0x422fc5]=_0x433c01;}if(!_[_0xde22('0x64')]([_0xde22('0x26'),_0xde22('0x65'),_0xde22('0x66'),_0xde22('0x5e'),'gotoif'],_0x23a651[_0xde22('0x67')][_0xde22('0x5d')]())){channels[_0x23a651['uniqueid']][_0xde22('0x68')]=_0x23a651['application'];channels[_0x23a651[_0xde22('0x11')]][_0xde22('0x69')]=_0x23a651['appdata'];}}}catch(_0x48547b){utils[_0xde22('0x1c')](util[_0xde22('0x13')](_0xde22('0x5a'),_0x23a651[_0xde22('0x11')]),_0x48547b);}};