7b8a6b7245b22d862a0e184209091e4d7a7cb969
[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 _0xfaf2=['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','xmd-queue','xmcs-queue','lastapplication','Queue','ContactId','xmd-cdrtype','[%s][calls][varset]\x20variable:xmd-cdrtype\x20value:%s','outboundrouteid','[%s][calls][varset]\x20variable:outboundrouteid\x20value:%s','routeid','sipcallid','[%s][calls][varset]','newexten','[%s][calls][newexten]','[%s][calls][newexten]\x20application:%s\x20appdata:%s','application','toLowerCase','set','startsWith','appdata','split','includes','execif','lastdata','lodash','util','./utils','FAILED','NO\x20ANSWER','ANSWERED','BUSY','format','[%s][calls][writeDB]\x20channel:%s\x20queue:%s\x20agent:%s\x20interface:%s\x20calleridnum:%s\x20connectedlinenum:%s\x20lastevent:%s','uniqueid','channel','queue','membername','calleridnum','connectedlinenum','lastevent','accountcode','getUserByInternal','then','request','CreateVoiceCallReport','newchannel','debug','[%s][calls][newchannel]','linkedid','OutgoingSpoolFailed','info','[%s][calls][newchannel]\x20context:%s\x20exten:%s','context','exten','DOCUMENTATION','error','newstate','[%s][calls][newstate]','channelstate','isNil','systemanswertime','now','transfer','[%s][calls][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','answertime','disposition','toNumber','hangup','callerid','[%s][calls][hangup]\x20callerid:%s\x20reason:%s','cause-txt','endtime','diffTime','starttime','billableseconds','localtwolinkedid','[%s][calls][attendedtransfer]','transfereechannel','[%s][calls][attendedtransfer]\x20localtwolinkedid:%s\x20destinationchannel:%s','origtransfereruniqueid','secondtransfererchannel','destinationchannel','userfield','_attended','transfertargetchannel','origtransfererchannel','musiconholdstart','[%s][calls][musiconholdstart]','musiconholdstartAt','[%s][calls][musiconholdstop]','mohtime','[%s][calls][musiconholdstop]\x20mohtime:%s','variable'];(function(_0x75f869,_0x3690d6){var _0x10af8b=function(_0x22d3ff){while(--_0x22d3ff){_0x75f869['push'](_0x75f869['shift']());}};_0x10af8b(++_0x3690d6);}(_0xfaf2,0x8b));var _0x2faf=function(_0x3ecce9,_0x35c336){_0x3ecce9=_0x3ecce9-0x0;var _0x89dd90=_0xfaf2[_0x3ecce9];return _0x89dd90;};'use strict';var _=require(_0x2faf('0x0'));var util=require(_0x2faf('0x1'));var utils=require(_0x2faf('0x2'));var dispositions=['NO\x20ANSWER',_0x2faf('0x3'),_0x2faf('0x3'),_0x2faf('0x4'),_0x2faf('0x4'),_0x2faf('0x4'),_0x2faf('0x5'),_0x2faf('0x6'),'FAILED',_0x2faf('0x3'),'FAILED'];var channels={};function writeDB(_0x4cdfc4){utils['info'](util[_0x2faf('0x7')](_0x2faf('0x8'),_0x4cdfc4[_0x2faf('0x9')],_0x4cdfc4[_0x2faf('0xa')],_0x4cdfc4[_0x2faf('0xb')],_0x4cdfc4[_0x2faf('0xc')],_0x4cdfc4['interface'],_0x4cdfc4[_0x2faf('0xd')],_0x4cdfc4[_0x2faf('0xe')],_0x4cdfc4[_0x2faf('0xf')]));if(_0x4cdfc4[_0x2faf('0x10')]){utils[_0x2faf('0x11')](_0x4cdfc4['accountcode'])[_0x2faf('0x12')](function(_0x36aa13){if(_0x36aa13){_0x4cdfc4['UserId']=_0x36aa13['id'];}utils[_0x2faf('0x13')]('CreateVoiceCallReport',_0x4cdfc4);});}else{utils[_0x2faf('0x13')](_0x2faf('0x14'),_0x4cdfc4);}if(channels[_0x4cdfc4[_0x2faf('0x9')]]){delete channels[_0x4cdfc4['uniqueid']];}}exports[_0x2faf('0x15')]=function(_0x189db1){try{utils[_0x2faf('0x16')](util[_0x2faf('0x7')](_0x2faf('0x17'),_0x189db1['uniqueid']),_0x189db1);if(_0x189db1[_0x2faf('0x9')]==_0x189db1[_0x2faf('0x18')]&&_0x189db1[_0x2faf('0xa')]!=_0x2faf('0x19')){utils[_0x2faf('0x1a')](util[_0x2faf('0x7')](_0x2faf('0x1b'),_0x189db1['uniqueid'],_0x189db1[_0x2faf('0x1c')],_0x189db1['exten']));channels[_0x189db1[_0x2faf('0x9')]]={'uniqueid':_0x189db1[_0x2faf('0x9')],'accountcode':_0x189db1[_0x2faf('0x10')],'source':_0x189db1[_0x2faf('0xd')],'destination':_0x189db1[_0x2faf('0x1d')],'destinationcontext':_0x189db1[_0x2faf('0x1c')],'channel':_0x189db1[_0x2faf('0xa')],'starttime':utils['now'](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':_0x2faf('0x1e')};}}catch(_0x3eafe4){utils[_0x2faf('0x1f')](util[_0x2faf('0x7')](_0x2faf('0x17'),_0x189db1[_0x2faf('0x9')]),_0x3eafe4);}};exports[_0x2faf('0x20')]=function(_0x1e696b){try{utils['debug'](util[_0x2faf('0x7')](_0x2faf('0x21'),_0x1e696b[_0x2faf('0x9')]),_0x1e696b);if(!_['isNil'](channels[_0x1e696b[_0x2faf('0x9')]])&&_0x1e696b[_0x2faf('0x22')]==0x6){utils[_0x2faf('0x1a')](util['format']('[%s][calls][newstate]\x20context:%s\x20channel:%s',_0x1e696b['uniqueid'],_0x1e696b[_0x2faf('0x1c')],_0x1e696b[_0x2faf('0xa')]));if(_[_0x2faf('0x23')](channels[_0x1e696b[_0x2faf('0x9')]]['systemanswertime'])){channels[_0x1e696b['uniqueid']][_0x2faf('0x24')]=utils[_0x2faf('0x25')]();}}else if(!_[_0x2faf('0x23')](channels[_0x1e696b[_0x2faf('0x18')]])&&_0x1e696b['channelstate']==0x6&&_0x1e696b[_0x2faf('0x1c')]!=_0x2faf('0x26')){utils['info'](util[_0x2faf('0x7')](_0x2faf('0x27'),_0x1e696b[_0x2faf('0x9')],_0x1e696b['linkedid'],_0x1e696b[_0x2faf('0x1c')],_0x1e696b[_0x2faf('0xa')]));channels[_0x1e696b[_0x2faf('0x18')]][_0x2faf('0x10')]=_0x1e696b[_0x2faf('0x10')];channels[_0x1e696b[_0x2faf('0x18')]]['destinationchannel']=_0x1e696b[_0x2faf('0xa')];if(_[_0x2faf('0x23')](channels[_0x1e696b[_0x2faf('0x18')]][_0x2faf('0x28')])){channels[_0x1e696b[_0x2faf('0x18')]][_0x2faf('0x28')]=utils['now']();}channels[_0x1e696b[_0x2faf('0x18')]][_0x2faf('0x29')]=dispositions[_[_0x2faf('0x2a')](_0x1e696b['channelstate'])]||_0x2faf('0x5');}}catch(_0x60aff0){utils[_0x2faf('0x1f')](util[_0x2faf('0x7')]('[%s][calls][newstate]',_0x1e696b['uniqueid']),_0x60aff0);}};exports[_0x2faf('0x2b')]=function(_0x5e005f){try{if(!_[_0x2faf('0x23')](channels[_0x5e005f['uniqueid']])){utils[_0x2faf('0x16')](util[_0x2faf('0x7')]('[%s][calls][hangup]',_0x5e005f[_0x2faf('0x9')]),_0x5e005f);if(_['isNil'](channels[_0x5e005f[_0x2faf('0x9')]][_0x2faf('0x2c')])){channels[_0x5e005f[_0x2faf('0x9')]][_0x2faf('0x2c')]=_0x5e005f['calleridname']+'\x20<'+_0x5e005f[_0x2faf('0xd')]+'>';}utils[_0x2faf('0x1a')](util[_0x2faf('0x7')](_0x2faf('0x2d'),_0x5e005f[_0x2faf('0x9')],channels[_0x5e005f[_0x2faf('0x9')]][_0x2faf('0x2c')],_0x5e005f[_0x2faf('0x2e')]));channels[_0x5e005f[_0x2faf('0x9')]][_0x2faf('0x2f')]=utils['now']();channels[_0x5e005f[_0x2faf('0x9')]]['duration']=utils[_0x2faf('0x30')](channels[_0x5e005f['uniqueid']][_0x2faf('0x2f')],channels[_0x5e005f[_0x2faf('0x9')]][_0x2faf('0x31')]);channels[_0x5e005f[_0x2faf('0x9')]][_0x2faf('0x32')]=channels[_0x5e005f['uniqueid']]['answertime']?utils['diffTime'](channels[_0x5e005f[_0x2faf('0x9')]][_0x2faf('0x2f')],channels[_0x5e005f[_0x2faf('0x9')]][_0x2faf('0x28')]):0x0;writeDB(channels[_0x5e005f['uniqueid']]);}}catch(_0x214ec3){utils[_0x2faf('0x1f')](util['format']('[%s][calls][hangup]',_0x5e005f[_0x2faf('0x9')]),_0x214ec3);}};exports['attendedtransfer']=function(_0x4745d7){try{if(!_[_0x2faf('0x23')](channels[_0x4745d7[_0x2faf('0x33')]])){utils[_0x2faf('0x16')](util['format'](_0x2faf('0x34'),_0x4745d7['origtransfereruniqueid']),_0x4745d7);if(channels[_0x4745d7[_0x2faf('0x33')]][_0x2faf('0xa')]==_0x4745d7[_0x2faf('0x35')]){utils[_0x2faf('0x1a')](util[_0x2faf('0x7')](_0x2faf('0x36'),_0x4745d7[_0x2faf('0x37')],_0x4745d7[_0x2faf('0x33')],_0x4745d7[_0x2faf('0x38')]));channels[_0x4745d7[_0x2faf('0x33')]][_0x2faf('0x39')]=_0x4745d7[_0x2faf('0x38')];channels[_0x4745d7[_0x2faf('0x33')]][_0x2faf('0x3a')]=_0x2faf('0x3b');}else if(channels[_0x4745d7[_0x2faf('0x33')]][_0x2faf('0xa')]=_0x4745d7[_0x2faf('0x3c')]){utils['info'](util['format'](_0x2faf('0x36'),_0x4745d7[_0x2faf('0x37')],_0x4745d7[_0x2faf('0x33')],_0x4745d7['origtransfererchannel']));channels[_0x4745d7[_0x2faf('0x33')]][_0x2faf('0x39')]=_0x4745d7[_0x2faf('0x3d')];channels[_0x4745d7[_0x2faf('0x33')]][_0x2faf('0x3a')]=_0x2faf('0x3b');}}}catch(_0x1f1742){utils['error'](util[_0x2faf('0x7')](_0x2faf('0x34'),_0x4745d7[_0x2faf('0x37')]),_0x1f1742);}};exports[_0x2faf('0x3e')]=function(_0x460f26){try{if(!_[_0x2faf('0x23')](channels[_0x460f26[_0x2faf('0x9')]])){utils[_0x2faf('0x16')](util[_0x2faf('0x7')](_0x2faf('0x3f'),_0x460f26['uniqueid']),_0x460f26);channels[_0x460f26[_0x2faf('0x9')]][_0x2faf('0x40')]=utils['now']();utils['info'](util[_0x2faf('0x7')]('[%s][calls][musiconholdstart]\x20musiconholdstartAt:%s',_0x460f26[_0x2faf('0x9')],channels[_0x460f26[_0x2faf('0x9')]][_0x2faf('0x40')]));}}catch(_0x231bf9){utils[_0x2faf('0x1f')](util[_0x2faf('0x7')]('[%s][calls][musiconholdstart]',_0x460f26[_0x2faf('0x9')]),_0x231bf9);}};exports['musiconholdstop']=function(_0x93fcb5){try{if(!_[_0x2faf('0x23')](channels[_0x93fcb5[_0x2faf('0x9')]])){utils['debug'](util[_0x2faf('0x7')](_0x2faf('0x41'),_0x93fcb5[_0x2faf('0x9')]),_0x93fcb5);if(!_[_0x2faf('0x23')](channels[_0x93fcb5[_0x2faf('0x9')]][_0x2faf('0x40')])){channels[_0x93fcb5[_0x2faf('0x9')]][_0x2faf('0x42')]+=utils[_0x2faf('0x30')](utils[_0x2faf('0x25')](),channels[_0x93fcb5['uniqueid']][_0x2faf('0x40')]);utils[_0x2faf('0x1a')](util[_0x2faf('0x7')](_0x2faf('0x43'),_0x93fcb5[_0x2faf('0x9')],channels[_0x93fcb5[_0x2faf('0x9')]][_0x2faf('0x42')]));delete channels[_0x93fcb5[_0x2faf('0x9')]][_0x2faf('0x40')];}}}catch(_0x55dfc3){utils[_0x2faf('0x1f')](util[_0x2faf('0x7')](_0x2faf('0x41'),_0x93fcb5[_0x2faf('0x9')]),_0x55dfc3);}};exports['varset']=function(_0x32a5e2){try{if(!_[_0x2faf('0x23')](channels[_0x32a5e2[_0x2faf('0x9')]])){utils['debug'](util[_0x2faf('0x7')]('[%s][calls][varset]',_0x32a5e2[_0x2faf('0x9')]),_0x32a5e2);if(!_[_0x2faf('0x23')](_0x32a5e2[_0x2faf('0x44')][_0x2faf('0x45')])){utils[_0x2faf('0x1a')](util[_0x2faf('0x7')](_0x2faf('0x46'),_0x32a5e2['uniqueid'],_0x32a5e2[_0x2faf('0x47')]));channels[_0x32a5e2[_0x2faf('0x9')]][_0x2faf('0x48')]=_0x32a5e2[_0x2faf('0x47')];}if(!_[_0x2faf('0x23')](_0x32a5e2['variable'][_0x2faf('0x49')])){utils[_0x2faf('0x1a')](util[_0x2faf('0x7')](_0x2faf('0x4a'),_0x32a5e2[_0x2faf('0x9')],_0x32a5e2[_0x2faf('0x47')]));channels[_0x32a5e2[_0x2faf('0x9')]][_0x2faf('0x4b')]=_0x32a5e2['value'];channels[_0x32a5e2[_0x2faf('0x9')]][_0x2faf('0x2c')]='\x22'+_0x32a5e2[_0x2faf('0x47')]+_0x2faf('0x4c')+_0x32a5e2[_0x2faf('0x47')]+'>';}if(!_['isNil'](_0x32a5e2['variable'][_0x2faf('0x4d')])||!_[_0x2faf('0x23')](_0x32a5e2['variable'][_0x2faf('0x4e')])){utils[_0x2faf('0x1a')](util[_0x2faf('0x7')](_0x2faf('0x4f'),_0x32a5e2[_0x2faf('0x9')],!_[_0x2faf('0x23')](_0x32a5e2[_0x2faf('0x44')][_0x2faf('0x4d')])?_0x2faf('0x4d'):_0x2faf('0x4e'),_0x32a5e2[_0x2faf('0x47')]));channels[_0x32a5e2[_0x2faf('0x9')]][_0x2faf('0x2c')]=_0x32a5e2[_0x2faf('0x47')];}if(!_[_0x2faf('0x23')](_0x32a5e2['variable'][_0x2faf('0x50')])||!_[_0x2faf('0x23')](_0x32a5e2[_0x2faf('0x44')][_0x2faf('0x51')])){utils[_0x2faf('0x1a')](util['format'](_0x2faf('0x4f'),_0x32a5e2[_0x2faf('0x9')],!_[_0x2faf('0x23')](_0x32a5e2[_0x2faf('0x44')]['xmd-queue'])?'xmd-queue':_0x2faf('0x51'),_0x32a5e2['value']));channels[_0x32a5e2['uniqueid']][_0x2faf('0x52')]=_0x2faf('0x53');channels[_0x32a5e2['uniqueid']]['lastdata']=_0x32a5e2['value'];channels[_0x32a5e2[_0x2faf('0x9')]][_0x2faf('0xb')]=!![];}if(!_['isNil'](_0x32a5e2['variable']['xmd-contactid'])){utils[_0x2faf('0x1a')](util['format']('[%s][calls][varset]\x20variable:xmd-contactid\x20value:%s',_0x32a5e2[_0x2faf('0x9')],_0x32a5e2[_0x2faf('0x47')]));channels[_0x32a5e2[_0x2faf('0x9')]][_0x2faf('0x54')]=_0x32a5e2['value'];}if(!_['isNil'](_0x32a5e2[_0x2faf('0x44')][_0x2faf('0x55')])){utils[_0x2faf('0x1a')](util[_0x2faf('0x7')](_0x2faf('0x56'),_0x32a5e2['uniqueid'],_0x32a5e2['value']));channels[_0x32a5e2[_0x2faf('0x9')]]['type']=_0x32a5e2['value'];}if(!_[_0x2faf('0x23')](_0x32a5e2[_0x2faf('0x44')][_0x2faf('0x57')])){utils['info'](util[_0x2faf('0x7')](_0x2faf('0x58'),_0x32a5e2[_0x2faf('0x9')],_0x32a5e2[_0x2faf('0x47')]));channels[_0x32a5e2[_0x2faf('0x9')]][_0x2faf('0x59')]=_0x32a5e2[_0x2faf('0x47')];}if(!_[_0x2faf('0x23')](_0x32a5e2[_0x2faf('0x44')][_0x2faf('0x5a')])){utils[_0x2faf('0x1a')](util[_0x2faf('0x7')]('[%s][calls][varset]\x20variable:sipcallid\x20value:%s',_0x32a5e2[_0x2faf('0x9')],_0x32a5e2[_0x2faf('0x47')]));channels[_0x32a5e2[_0x2faf('0x9')]][_0x2faf('0x5a')]=_0x32a5e2['value'];}}}catch(_0x2d9cd7){utils[_0x2faf('0x1f')](util[_0x2faf('0x7')](_0x2faf('0x5b'),_0x32a5e2[_0x2faf('0x9')]),_0x2d9cd7);}};exports[_0x2faf('0x5c')]=function(_0x511a9d){try{if(!_['isNil'](channels[_0x511a9d[_0x2faf('0x9')]])){utils['debug'](util[_0x2faf('0x7')](_0x2faf('0x5d'),_0x511a9d[_0x2faf('0x9')]),_0x511a9d);utils['info'](util[_0x2faf('0x7')](_0x2faf('0x5e'),_0x511a9d['uniqueid'],_0x511a9d[_0x2faf('0x5f')],_0x511a9d['appdata']));if(_0x511a9d[_0x2faf('0x5f')][_0x2faf('0x60')]()==_0x2faf('0x61')&&_[_0x2faf('0x62')](_0x511a9d[_0x2faf('0x63')][_0x2faf('0x60')](),'cdr')){var _0x4ae826=_0x511a9d[_0x2faf('0x63')][_0x2faf('0x64')]('=');var _0x23e0b3=_0x4ae826[0x0]['substring'](_0x4ae826[0x0]['lastIndexOf']('(')+0x1,_0x4ae826[0x0]['lastIndexOf'](')'));var _0xf12eeb=_0x4ae826[0x1];channels[_0x511a9d[_0x2faf('0x9')]][_0x23e0b3]=_0xf12eeb;}if(!_[_0x2faf('0x65')]([_0x2faf('0x2b'),'noop',_0x2faf('0x66'),_0x2faf('0x61'),'gotoif'],_0x511a9d[_0x2faf('0x5f')][_0x2faf('0x60')]())){channels[_0x511a9d[_0x2faf('0x9')]][_0x2faf('0x52')]=_0x511a9d[_0x2faf('0x5f')];channels[_0x511a9d[_0x2faf('0x9')]][_0x2faf('0x67')]=_0x511a9d[_0x2faf('0x63')];}}}catch(_0x3494f5){utils['error'](util[_0x2faf('0x7')]('[%s][calls][newexten]',_0x511a9d['uniqueid']),_0x3494f5);}};