Built motion from commit dc14b02d.|2.6.27
[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 _0xef02=['membername','lodash','moment','util','../../../config/environment','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceCallReport','./voiceAgentReport','./voiceDialReport','./userReport','agents','telephones','prototype','sync','realtime','xdr','disabled','bind','custom:voiceCallReport','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindTransfer','attendedtransfer','attendedTransfer','findAgent','isNil','find','accountcode','SIP/%s','name','voiceQueueReport','length','lastAssignedTo','interface','format','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexitAt','create','match','getAgentByInternal','keys','getCallType','split','calleridnum','outbound','internal','destination','exten','type','dialer','lastapplication','queue','lastdata','callerid','context','xcally-motion-preview','destinationchannel','channel','calleridpreview','disposition','connectedlinenum','\x22%s\x22\x20<%s>','calleridname','transfers','linkedid','transfereelinkedid','uniqueid','UserId','monitor','monitors','filename','createdAt','connectedlinename','originatecalleridnum','xcally-motion-dialer','isArray','forEach','startsWith','Local','substring','indexOf','mobile','phone','lastIndexOf'];(function(_0x43a044,_0xa28956){var _0x462db0=function(_0x15f1b0){while(--_0x15f1b0){_0x43a044['push'](_0x43a044['shift']());}};_0x462db0(++_0xa28956);}(_0xef02,0x1d7));var _0x2ef0=function(_0x9c8b4a,_0x2387ff){_0x9c8b4a=_0x9c8b4a-0x0;var _0x198bef=_0xef02[_0x9c8b4a];return _0x198bef;};'use strict';var _=require(_0x2ef0('0x0'));var moment=require(_0x2ef0('0x1'));var util=require(_0x2ef0('0x2'));var config=require(_0x2ef0('0x3'));var ami=require(_0x2ef0('0x4'));var RpcVoiceAgentReport=require(_0x2ef0('0x5'));var RpcVoiceCallReport=require(_0x2ef0('0x6'));var RpcVoiceDialReport=require(_0x2ef0('0x7'));var RpcMemberReport=require(_0x2ef0('0x8'));var RpcVoiceQueueReport=require('../rpc/voiceQueueReport');var RpcVoiceRecording=require(_0x2ef0('0x9'));var RpcVoiceTransferReport=require(_0x2ef0('0xa'));var VoiceQueueReport=require('./voiceQueueReport');var VoiceCallReport=require(_0x2ef0('0xb'));var VoiceAgentReport=require(_0x2ef0('0xc'));var VoiceDialReport=require(_0x2ef0('0xd'));var UserReport=require(_0x2ef0('0xe'));function Report(_0x37f410){this['realtime']=_0x37f410;this['agents']=_0x37f410[_0x2ef0('0xf')];this['telephones']=_0x37f410[_0x2ef0('0x10')];}Report[_0x2ef0('0x11')][_0x2ef0('0x12')]=function(_0xcab69f){var _0x247d14=new VoiceQueueReport(this[_0x2ef0('0x13')]);var _0x26ce69=new VoiceAgentReport(this['realtime']);var _0x197042=new VoiceDialReport(this[_0x2ef0('0x13')]);var _0x1ad7ad=new VoiceCallReport(this[_0x2ef0('0x13')]);var _0x46ad6a=new UserReport(this[_0x2ef0('0x13')]);if(config[_0x2ef0('0x14')]&&config[_0x2ef0('0x14')][_0x2ef0('0x15')]){ami['on']('custom:voiceQueueReport',this['voiceQueueReport'][_0x2ef0('0x16')](this));ami['on'](_0x2ef0('0x17'),this['voiceCallReport'][_0x2ef0('0x16')](this));ami['on'](_0x2ef0('0x18'),this[_0x2ef0('0x19')][_0x2ef0('0x16')](this));ami['on'](_0x2ef0('0x1a'),this[_0x2ef0('0x1b')][_0x2ef0('0x16')](this));ami['on']('blindtransfer',this[_0x2ef0('0x1c')][_0x2ef0('0x16')](this));ami['on'](_0x2ef0('0x1d'),this[_0x2ef0('0x1e')][_0x2ef0('0x16')](this));}};Report[_0x2ef0('0x11')][_0x2ef0('0x1f')]=function(_0x32d5d3){var _0x56b3a2;_0x56b3a2=_['find'](this['agents'],function(_0x47361e){return _0x47361e['accountcode']==_0x32d5d3||_0x47361e['name']==_0x32d5d3;});if(_[_0x2ef0('0x20')](_0x56b3a2)){var _0x709c2c=_[_0x2ef0('0x21')](this[_0x2ef0('0x10')],function(_0x334926){return _0x334926[_0x2ef0('0x22')]==_0x32d5d3||_0x334926['name']==_0x32d5d3;});if(_0x709c2c){_0x56b3a2=_['find'](this[_0x2ef0('0xf')],function(_0x544929){return _0x544929['interface']==util['format'](_0x2ef0('0x23'),_0x709c2c[_0x2ef0('0x24')]);});}}return _0x56b3a2;};Report[_0x2ef0('0x11')][_0x2ef0('0x25')]=function(_0x1a2b61){for(var _0x20fcd7=0x0;_0x20fcd7<_0x1a2b61[_0x2ef0('0x26')];_0x20fcd7+=0x1){var _0x34ba60=this[_0x2ef0('0x1f')](_0x1a2b61[_0x20fcd7]['connectedlinenum']);if(_0x34ba60){_0x1a2b61[_0x20fcd7][_0x2ef0('0x22')]=_0x34ba60[_0x2ef0('0x22')];_0x1a2b61[_0x20fcd7]['assigned']=!![];_0x1a2b61[_0x20fcd7][_0x2ef0('0x27')]=_0x34ba60[_0x2ef0('0x24')];_0x1a2b61[_0x20fcd7][_0x2ef0('0x28')]=_['isNil'](_0x34ba60['interface'])?util[_0x2ef0('0x29')](_0x2ef0('0x23'),_0x34ba60['name']):_0x34ba60[_0x2ef0('0x28')];if(_0x1a2b61[_0x20fcd7][_0x2ef0('0x2a')]){_0x1a2b61[_0x20fcd7][_0x2ef0('0x2b')]=moment()[_0x2ef0('0x29')](_0x2ef0('0x2c'));}if(_0x1a2b61[_0x20fcd7]['queuecallerexit']){_0x1a2b61[_0x20fcd7][_0x2ef0('0x2d')]=moment()[_0x2ef0('0x29')](_0x2ef0('0x2c'));}RpcMemberReport[_0x2ef0('0x25')](_0x1a2b61[_0x20fcd7]);}RpcVoiceQueueReport[_0x2ef0('0x2e')](_0x1a2b61[_0x20fcd7]);}};function extractCalleridNumber(_0x442397){var _0x9edc4=_0x442397[_0x2ef0('0x2f')](/<(.*?)>/);return _0x9edc4?_0x9edc4[0x1]:_0x442397;}Report['prototype'][_0x2ef0('0x30')]=function(_0x585319){for(var _0x359bce=0x0;_0x359bce<Object[_0x2ef0('0x31')](this['agents'])[_0x2ef0('0x26')];_0x359bce++){var _0x2dfbb9=Object[_0x2ef0('0x31')](this[_0x2ef0('0xf')])[_0x359bce];var _0x2d4e4b=this[_0x2ef0('0xf')][_0x2dfbb9];if(_0x2d4e4b[_0x2ef0('0x22')]===Number(_0x585319))return _0x2d4e4b;}return null;};Report[_0x2ef0('0x11')][_0x2ef0('0x32')]=function(_0x4c4153){var _0xdfaabb=_0x4c4153['channel'][_0x2ef0('0x33')]('-')[0x0];var _0x15d4bd=this['agents'][_0xdfaabb];if(!_0x15d4bd)_0x15d4bd=this['getAgentByInternal'](_0x4c4153[_0x2ef0('0x34')]);return!_0x15d4bd?_0x2ef0('0x35'):_0x2ef0('0x36');};Report[_0x2ef0('0x11')]['voiceCallReport']=function(_0xdc594){_0xdc594[_0x2ef0('0x37')]=_0xdc594[_0x2ef0('0x37')]||_0xdc594[_0x2ef0('0x38')];if(_0xdc594[_0x2ef0('0x39')]==_0x2ef0('0x3a')){_0xdc594[_0x2ef0('0x3b')]=_0x2ef0('0x3c');_0xdc594[_0x2ef0('0x3d')]=_0xdc594[_0x2ef0('0x3c')];if(_0xdc594['context']=='from-voip-provider'){_0xdc594['accountcode']='';_0xdc594[_0x2ef0('0x37')]=extractCalleridNumber(_0xdc594[_0x2ef0('0x3e')]);}else if(_0xdc594[_0x2ef0('0x3f')]=='from-sip'){if(_0xdc594[_0x2ef0('0x37')]==_0x2ef0('0x40')){_0xdc594['destination']=extractCalleridNumber(_0xdc594['calleridpreview']);_0xdc594[_0x2ef0('0x34')]=_0xdc594['originatecalleridnum'];_0xdc594[_0x2ef0('0x41')]=[_0xdc594[_0x2ef0('0x42')],_0xdc594[_0x2ef0('0x42')]=_0xdc594['destinationchannel']][0x0];_0xdc594[_0x2ef0('0x3e')]=_0xdc594[_0x2ef0('0x43')];}else{_0xdc594[_0x2ef0('0x37')]=_0xdc594['calleridnum'];_0xdc594[_0x2ef0('0x34')]=_0xdc594['originatecalleridnum'];if(_0xdc594[_0x2ef0('0x44')]=='ANSWERED'){_0xdc594[_0x2ef0('0x22')]=_0xdc594[_0x2ef0('0x45')];}else{_0xdc594[_0x2ef0('0x22')]='';}}}}else{_0xdc594[_0x2ef0('0x3e')]=util[_0x2ef0('0x29')](_0x2ef0('0x46'),_0xdc594[_0x2ef0('0x47')],_0xdc594[_0x2ef0('0x34')]);}if(RpcVoiceTransferReport[_0x2ef0('0x48')][_0xdc594[_0x2ef0('0x49')]]){var _0x4f7ac0=RpcVoiceTransferReport['transfers'][_0xdc594[_0x2ef0('0x49')]];_0x4f7ac0[_0x2ef0('0x4a')]=_0xdc594[_0x2ef0('0x4b')];RpcVoiceTransferReport[_0x2ef0('0x1c')](_0x4f7ac0);delete RpcVoiceTransferReport[_0x2ef0('0x48')][_0xdc594[_0x2ef0('0x49')]];}if(_[_0x2ef0('0x20')](_0xdc594[_0x2ef0('0x39')])){_0xdc594['type']=this[_0x2ef0('0x32')](_0xdc594);}if(_[_0x2ef0('0x20')](_0xdc594[_0x2ef0('0x4c')])){var _0x22cbf0=_0xdc594[_0x2ef0('0x42')][_0x2ef0('0x33')]('-')[0x0];var _0x4f3d2a=this[_0x2ef0('0xf')][_0x22cbf0];if(!_0x4f3d2a)_0x4f3d2a=this['getAgentByInternal'](_0xdc594[_0x2ef0('0x22')]);if(_0x4f3d2a){_0xdc594[_0x2ef0('0x4c')]=_0x4f3d2a['id'];_0xdc594['membername']=_0x4f3d2a[_0x2ef0('0x24')];}}RpcVoiceCallReport[_0x2ef0('0x2e')](_0xdc594);if(_0xdc594[_0x2ef0('0x4d')]){for(var _0x3e2455=0x0;_0x3e2455<_0xdc594[_0x2ef0('0x4e')][_0x2ef0('0x26')];_0x3e2455+=0x1){_0xdc594['monitorFilename']=_0xdc594['monitors'][_0x3e2455][_0x2ef0('0x4f')];_0xdc594[_0x2ef0('0x50')]=_0xdc594[_0x2ef0('0x4e')][_0x3e2455][_0x2ef0('0x50')];if(_0xdc594[_0x2ef0('0x38')]=='xcally-motion-preview'){_0xdc594[_0x2ef0('0x34')]=_0xdc594[_0x2ef0('0x45')];_0xdc594[_0x2ef0('0x47')]=_0xdc594[_0x2ef0('0x51')];_0xdc594[_0x2ef0('0x45')]=_0xdc594[_0x2ef0('0x22')];_0xdc594['connectedlinename']=_0xdc594['membername'];_0xdc594['exten']=_0xdc594[_0x2ef0('0x52')];}else if(_0xdc594[_0x2ef0('0x38')]==_0x2ef0('0x53')){_0xdc594['calleridnum']=_0xdc594[_0x2ef0('0x37')];_0xdc594[_0x2ef0('0x38')]=_0xdc594['originatecalleridnum'];}RpcVoiceRecording[_0x2ef0('0x2e')](_0xdc594);}}};Report['prototype'][_0x2ef0('0x19')]=function(_0x3d27f1){if(_[_0x2ef0('0x54')](_0x3d27f1)){_0x3d27f1[_0x2ef0('0x55')](function(_0x32c827){RpcVoiceAgentReport['create'](_0x32c827);});}else{RpcVoiceAgentReport[_0x2ef0('0x2e')](_0x3d27f1);}};Report[_0x2ef0('0x11')][_0x2ef0('0x1b')]=function(_0x2f8f82){RpcVoiceDialReport[_0x2ef0('0x2e')](_0x2f8f82);var _0x1a8085;var _0x39ce1d;var _0x4390f1=_0x2f8f82[_0x2ef0('0x42')];if(_[_0x2ef0('0x56')](_0x4390f1,_0x2ef0('0x57'))){_0x39ce1d=_0x4390f1[_0x2ef0('0x58')](_0x4390f1['indexOf']('/')+0x1,_0x4390f1[_0x2ef0('0x59')]('@'));_0x1a8085=_[_0x2ef0('0x21')](this[_0x2ef0('0xf')],function(_0xcb07bb){return _0xcb07bb[_0x2ef0('0x5a')]==_0x39ce1d||_0xcb07bb[_0x2ef0('0x5b')]==_0x39ce1d||_0xcb07bb[_0x2ef0('0x22')]==_0x39ce1d;});}else{_0x39ce1d=_0x4390f1[_0x2ef0('0x58')](_0x4390f1['indexOf']('/')+0x1,_0x4390f1[_0x2ef0('0x5c')]('-'));_0x1a8085=this[_0x2ef0('0x1f')](_0x39ce1d);}if(_0x1a8085){_0x2f8f82[_0x2ef0('0x28')]=_[_0x2ef0('0x20')](_0x1a8085[_0x2ef0('0x28')])?util[_0x2ef0('0x29')](_0x2ef0('0x23'),_0x1a8085['name']):_0x1a8085[_0x2ef0('0x28')];_0x2f8f82[_0x2ef0('0x5d')]=_0x1a8085[_0x2ef0('0x24')];_0x2f8f82[_0x2ef0('0x22')]=_0x1a8085['accountcode'];RpcMemberReport[_0x2ef0('0x1b')](_0x2f8f82);}};Report[_0x2ef0('0x11')][_0x2ef0('0x1c')]=function(_0x5ba036){RpcVoiceTransferReport[_0x2ef0('0x48')][_0x5ba036['transfererlinkedid']]=_0x5ba036;};Report['prototype'][_0x2ef0('0x1e')]=function(_0x1f94f3){RpcVoiceTransferReport[_0x2ef0('0x1e')](_0x1f94f3);};module['exports']=Report;