Built motion from commit (unavailable).|2.5.21
[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 _0x3f8e=['isNil','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexitAt','create','match','voiceCallReport','destination','exten','type','dialer','lastapplication','queue','lastdata','context','from-voip-provider','callerid','from-sip','xcally-motion-preview','calleridpreview','calleridnum','originatecalleridnum','channel','destinationchannel','disposition','\x22%s\x22\x20<%s>','calleridname','transfers','linkedid','transfereelinkedid','uniqueid','monitors','monitorFilename','createdAt','connectedlinename','membername','xcally-motion-dialer','isArray','forEach','startsWith','substring','indexOf','mobile','phone','voiceDialReport','transfererlinkedid','attendedTransfer','exports','lodash','moment','util','../../../config/environment','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceDialReport','./userReport','realtime','agents','telephones','prototype','sync','custom:voiceQueueReport','voiceQueueReport','bind','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','blindtransfer','blindTransfer','findAgent','find','name','accountcode','interface','format','SIP/%s','length','connectedlinenum','lastAssignedTo'];(function(_0x39096d,_0x51f8a0){var _0x13da4f=function(_0x11e6b2){while(--_0x11e6b2){_0x39096d['push'](_0x39096d['shift']());}};_0x13da4f(++_0x51f8a0);}(_0x3f8e,0x1e4));var _0xe3f8=function(_0x5202f0,_0x3f14d7){_0x5202f0=_0x5202f0-0x0;var _0x17817e=_0x3f8e[_0x5202f0];return _0x17817e;};'use strict';var _=require(_0xe3f8('0x0'));var moment=require(_0xe3f8('0x1'));var util=require(_0xe3f8('0x2'));var config=require(_0xe3f8('0x3'));var ami=require(_0xe3f8('0x4'));var RpcVoiceAgentReport=require(_0xe3f8('0x5'));var RpcVoiceCallReport=require(_0xe3f8('0x6'));var RpcVoiceDialReport=require(_0xe3f8('0x7'));var RpcMemberReport=require(_0xe3f8('0x8'));var RpcVoiceQueueReport=require(_0xe3f8('0x9'));var RpcVoiceRecording=require(_0xe3f8('0xa'));var RpcVoiceTransferReport=require(_0xe3f8('0xb'));var VoiceQueueReport=require(_0xe3f8('0xc'));var VoiceCallReport=require('./voiceCallReport');var VoiceAgentReport=require('./voiceAgentReport');var VoiceDialReport=require(_0xe3f8('0xd'));var UserReport=require(_0xe3f8('0xe'));function Report(_0x535426){this[_0xe3f8('0xf')]=_0x535426;this[_0xe3f8('0x10')]=_0x535426['agents'];this[_0xe3f8('0x11')]=_0x535426[_0xe3f8('0x11')];}Report[_0xe3f8('0x12')][_0xe3f8('0x13')]=function(_0x330b67){var _0x163a08=new VoiceQueueReport(this[_0xe3f8('0xf')]);var _0x27e0e8=new VoiceAgentReport(this['realtime']);var _0x5ce4fd=new VoiceDialReport(this[_0xe3f8('0xf')]);var _0x4fe85a=new VoiceCallReport(this[_0xe3f8('0xf')]);var _0x3ff99b=new UserReport(this[_0xe3f8('0xf')]);if(config['xdr']&&config['xdr']['disabled']){ami['on'](_0xe3f8('0x14'),this[_0xe3f8('0x15')][_0xe3f8('0x16')](this));ami['on']('custom:voiceCallReport',this['voiceCallReport'][_0xe3f8('0x16')](this));ami['on'](_0xe3f8('0x17'),this[_0xe3f8('0x18')][_0xe3f8('0x16')](this));ami['on'](_0xe3f8('0x19'),this['voiceDialReport']['bind'](this));ami['on'](_0xe3f8('0x1a'),this[_0xe3f8('0x1b')][_0xe3f8('0x16')](this));ami['on']('attendedtransfer',this['attendedTransfer'][_0xe3f8('0x16')](this));}};Report[_0xe3f8('0x12')][_0xe3f8('0x1c')]=function(_0x5eccc8){var _0x30292b;_0x30292b=_[_0xe3f8('0x1d')](this[_0xe3f8('0x10')],function(_0xbe6707){return _0xbe6707['accountcode']==_0x5eccc8||_0xbe6707[_0xe3f8('0x1e')]==_0x5eccc8;});if(_['isNil'](_0x30292b)){var _0xb1456b=_[_0xe3f8('0x1d')](this[_0xe3f8('0x11')],function(_0x5bb8d6){return _0x5bb8d6[_0xe3f8('0x1f')]==_0x5eccc8||_0x5bb8d6[_0xe3f8('0x1e')]==_0x5eccc8;});if(_0xb1456b){_0x30292b=_['find'](this['agents'],function(_0x4b2d5a){return _0x4b2d5a[_0xe3f8('0x20')]==util[_0xe3f8('0x21')](_0xe3f8('0x22'),_0xb1456b['name']);});}}return _0x30292b;};Report[_0xe3f8('0x12')]['voiceQueueReport']=function(_0x50bc8e){for(var _0x5e0545=0x0;_0x5e0545<_0x50bc8e[_0xe3f8('0x23')];_0x5e0545+=0x1){var _0x2eef79=this[_0xe3f8('0x1c')](_0x50bc8e[_0x5e0545][_0xe3f8('0x24')]);if(_0x2eef79){_0x50bc8e[_0x5e0545][_0xe3f8('0x1f')]=_0x2eef79[_0xe3f8('0x1f')];_0x50bc8e[_0x5e0545]['assigned']=!![];_0x50bc8e[_0x5e0545][_0xe3f8('0x25')]=_0x2eef79[_0xe3f8('0x1e')];_0x50bc8e[_0x5e0545][_0xe3f8('0x20')]=_[_0xe3f8('0x26')](_0x2eef79[_0xe3f8('0x20')])?util[_0xe3f8('0x21')](_0xe3f8('0x22'),_0x2eef79[_0xe3f8('0x1e')]):_0x2eef79['interface'];if(_0x50bc8e[_0x5e0545][_0xe3f8('0x27')]){_0x50bc8e[_0x5e0545][_0xe3f8('0x28')]=moment()[_0xe3f8('0x21')](_0xe3f8('0x29'));}if(_0x50bc8e[_0x5e0545]['queuecallerexit']){_0x50bc8e[_0x5e0545][_0xe3f8('0x2a')]=moment()[_0xe3f8('0x21')](_0xe3f8('0x29'));}RpcMemberReport[_0xe3f8('0x15')](_0x50bc8e[_0x5e0545]);}RpcVoiceQueueReport[_0xe3f8('0x2b')](_0x50bc8e[_0x5e0545]);}};function extractCalleridNumber(_0x1151ed){var _0x52cba8=_0x1151ed[_0xe3f8('0x2c')](/<(.*?)>/);return _0x52cba8?_0x52cba8[0x1]:_0x1151ed;}Report[_0xe3f8('0x12')][_0xe3f8('0x2d')]=function(_0x482506){_0x482506[_0xe3f8('0x2e')]=_0x482506['destination']||_0x482506[_0xe3f8('0x2f')];if(_0x482506[_0xe3f8('0x30')]==_0xe3f8('0x31')){_0x482506[_0xe3f8('0x32')]=_0xe3f8('0x33');_0x482506[_0xe3f8('0x34')]=_0x482506['queue'];if(_0x482506[_0xe3f8('0x35')]==_0xe3f8('0x36')){_0x482506['accountcode']='';_0x482506[_0xe3f8('0x2e')]=extractCalleridNumber(_0x482506[_0xe3f8('0x37')]);}else if(_0x482506[_0xe3f8('0x35')]==_0xe3f8('0x38')){if(_0x482506[_0xe3f8('0x2e')]==_0xe3f8('0x39')){_0x482506[_0xe3f8('0x2e')]=extractCalleridNumber(_0x482506[_0xe3f8('0x3a')]);_0x482506[_0xe3f8('0x3b')]=_0x482506[_0xe3f8('0x3c')];_0x482506['destinationchannel']=[_0x482506['channel'],_0x482506[_0xe3f8('0x3d')]=_0x482506[_0xe3f8('0x3e')]][0x0];_0x482506[_0xe3f8('0x37')]=_0x482506[_0xe3f8('0x3a')];}else{_0x482506[_0xe3f8('0x2e')]=_0x482506[_0xe3f8('0x3b')];_0x482506[_0xe3f8('0x3b')]=_0x482506[_0xe3f8('0x3c')];if(_0x482506[_0xe3f8('0x3f')]=='ANSWERED'){_0x482506['accountcode']=_0x482506[_0xe3f8('0x24')];}else{_0x482506[_0xe3f8('0x1f')]='';}}}}else{_0x482506['callerid']=util[_0xe3f8('0x21')](_0xe3f8('0x40'),_0x482506[_0xe3f8('0x41')],_0x482506[_0xe3f8('0x3b')]);}if(RpcVoiceTransferReport[_0xe3f8('0x42')][_0x482506[_0xe3f8('0x43')]]){var _0x297e33=RpcVoiceTransferReport['transfers'][_0x482506[_0xe3f8('0x43')]];_0x297e33[_0xe3f8('0x44')]=_0x482506[_0xe3f8('0x45')];RpcVoiceTransferReport[_0xe3f8('0x1b')](_0x297e33);delete RpcVoiceTransferReport[_0xe3f8('0x42')][_0x482506[_0xe3f8('0x43')]];}RpcVoiceCallReport[_0xe3f8('0x2b')](_0x482506);if(_0x482506['monitor']){for(var _0x47948f=0x0;_0x47948f<_0x482506[_0xe3f8('0x46')][_0xe3f8('0x23')];_0x47948f+=0x1){_0x482506[_0xe3f8('0x47')]=_0x482506[_0xe3f8('0x46')][_0x47948f]['filename'];_0x482506[_0xe3f8('0x48')]=_0x482506[_0xe3f8('0x46')][_0x47948f][_0xe3f8('0x48')];if(_0x482506['exten']==_0xe3f8('0x39')){_0x482506[_0xe3f8('0x3b')]=_0x482506[_0xe3f8('0x24')];_0x482506[_0xe3f8('0x41')]=_0x482506[_0xe3f8('0x49')];_0x482506[_0xe3f8('0x24')]=_0x482506[_0xe3f8('0x1f')];_0x482506['connectedlinename']=_0x482506[_0xe3f8('0x4a')];_0x482506[_0xe3f8('0x2f')]=_0x482506[_0xe3f8('0x3c')];}else if(_0x482506[_0xe3f8('0x2f')]==_0xe3f8('0x4b')){_0x482506[_0xe3f8('0x3b')]=_0x482506[_0xe3f8('0x2e')];_0x482506[_0xe3f8('0x2f')]=_0x482506[_0xe3f8('0x3c')];}RpcVoiceRecording[_0xe3f8('0x2b')](_0x482506);}}};Report[_0xe3f8('0x12')][_0xe3f8('0x18')]=function(_0x3037ff){if(_[_0xe3f8('0x4c')](_0x3037ff)){_0x3037ff[_0xe3f8('0x4d')](function(_0x17708e){RpcVoiceAgentReport[_0xe3f8('0x2b')](_0x17708e);});}else{RpcVoiceAgentReport[_0xe3f8('0x2b')](_0x3037ff);}};Report['prototype']['voiceDialReport']=function(_0x595d63){RpcVoiceDialReport[_0xe3f8('0x2b')](_0x595d63);var _0x1279ae;var _0x1d4520;var _0x437f9e=_0x595d63['channel'];if(_[_0xe3f8('0x4e')](_0x437f9e,'Local')){_0x1d4520=_0x437f9e[_0xe3f8('0x4f')](_0x437f9e['indexOf']('/')+0x1,_0x437f9e[_0xe3f8('0x50')]('@'));_0x1279ae=_['find'](this[_0xe3f8('0x10')],function(_0x154654){return _0x154654[_0xe3f8('0x51')]==_0x1d4520||_0x154654[_0xe3f8('0x52')]==_0x1d4520||_0x154654['accountcode']==_0x1d4520;});}else{_0x1d4520=_0x437f9e[_0xe3f8('0x4f')](_0x437f9e[_0xe3f8('0x50')]('/')+0x1,_0x437f9e['lastIndexOf']('-'));_0x1279ae=this[_0xe3f8('0x1c')](_0x1d4520);}if(_0x1279ae){_0x595d63[_0xe3f8('0x20')]=_[_0xe3f8('0x26')](_0x1279ae[_0xe3f8('0x20')])?util[_0xe3f8('0x21')]('SIP/%s',_0x1279ae['name']):_0x1279ae[_0xe3f8('0x20')];_0x595d63[_0xe3f8('0x4a')]=_0x1279ae[_0xe3f8('0x1e')];_0x595d63[_0xe3f8('0x1f')]=_0x1279ae[_0xe3f8('0x1f')];RpcMemberReport[_0xe3f8('0x53')](_0x595d63);}};Report['prototype'][_0xe3f8('0x1b')]=function(_0x109dcb){RpcVoiceTransferReport[_0xe3f8('0x42')][_0x109dcb[_0xe3f8('0x54')]]=_0x109dcb;};Report[_0xe3f8('0x12')][_0xe3f8('0x55')]=function(_0x3cd7f8){RpcVoiceTransferReport[_0xe3f8('0x55')](_0x3cd7f8);};module[_0xe3f8('0x56')]=Report;