Built motion from commit 25580385.|2.6.2
[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 _0x0783=['membername','monitors','monitorFilename','filename','createdAt','connectedlinename','voiceAgentReport','isArray','forEach','Local','mobile','phone','substring','indexOf','transfererlinkedid','exports','lodash','util','../../../config/environment','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceCallReport','./voiceAgentReport','./voiceDialReport','./userReport','agents','telephones','prototype','sync','realtime','xdr','disabled','custom:voiceQueueReport','voiceQueueReport','custom:voiceCallReport','voiceCallReport','bind','custom:voiceAgentReport','custom:voiceDialReport','voiceDialReport','attendedtransfer','attendedTransfer','findAgent','accountcode','name','isNil','find','interface','SIP/%s','length','connectedlinenum','assigned','lastAssignedTo','format','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','match','getAgentByInternal','keys','channel','split','calleridnum','outbound','destination','exten','type','dialer','lastapplication','queue','lastdata','context','from-voip-provider','callerid','from-sip','xcally-motion-preview','calleridpreview','originatecalleridnum','destinationchannel','ANSWERED','\x22%s\x22\x20<%s>','calleridname','transfers','linkedid','transfereelinkedid','uniqueid','blindTransfer','getCallType','UserId'];(function(_0x54a8c2,_0x5c966e){var _0x5c9e02=function(_0x305912){while(--_0x305912){_0x54a8c2['push'](_0x54a8c2['shift']());}};_0x5c9e02(++_0x5c966e);}(_0x0783,0xd2));var _0x3078=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x0783[_0x321bb2];return _0x9c12ed;};'use strict';var _=require(_0x3078('0x0'));var moment=require('moment');var util=require(_0x3078('0x1'));var config=require(_0x3078('0x2'));var ami=require('../ami');var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');var RpcVoiceCallReport=require(_0x3078('0x3'));var RpcVoiceDialReport=require(_0x3078('0x4'));var RpcMemberReport=require(_0x3078('0x5'));var RpcVoiceQueueReport=require(_0x3078('0x6'));var RpcVoiceRecording=require(_0x3078('0x7'));var RpcVoiceTransferReport=require(_0x3078('0x8'));var VoiceQueueReport=require(_0x3078('0x9'));var VoiceCallReport=require(_0x3078('0xa'));var VoiceAgentReport=require(_0x3078('0xb'));var VoiceDialReport=require(_0x3078('0xc'));var UserReport=require(_0x3078('0xd'));function Report(_0x803402){this['realtime']=_0x803402;this[_0x3078('0xe')]=_0x803402['agents'];this[_0x3078('0xf')]=_0x803402[_0x3078('0xf')];}Report[_0x3078('0x10')][_0x3078('0x11')]=function(_0x55d8de){var _0x3ced4a=new VoiceQueueReport(this[_0x3078('0x12')]);var _0x3482fb=new VoiceAgentReport(this[_0x3078('0x12')]);var _0x2994de=new VoiceDialReport(this['realtime']);var _0x326c83=new VoiceCallReport(this[_0x3078('0x12')]);var _0x2ee873=new UserReport(this[_0x3078('0x12')]);if(config[_0x3078('0x13')]&&config[_0x3078('0x13')][_0x3078('0x14')]){ami['on'](_0x3078('0x15'),this[_0x3078('0x16')]['bind'](this));ami['on'](_0x3078('0x17'),this[_0x3078('0x18')][_0x3078('0x19')](this));ami['on'](_0x3078('0x1a'),this['voiceAgentReport'][_0x3078('0x19')](this));ami['on'](_0x3078('0x1b'),this[_0x3078('0x1c')][_0x3078('0x19')](this));ami['on']('blindtransfer',this['blindTransfer'][_0x3078('0x19')](this));ami['on'](_0x3078('0x1d'),this[_0x3078('0x1e')][_0x3078('0x19')](this));}};Report[_0x3078('0x10')][_0x3078('0x1f')]=function(_0x2c442a){var _0x5f5d42;_0x5f5d42=_['find'](this['agents'],function(_0xaff4c7){return _0xaff4c7[_0x3078('0x20')]==_0x2c442a||_0xaff4c7[_0x3078('0x21')]==_0x2c442a;});if(_[_0x3078('0x22')](_0x5f5d42)){var _0x50ddeb=_[_0x3078('0x23')](this['telephones'],function(_0xa58d76){return _0xa58d76[_0x3078('0x20')]==_0x2c442a||_0xa58d76[_0x3078('0x21')]==_0x2c442a;});if(_0x50ddeb){_0x5f5d42=_[_0x3078('0x23')](this[_0x3078('0xe')],function(_0x3b5577){return _0x3b5577[_0x3078('0x24')]==util['format'](_0x3078('0x25'),_0x50ddeb['name']);});}}return _0x5f5d42;};Report[_0x3078('0x10')][_0x3078('0x16')]=function(_0x32e2ee){for(var _0x4ca71c=0x0;_0x4ca71c<_0x32e2ee[_0x3078('0x26')];_0x4ca71c+=0x1){var _0x5ebeb5=this[_0x3078('0x1f')](_0x32e2ee[_0x4ca71c][_0x3078('0x27')]);if(_0x5ebeb5){_0x32e2ee[_0x4ca71c][_0x3078('0x20')]=_0x5ebeb5['accountcode'];_0x32e2ee[_0x4ca71c][_0x3078('0x28')]=!![];_0x32e2ee[_0x4ca71c][_0x3078('0x29')]=_0x5ebeb5['name'];_0x32e2ee[_0x4ca71c][_0x3078('0x24')]=_[_0x3078('0x22')](_0x5ebeb5[_0x3078('0x24')])?util[_0x3078('0x2a')]('SIP/%s',_0x5ebeb5['name']):_0x5ebeb5['interface'];if(_0x32e2ee[_0x4ca71c][_0x3078('0x2b')]){_0x32e2ee[_0x4ca71c][_0x3078('0x2c')]=moment()[_0x3078('0x2a')](_0x3078('0x2d'));}if(_0x32e2ee[_0x4ca71c][_0x3078('0x2e')]){_0x32e2ee[_0x4ca71c][_0x3078('0x2f')]=moment()[_0x3078('0x2a')]('YYYY-MM-DD\x20HH:mm:ss');}RpcMemberReport[_0x3078('0x16')](_0x32e2ee[_0x4ca71c]);}RpcVoiceQueueReport[_0x3078('0x30')](_0x32e2ee[_0x4ca71c]);}};function extractCalleridNumber(_0x59f5a0){var _0x5f242c=_0x59f5a0[_0x3078('0x31')](/<(.*?)>/);return _0x5f242c?_0x5f242c[0x1]:_0x59f5a0;}Report[_0x3078('0x10')][_0x3078('0x32')]=function(_0x47ccf9){for(var _0x5ed416=0x0;_0x5ed416<Object[_0x3078('0x33')](this[_0x3078('0xe')])[_0x3078('0x26')];_0x5ed416++){var _0x488add=Object['keys'](this[_0x3078('0xe')])[_0x5ed416];var _0xcb6b17=this[_0x3078('0xe')][_0x488add];if(_0xcb6b17[_0x3078('0x20')]===Number(_0x47ccf9))return _0xcb6b17;}return null;};Report[_0x3078('0x10')]['getCallType']=function(_0x27f4fa){var _0x572590=_0x27f4fa[_0x3078('0x34')][_0x3078('0x35')]('-')[0x0];var _0x5d2e85=this[_0x3078('0xe')][_0x572590];if(!_0x5d2e85)_0x5d2e85=this['getAgentByInternal'](_0x27f4fa[_0x3078('0x36')]);return!_0x5d2e85?_0x3078('0x37'):'internal';};Report[_0x3078('0x10')]['voiceCallReport']=function(_0x449b27){_0x449b27[_0x3078('0x38')]=_0x449b27[_0x3078('0x38')]||_0x449b27[_0x3078('0x39')];if(_0x449b27[_0x3078('0x3a')]==_0x3078('0x3b')){_0x449b27[_0x3078('0x3c')]=_0x3078('0x3d');_0x449b27[_0x3078('0x3e')]=_0x449b27[_0x3078('0x3d')];if(_0x449b27[_0x3078('0x3f')]==_0x3078('0x40')){_0x449b27['accountcode']='';_0x449b27[_0x3078('0x38')]=extractCalleridNumber(_0x449b27[_0x3078('0x41')]);}else if(_0x449b27[_0x3078('0x3f')]==_0x3078('0x42')){if(_0x449b27['destination']==_0x3078('0x43')){_0x449b27['destination']=extractCalleridNumber(_0x449b27[_0x3078('0x44')]);_0x449b27[_0x3078('0x36')]=_0x449b27[_0x3078('0x45')];_0x449b27[_0x3078('0x46')]=[_0x449b27[_0x3078('0x34')],_0x449b27[_0x3078('0x34')]=_0x449b27['destinationchannel']][0x0];_0x449b27[_0x3078('0x41')]=_0x449b27['calleridpreview'];}else{_0x449b27['destination']=_0x449b27[_0x3078('0x36')];_0x449b27['calleridnum']=_0x449b27['originatecalleridnum'];if(_0x449b27['disposition']==_0x3078('0x47')){_0x449b27[_0x3078('0x20')]=_0x449b27[_0x3078('0x27')];}else{_0x449b27[_0x3078('0x20')]='';}}}}else{_0x449b27[_0x3078('0x41')]=util['format'](_0x3078('0x48'),_0x449b27[_0x3078('0x49')],_0x449b27[_0x3078('0x36')]);}if(RpcVoiceTransferReport[_0x3078('0x4a')][_0x449b27[_0x3078('0x4b')]]){var _0x369f75=RpcVoiceTransferReport[_0x3078('0x4a')][_0x449b27['linkedid']];_0x369f75[_0x3078('0x4c')]=_0x449b27[_0x3078('0x4d')];RpcVoiceTransferReport[_0x3078('0x4e')](_0x369f75);delete RpcVoiceTransferReport[_0x3078('0x4a')][_0x449b27[_0x3078('0x4b')]];}if(_['isNil'](_0x449b27['type'])){_0x449b27[_0x3078('0x3a')]=this[_0x3078('0x4f')](_0x449b27);}if(_['isNil'](_0x449b27[_0x3078('0x50')])){var _0x628e90=_0x449b27['channel'][_0x3078('0x35')]('-')[0x0];var _0x1af1dc=this[_0x3078('0xe')][_0x628e90];if(!_0x1af1dc)_0x1af1dc=this['getAgentByInternal'](_0x449b27[_0x3078('0x20')]);if(_0x1af1dc){_0x449b27['UserId']=_0x1af1dc['id'];_0x449b27[_0x3078('0x51')]=_0x1af1dc[_0x3078('0x21')];}}RpcVoiceCallReport[_0x3078('0x30')](_0x449b27);if(_0x449b27['monitor']){for(var _0x46d653=0x0;_0x46d653<_0x449b27[_0x3078('0x52')][_0x3078('0x26')];_0x46d653+=0x1){_0x449b27[_0x3078('0x53')]=_0x449b27['monitors'][_0x46d653][_0x3078('0x54')];_0x449b27[_0x3078('0x55')]=_0x449b27[_0x3078('0x52')][_0x46d653][_0x3078('0x55')];if(_0x449b27['exten']==_0x3078('0x43')){_0x449b27[_0x3078('0x36')]=_0x449b27[_0x3078('0x27')];_0x449b27[_0x3078('0x49')]=_0x449b27['connectedlinename'];_0x449b27[_0x3078('0x27')]=_0x449b27[_0x3078('0x20')];_0x449b27[_0x3078('0x56')]=_0x449b27[_0x3078('0x51')];_0x449b27[_0x3078('0x39')]=_0x449b27[_0x3078('0x45')];}else if(_0x449b27['exten']=='xcally-motion-dialer'){_0x449b27['calleridnum']=_0x449b27[_0x3078('0x38')];_0x449b27['exten']=_0x449b27['originatecalleridnum'];}RpcVoiceRecording[_0x3078('0x30')](_0x449b27);}}};Report['prototype'][_0x3078('0x57')]=function(_0xe42454){if(_[_0x3078('0x58')](_0xe42454)){_0xe42454[_0x3078('0x59')](function(_0x24b0ee){RpcVoiceAgentReport['create'](_0x24b0ee);});}else{RpcVoiceAgentReport[_0x3078('0x30')](_0xe42454);}};Report[_0x3078('0x10')][_0x3078('0x1c')]=function(_0x2f2c88){RpcVoiceDialReport[_0x3078('0x30')](_0x2f2c88);var _0x1f5eeb;var _0x495f13;var _0x2ff64a=_0x2f2c88[_0x3078('0x34')];if(_['startsWith'](_0x2ff64a,_0x3078('0x5a'))){_0x495f13=_0x2ff64a['substring'](_0x2ff64a['indexOf']('/')+0x1,_0x2ff64a['indexOf']('@'));_0x1f5eeb=_[_0x3078('0x23')](this['agents'],function(_0x188cac){return _0x188cac[_0x3078('0x5b')]==_0x495f13||_0x188cac[_0x3078('0x5c')]==_0x495f13||_0x188cac[_0x3078('0x20')]==_0x495f13;});}else{_0x495f13=_0x2ff64a[_0x3078('0x5d')](_0x2ff64a[_0x3078('0x5e')]('/')+0x1,_0x2ff64a['lastIndexOf']('-'));_0x1f5eeb=this[_0x3078('0x1f')](_0x495f13);}if(_0x1f5eeb){_0x2f2c88[_0x3078('0x24')]=_['isNil'](_0x1f5eeb[_0x3078('0x24')])?util['format']('SIP/%s',_0x1f5eeb[_0x3078('0x21')]):_0x1f5eeb['interface'];_0x2f2c88['membername']=_0x1f5eeb[_0x3078('0x21')];_0x2f2c88[_0x3078('0x20')]=_0x1f5eeb[_0x3078('0x20')];RpcMemberReport[_0x3078('0x1c')](_0x2f2c88);}};Report['prototype'][_0x3078('0x4e')]=function(_0x490d28){RpcVoiceTransferReport[_0x3078('0x4a')][_0x490d28[_0x3078('0x5f')]]=_0x490d28;};Report[_0x3078('0x10')][_0x3078('0x1e')]=function(_0x4ac700){RpcVoiceTransferReport[_0x3078('0x1e')](_0x4ac700);};module[_0x3078('0x60')]=Report;