Built motion from commit 19a84241.|2.5.34
[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 _0x01be=['context','callerid','from-sip','xcally-motion-preview','calleridpreview','originatecalleridnum','destinationchannel','channel','calleridnum','disposition','ANSWERED','\x22%s\x22\x20<%s>','calleridname','transfers','linkedid','transfereelinkedid','uniqueid','monitor','monitors','monitorFilename','filename','createdAt','connectedlinename','membername','xcally-motion-dialer','isArray','forEach','startsWith','Local','indexOf','substring','transfererlinkedid','lodash','moment','util','../../../config/environment','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','./voiceCallReport','./voiceAgentReport','./voiceDialReport','./userReport','realtime','agents','telephones','prototype','sync','xdr','disabled','voiceQueueReport','bind','custom:voiceCallReport','voiceCallReport','custom:voiceAgentReport','voiceAgentReport','voiceDialReport','blindTransfer','attendedtransfer','attendedTransfer','findAgent','find','accountcode','name','interface','format','SIP/%s','length','connectedlinenum','lastAssignedTo','isNil','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','match','destination','exten','dialer','queue','lastdata'];(function(_0x347498,_0x332242){var _0x334f2b=function(_0x4156d1){while(--_0x4156d1){_0x347498['push'](_0x347498['shift']());}};_0x334f2b(++_0x332242);}(_0x01be,0x1d3));var _0xe01b=function(_0x346abb,_0x3d01b){_0x346abb=_0x346abb-0x0;var _0x3d5cc8=_0x01be[_0x346abb];return _0x3d5cc8;};'use strict';var _=require(_0xe01b('0x0'));var moment=require(_0xe01b('0x1'));var util=require(_0xe01b('0x2'));var config=require(_0xe01b('0x3'));var ami=require(_0xe01b('0x4'));var RpcVoiceAgentReport=require(_0xe01b('0x5'));var RpcVoiceCallReport=require(_0xe01b('0x6'));var RpcVoiceDialReport=require(_0xe01b('0x7'));var RpcMemberReport=require(_0xe01b('0x8'));var RpcVoiceQueueReport=require(_0xe01b('0x9'));var RpcVoiceRecording=require(_0xe01b('0xa'));var RpcVoiceTransferReport=require('../rpc/voiceTransferReport');var VoiceQueueReport=require('./voiceQueueReport');var VoiceCallReport=require(_0xe01b('0xb'));var VoiceAgentReport=require(_0xe01b('0xc'));var VoiceDialReport=require(_0xe01b('0xd'));var UserReport=require(_0xe01b('0xe'));function Report(_0x19d1eb){this[_0xe01b('0xf')]=_0x19d1eb;this['agents']=_0x19d1eb[_0xe01b('0x10')];this[_0xe01b('0x11')]=_0x19d1eb[_0xe01b('0x11')];}Report[_0xe01b('0x12')][_0xe01b('0x13')]=function(_0x19f53e){var _0x2e1645=new VoiceQueueReport(this['realtime']);var _0x12ffb8=new VoiceAgentReport(this[_0xe01b('0xf')]);var _0x2e47c0=new VoiceDialReport(this[_0xe01b('0xf')]);var _0x34fb08=new VoiceCallReport(this[_0xe01b('0xf')]);var _0x3d8fec=new UserReport(this[_0xe01b('0xf')]);if(config[_0xe01b('0x14')]&&config['xdr'][_0xe01b('0x15')]){ami['on']('custom:voiceQueueReport',this[_0xe01b('0x16')][_0xe01b('0x17')](this));ami['on'](_0xe01b('0x18'),this[_0xe01b('0x19')][_0xe01b('0x17')](this));ami['on'](_0xe01b('0x1a'),this[_0xe01b('0x1b')][_0xe01b('0x17')](this));ami['on']('custom:voiceDialReport',this[_0xe01b('0x1c')]['bind'](this));ami['on']('blindtransfer',this[_0xe01b('0x1d')][_0xe01b('0x17')](this));ami['on'](_0xe01b('0x1e'),this[_0xe01b('0x1f')][_0xe01b('0x17')](this));}};Report[_0xe01b('0x12')][_0xe01b('0x20')]=function(_0xd159af){var _0x41fb0c;_0x41fb0c=_[_0xe01b('0x21')](this[_0xe01b('0x10')],function(_0x2a627b){return _0x2a627b[_0xe01b('0x22')]==_0xd159af||_0x2a627b[_0xe01b('0x23')]==_0xd159af;});if(_['isNil'](_0x41fb0c)){var _0x542701=_['find'](this['telephones'],function(_0x307e15){return _0x307e15[_0xe01b('0x22')]==_0xd159af||_0x307e15[_0xe01b('0x23')]==_0xd159af;});if(_0x542701){_0x41fb0c=_[_0xe01b('0x21')](this[_0xe01b('0x10')],function(_0x5a075d){return _0x5a075d[_0xe01b('0x24')]==util[_0xe01b('0x25')](_0xe01b('0x26'),_0x542701[_0xe01b('0x23')]);});}}return _0x41fb0c;};Report[_0xe01b('0x12')][_0xe01b('0x16')]=function(_0xc510b5){for(var _0x1bbfcc=0x0;_0x1bbfcc<_0xc510b5[_0xe01b('0x27')];_0x1bbfcc+=0x1){var _0x2153b9=this['findAgent'](_0xc510b5[_0x1bbfcc][_0xe01b('0x28')]);if(_0x2153b9){_0xc510b5[_0x1bbfcc][_0xe01b('0x22')]=_0x2153b9[_0xe01b('0x22')];_0xc510b5[_0x1bbfcc]['assigned']=!![];_0xc510b5[_0x1bbfcc][_0xe01b('0x29')]=_0x2153b9[_0xe01b('0x23')];_0xc510b5[_0x1bbfcc][_0xe01b('0x24')]=_[_0xe01b('0x2a')](_0x2153b9['interface'])?util['format'](_0xe01b('0x26'),_0x2153b9[_0xe01b('0x23')]):_0x2153b9['interface'];if(_0xc510b5[_0x1bbfcc][_0xe01b('0x2b')]){_0xc510b5[_0x1bbfcc][_0xe01b('0x2c')]=moment()['format'](_0xe01b('0x2d'));}if(_0xc510b5[_0x1bbfcc][_0xe01b('0x2e')]){_0xc510b5[_0x1bbfcc][_0xe01b('0x2f')]=moment()[_0xe01b('0x25')]('YYYY-MM-DD\x20HH:mm:ss');}RpcMemberReport[_0xe01b('0x16')](_0xc510b5[_0x1bbfcc]);}RpcVoiceQueueReport[_0xe01b('0x30')](_0xc510b5[_0x1bbfcc]);}};function extractCalleridNumber(_0x38d7e9){var _0x39dd5e=_0x38d7e9[_0xe01b('0x31')](/<(.*?)>/);return _0x39dd5e?_0x39dd5e[0x1]:_0x38d7e9;}Report['prototype'][_0xe01b('0x19')]=function(_0x322719){_0x322719[_0xe01b('0x32')]=_0x322719[_0xe01b('0x32')]||_0x322719[_0xe01b('0x33')];if(_0x322719['type']==_0xe01b('0x34')){_0x322719['lastapplication']=_0xe01b('0x35');_0x322719[_0xe01b('0x36')]=_0x322719[_0xe01b('0x35')];if(_0x322719[_0xe01b('0x37')]=='from-voip-provider'){_0x322719[_0xe01b('0x22')]='';_0x322719[_0xe01b('0x32')]=extractCalleridNumber(_0x322719[_0xe01b('0x38')]);}else if(_0x322719[_0xe01b('0x37')]==_0xe01b('0x39')){if(_0x322719[_0xe01b('0x32')]==_0xe01b('0x3a')){_0x322719[_0xe01b('0x32')]=extractCalleridNumber(_0x322719[_0xe01b('0x3b')]);_0x322719['calleridnum']=_0x322719[_0xe01b('0x3c')];_0x322719[_0xe01b('0x3d')]=[_0x322719[_0xe01b('0x3e')],_0x322719[_0xe01b('0x3e')]=_0x322719[_0xe01b('0x3d')]][0x0];_0x322719[_0xe01b('0x38')]=_0x322719[_0xe01b('0x3b')];}else{_0x322719[_0xe01b('0x32')]=_0x322719[_0xe01b('0x3f')];_0x322719['calleridnum']=_0x322719[_0xe01b('0x3c')];if(_0x322719[_0xe01b('0x40')]==_0xe01b('0x41')){_0x322719[_0xe01b('0x22')]=_0x322719[_0xe01b('0x28')];}else{_0x322719[_0xe01b('0x22')]='';}}}}else{_0x322719[_0xe01b('0x38')]=util['format'](_0xe01b('0x42'),_0x322719[_0xe01b('0x43')],_0x322719[_0xe01b('0x3f')]);}if(RpcVoiceTransferReport[_0xe01b('0x44')][_0x322719[_0xe01b('0x45')]]){var _0x5831e8=RpcVoiceTransferReport[_0xe01b('0x44')][_0x322719[_0xe01b('0x45')]];_0x5831e8[_0xe01b('0x46')]=_0x322719[_0xe01b('0x47')];RpcVoiceTransferReport[_0xe01b('0x1d')](_0x5831e8);delete RpcVoiceTransferReport[_0xe01b('0x44')][_0x322719['linkedid']];}RpcVoiceCallReport[_0xe01b('0x30')](_0x322719);if(_0x322719[_0xe01b('0x48')]){for(var _0x3b3c1d=0x0;_0x3b3c1d<_0x322719[_0xe01b('0x49')][_0xe01b('0x27')];_0x3b3c1d+=0x1){_0x322719[_0xe01b('0x4a')]=_0x322719[_0xe01b('0x49')][_0x3b3c1d][_0xe01b('0x4b')];_0x322719['createdAt']=_0x322719[_0xe01b('0x49')][_0x3b3c1d][_0xe01b('0x4c')];if(_0x322719[_0xe01b('0x33')]==_0xe01b('0x3a')){_0x322719['calleridnum']=_0x322719[_0xe01b('0x28')];_0x322719['calleridname']=_0x322719[_0xe01b('0x4d')];_0x322719[_0xe01b('0x28')]=_0x322719[_0xe01b('0x22')];_0x322719['connectedlinename']=_0x322719[_0xe01b('0x4e')];_0x322719[_0xe01b('0x33')]=_0x322719[_0xe01b('0x3c')];}else if(_0x322719['exten']==_0xe01b('0x4f')){_0x322719[_0xe01b('0x3f')]=_0x322719[_0xe01b('0x32')];_0x322719[_0xe01b('0x33')]=_0x322719[_0xe01b('0x3c')];}RpcVoiceRecording[_0xe01b('0x30')](_0x322719);}}};Report[_0xe01b('0x12')][_0xe01b('0x1b')]=function(_0x690fad){if(_[_0xe01b('0x50')](_0x690fad)){_0x690fad[_0xe01b('0x51')](function(_0x39c46f){RpcVoiceAgentReport[_0xe01b('0x30')](_0x39c46f);});}else{RpcVoiceAgentReport['create'](_0x690fad);}};Report['prototype'][_0xe01b('0x1c')]=function(_0x20f081){RpcVoiceDialReport[_0xe01b('0x30')](_0x20f081);var _0x3a88f0;var _0x5e3cf2;var _0x5b95e1=_0x20f081[_0xe01b('0x3e')];if(_[_0xe01b('0x52')](_0x5b95e1,_0xe01b('0x53'))){_0x5e3cf2=_0x5b95e1['substring'](_0x5b95e1[_0xe01b('0x54')]('/')+0x1,_0x5b95e1[_0xe01b('0x54')]('@'));_0x3a88f0=_['find'](this[_0xe01b('0x10')],function(_0x9ac30){return _0x9ac30['mobile']==_0x5e3cf2||_0x9ac30['phone']==_0x5e3cf2||_0x9ac30[_0xe01b('0x22')]==_0x5e3cf2;});}else{_0x5e3cf2=_0x5b95e1[_0xe01b('0x55')](_0x5b95e1[_0xe01b('0x54')]('/')+0x1,_0x5b95e1['lastIndexOf']('-'));_0x3a88f0=this[_0xe01b('0x20')](_0x5e3cf2);}if(_0x3a88f0){_0x20f081[_0xe01b('0x24')]=_['isNil'](_0x3a88f0[_0xe01b('0x24')])?util[_0xe01b('0x25')](_0xe01b('0x26'),_0x3a88f0[_0xe01b('0x23')]):_0x3a88f0[_0xe01b('0x24')];_0x20f081['membername']=_0x3a88f0['name'];_0x20f081['accountcode']=_0x3a88f0[_0xe01b('0x22')];RpcMemberReport[_0xe01b('0x1c')](_0x20f081);}};Report[_0xe01b('0x12')][_0xe01b('0x1d')]=function(_0x3e714a){RpcVoiceTransferReport['transfers'][_0x3e714a[_0xe01b('0x56')]]=_0x3e714a;};Report[_0xe01b('0x12')]['attendedTransfer']=function(_0x3d8c5a){RpcVoiceTransferReport[_0xe01b('0x1f')](_0x3d8c5a);};module['exports']=Report;