4fe35bb61a162f1b1cff85302955032c1d2a739b
[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 _0x5462=['name','interface','format','length','connectedlinenum','assigned','lastAssignedTo','isNil','SIP/%s','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','match','getAgentByInternal','keys','getCallType','split','internal','voiceCallReport','destination','exten','type','dialer','lastapplication','queue','from-voip-provider','callerid','context','from-sip','xcally-motion-preview','calleridpreview','calleridnum','originatecalleridnum','destinationchannel','channel','disposition','ANSWERED','\x22%s\x22\x20<%s>','calleridname','transfers','linkedid','transfereelinkedid','uniqueid','UserId','monitorFilename','monitors','filename','createdAt','connectedlinename','voiceAgentReport','isArray','forEach','voiceDialReport','startsWith','Local','substring','indexOf','mobile','phone','lastIndexOf','transfererlinkedid','exports','lodash','moment','util','../../../config/environment','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/memberReport','../rpc/voiceTransferReport','./voiceQueueReport','./voiceCallReport','./voiceDialReport','./userReport','realtime','agents','prototype','sync','xdr','disabled','voiceQueueReport','bind','custom:voiceCallReport','custom:voiceAgentReport','custom:voiceDialReport','blindTransfer','attendedTransfer','findAgent','find','accountcode'];(function(_0x49c7d1,_0x203a7d){var _0x2f88d7=function(_0x29b582){while(--_0x29b582){_0x49c7d1['push'](_0x49c7d1['shift']());}};_0x2f88d7(++_0x203a7d);}(_0x5462,0x1b9));var _0x2546=function(_0xd4636c,_0x34dbf6){_0xd4636c=_0xd4636c-0x0;var _0x5ee17d=_0x5462[_0xd4636c];return _0x5ee17d;};'use strict';var _=require(_0x2546('0x0'));var moment=require(_0x2546('0x1'));var util=require(_0x2546('0x2'));var config=require(_0x2546('0x3'));var ami=require(_0x2546('0x4'));var RpcVoiceAgentReport=require(_0x2546('0x5'));var RpcVoiceCallReport=require(_0x2546('0x6'));var RpcVoiceDialReport=require('../rpc/voiceDialReport');var RpcMemberReport=require(_0x2546('0x7'));var RpcVoiceQueueReport=require('../rpc/voiceQueueReport');var RpcVoiceRecording=require('../rpc/voiceRecording');var RpcVoiceTransferReport=require(_0x2546('0x8'));var VoiceQueueReport=require(_0x2546('0x9'));var VoiceCallReport=require(_0x2546('0xa'));var VoiceAgentReport=require('./voiceAgentReport');var VoiceDialReport=require(_0x2546('0xb'));var UserReport=require(_0x2546('0xc'));function Report(_0x3f3308){this[_0x2546('0xd')]=_0x3f3308;this[_0x2546('0xe')]=_0x3f3308['agents'];this['telephones']=_0x3f3308['telephones'];}Report[_0x2546('0xf')][_0x2546('0x10')]=function(_0x366752){var _0x5205e5=new VoiceQueueReport(this[_0x2546('0xd')]);var _0x337427=new VoiceAgentReport(this[_0x2546('0xd')]);var _0x170628=new VoiceDialReport(this[_0x2546('0xd')]);var _0xddb8b8=new VoiceCallReport(this['realtime']);var _0x45fb0b=new UserReport(this['realtime']);if(config[_0x2546('0x11')]&&config[_0x2546('0x11')][_0x2546('0x12')]){ami['on']('custom:voiceQueueReport',this[_0x2546('0x13')][_0x2546('0x14')](this));ami['on'](_0x2546('0x15'),this['voiceCallReport'][_0x2546('0x14')](this));ami['on'](_0x2546('0x16'),this['voiceAgentReport']['bind'](this));ami['on'](_0x2546('0x17'),this['voiceDialReport'][_0x2546('0x14')](this));ami['on']('blindtransfer',this[_0x2546('0x18')][_0x2546('0x14')](this));ami['on']('attendedtransfer',this[_0x2546('0x19')][_0x2546('0x14')](this));}};Report[_0x2546('0xf')][_0x2546('0x1a')]=function(_0x318ee6){var _0xc4db9a;_0xc4db9a=_[_0x2546('0x1b')](this['agents'],function(_0xfbe468){return _0xfbe468[_0x2546('0x1c')]==_0x318ee6||_0xfbe468[_0x2546('0x1d')]==_0x318ee6;});if(_['isNil'](_0xc4db9a)){var _0x18129a=_[_0x2546('0x1b')](this['telephones'],function(_0x5ad4c0){return _0x5ad4c0['accountcode']==_0x318ee6||_0x5ad4c0[_0x2546('0x1d')]==_0x318ee6;});if(_0x18129a){_0xc4db9a=_[_0x2546('0x1b')](this[_0x2546('0xe')],function(_0x193853){return _0x193853[_0x2546('0x1e')]==util[_0x2546('0x1f')]('SIP/%s',_0x18129a['name']);});}}return _0xc4db9a;};Report['prototype'][_0x2546('0x13')]=function(_0x5cb77a){for(var _0x1a8eeb=0x0;_0x1a8eeb<_0x5cb77a[_0x2546('0x20')];_0x1a8eeb+=0x1){var _0x3b3fb9=this[_0x2546('0x1a')](_0x5cb77a[_0x1a8eeb][_0x2546('0x21')]);if(_0x3b3fb9){_0x5cb77a[_0x1a8eeb][_0x2546('0x1c')]=_0x3b3fb9[_0x2546('0x1c')];_0x5cb77a[_0x1a8eeb][_0x2546('0x22')]=!![];_0x5cb77a[_0x1a8eeb][_0x2546('0x23')]=_0x3b3fb9[_0x2546('0x1d')];_0x5cb77a[_0x1a8eeb][_0x2546('0x1e')]=_[_0x2546('0x24')](_0x3b3fb9[_0x2546('0x1e')])?util['format'](_0x2546('0x25'),_0x3b3fb9[_0x2546('0x1d')]):_0x3b3fb9[_0x2546('0x1e')];if(_0x5cb77a[_0x1a8eeb][_0x2546('0x26')]){_0x5cb77a[_0x1a8eeb][_0x2546('0x27')]=moment()[_0x2546('0x1f')](_0x2546('0x28'));}if(_0x5cb77a[_0x1a8eeb][_0x2546('0x29')]){_0x5cb77a[_0x1a8eeb][_0x2546('0x2a')]=moment()[_0x2546('0x1f')](_0x2546('0x28'));}RpcMemberReport['voiceQueueReport'](_0x5cb77a[_0x1a8eeb]);}RpcVoiceQueueReport[_0x2546('0x2b')](_0x5cb77a[_0x1a8eeb]);}};function extractCalleridNumber(_0x3d7b81){var _0x22866e=_0x3d7b81[_0x2546('0x2c')](/<(.*?)>/);return _0x22866e?_0x22866e[0x1]:_0x3d7b81;}Report[_0x2546('0xf')][_0x2546('0x2d')]=function(_0x24d532){for(var _0x2b5db8=0x0;_0x2b5db8<Object[_0x2546('0x2e')](this['agents'])[_0x2546('0x20')];_0x2b5db8++){var _0x361b7d=Object[_0x2546('0x2e')](this['agents'])[_0x2b5db8];var _0x1b0748=this[_0x2546('0xe')][_0x361b7d];if(_0x1b0748['accountcode']===Number(_0x24d532))return _0x1b0748;}return null;};Report[_0x2546('0xf')][_0x2546('0x2f')]=function(_0x56f78f){var _0x58f4c4=_0x56f78f['channel'][_0x2546('0x30')]('-')[0x0];var _0xe5b65e=this[_0x2546('0xe')][_0x58f4c4];if(!_0xe5b65e)_0xe5b65e=this[_0x2546('0x2d')](_0x56f78f['calleridnum']);return!_0xe5b65e?'outbound':_0x2546('0x31');};Report[_0x2546('0xf')][_0x2546('0x32')]=function(_0x5f54fb){_0x5f54fb[_0x2546('0x33')]=_0x5f54fb[_0x2546('0x33')]||_0x5f54fb[_0x2546('0x34')];if(_0x5f54fb[_0x2546('0x35')]==_0x2546('0x36')){_0x5f54fb[_0x2546('0x37')]=_0x2546('0x38');_0x5f54fb['lastdata']=_0x5f54fb[_0x2546('0x38')];if(_0x5f54fb['context']==_0x2546('0x39')){_0x5f54fb[_0x2546('0x1c')]='';_0x5f54fb['destination']=extractCalleridNumber(_0x5f54fb[_0x2546('0x3a')]);}else if(_0x5f54fb[_0x2546('0x3b')]==_0x2546('0x3c')){if(_0x5f54fb[_0x2546('0x33')]==_0x2546('0x3d')){_0x5f54fb[_0x2546('0x33')]=extractCalleridNumber(_0x5f54fb[_0x2546('0x3e')]);_0x5f54fb[_0x2546('0x3f')]=_0x5f54fb[_0x2546('0x40')];_0x5f54fb[_0x2546('0x41')]=[_0x5f54fb[_0x2546('0x42')],_0x5f54fb[_0x2546('0x42')]=_0x5f54fb[_0x2546('0x41')]][0x0];_0x5f54fb[_0x2546('0x3a')]=_0x5f54fb[_0x2546('0x3e')];}else{_0x5f54fb[_0x2546('0x33')]=_0x5f54fb[_0x2546('0x3f')];_0x5f54fb[_0x2546('0x3f')]=_0x5f54fb[_0x2546('0x40')];if(_0x5f54fb[_0x2546('0x43')]==_0x2546('0x44')){_0x5f54fb['accountcode']=_0x5f54fb[_0x2546('0x21')];}else{_0x5f54fb[_0x2546('0x1c')]='';}}}}else{_0x5f54fb[_0x2546('0x3a')]=util['format'](_0x2546('0x45'),_0x5f54fb[_0x2546('0x46')],_0x5f54fb[_0x2546('0x3f')]);}if(RpcVoiceTransferReport['transfers'][_0x5f54fb['linkedid']]){var _0x30a62e=RpcVoiceTransferReport[_0x2546('0x47')][_0x5f54fb[_0x2546('0x48')]];_0x30a62e[_0x2546('0x49')]=_0x5f54fb[_0x2546('0x4a')];RpcVoiceTransferReport['blindTransfer'](_0x30a62e);delete RpcVoiceTransferReport[_0x2546('0x47')][_0x5f54fb[_0x2546('0x48')]];}if(_[_0x2546('0x24')](_0x5f54fb[_0x2546('0x35')])){_0x5f54fb['type']=this[_0x2546('0x2f')](_0x5f54fb);}if(_[_0x2546('0x24')](_0x5f54fb[_0x2546('0x4b')])){var _0x228a9d=_0x5f54fb[_0x2546('0x42')][_0x2546('0x30')]('-')[0x0];var _0x4dc7f6=this[_0x2546('0xe')][_0x228a9d];if(!_0x4dc7f6)_0x4dc7f6=this[_0x2546('0x2d')](_0x5f54fb[_0x2546('0x1c')]);if(_0x4dc7f6){_0x5f54fb[_0x2546('0x4b')]=_0x4dc7f6['id'];_0x5f54fb['membername']=_0x4dc7f6[_0x2546('0x1d')];}}RpcVoiceCallReport[_0x2546('0x2b')](_0x5f54fb);if(_0x5f54fb['monitor']){for(var _0x3def95=0x0;_0x3def95<_0x5f54fb['monitors']['length'];_0x3def95+=0x1){_0x5f54fb[_0x2546('0x4c')]=_0x5f54fb[_0x2546('0x4d')][_0x3def95][_0x2546('0x4e')];_0x5f54fb[_0x2546('0x4f')]=_0x5f54fb[_0x2546('0x4d')][_0x3def95][_0x2546('0x4f')];if(_0x5f54fb[_0x2546('0x34')]==_0x2546('0x3d')){_0x5f54fb['calleridnum']=_0x5f54fb['connectedlinenum'];_0x5f54fb['calleridname']=_0x5f54fb[_0x2546('0x50')];_0x5f54fb[_0x2546('0x21')]=_0x5f54fb[_0x2546('0x1c')];_0x5f54fb['connectedlinename']=_0x5f54fb['membername'];_0x5f54fb['exten']=_0x5f54fb[_0x2546('0x40')];}else if(_0x5f54fb[_0x2546('0x34')]=='xcally-motion-dialer'){_0x5f54fb['calleridnum']=_0x5f54fb[_0x2546('0x33')];_0x5f54fb['exten']=_0x5f54fb[_0x2546('0x40')];}RpcVoiceRecording[_0x2546('0x2b')](_0x5f54fb);}}};Report['prototype'][_0x2546('0x51')]=function(_0x2c0891){if(_[_0x2546('0x52')](_0x2c0891)){_0x2c0891[_0x2546('0x53')](function(_0x3d7c4d){RpcVoiceAgentReport[_0x2546('0x2b')](_0x3d7c4d);});}else{RpcVoiceAgentReport['create'](_0x2c0891);}};Report[_0x2546('0xf')][_0x2546('0x54')]=function(_0xbd71cd){RpcVoiceDialReport['create'](_0xbd71cd);var _0x21ae19;var _0xac33c9;var _0x494676=_0xbd71cd[_0x2546('0x42')];if(_[_0x2546('0x55')](_0x494676,_0x2546('0x56'))){_0xac33c9=_0x494676[_0x2546('0x57')](_0x494676[_0x2546('0x58')]('/')+0x1,_0x494676[_0x2546('0x58')]('@'));_0x21ae19=_[_0x2546('0x1b')](this['agents'],function(_0x372a9a){return _0x372a9a[_0x2546('0x59')]==_0xac33c9||_0x372a9a[_0x2546('0x5a')]==_0xac33c9||_0x372a9a[_0x2546('0x1c')]==_0xac33c9;});}else{_0xac33c9=_0x494676[_0x2546('0x57')](_0x494676[_0x2546('0x58')]('/')+0x1,_0x494676[_0x2546('0x5b')]('-'));_0x21ae19=this[_0x2546('0x1a')](_0xac33c9);}if(_0x21ae19){_0xbd71cd[_0x2546('0x1e')]=_[_0x2546('0x24')](_0x21ae19[_0x2546('0x1e')])?util[_0x2546('0x1f')]('SIP/%s',_0x21ae19['name']):_0x21ae19[_0x2546('0x1e')];_0xbd71cd['membername']=_0x21ae19['name'];_0xbd71cd[_0x2546('0x1c')]=_0x21ae19[_0x2546('0x1c')];RpcMemberReport[_0x2546('0x54')](_0xbd71cd);}};Report[_0x2546('0xf')][_0x2546('0x18')]=function(_0x173dee){RpcVoiceTransferReport[_0x2546('0x47')][_0x173dee[_0x2546('0x5c')]]=_0x173dee;};Report[_0x2546('0xf')]['attendedTransfer']=function(_0x258b67){RpcVoiceTransferReport[_0x2546('0x19')](_0x258b67);};module[_0x2546('0x5d')]=Report;