709fc80ecc4eb92c0fe8c95a17a65b50b9c90584
[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 _0xaa1f=['lastAssignedTo','interface','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','match','getAgentByInternal','keys','getCallType','calleridnum','outbound','internal','destination','exten','dialer','lastapplication','queue','lastdata','context','from-voip-provider','callerid','from-sip','xcally-motion-preview','calleridpreview','destinationchannel','channel','disposition','ANSWERED','connectedlinenum','\x22%s\x22\x20<%s>','transfers','transfereelinkedid','uniqueid','linkedid','type','UserId','length','monitorFilename','createdAt','calleridname','connectedlinename','membername','originatecalleridnum','xcally-motion-dialer','isArray','forEach','Local','indexOf','mobile','phone','substring','lastIndexOf','transfererlinkedid','exports','moment','util','../ami','../rpc/voiceAgentReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceAgentReport','./voiceDialReport','realtime','agents','telephones','prototype','sync','disabled','custom:voiceQueueReport','voiceQueueReport','custom:voiceCallReport','voiceCallReport','bind','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindtransfer','blindTransfer','attendedtransfer','attendedTransfer','findAgent','find','accountcode','isNil','format','SIP/%s','name','assigned'];(function(_0x45518f,_0x475a6b){var _0x198175=function(_0x40d333){while(--_0x40d333){_0x45518f['push'](_0x45518f['shift']());}};_0x198175(++_0x475a6b);}(_0xaa1f,0xf7));var _0xfaa1=function(_0x53cd13,_0xd5355e){_0x53cd13=_0x53cd13-0x0;var _0xc285e2=_0xaa1f[_0x53cd13];return _0xc285e2;};'use strict';var _=require('lodash');var moment=require(_0xfaa1('0x0'));var util=require(_0xfaa1('0x1'));var config=require('../../../config/environment');var ami=require(_0xfaa1('0x2'));var RpcVoiceAgentReport=require(_0xfaa1('0x3'));var RpcVoiceCallReport=require('../rpc/voiceCallReport');var RpcVoiceDialReport=require('../rpc/voiceDialReport');var RpcMemberReport=require(_0xfaa1('0x4'));var RpcVoiceQueueReport=require(_0xfaa1('0x5'));var RpcVoiceRecording=require(_0xfaa1('0x6'));var RpcVoiceTransferReport=require(_0xfaa1('0x7'));var VoiceQueueReport=require(_0xfaa1('0x8'));var VoiceCallReport=require('./voiceCallReport');var VoiceAgentReport=require(_0xfaa1('0x9'));var VoiceDialReport=require(_0xfaa1('0xa'));var UserReport=require('./userReport');function Report(_0x51ca6d){this[_0xfaa1('0xb')]=_0x51ca6d;this[_0xfaa1('0xc')]=_0x51ca6d['agents'];this[_0xfaa1('0xd')]=_0x51ca6d[_0xfaa1('0xd')];}Report[_0xfaa1('0xe')][_0xfaa1('0xf')]=function(_0x377b73){var _0x378da6=new VoiceQueueReport(this[_0xfaa1('0xb')]);var _0x283b3b=new VoiceAgentReport(this['realtime']);var _0x3ac488=new VoiceDialReport(this['realtime']);var _0x22aa64=new VoiceCallReport(this['realtime']);var _0x1ca9cb=new UserReport(this[_0xfaa1('0xb')]);if(config['xdr']&&config['xdr'][_0xfaa1('0x10')]){ami['on'](_0xfaa1('0x11'),this[_0xfaa1('0x12')]['bind'](this));ami['on'](_0xfaa1('0x13'),this[_0xfaa1('0x14')][_0xfaa1('0x15')](this));ami['on'](_0xfaa1('0x16'),this[_0xfaa1('0x17')][_0xfaa1('0x15')](this));ami['on'](_0xfaa1('0x18'),this[_0xfaa1('0x19')][_0xfaa1('0x15')](this));ami['on'](_0xfaa1('0x1a'),this[_0xfaa1('0x1b')]['bind'](this));ami['on'](_0xfaa1('0x1c'),this[_0xfaa1('0x1d')][_0xfaa1('0x15')](this));}};Report[_0xfaa1('0xe')][_0xfaa1('0x1e')]=function(_0x479fe7){var _0x200bb1;_0x200bb1=_[_0xfaa1('0x1f')](this[_0xfaa1('0xc')],function(_0x26713c){return _0x26713c[_0xfaa1('0x20')]==_0x479fe7||_0x26713c['name']==_0x479fe7;});if(_[_0xfaa1('0x21')](_0x200bb1)){var _0x2b8d51=_[_0xfaa1('0x1f')](this[_0xfaa1('0xd')],function(_0x573d5f){return _0x573d5f[_0xfaa1('0x20')]==_0x479fe7||_0x573d5f['name']==_0x479fe7;});if(_0x2b8d51){_0x200bb1=_[_0xfaa1('0x1f')](this[_0xfaa1('0xc')],function(_0x4176ca){return _0x4176ca['interface']==util[_0xfaa1('0x22')](_0xfaa1('0x23'),_0x2b8d51[_0xfaa1('0x24')]);});}}return _0x200bb1;};Report[_0xfaa1('0xe')][_0xfaa1('0x12')]=function(_0x27dbe2){for(var _0x3d4345=0x0;_0x3d4345<_0x27dbe2['length'];_0x3d4345+=0x1){var _0x21bd98=this['findAgent'](_0x27dbe2[_0x3d4345]['connectedlinenum']);if(_0x21bd98){_0x27dbe2[_0x3d4345][_0xfaa1('0x20')]=_0x21bd98[_0xfaa1('0x20')];_0x27dbe2[_0x3d4345][_0xfaa1('0x25')]=!![];_0x27dbe2[_0x3d4345][_0xfaa1('0x26')]=_0x21bd98['name'];_0x27dbe2[_0x3d4345][_0xfaa1('0x27')]=_[_0xfaa1('0x21')](_0x21bd98[_0xfaa1('0x27')])?util[_0xfaa1('0x22')]('SIP/%s',_0x21bd98[_0xfaa1('0x24')]):_0x21bd98['interface'];if(_0x27dbe2[_0x3d4345][_0xfaa1('0x28')]){_0x27dbe2[_0x3d4345][_0xfaa1('0x29')]=moment()['format'](_0xfaa1('0x2a'));}if(_0x27dbe2[_0x3d4345][_0xfaa1('0x2b')]){_0x27dbe2[_0x3d4345][_0xfaa1('0x2c')]=moment()[_0xfaa1('0x22')](_0xfaa1('0x2a'));}RpcMemberReport[_0xfaa1('0x12')](_0x27dbe2[_0x3d4345]);}RpcVoiceQueueReport[_0xfaa1('0x2d')](_0x27dbe2[_0x3d4345]);}};function extractCalleridNumber(_0x4ceddb){var _0x397c2e=_0x4ceddb[_0xfaa1('0x2e')](/<(.*?)>/);return _0x397c2e?_0x397c2e[0x1]:_0x4ceddb;}Report[_0xfaa1('0xe')][_0xfaa1('0x2f')]=function(_0x531582){for(var _0xa18a71=0x0;_0xa18a71<Object[_0xfaa1('0x30')](this['agents'])['length'];_0xa18a71++){var _0x21e33e=Object['keys'](this[_0xfaa1('0xc')])[_0xa18a71];var _0x1d856b=this[_0xfaa1('0xc')][_0x21e33e];if(_0x1d856b[_0xfaa1('0x20')]===Number(_0x531582))return _0x1d856b;}return null;};Report['prototype'][_0xfaa1('0x31')]=function(_0x5e4b53){var _0x411df7=_0x5e4b53['channel']['split']('-')[0x0];var _0x3f7f25=this[_0xfaa1('0xc')][_0x411df7];if(!_0x3f7f25)_0x3f7f25=this[_0xfaa1('0x2f')](_0x5e4b53[_0xfaa1('0x32')]);return!_0x3f7f25?_0xfaa1('0x33'):_0xfaa1('0x34');};Report[_0xfaa1('0xe')]['voiceCallReport']=function(_0x5f2bc8){_0x5f2bc8['destination']=_0x5f2bc8[_0xfaa1('0x35')]||_0x5f2bc8[_0xfaa1('0x36')];if(_0x5f2bc8['type']==_0xfaa1('0x37')){_0x5f2bc8[_0xfaa1('0x38')]=_0xfaa1('0x39');_0x5f2bc8[_0xfaa1('0x3a')]=_0x5f2bc8[_0xfaa1('0x39')];if(_0x5f2bc8[_0xfaa1('0x3b')]==_0xfaa1('0x3c')){_0x5f2bc8[_0xfaa1('0x20')]='';_0x5f2bc8[_0xfaa1('0x35')]=extractCalleridNumber(_0x5f2bc8[_0xfaa1('0x3d')]);}else if(_0x5f2bc8[_0xfaa1('0x3b')]==_0xfaa1('0x3e')){if(_0x5f2bc8[_0xfaa1('0x35')]==_0xfaa1('0x3f')){_0x5f2bc8[_0xfaa1('0x35')]=extractCalleridNumber(_0x5f2bc8[_0xfaa1('0x40')]);_0x5f2bc8[_0xfaa1('0x32')]=_0x5f2bc8['originatecalleridnum'];_0x5f2bc8[_0xfaa1('0x41')]=[_0x5f2bc8[_0xfaa1('0x42')],_0x5f2bc8[_0xfaa1('0x42')]=_0x5f2bc8['destinationchannel']][0x0];_0x5f2bc8['callerid']=_0x5f2bc8[_0xfaa1('0x40')];}else{_0x5f2bc8[_0xfaa1('0x35')]=_0x5f2bc8[_0xfaa1('0x32')];_0x5f2bc8[_0xfaa1('0x32')]=_0x5f2bc8['originatecalleridnum'];if(_0x5f2bc8[_0xfaa1('0x43')]==_0xfaa1('0x44')){_0x5f2bc8[_0xfaa1('0x20')]=_0x5f2bc8[_0xfaa1('0x45')];}else{_0x5f2bc8[_0xfaa1('0x20')]='';}}}}else{_0x5f2bc8[_0xfaa1('0x3d')]=util[_0xfaa1('0x22')](_0xfaa1('0x46'),_0x5f2bc8['calleridname'],_0x5f2bc8[_0xfaa1('0x32')]);}if(RpcVoiceTransferReport['transfers'][_0x5f2bc8['linkedid']]){var _0x2b2aec=RpcVoiceTransferReport[_0xfaa1('0x47')][_0x5f2bc8['linkedid']];_0x2b2aec[_0xfaa1('0x48')]=_0x5f2bc8[_0xfaa1('0x49')];RpcVoiceTransferReport[_0xfaa1('0x1b')](_0x2b2aec);delete RpcVoiceTransferReport[_0xfaa1('0x47')][_0x5f2bc8[_0xfaa1('0x4a')]];}if(_['isNil'](_0x5f2bc8[_0xfaa1('0x4b')])){_0x5f2bc8[_0xfaa1('0x4b')]=this[_0xfaa1('0x31')](_0x5f2bc8);}if(_[_0xfaa1('0x21')](_0x5f2bc8[_0xfaa1('0x4c')])){var _0x3a594c=_0x5f2bc8[_0xfaa1('0x42')]['split']('-')[0x0];var _0x45624c=this[_0xfaa1('0xc')][_0x3a594c];if(!_0x45624c)_0x45624c=this[_0xfaa1('0x2f')](_0x5f2bc8[_0xfaa1('0x20')]);if(_0x45624c){_0x5f2bc8[_0xfaa1('0x4c')]=_0x45624c['id'];_0x5f2bc8['membername']=_0x45624c['name'];}}RpcVoiceCallReport[_0xfaa1('0x2d')](_0x5f2bc8);if(_0x5f2bc8['monitor']){for(var _0x9f8130=0x0;_0x9f8130<_0x5f2bc8['monitors'][_0xfaa1('0x4d')];_0x9f8130+=0x1){_0x5f2bc8[_0xfaa1('0x4e')]=_0x5f2bc8['monitors'][_0x9f8130]['filename'];_0x5f2bc8[_0xfaa1('0x4f')]=_0x5f2bc8['monitors'][_0x9f8130][_0xfaa1('0x4f')];if(_0x5f2bc8[_0xfaa1('0x36')]==_0xfaa1('0x3f')){_0x5f2bc8[_0xfaa1('0x32')]=_0x5f2bc8[_0xfaa1('0x45')];_0x5f2bc8[_0xfaa1('0x50')]=_0x5f2bc8['connectedlinename'];_0x5f2bc8['connectedlinenum']=_0x5f2bc8[_0xfaa1('0x20')];_0x5f2bc8[_0xfaa1('0x51')]=_0x5f2bc8[_0xfaa1('0x52')];_0x5f2bc8[_0xfaa1('0x36')]=_0x5f2bc8[_0xfaa1('0x53')];}else if(_0x5f2bc8['exten']==_0xfaa1('0x54')){_0x5f2bc8[_0xfaa1('0x32')]=_0x5f2bc8['destination'];_0x5f2bc8[_0xfaa1('0x36')]=_0x5f2bc8[_0xfaa1('0x53')];}RpcVoiceRecording[_0xfaa1('0x2d')](_0x5f2bc8);}}};Report[_0xfaa1('0xe')][_0xfaa1('0x17')]=function(_0x28ebed){if(_[_0xfaa1('0x55')](_0x28ebed)){_0x28ebed[_0xfaa1('0x56')](function(_0x327389){RpcVoiceAgentReport['create'](_0x327389);});}else{RpcVoiceAgentReport[_0xfaa1('0x2d')](_0x28ebed);}};Report[_0xfaa1('0xe')][_0xfaa1('0x19')]=function(_0x5716ff){RpcVoiceDialReport['create'](_0x5716ff);var _0x42d83d;var _0x493071;var _0xe74701=_0x5716ff[_0xfaa1('0x42')];if(_['startsWith'](_0xe74701,_0xfaa1('0x57'))){_0x493071=_0xe74701['substring'](_0xe74701[_0xfaa1('0x58')]('/')+0x1,_0xe74701[_0xfaa1('0x58')]('@'));_0x42d83d=_[_0xfaa1('0x1f')](this[_0xfaa1('0xc')],function(_0x2243ad){return _0x2243ad[_0xfaa1('0x59')]==_0x493071||_0x2243ad[_0xfaa1('0x5a')]==_0x493071||_0x2243ad[_0xfaa1('0x20')]==_0x493071;});}else{_0x493071=_0xe74701[_0xfaa1('0x5b')](_0xe74701['indexOf']('/')+0x1,_0xe74701[_0xfaa1('0x5c')]('-'));_0x42d83d=this[_0xfaa1('0x1e')](_0x493071);}if(_0x42d83d){_0x5716ff['interface']=_[_0xfaa1('0x21')](_0x42d83d[_0xfaa1('0x27')])?util[_0xfaa1('0x22')](_0xfaa1('0x23'),_0x42d83d['name']):_0x42d83d[_0xfaa1('0x27')];_0x5716ff[_0xfaa1('0x52')]=_0x42d83d[_0xfaa1('0x24')];_0x5716ff['accountcode']=_0x42d83d[_0xfaa1('0x20')];RpcMemberReport[_0xfaa1('0x19')](_0x5716ff);}};Report[_0xfaa1('0xe')][_0xfaa1('0x1b')]=function(_0x29d86c){RpcVoiceTransferReport[_0xfaa1('0x47')][_0x29d86c[_0xfaa1('0x5d')]]=_0x29d86c;};Report[_0xfaa1('0xe')][_0xfaa1('0x1d')]=function(_0xc2ed10){RpcVoiceTransferReport[_0xfaa1('0x1d')](_0xc2ed10);};module[_0xfaa1('0x5e')]=Report;