d5c60d2e23dddfc5c9966b08de9e27528d246df3
[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 _0xc07f=['channelstate','systemanswertime','transfer','answertime','toNumber','error','stack','hangup','calleridname','endtime','duration','diffTime','starttime','attendedtransfer','localtwolinkedid','transfereechannel','secondtransfererchannel','_attended','transfertargetchannel','destinationchannel','origtransfererchannel','userfield','musiconholdstart','musiconholdstop','musiconholdstartAt','mohtime','xmd-originatecalleridnum','variable','xmd-phone','xmd-callerid-preview','xmd-queue','lastdata','value','xmd-contactid','xmd-cdrtype','outboundrouteid','routeid','sipcallid','newexten','application','toLowerCase','set','startsWith','appdata','split','substring','lastIndexOf','includes','noop','execif','gotoif','lodash','util','./utils','NO\x20ANSWER','FAILED','BUSY','info','format','CALL|%s|%s|%s|%s|%s|%s|%s|%s','uniqueid','channel','type','accountcode','source','destination','callerid','disposition','then','CreateVoiceCallReport','request','newchannel','linkedid','OutgoingSpoolFailed','calleridnum','context','now','DOCUMENTATION','isNil'];(function(_0x23d789,_0x9aeb78){var _0x567afd=function(_0x4cdfff){while(--_0x4cdfff){_0x23d789['push'](_0x23d789['shift']());}};_0x567afd(++_0x9aeb78);}(_0xc07f,0x82));var _0xfc07=function(_0x3fa939,_0x346ccc){_0x3fa939=_0x3fa939-0x0;var _0x3c9a17=_0xc07f[_0x3fa939];return _0x3c9a17;};'use strict';var _=require(_0xfc07('0x0'));var util=require(_0xfc07('0x1'));var utils=require(_0xfc07('0x2'));var dispositions=[_0xfc07('0x3'),_0xfc07('0x4'),_0xfc07('0x4'),'NO\x20ANSWER',_0xfc07('0x3'),_0xfc07('0x3'),'ANSWERED',_0xfc07('0x5'),_0xfc07('0x4'),_0xfc07('0x4'),_0xfc07('0x4')];var channels={};function writeDB(_0x36103e){utils[_0xfc07('0x6')](util[_0xfc07('0x7')](_0xfc07('0x8'),_0x36103e[_0xfc07('0x9')],_0x36103e[_0xfc07('0xa')],_0x36103e[_0xfc07('0xb')],_0x36103e[_0xfc07('0xc')],_0x36103e[_0xfc07('0xd')],_0x36103e[_0xfc07('0xe')],_0x36103e[_0xfc07('0xf')],_0x36103e[_0xfc07('0x10')]));if(_0x36103e[_0xfc07('0xc')]){utils['getUserByInternal'](_0x36103e[_0xfc07('0xc')])[_0xfc07('0x11')](function(_0x463a57){if(_0x463a57){_0x36103e['UserId']=_0x463a57['id'];}utils['request'](_0xfc07('0x12'),_0x36103e);});}else{utils[_0xfc07('0x13')]('CreateVoiceCallReport',_0x36103e);}if(channels[_0x36103e[_0xfc07('0x9')]]){delete channels[_0x36103e['uniqueid']];}}exports[_0xfc07('0x14')]=function(_0x317239){try{if(_0x317239['uniqueid']==_0x317239[_0xfc07('0x15')]&&_0x317239[_0xfc07('0xa')]!=_0xfc07('0x16')){channels[_0x317239['uniqueid']]={'uniqueid':_0x317239[_0xfc07('0x9')],'accountcode':_0x317239['accountcode'],'source':_0x317239[_0xfc07('0x17')],'destination':_0x317239['exten'],'destinationcontext':_0x317239[_0xfc07('0x18')],'channel':_0x317239['channel'],'starttime':utils[_0xfc07('0x19')](),'answertime':null,'systemanswertime':null,'mohtime':0x0,'disposition':'NO\x20ANSWER','amaflags':_0xfc07('0x1a')};}}catch(_0xf619e1){utils['error'](_0xf619e1['stack']);}};exports['newstate']=function(_0x49459a){try{if(!_[_0xfc07('0x1b')](channels[_0x49459a['uniqueid']])&&_0x49459a[_0xfc07('0x1c')]==0x6){if(_['isNil'](channels[_0x49459a['uniqueid']][_0xfc07('0x1d')])){channels[_0x49459a[_0xfc07('0x9')]][_0xfc07('0x1d')]=utils[_0xfc07('0x19')]();}}else if(!_['isNil'](channels[_0x49459a[_0xfc07('0x15')]])&&_0x49459a[_0xfc07('0x1c')]==0x6&&_0x49459a[_0xfc07('0x18')]!=_0xfc07('0x1e')){channels[_0x49459a['linkedid']]['accountcode']=_0x49459a[_0xfc07('0xc')];channels[_0x49459a['linkedid']]['destinationchannel']=_0x49459a[_0xfc07('0xa')];if(_['isNil'](channels[_0x49459a[_0xfc07('0x15')]][_0xfc07('0x1f')])){channels[_0x49459a[_0xfc07('0x15')]][_0xfc07('0x1f')]=utils[_0xfc07('0x19')]();}channels[_0x49459a['linkedid']][_0xfc07('0x10')]=dispositions[_[_0xfc07('0x20')](_0x49459a['channelstate'])]||'ANSWERED';}}catch(_0xad7a64){utils[_0xfc07('0x21')](_0xad7a64[_0xfc07('0x22')]);}};exports[_0xfc07('0x23')]=function(_0x20d91c){try{if(!_[_0xfc07('0x1b')](channels[_0x20d91c[_0xfc07('0x9')]])){if(_[_0xfc07('0x1b')](channels[_0x20d91c[_0xfc07('0x9')]][_0xfc07('0xf')])){channels[_0x20d91c[_0xfc07('0x9')]][_0xfc07('0xf')]=_0x20d91c[_0xfc07('0x24')]+'\x20<'+_0x20d91c[_0xfc07('0x17')]+'>';}channels[_0x20d91c['uniqueid']][_0xfc07('0x25')]=utils[_0xfc07('0x19')]();channels[_0x20d91c['uniqueid']][_0xfc07('0x26')]=utils[_0xfc07('0x27')](channels[_0x20d91c[_0xfc07('0x9')]][_0xfc07('0x25')],channels[_0x20d91c['uniqueid']][_0xfc07('0x28')]);channels[_0x20d91c[_0xfc07('0x9')]]['billableseconds']=channels[_0x20d91c[_0xfc07('0x9')]][_0xfc07('0x1f')]?utils['diffTime'](channels[_0x20d91c['uniqueid']][_0xfc07('0x25')],channels[_0x20d91c[_0xfc07('0x9')]][_0xfc07('0x1f')]):0x0;writeDB(channels[_0x20d91c[_0xfc07('0x9')]]);}}catch(_0x19ce3b){utils[_0xfc07('0x21')](_0x19ce3b[_0xfc07('0x22')]);}};exports[_0xfc07('0x29')]=function(_0x121f58){try{if(!_[_0xfc07('0x1b')](channels[_0x121f58[_0xfc07('0x2a')]])){if(channels[_0x121f58['localtwolinkedid']][_0xfc07('0xa')]==_0x121f58[_0xfc07('0x2b')]){channels[_0x121f58[_0xfc07('0x2a')]]['destinationchannel']=_0x121f58[_0xfc07('0x2c')];channels[_0x121f58[_0xfc07('0x2a')]]['userfield']=_0xfc07('0x2d');}else if(channels[_0x121f58[_0xfc07('0x2a')]]['channel']=_0x121f58[_0xfc07('0x2e')]){channels[_0x121f58[_0xfc07('0x2a')]][_0xfc07('0x2f')]=_0x121f58[_0xfc07('0x30')];channels[_0x121f58[_0xfc07('0x2a')]][_0xfc07('0x31')]=_0xfc07('0x2d');}}}catch(_0xa29586){utils[_0xfc07('0x21')](_0xa29586[_0xfc07('0x22')]);}};exports[_0xfc07('0x32')]=function(_0x5a5b36){try{if(!_[_0xfc07('0x1b')](channels[_0x5a5b36[_0xfc07('0x9')]])){channels[_0x5a5b36[_0xfc07('0x9')]]['musiconholdstartAt']=utils[_0xfc07('0x19')]();}}catch(_0x19b705){utils[_0xfc07('0x21')](_0x19b705['stack']);}};exports[_0xfc07('0x33')]=function(_0xb1cba8){try{if(!_[_0xfc07('0x1b')](channels[_0xb1cba8[_0xfc07('0x9')]])){if(!_[_0xfc07('0x1b')](channels[_0xb1cba8[_0xfc07('0x9')]][_0xfc07('0x34')])){channels[_0xb1cba8[_0xfc07('0x9')]][_0xfc07('0x35')]+=utils[_0xfc07('0x27')](utils[_0xfc07('0x19')](),channels[_0xb1cba8[_0xfc07('0x9')]]['musiconholdstartAt']);delete channels[_0xb1cba8[_0xfc07('0x9')]][_0xfc07('0x34')];}}}catch(_0x3ec762){utils[_0xfc07('0x21')](_0x3ec762[_0xfc07('0x22')]);}};exports['varset']=function(_0x34c9b9){try{if(!_[_0xfc07('0x1b')](channels[_0x34c9b9[_0xfc07('0x9')]])){if(!_[_0xfc07('0x1b')](_0x34c9b9['variable'][_0xfc07('0x36')])){channels[_0x34c9b9[_0xfc07('0x9')]]['source']=_0x34c9b9['value'];}if(!_[_0xfc07('0x1b')](_0x34c9b9[_0xfc07('0x37')][_0xfc07('0x38')])){channels[_0x34c9b9[_0xfc07('0x9')]][_0xfc07('0xe')]=_0x34c9b9['value'];channels[_0x34c9b9[_0xfc07('0x9')]][_0xfc07('0xf')]='\x22'+_0x34c9b9['value']+'\x22\x20<'+_0x34c9b9['value']+'>';}if(!_['isNil'](_0x34c9b9['variable'][_0xfc07('0x39')])||!_[_0xfc07('0x1b')](_0x34c9b9['variable']['xmd-callerid'])){channels[_0x34c9b9[_0xfc07('0x9')]][_0xfc07('0xf')]=_0x34c9b9['value'];}if(!_['isNil'](_0x34c9b9[_0xfc07('0x37')][_0xfc07('0x3a')])||!_[_0xfc07('0x1b')](_0x34c9b9[_0xfc07('0x37')]['xmcs-queue'])){channels[_0x34c9b9[_0xfc07('0x9')]]['lastapplication']='Queue';channels[_0x34c9b9[_0xfc07('0x9')]][_0xfc07('0x3b')]=_0x34c9b9[_0xfc07('0x3c')];channels[_0x34c9b9[_0xfc07('0x9')]]['queue']=!![];}if(!_['isNil'](_0x34c9b9[_0xfc07('0x37')][_0xfc07('0x3d')])){channels[_0x34c9b9[_0xfc07('0x9')]]['ContactId']=_0x34c9b9[_0xfc07('0x3c')];}if(!_['isNil'](_0x34c9b9[_0xfc07('0x37')][_0xfc07('0x3e')])){channels[_0x34c9b9[_0xfc07('0x9')]]['type']=_0x34c9b9[_0xfc07('0x3c')];}if(!_[_0xfc07('0x1b')](_0x34c9b9[_0xfc07('0x37')][_0xfc07('0x3f')])){channels[_0x34c9b9[_0xfc07('0x9')]][_0xfc07('0x40')]=_0x34c9b9[_0xfc07('0x3c')];}if(!_['isNil'](_0x34c9b9[_0xfc07('0x37')][_0xfc07('0x41')])){channels[_0x34c9b9[_0xfc07('0x9')]][_0xfc07('0x41')]=_0x34c9b9[_0xfc07('0x3c')];}}}catch(_0x40c70d){utils[_0xfc07('0x21')](_0x40c70d['stack']);}};exports[_0xfc07('0x42')]=function(_0x22b845){try{if(!_['isNil'](channels[_0x22b845[_0xfc07('0x9')]])){if(_0x22b845[_0xfc07('0x43')][_0xfc07('0x44')]()==_0xfc07('0x45')&&_[_0xfc07('0x46')](_0x22b845['appdata'][_0xfc07('0x44')](),'cdr')){var _0x3fe07b=_0x22b845[_0xfc07('0x47')][_0xfc07('0x48')]('=');var _0x8486c7=_0x3fe07b[0x0][_0xfc07('0x49')](_0x3fe07b[0x0]['lastIndexOf']('(')+0x1,_0x3fe07b[0x0][_0xfc07('0x4a')](')'));var _0x387f25=_0x3fe07b[0x1];channels[_0x22b845[_0xfc07('0x9')]][_0x8486c7]=_0x387f25;}if(!_[_0xfc07('0x4b')]([_0xfc07('0x23'),_0xfc07('0x4c'),_0xfc07('0x4d'),_0xfc07('0x45'),_0xfc07('0x4e')],_0x22b845[_0xfc07('0x43')]['toLowerCase']())){channels[_0x22b845['uniqueid']]['lastapplication']=_0x22b845[_0xfc07('0x43')];channels[_0x22b845['uniqueid']][_0xfc07('0x3b')]=_0x22b845[_0xfc07('0x47')];}}}catch(_0x4e08ad){utils[_0xfc07('0x21')](_0x4e08ad['stack']);}};