038c3a2472b28ffdb16002a910333fee4c5a102a
[motion2.git] / server / services / ami / report / index.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 _0x1ddb=['../rpc/voiceAgentReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceCallReport','./voiceAgentReport','./voiceDialReport','./userReport','agents','telephones','sync','realtime','xdr','disabled','custom:voiceQueueReport','bind','voiceCallReport','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','blindtransfer','blindTransfer','attendedtransfer','prototype','findAgent','find','accountcode','name','isNil','interface','format','voiceQueueReport','length','connectedlinenum','assigned','lastAssignedTo','SIP/%s','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','match','keys','channel','split','getAgentByInternal','calleridnum','outbound','internal','destination','exten','type','dialer','queue','context','from-voip-provider','callerid','from-sip','xcally-motion-preview','calleridpreview','originatecalleridnum','destinationchannel','disposition','ANSWERED','\x22%s\x22\x20<%s>','calleridname','transfers','linkedid','transfereelinkedid','uniqueid','getCallType','UserId','membername','create','monitor','monitors','filename','createdAt','connectedlinename','xcally-motion-dialer','isArray','forEach','Local','substring','indexOf','mobile','phone','lastIndexOf','transfererlinkedid','attendedTransfer','exports','lodash','moment','util','../../../config/environment'];(function(_0xdaf192,_0x328fad){var _0x1790a8=function(_0xf4297a){while(--_0xf4297a){_0xdaf192['push'](_0xdaf192['shift']());}};_0x1790a8(++_0x328fad);}(_0x1ddb,0x122));var _0xb1dd=function(_0x4d560a,_0x48d9dd){_0x4d560a=_0x4d560a-0x0;var _0x368b51=_0x1ddb[_0x4d560a];return _0x368b51;};'use strict';var _=require(_0xb1dd('0x0'));var moment=require(_0xb1dd('0x1'));var util=require(_0xb1dd('0x2'));var config=require(_0xb1dd('0x3'));var ami=require('../ami');var RpcVoiceAgentReport=require(_0xb1dd('0x4'));var RpcVoiceCallReport=require('../rpc/voiceCallReport');var RpcVoiceDialReport=require(_0xb1dd('0x5'));var RpcMemberReport=require(_0xb1dd('0x6'));var RpcVoiceQueueReport=require('../rpc/voiceQueueReport');var RpcVoiceRecording=require(_0xb1dd('0x7'));var RpcVoiceTransferReport=require(_0xb1dd('0x8'));var VoiceQueueReport=require(_0xb1dd('0x9'));var VoiceCallReport=require(_0xb1dd('0xa'));var VoiceAgentReport=require(_0xb1dd('0xb'));var VoiceDialReport=require(_0xb1dd('0xc'));var UserReport=require(_0xb1dd('0xd'));function Report(_0x226191){this['realtime']=_0x226191;this[_0xb1dd('0xe')]=_0x226191[_0xb1dd('0xe')];this[_0xb1dd('0xf')]=_0x226191['telephones'];}Report['prototype'][_0xb1dd('0x10')]=function(_0x40ae58){var _0x361c58=new VoiceQueueReport(this['realtime']);var _0x57a400=new VoiceAgentReport(this['realtime']);var _0xb1c958=new VoiceDialReport(this[_0xb1dd('0x11')]);var _0x53bcaf=new VoiceCallReport(this['realtime']);var _0x3bc26e=new UserReport(this['realtime']);if(config[_0xb1dd('0x12')]&&config[_0xb1dd('0x12')][_0xb1dd('0x13')]){ami['on'](_0xb1dd('0x14'),this['voiceQueueReport'][_0xb1dd('0x15')](this));ami['on']('custom:voiceCallReport',this[_0xb1dd('0x16')][_0xb1dd('0x15')](this));ami['on'](_0xb1dd('0x17'),this[_0xb1dd('0x18')]['bind'](this));ami['on'](_0xb1dd('0x19'),this['voiceDialReport']['bind'](this));ami['on'](_0xb1dd('0x1a'),this[_0xb1dd('0x1b')][_0xb1dd('0x15')](this));ami['on'](_0xb1dd('0x1c'),this['attendedTransfer']['bind'](this));}};Report[_0xb1dd('0x1d')][_0xb1dd('0x1e')]=function(_0x358b97){var _0x671050;_0x671050=_[_0xb1dd('0x1f')](this['agents'],function(_0x5506c2){return _0x5506c2[_0xb1dd('0x20')]==_0x358b97||_0x5506c2[_0xb1dd('0x21')]==_0x358b97;});if(_[_0xb1dd('0x22')](_0x671050)){var _0xac51a6=_['find'](this['telephones'],function(_0x3b5f57){return _0x3b5f57[_0xb1dd('0x20')]==_0x358b97||_0x3b5f57['name']==_0x358b97;});if(_0xac51a6){_0x671050=_['find'](this[_0xb1dd('0xe')],function(_0x30df80){return _0x30df80[_0xb1dd('0x23')]==util[_0xb1dd('0x24')]('SIP/%s',_0xac51a6[_0xb1dd('0x21')]);});}}return _0x671050;};Report['prototype'][_0xb1dd('0x25')]=function(_0x26d913){for(var _0x707f9f=0x0;_0x707f9f<_0x26d913[_0xb1dd('0x26')];_0x707f9f+=0x1){var _0x59b0be=this['findAgent'](_0x26d913[_0x707f9f][_0xb1dd('0x27')]);if(_0x59b0be){_0x26d913[_0x707f9f]['accountcode']=_0x59b0be[_0xb1dd('0x20')];_0x26d913[_0x707f9f][_0xb1dd('0x28')]=!![];_0x26d913[_0x707f9f][_0xb1dd('0x29')]=_0x59b0be[_0xb1dd('0x21')];_0x26d913[_0x707f9f]['interface']=_['isNil'](_0x59b0be[_0xb1dd('0x23')])?util[_0xb1dd('0x24')](_0xb1dd('0x2a'),_0x59b0be[_0xb1dd('0x21')]):_0x59b0be[_0xb1dd('0x23')];if(_0x26d913[_0x707f9f][_0xb1dd('0x2b')]){_0x26d913[_0x707f9f][_0xb1dd('0x2c')]=moment()[_0xb1dd('0x24')](_0xb1dd('0x2d'));}if(_0x26d913[_0x707f9f][_0xb1dd('0x2e')]){_0x26d913[_0x707f9f][_0xb1dd('0x2f')]=moment()['format'](_0xb1dd('0x2d'));}RpcMemberReport['voiceQueueReport'](_0x26d913[_0x707f9f]);}RpcVoiceQueueReport['create'](_0x26d913[_0x707f9f]);}};function extractCalleridNumber(_0x2a920e){var _0x1a49f0=_0x2a920e[_0xb1dd('0x30')](/<(.*?)>/);return _0x1a49f0?_0x1a49f0[0x1]:_0x2a920e;}Report[_0xb1dd('0x1d')]['getAgentByInternal']=function(_0x190ae1){for(var _0xe77563=0x0;_0xe77563<Object[_0xb1dd('0x31')](this[_0xb1dd('0xe')])['length'];_0xe77563++){var _0xecaf8a=Object[_0xb1dd('0x31')](this[_0xb1dd('0xe')])[_0xe77563];var _0xdab89e=this[_0xb1dd('0xe')][_0xecaf8a];if(_0xdab89e[_0xb1dd('0x20')]===Number(_0x190ae1))return _0xdab89e;}return null;};Report[_0xb1dd('0x1d')]['getCallType']=function(_0x12ffdf){var _0x1cfd35=_0x12ffdf[_0xb1dd('0x32')][_0xb1dd('0x33')]('-')[0x0];var _0x332a5f=this[_0xb1dd('0xe')][_0x1cfd35];if(!_0x332a5f)_0x332a5f=this[_0xb1dd('0x34')](_0x12ffdf[_0xb1dd('0x35')]);return!_0x332a5f?_0xb1dd('0x36'):_0xb1dd('0x37');};Report[_0xb1dd('0x1d')][_0xb1dd('0x16')]=function(_0x4f4802){_0x4f4802[_0xb1dd('0x38')]=_0x4f4802[_0xb1dd('0x38')]||_0x4f4802[_0xb1dd('0x39')];if(_0x4f4802[_0xb1dd('0x3a')]==_0xb1dd('0x3b')){_0x4f4802['lastapplication']=_0xb1dd('0x3c');_0x4f4802['lastdata']=_0x4f4802['queue'];if(_0x4f4802[_0xb1dd('0x3d')]==_0xb1dd('0x3e')){_0x4f4802['accountcode']='';_0x4f4802[_0xb1dd('0x38')]=extractCalleridNumber(_0x4f4802[_0xb1dd('0x3f')]);}else if(_0x4f4802[_0xb1dd('0x3d')]==_0xb1dd('0x40')){if(_0x4f4802[_0xb1dd('0x38')]==_0xb1dd('0x41')){_0x4f4802['destination']=extractCalleridNumber(_0x4f4802[_0xb1dd('0x42')]);_0x4f4802[_0xb1dd('0x35')]=_0x4f4802[_0xb1dd('0x43')];_0x4f4802['destinationchannel']=[_0x4f4802[_0xb1dd('0x32')],_0x4f4802[_0xb1dd('0x32')]=_0x4f4802[_0xb1dd('0x44')]][0x0];_0x4f4802['callerid']=_0x4f4802['calleridpreview'];}else{_0x4f4802['destination']=_0x4f4802[_0xb1dd('0x35')];_0x4f4802[_0xb1dd('0x35')]=_0x4f4802[_0xb1dd('0x43')];if(_0x4f4802[_0xb1dd('0x45')]==_0xb1dd('0x46')){_0x4f4802[_0xb1dd('0x20')]=_0x4f4802[_0xb1dd('0x27')];}else{_0x4f4802['accountcode']='';}}}}else{_0x4f4802['callerid']=util[_0xb1dd('0x24')](_0xb1dd('0x47'),_0x4f4802[_0xb1dd('0x48')],_0x4f4802[_0xb1dd('0x35')]);}if(RpcVoiceTransferReport[_0xb1dd('0x49')][_0x4f4802[_0xb1dd('0x4a')]]){var _0x14f515=RpcVoiceTransferReport['transfers'][_0x4f4802[_0xb1dd('0x4a')]];_0x14f515[_0xb1dd('0x4b')]=_0x4f4802[_0xb1dd('0x4c')];RpcVoiceTransferReport['blindTransfer'](_0x14f515);delete RpcVoiceTransferReport[_0xb1dd('0x49')][_0x4f4802[_0xb1dd('0x4a')]];}if(_[_0xb1dd('0x22')](_0x4f4802[_0xb1dd('0x3a')])){_0x4f4802[_0xb1dd('0x3a')]=this[_0xb1dd('0x4d')](_0x4f4802);}if(_['isNil'](_0x4f4802[_0xb1dd('0x4e')])){var _0xd30caf=_0x4f4802['channel'][_0xb1dd('0x33')]('-')[0x0];var _0x1cced0=this[_0xb1dd('0xe')][_0xd30caf];if(!_0x1cced0)_0x1cced0=this[_0xb1dd('0x34')](_0x4f4802[_0xb1dd('0x20')]);if(_0x1cced0){_0x4f4802[_0xb1dd('0x4e')]=_0x1cced0['id'];_0x4f4802[_0xb1dd('0x4f')]=_0x1cced0[_0xb1dd('0x21')];}}RpcVoiceCallReport[_0xb1dd('0x50')](_0x4f4802);if(_0x4f4802[_0xb1dd('0x51')]){for(var _0x44e450=0x0;_0x44e450<_0x4f4802['monitors']['length'];_0x44e450+=0x1){_0x4f4802['monitorFilename']=_0x4f4802[_0xb1dd('0x52')][_0x44e450][_0xb1dd('0x53')];_0x4f4802['createdAt']=_0x4f4802[_0xb1dd('0x52')][_0x44e450][_0xb1dd('0x54')];if(_0x4f4802['exten']==_0xb1dd('0x41')){_0x4f4802['calleridnum']=_0x4f4802['connectedlinenum'];_0x4f4802[_0xb1dd('0x48')]=_0x4f4802[_0xb1dd('0x55')];_0x4f4802[_0xb1dd('0x27')]=_0x4f4802[_0xb1dd('0x20')];_0x4f4802[_0xb1dd('0x55')]=_0x4f4802[_0xb1dd('0x4f')];_0x4f4802[_0xb1dd('0x39')]=_0x4f4802[_0xb1dd('0x43')];}else if(_0x4f4802[_0xb1dd('0x39')]==_0xb1dd('0x56')){_0x4f4802[_0xb1dd('0x35')]=_0x4f4802['destination'];_0x4f4802[_0xb1dd('0x39')]=_0x4f4802[_0xb1dd('0x43')];}RpcVoiceRecording[_0xb1dd('0x50')](_0x4f4802);}}};Report[_0xb1dd('0x1d')]['voiceAgentReport']=function(_0xef6fff){if(_[_0xb1dd('0x57')](_0xef6fff)){_0xef6fff[_0xb1dd('0x58')](function(_0xc197dc){RpcVoiceAgentReport[_0xb1dd('0x50')](_0xc197dc);});}else{RpcVoiceAgentReport[_0xb1dd('0x50')](_0xef6fff);}};Report[_0xb1dd('0x1d')]['voiceDialReport']=function(_0x2725b2){RpcVoiceDialReport[_0xb1dd('0x50')](_0x2725b2);var _0x30ced0;var _0x3c55e6;var _0x674a52=_0x2725b2['channel'];if(_['startsWith'](_0x674a52,_0xb1dd('0x59'))){_0x3c55e6=_0x674a52[_0xb1dd('0x5a')](_0x674a52[_0xb1dd('0x5b')]('/')+0x1,_0x674a52[_0xb1dd('0x5b')]('@'));_0x30ced0=_['find'](this[_0xb1dd('0xe')],function(_0x5c0685){return _0x5c0685[_0xb1dd('0x5c')]==_0x3c55e6||_0x5c0685[_0xb1dd('0x5d')]==_0x3c55e6||_0x5c0685[_0xb1dd('0x20')]==_0x3c55e6;});}else{_0x3c55e6=_0x674a52[_0xb1dd('0x5a')](_0x674a52[_0xb1dd('0x5b')]('/')+0x1,_0x674a52[_0xb1dd('0x5e')]('-'));_0x30ced0=this[_0xb1dd('0x1e')](_0x3c55e6);}if(_0x30ced0){_0x2725b2[_0xb1dd('0x23')]=_['isNil'](_0x30ced0[_0xb1dd('0x23')])?util['format'](_0xb1dd('0x2a'),_0x30ced0[_0xb1dd('0x21')]):_0x30ced0['interface'];_0x2725b2[_0xb1dd('0x4f')]=_0x30ced0[_0xb1dd('0x21')];_0x2725b2[_0xb1dd('0x20')]=_0x30ced0[_0xb1dd('0x20')];RpcMemberReport['voiceDialReport'](_0x2725b2);}};Report['prototype'][_0xb1dd('0x1b')]=function(_0x66f10b){RpcVoiceTransferReport['transfers'][_0x66f10b[_0xb1dd('0x5f')]]=_0x66f10b;};Report[_0xb1dd('0x1d')][_0xb1dd('0x60')]=function(_0x191927){RpcVoiceTransferReport[_0xb1dd('0x60')](_0x191927);};module[_0xb1dd('0x61')]=Report;