Built motion from commit 44b1f254.|2.6.26
[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 _0x7d2f=['split','calleridnum','outbound','destination','exten','dialer','queue','context','from-voip-provider','callerid','from-sip','xcally-motion-preview','calleridpreview','originatecalleridnum','destinationchannel','disposition','ANSWERED','\x22%s\x22\x20<%s>','calleridname','transfers','linkedid','transfereelinkedid','blindTransfer','type','UserId','membername','monitors','monitorFilename','filename','createdAt','connectedlinename','xcally-motion-dialer','isArray','forEach','create','startsWith','Local','substring','indexOf','mobile','lastIndexOf','transfererlinkedid','exports','lodash','moment','util','../rpc/voiceAgentReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceCallReport','./voiceDialReport','./userReport','realtime','agents','telephones','prototype','xdr','disabled','custom:voiceQueueReport','bind','custom:voiceCallReport','voiceCallReport','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindtransfer','attendedtransfer','attendedTransfer','find','accountcode','name','interface','format','voiceQueueReport','length','findAgent','connectedlinenum','assigned','isNil','SIP/%s','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','match','getAgentByInternal','keys','getCallType','channel'];(function(_0x1f3aec,_0x24c18e){var _0x409f0d=function(_0x52b818){while(--_0x52b818){_0x1f3aec['push'](_0x1f3aec['shift']());}};_0x409f0d(++_0x24c18e);}(_0x7d2f,0xe9));var _0xf7d2=function(_0x1f711c,_0x358a89){_0x1f711c=_0x1f711c-0x0;var _0x18d183=_0x7d2f[_0x1f711c];return _0x18d183;};'use strict';var _=require(_0xf7d2('0x0'));var moment=require(_0xf7d2('0x1'));var util=require(_0xf7d2('0x2'));var config=require('../../../config/environment');var ami=require('../ami');var RpcVoiceAgentReport=require(_0xf7d2('0x3'));var RpcVoiceCallReport=require('../rpc/voiceCallReport');var RpcVoiceDialReport=require(_0xf7d2('0x4'));var RpcMemberReport=require(_0xf7d2('0x5'));var RpcVoiceQueueReport=require(_0xf7d2('0x6'));var RpcVoiceRecording=require(_0xf7d2('0x7'));var RpcVoiceTransferReport=require(_0xf7d2('0x8'));var VoiceQueueReport=require(_0xf7d2('0x9'));var VoiceCallReport=require(_0xf7d2('0xa'));var VoiceAgentReport=require('./voiceAgentReport');var VoiceDialReport=require(_0xf7d2('0xb'));var UserReport=require(_0xf7d2('0xc'));function Report(_0x3d256e){this[_0xf7d2('0xd')]=_0x3d256e;this['agents']=_0x3d256e[_0xf7d2('0xe')];this[_0xf7d2('0xf')]=_0x3d256e[_0xf7d2('0xf')];}Report[_0xf7d2('0x10')]['sync']=function(_0x3d6475){var _0x29c505=new VoiceQueueReport(this[_0xf7d2('0xd')]);var _0x4ef9e9=new VoiceAgentReport(this[_0xf7d2('0xd')]);var _0x1b25f0=new VoiceDialReport(this['realtime']);var _0x186050=new VoiceCallReport(this[_0xf7d2('0xd')]);var _0x8f9070=new UserReport(this[_0xf7d2('0xd')]);if(config[_0xf7d2('0x11')]&&config[_0xf7d2('0x11')][_0xf7d2('0x12')]){ami['on'](_0xf7d2('0x13'),this['voiceQueueReport'][_0xf7d2('0x14')](this));ami['on'](_0xf7d2('0x15'),this[_0xf7d2('0x16')]['bind'](this));ami['on'](_0xf7d2('0x17'),this[_0xf7d2('0x18')]['bind'](this));ami['on'](_0xf7d2('0x19'),this[_0xf7d2('0x1a')][_0xf7d2('0x14')](this));ami['on'](_0xf7d2('0x1b'),this['blindTransfer']['bind'](this));ami['on'](_0xf7d2('0x1c'),this[_0xf7d2('0x1d')][_0xf7d2('0x14')](this));}};Report[_0xf7d2('0x10')]['findAgent']=function(_0x58d6d7){var _0x48b909;_0x48b909=_[_0xf7d2('0x1e')](this['agents'],function(_0x2025be){return _0x2025be[_0xf7d2('0x1f')]==_0x58d6d7||_0x2025be[_0xf7d2('0x20')]==_0x58d6d7;});if(_['isNil'](_0x48b909)){var _0x4cbe6b=_['find'](this[_0xf7d2('0xf')],function(_0x3db9e1){return _0x3db9e1[_0xf7d2('0x1f')]==_0x58d6d7||_0x3db9e1[_0xf7d2('0x20')]==_0x58d6d7;});if(_0x4cbe6b){_0x48b909=_['find'](this[_0xf7d2('0xe')],function(_0x37dd32){return _0x37dd32[_0xf7d2('0x21')]==util[_0xf7d2('0x22')]('SIP/%s',_0x4cbe6b['name']);});}}return _0x48b909;};Report[_0xf7d2('0x10')][_0xf7d2('0x23')]=function(_0x546065){for(var _0x505159=0x0;_0x505159<_0x546065[_0xf7d2('0x24')];_0x505159+=0x1){var _0x19be2c=this[_0xf7d2('0x25')](_0x546065[_0x505159][_0xf7d2('0x26')]);if(_0x19be2c){_0x546065[_0x505159]['accountcode']=_0x19be2c[_0xf7d2('0x1f')];_0x546065[_0x505159][_0xf7d2('0x27')]=!![];_0x546065[_0x505159]['lastAssignedTo']=_0x19be2c[_0xf7d2('0x20')];_0x546065[_0x505159]['interface']=_[_0xf7d2('0x28')](_0x19be2c[_0xf7d2('0x21')])?util[_0xf7d2('0x22')](_0xf7d2('0x29'),_0x19be2c[_0xf7d2('0x20')]):_0x19be2c[_0xf7d2('0x21')];if(_0x546065[_0x505159][_0xf7d2('0x2a')]){_0x546065[_0x505159][_0xf7d2('0x2b')]=moment()[_0xf7d2('0x22')](_0xf7d2('0x2c'));}if(_0x546065[_0x505159][_0xf7d2('0x2d')]){_0x546065[_0x505159][_0xf7d2('0x2e')]=moment()[_0xf7d2('0x22')](_0xf7d2('0x2c'));}RpcMemberReport[_0xf7d2('0x23')](_0x546065[_0x505159]);}RpcVoiceQueueReport['create'](_0x546065[_0x505159]);}};function extractCalleridNumber(_0x39b3c0){var _0x188d91=_0x39b3c0[_0xf7d2('0x2f')](/<(.*?)>/);return _0x188d91?_0x188d91[0x1]:_0x39b3c0;}Report[_0xf7d2('0x10')][_0xf7d2('0x30')]=function(_0x1baceb){for(var _0x4a531e=0x0;_0x4a531e<Object[_0xf7d2('0x31')](this[_0xf7d2('0xe')])[_0xf7d2('0x24')];_0x4a531e++){var _0x26186a=Object[_0xf7d2('0x31')](this[_0xf7d2('0xe')])[_0x4a531e];var _0x50439c=this[_0xf7d2('0xe')][_0x26186a];if(_0x50439c['accountcode']===Number(_0x1baceb))return _0x50439c;}return null;};Report[_0xf7d2('0x10')][_0xf7d2('0x32')]=function(_0x17db98){var _0x164d7c=_0x17db98[_0xf7d2('0x33')][_0xf7d2('0x34')]('-')[0x0];var _0x3f3783=this[_0xf7d2('0xe')][_0x164d7c];if(!_0x3f3783)_0x3f3783=this[_0xf7d2('0x30')](_0x17db98[_0xf7d2('0x35')]);return!_0x3f3783?_0xf7d2('0x36'):'internal';};Report[_0xf7d2('0x10')][_0xf7d2('0x16')]=function(_0x3d75a8){_0x3d75a8['destination']=_0x3d75a8[_0xf7d2('0x37')]||_0x3d75a8[_0xf7d2('0x38')];if(_0x3d75a8['type']==_0xf7d2('0x39')){_0x3d75a8['lastapplication']=_0xf7d2('0x3a');_0x3d75a8['lastdata']=_0x3d75a8[_0xf7d2('0x3a')];if(_0x3d75a8[_0xf7d2('0x3b')]==_0xf7d2('0x3c')){_0x3d75a8[_0xf7d2('0x1f')]='';_0x3d75a8[_0xf7d2('0x37')]=extractCalleridNumber(_0x3d75a8[_0xf7d2('0x3d')]);}else if(_0x3d75a8[_0xf7d2('0x3b')]==_0xf7d2('0x3e')){if(_0x3d75a8[_0xf7d2('0x37')]==_0xf7d2('0x3f')){_0x3d75a8[_0xf7d2('0x37')]=extractCalleridNumber(_0x3d75a8[_0xf7d2('0x40')]);_0x3d75a8[_0xf7d2('0x35')]=_0x3d75a8[_0xf7d2('0x41')];_0x3d75a8[_0xf7d2('0x42')]=[_0x3d75a8[_0xf7d2('0x33')],_0x3d75a8[_0xf7d2('0x33')]=_0x3d75a8[_0xf7d2('0x42')]][0x0];_0x3d75a8[_0xf7d2('0x3d')]=_0x3d75a8[_0xf7d2('0x40')];}else{_0x3d75a8['destination']=_0x3d75a8[_0xf7d2('0x35')];_0x3d75a8['calleridnum']=_0x3d75a8[_0xf7d2('0x41')];if(_0x3d75a8[_0xf7d2('0x43')]==_0xf7d2('0x44')){_0x3d75a8['accountcode']=_0x3d75a8['connectedlinenum'];}else{_0x3d75a8[_0xf7d2('0x1f')]='';}}}}else{_0x3d75a8[_0xf7d2('0x3d')]=util[_0xf7d2('0x22')](_0xf7d2('0x45'),_0x3d75a8[_0xf7d2('0x46')],_0x3d75a8['calleridnum']);}if(RpcVoiceTransferReport[_0xf7d2('0x47')][_0x3d75a8[_0xf7d2('0x48')]]){var _0x1257c5=RpcVoiceTransferReport[_0xf7d2('0x47')][_0x3d75a8[_0xf7d2('0x48')]];_0x1257c5[_0xf7d2('0x49')]=_0x3d75a8['uniqueid'];RpcVoiceTransferReport[_0xf7d2('0x4a')](_0x1257c5);delete RpcVoiceTransferReport[_0xf7d2('0x47')][_0x3d75a8[_0xf7d2('0x48')]];}if(_[_0xf7d2('0x28')](_0x3d75a8[_0xf7d2('0x4b')])){_0x3d75a8[_0xf7d2('0x4b')]=this['getCallType'](_0x3d75a8);}if(_['isNil'](_0x3d75a8[_0xf7d2('0x4c')])){var _0x1c4005=_0x3d75a8[_0xf7d2('0x33')]['split']('-')[0x0];var _0x12b577=this[_0xf7d2('0xe')][_0x1c4005];if(!_0x12b577)_0x12b577=this[_0xf7d2('0x30')](_0x3d75a8[_0xf7d2('0x1f')]);if(_0x12b577){_0x3d75a8['UserId']=_0x12b577['id'];_0x3d75a8[_0xf7d2('0x4d')]=_0x12b577['name'];}}RpcVoiceCallReport['create'](_0x3d75a8);if(_0x3d75a8['monitor']){for(var _0x57718a=0x0;_0x57718a<_0x3d75a8[_0xf7d2('0x4e')][_0xf7d2('0x24')];_0x57718a+=0x1){_0x3d75a8[_0xf7d2('0x4f')]=_0x3d75a8[_0xf7d2('0x4e')][_0x57718a][_0xf7d2('0x50')];_0x3d75a8[_0xf7d2('0x51')]=_0x3d75a8[_0xf7d2('0x4e')][_0x57718a][_0xf7d2('0x51')];if(_0x3d75a8[_0xf7d2('0x38')]==_0xf7d2('0x3f')){_0x3d75a8[_0xf7d2('0x35')]=_0x3d75a8[_0xf7d2('0x26')];_0x3d75a8[_0xf7d2('0x46')]=_0x3d75a8['connectedlinename'];_0x3d75a8[_0xf7d2('0x26')]=_0x3d75a8[_0xf7d2('0x1f')];_0x3d75a8[_0xf7d2('0x52')]=_0x3d75a8[_0xf7d2('0x4d')];_0x3d75a8[_0xf7d2('0x38')]=_0x3d75a8[_0xf7d2('0x41')];}else if(_0x3d75a8[_0xf7d2('0x38')]==_0xf7d2('0x53')){_0x3d75a8[_0xf7d2('0x35')]=_0x3d75a8['destination'];_0x3d75a8['exten']=_0x3d75a8['originatecalleridnum'];}RpcVoiceRecording['create'](_0x3d75a8);}}};Report[_0xf7d2('0x10')][_0xf7d2('0x18')]=function(_0x9cea84){if(_[_0xf7d2('0x54')](_0x9cea84)){_0x9cea84[_0xf7d2('0x55')](function(_0x1c5f7e){RpcVoiceAgentReport[_0xf7d2('0x56')](_0x1c5f7e);});}else{RpcVoiceAgentReport['create'](_0x9cea84);}};Report['prototype'][_0xf7d2('0x1a')]=function(_0x31c004){RpcVoiceDialReport[_0xf7d2('0x56')](_0x31c004);var _0x345b54;var _0x5d62ce;var _0x14f7e0=_0x31c004[_0xf7d2('0x33')];if(_[_0xf7d2('0x57')](_0x14f7e0,_0xf7d2('0x58'))){_0x5d62ce=_0x14f7e0[_0xf7d2('0x59')](_0x14f7e0[_0xf7d2('0x5a')]('/')+0x1,_0x14f7e0[_0xf7d2('0x5a')]('@'));_0x345b54=_[_0xf7d2('0x1e')](this[_0xf7d2('0xe')],function(_0x1428ef){return _0x1428ef[_0xf7d2('0x5b')]==_0x5d62ce||_0x1428ef['phone']==_0x5d62ce||_0x1428ef[_0xf7d2('0x1f')]==_0x5d62ce;});}else{_0x5d62ce=_0x14f7e0[_0xf7d2('0x59')](_0x14f7e0[_0xf7d2('0x5a')]('/')+0x1,_0x14f7e0[_0xf7d2('0x5c')]('-'));_0x345b54=this[_0xf7d2('0x25')](_0x5d62ce);}if(_0x345b54){_0x31c004['interface']=_[_0xf7d2('0x28')](_0x345b54[_0xf7d2('0x21')])?util[_0xf7d2('0x22')](_0xf7d2('0x29'),_0x345b54['name']):_0x345b54[_0xf7d2('0x21')];_0x31c004[_0xf7d2('0x4d')]=_0x345b54[_0xf7d2('0x20')];_0x31c004[_0xf7d2('0x1f')]=_0x345b54['accountcode'];RpcMemberReport['voiceDialReport'](_0x31c004);}};Report[_0xf7d2('0x10')]['blindTransfer']=function(_0x2bd49e){RpcVoiceTransferReport[_0xf7d2('0x47')][_0x2bd49e[_0xf7d2('0x5d')]]=_0x2bd49e;};Report[_0xf7d2('0x10')][_0xf7d2('0x1d')]=function(_0x43b806){RpcVoiceTransferReport[_0xf7d2('0x1d')](_0x43b806);};module[_0xf7d2('0x5e')]=Report;