Built motion from commit c738b9ac.|2.6.25
[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 _0x8f3e=['telephones','prototype','sync','xdr','disabled','custom:voiceQueueReport','voiceQueueReport','bind','custom:voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindtransfer','blindTransfer','attendedtransfer','attendedTransfer','findAgent','find','accountcode','name','format','SIP/%s','assigned','lastAssignedTo','interface','isNil','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','match','getAgentByInternal','keys','length','getCallType','channel','internal','voiceCallReport','destination','exten','type','dialer','lastapplication','lastdata','context','from-voip-provider','callerid','xcally-motion-preview','calleridpreview','calleridnum','originatecalleridnum','disposition','ANSWERED','connectedlinenum','\x22%s\x22\x20<%s>','transfers','linkedid','transfereelinkedid','UserId','membername','create','monitor','monitorFilename','monitors','filename','createdAt','calleridname','connectedlinename','xcally-motion-dialer','voiceAgentReport','isArray','forEach','startsWith','Local','substring','indexOf','mobile','phone','lastIndexOf','transfererlinkedid','lodash','moment','util','../../../config/environment','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceAgentReport','./voiceDialReport','./userReport','realtime','agents'];(function(_0x526589,_0x5b9207){var _0x4ea997=function(_0x524516){while(--_0x524516){_0x526589['push'](_0x526589['shift']());}};_0x4ea997(++_0x5b9207);}(_0x8f3e,0x1cb));var _0xe8f3=function(_0x1c5319,_0x3a5250){_0x1c5319=_0x1c5319-0x0;var _0x540520=_0x8f3e[_0x1c5319];return _0x540520;};'use strict';var _=require(_0xe8f3('0x0'));var moment=require(_0xe8f3('0x1'));var util=require(_0xe8f3('0x2'));var config=require(_0xe8f3('0x3'));var ami=require(_0xe8f3('0x4'));var RpcVoiceAgentReport=require(_0xe8f3('0x5'));var RpcVoiceCallReport=require(_0xe8f3('0x6'));var RpcVoiceDialReport=require(_0xe8f3('0x7'));var RpcMemberReport=require(_0xe8f3('0x8'));var RpcVoiceQueueReport=require('../rpc/voiceQueueReport');var RpcVoiceRecording=require(_0xe8f3('0x9'));var RpcVoiceTransferReport=require(_0xe8f3('0xa'));var VoiceQueueReport=require('./voiceQueueReport');var VoiceCallReport=require('./voiceCallReport');var VoiceAgentReport=require(_0xe8f3('0xb'));var VoiceDialReport=require(_0xe8f3('0xc'));var UserReport=require(_0xe8f3('0xd'));function Report(_0x45228d){this[_0xe8f3('0xe')]=_0x45228d;this['agents']=_0x45228d[_0xe8f3('0xf')];this[_0xe8f3('0x10')]=_0x45228d[_0xe8f3('0x10')];}Report[_0xe8f3('0x11')][_0xe8f3('0x12')]=function(_0x1c076a){var _0xbd62a0=new VoiceQueueReport(this[_0xe8f3('0xe')]);var _0x29bdd0=new VoiceAgentReport(this[_0xe8f3('0xe')]);var _0x4d0e9e=new VoiceDialReport(this[_0xe8f3('0xe')]);var _0x2e8c8b=new VoiceCallReport(this[_0xe8f3('0xe')]);var _0x35ead9=new UserReport(this[_0xe8f3('0xe')]);if(config[_0xe8f3('0x13')]&&config['xdr'][_0xe8f3('0x14')]){ami['on'](_0xe8f3('0x15'),this[_0xe8f3('0x16')][_0xe8f3('0x17')](this));ami['on']('custom:voiceCallReport',this['voiceCallReport'][_0xe8f3('0x17')](this));ami['on'](_0xe8f3('0x18'),this['voiceAgentReport'][_0xe8f3('0x17')](this));ami['on'](_0xe8f3('0x19'),this[_0xe8f3('0x1a')][_0xe8f3('0x17')](this));ami['on'](_0xe8f3('0x1b'),this[_0xe8f3('0x1c')][_0xe8f3('0x17')](this));ami['on'](_0xe8f3('0x1d'),this[_0xe8f3('0x1e')][_0xe8f3('0x17')](this));}};Report[_0xe8f3('0x11')][_0xe8f3('0x1f')]=function(_0xebebdc){var _0xa146af;_0xa146af=_[_0xe8f3('0x20')](this[_0xe8f3('0xf')],function(_0x2c15c7){return _0x2c15c7[_0xe8f3('0x21')]==_0xebebdc||_0x2c15c7[_0xe8f3('0x22')]==_0xebebdc;});if(_['isNil'](_0xa146af)){var _0x3a6f53=_['find'](this['telephones'],function(_0x2c0149){return _0x2c0149['accountcode']==_0xebebdc||_0x2c0149[_0xe8f3('0x22')]==_0xebebdc;});if(_0x3a6f53){_0xa146af=_['find'](this[_0xe8f3('0xf')],function(_0x2e989c){return _0x2e989c['interface']==util[_0xe8f3('0x23')](_0xe8f3('0x24'),_0x3a6f53['name']);});}}return _0xa146af;};Report['prototype'][_0xe8f3('0x16')]=function(_0x12a0d1){for(var _0x4b90fd=0x0;_0x4b90fd<_0x12a0d1['length'];_0x4b90fd+=0x1){var _0x4e4b71=this[_0xe8f3('0x1f')](_0x12a0d1[_0x4b90fd]['connectedlinenum']);if(_0x4e4b71){_0x12a0d1[_0x4b90fd][_0xe8f3('0x21')]=_0x4e4b71[_0xe8f3('0x21')];_0x12a0d1[_0x4b90fd][_0xe8f3('0x25')]=!![];_0x12a0d1[_0x4b90fd][_0xe8f3('0x26')]=_0x4e4b71[_0xe8f3('0x22')];_0x12a0d1[_0x4b90fd][_0xe8f3('0x27')]=_[_0xe8f3('0x28')](_0x4e4b71[_0xe8f3('0x27')])?util[_0xe8f3('0x23')](_0xe8f3('0x24'),_0x4e4b71[_0xe8f3('0x22')]):_0x4e4b71['interface'];if(_0x12a0d1[_0x4b90fd][_0xe8f3('0x29')]){_0x12a0d1[_0x4b90fd][_0xe8f3('0x2a')]=moment()[_0xe8f3('0x23')](_0xe8f3('0x2b'));}if(_0x12a0d1[_0x4b90fd][_0xe8f3('0x2c')]){_0x12a0d1[_0x4b90fd]['queuecallerexitAt']=moment()[_0xe8f3('0x23')]('YYYY-MM-DD\x20HH:mm:ss');}RpcMemberReport[_0xe8f3('0x16')](_0x12a0d1[_0x4b90fd]);}RpcVoiceQueueReport['create'](_0x12a0d1[_0x4b90fd]);}};function extractCalleridNumber(_0x9aadff){var _0x5cf43e=_0x9aadff[_0xe8f3('0x2d')](/<(.*?)>/);return _0x5cf43e?_0x5cf43e[0x1]:_0x9aadff;}Report[_0xe8f3('0x11')][_0xe8f3('0x2e')]=function(_0x1e3ac9){for(var _0x4ba83a=0x0;_0x4ba83a<Object[_0xe8f3('0x2f')](this[_0xe8f3('0xf')])[_0xe8f3('0x30')];_0x4ba83a++){var _0x4b363a=Object['keys'](this['agents'])[_0x4ba83a];var _0x44c1b5=this[_0xe8f3('0xf')][_0x4b363a];if(_0x44c1b5['accountcode']===Number(_0x1e3ac9))return _0x44c1b5;}return null;};Report[_0xe8f3('0x11')][_0xe8f3('0x31')]=function(_0x3a8103){var _0x2a1400=_0x3a8103[_0xe8f3('0x32')]['split']('-')[0x0];var _0x4fe312=this[_0xe8f3('0xf')][_0x2a1400];if(!_0x4fe312)_0x4fe312=this[_0xe8f3('0x2e')](_0x3a8103['calleridnum']);return!_0x4fe312?'outbound':_0xe8f3('0x33');};Report[_0xe8f3('0x11')][_0xe8f3('0x34')]=function(_0x4e6ecb){_0x4e6ecb[_0xe8f3('0x35')]=_0x4e6ecb['destination']||_0x4e6ecb[_0xe8f3('0x36')];if(_0x4e6ecb[_0xe8f3('0x37')]==_0xe8f3('0x38')){_0x4e6ecb[_0xe8f3('0x39')]='queue';_0x4e6ecb[_0xe8f3('0x3a')]=_0x4e6ecb['queue'];if(_0x4e6ecb[_0xe8f3('0x3b')]==_0xe8f3('0x3c')){_0x4e6ecb[_0xe8f3('0x21')]='';_0x4e6ecb[_0xe8f3('0x35')]=extractCalleridNumber(_0x4e6ecb[_0xe8f3('0x3d')]);}else if(_0x4e6ecb[_0xe8f3('0x3b')]=='from-sip'){if(_0x4e6ecb[_0xe8f3('0x35')]==_0xe8f3('0x3e')){_0x4e6ecb[_0xe8f3('0x35')]=extractCalleridNumber(_0x4e6ecb[_0xe8f3('0x3f')]);_0x4e6ecb[_0xe8f3('0x40')]=_0x4e6ecb[_0xe8f3('0x41')];_0x4e6ecb['destinationchannel']=[_0x4e6ecb[_0xe8f3('0x32')],_0x4e6ecb[_0xe8f3('0x32')]=_0x4e6ecb['destinationchannel']][0x0];_0x4e6ecb['callerid']=_0x4e6ecb[_0xe8f3('0x3f')];}else{_0x4e6ecb[_0xe8f3('0x35')]=_0x4e6ecb[_0xe8f3('0x40')];_0x4e6ecb[_0xe8f3('0x40')]=_0x4e6ecb['originatecalleridnum'];if(_0x4e6ecb[_0xe8f3('0x42')]==_0xe8f3('0x43')){_0x4e6ecb[_0xe8f3('0x21')]=_0x4e6ecb[_0xe8f3('0x44')];}else{_0x4e6ecb[_0xe8f3('0x21')]='';}}}}else{_0x4e6ecb['callerid']=util[_0xe8f3('0x23')](_0xe8f3('0x45'),_0x4e6ecb['calleridname'],_0x4e6ecb[_0xe8f3('0x40')]);}if(RpcVoiceTransferReport[_0xe8f3('0x46')][_0x4e6ecb[_0xe8f3('0x47')]]){var _0x2e7d5d=RpcVoiceTransferReport[_0xe8f3('0x46')][_0x4e6ecb['linkedid']];_0x2e7d5d[_0xe8f3('0x48')]=_0x4e6ecb['uniqueid'];RpcVoiceTransferReport[_0xe8f3('0x1c')](_0x2e7d5d);delete RpcVoiceTransferReport['transfers'][_0x4e6ecb['linkedid']];}if(_[_0xe8f3('0x28')](_0x4e6ecb[_0xe8f3('0x37')])){_0x4e6ecb[_0xe8f3('0x37')]=this[_0xe8f3('0x31')](_0x4e6ecb);}if(_[_0xe8f3('0x28')](_0x4e6ecb[_0xe8f3('0x49')])){var _0x13dca1=_0x4e6ecb[_0xe8f3('0x32')]['split']('-')[0x0];var _0x5b4380=this[_0xe8f3('0xf')][_0x13dca1];if(!_0x5b4380)_0x5b4380=this[_0xe8f3('0x2e')](_0x4e6ecb[_0xe8f3('0x21')]);if(_0x5b4380){_0x4e6ecb[_0xe8f3('0x49')]=_0x5b4380['id'];_0x4e6ecb[_0xe8f3('0x4a')]=_0x5b4380[_0xe8f3('0x22')];}}RpcVoiceCallReport[_0xe8f3('0x4b')](_0x4e6ecb);if(_0x4e6ecb[_0xe8f3('0x4c')]){for(var _0x408ea5=0x0;_0x408ea5<_0x4e6ecb['monitors'][_0xe8f3('0x30')];_0x408ea5+=0x1){_0x4e6ecb[_0xe8f3('0x4d')]=_0x4e6ecb[_0xe8f3('0x4e')][_0x408ea5][_0xe8f3('0x4f')];_0x4e6ecb[_0xe8f3('0x50')]=_0x4e6ecb[_0xe8f3('0x4e')][_0x408ea5]['createdAt'];if(_0x4e6ecb[_0xe8f3('0x36')]==_0xe8f3('0x3e')){_0x4e6ecb['calleridnum']=_0x4e6ecb[_0xe8f3('0x44')];_0x4e6ecb[_0xe8f3('0x51')]=_0x4e6ecb[_0xe8f3('0x52')];_0x4e6ecb[_0xe8f3('0x44')]=_0x4e6ecb['accountcode'];_0x4e6ecb['connectedlinename']=_0x4e6ecb['membername'];_0x4e6ecb[_0xe8f3('0x36')]=_0x4e6ecb[_0xe8f3('0x41')];}else if(_0x4e6ecb['exten']==_0xe8f3('0x53')){_0x4e6ecb[_0xe8f3('0x40')]=_0x4e6ecb[_0xe8f3('0x35')];_0x4e6ecb['exten']=_0x4e6ecb[_0xe8f3('0x41')];}RpcVoiceRecording[_0xe8f3('0x4b')](_0x4e6ecb);}}};Report['prototype'][_0xe8f3('0x54')]=function(_0x4922b5){if(_[_0xe8f3('0x55')](_0x4922b5)){_0x4922b5[_0xe8f3('0x56')](function(_0x12317d){RpcVoiceAgentReport[_0xe8f3('0x4b')](_0x12317d);});}else{RpcVoiceAgentReport[_0xe8f3('0x4b')](_0x4922b5);}};Report[_0xe8f3('0x11')][_0xe8f3('0x1a')]=function(_0x15f01a){RpcVoiceDialReport[_0xe8f3('0x4b')](_0x15f01a);var _0x1d7b2f;var _0x14379d;var _0xf4739a=_0x15f01a['channel'];if(_[_0xe8f3('0x57')](_0xf4739a,_0xe8f3('0x58'))){_0x14379d=_0xf4739a[_0xe8f3('0x59')](_0xf4739a['indexOf']('/')+0x1,_0xf4739a[_0xe8f3('0x5a')]('@'));_0x1d7b2f=_[_0xe8f3('0x20')](this[_0xe8f3('0xf')],function(_0x597a8d){return _0x597a8d[_0xe8f3('0x5b')]==_0x14379d||_0x597a8d[_0xe8f3('0x5c')]==_0x14379d||_0x597a8d[_0xe8f3('0x21')]==_0x14379d;});}else{_0x14379d=_0xf4739a['substring'](_0xf4739a[_0xe8f3('0x5a')]('/')+0x1,_0xf4739a[_0xe8f3('0x5d')]('-'));_0x1d7b2f=this['findAgent'](_0x14379d);}if(_0x1d7b2f){_0x15f01a['interface']=_[_0xe8f3('0x28')](_0x1d7b2f[_0xe8f3('0x27')])?util[_0xe8f3('0x23')](_0xe8f3('0x24'),_0x1d7b2f[_0xe8f3('0x22')]):_0x1d7b2f[_0xe8f3('0x27')];_0x15f01a[_0xe8f3('0x4a')]=_0x1d7b2f[_0xe8f3('0x22')];_0x15f01a[_0xe8f3('0x21')]=_0x1d7b2f[_0xe8f3('0x21')];RpcMemberReport[_0xe8f3('0x1a')](_0x15f01a);}};Report[_0xe8f3('0x11')][_0xe8f3('0x1c')]=function(_0x4e2804){RpcVoiceTransferReport[_0xe8f3('0x46')][_0x4e2804[_0xe8f3('0x5e')]]=_0x4e2804;};Report[_0xe8f3('0x11')]['attendedTransfer']=function(_0x2c09a3){RpcVoiceTransferReport[_0xe8f3('0x1e')](_0x2c09a3);};module['exports']=Report;