b306a280153ee5352ed437714d68f8ea9b2ed9ff
[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 _0xcfdf=['phone','lastIndexOf','exports','bluebird','moment','util','../../../config/environment','../../../config/logger','ami','../ami','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./userReport','agents','telephones','sync','realtime','xdr','custom:voiceQueueReport','voiceQueueReport','bind','custom:voiceCallReport','voiceCallReport','custom:voiceAgentReport','voiceDialReport','blindtransfer','blindTransfer','attendedtransfer','attendedTransfer','findAgent','find','accountcode','name','isNil','interface','SIP/%s','prototype','length','connectedlinenum','assigned','lastAssignedTo','format','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','match','destination','type','dialer','lastapplication','queue','context','from-voip-provider','from-sip','xcally-motion-preview','calleridnum','originatecalleridnum','destinationchannel','channel','callerid','calleridpreview','\x22%s\x22\x20<%s>','calleridname','monitor','monitors','filename','createdAt','exten','connectedlinename','membername','voiceAgentReport','forEach','Local','substring','indexOf','mobile'];(function(_0x4ccde9,_0x40fce2){var _0x280f19=function(_0x4aefa4){while(--_0x4aefa4){_0x4ccde9['push'](_0x4ccde9['shift']());}};_0x280f19(++_0x40fce2);}(_0xcfdf,0x14b));var _0xfcfd=function(_0x57b9bc,_0x564e60){_0x57b9bc=_0x57b9bc-0x0;var _0x2ef040=_0xcfdf[_0x57b9bc];return _0x2ef040;};'use strict';var BPromise=require(_0xfcfd('0x0'));var _=require('lodash');var moment=require(_0xfcfd('0x1'));var util=require(_0xfcfd('0x2'));var config=require(_0xfcfd('0x3'));var logger=require(_0xfcfd('0x4'))(_0xfcfd('0x5'));var ami=require(_0xfcfd('0x6'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');var RpcVoiceCallReport=require(_0xfcfd('0x7'));var RpcVoiceDialReport=require(_0xfcfd('0x8'));var RpcMemberReport=require(_0xfcfd('0x9'));var RpcVoiceQueueReport=require('../rpc/voiceQueueReport');var RpcVoiceRecording=require(_0xfcfd('0xa'));var RpcVoiceTransferReport=require(_0xfcfd('0xb'));var VoiceQueueReport=require('./voiceQueueReport');var VoiceCallReport=require('./voiceCallReport');var VoiceAgentReport=require('./voiceAgentReport');var VoiceDialReport=require('./voiceDialReport');var UserReport=require(_0xfcfd('0xc'));function Report(_0x4c83be){this['realtime']=_0x4c83be;this[_0xfcfd('0xd')]=_0x4c83be['agents'];this[_0xfcfd('0xe')]=_0x4c83be[_0xfcfd('0xe')];}Report['prototype'][_0xfcfd('0xf')]=function(_0x1f8c30){var _0x392bab=new VoiceQueueReport(this[_0xfcfd('0x10')]);var _0x564c6b=new VoiceAgentReport(this[_0xfcfd('0x10')]);var _0x18bb9d=new VoiceDialReport(this[_0xfcfd('0x10')]);var _0x54200b=new VoiceCallReport(this['realtime']);var _0xc99a=new UserReport(this[_0xfcfd('0x10')]);if(config[_0xfcfd('0x11')]&&config['xdr']['disabled']){ami['on'](_0xfcfd('0x12'),this[_0xfcfd('0x13')][_0xfcfd('0x14')](this));ami['on'](_0xfcfd('0x15'),this[_0xfcfd('0x16')][_0xfcfd('0x14')](this));ami['on'](_0xfcfd('0x17'),this['voiceAgentReport']['bind'](this));ami['on']('custom:voiceDialReport',this[_0xfcfd('0x18')][_0xfcfd('0x14')](this));ami['on'](_0xfcfd('0x19'),this[_0xfcfd('0x1a')]['bind'](this));ami['on'](_0xfcfd('0x1b'),this[_0xfcfd('0x1c')]['bind'](this));}};Report['prototype'][_0xfcfd('0x1d')]=function(_0x119431){var _0x6d6399=undefined;_0x6d6399=_[_0xfcfd('0x1e')](this[_0xfcfd('0xd')],function(_0x3c7830){return _0x3c7830[_0xfcfd('0x1f')]==_0x119431||_0x3c7830[_0xfcfd('0x20')]==_0x119431;});if(_[_0xfcfd('0x21')](_0x6d6399)){var _0x4aeaf3=_['find'](this[_0xfcfd('0xe')],function(_0x2184ed){return _0x2184ed[_0xfcfd('0x1f')]==_0x119431||_0x2184ed[_0xfcfd('0x20')]==_0x119431;});if(_0x4aeaf3){_0x6d6399=_[_0xfcfd('0x1e')](this[_0xfcfd('0xd')],function(_0x287360){return _0x287360[_0xfcfd('0x22')]==util['format'](_0xfcfd('0x23'),_0x4aeaf3[_0xfcfd('0x20')]);});}}return _0x6d6399;};Report[_0xfcfd('0x24')][_0xfcfd('0x13')]=function(_0x9b4586){for(var _0x371b34=0x0;_0x371b34<_0x9b4586[_0xfcfd('0x25')];_0x371b34+=0x1){var _0x5907cd=this[_0xfcfd('0x1d')](_0x9b4586[_0x371b34][_0xfcfd('0x26')]);if(_0x5907cd){_0x9b4586[_0x371b34]['accountcode']=_0x5907cd[_0xfcfd('0x1f')];_0x9b4586[_0x371b34][_0xfcfd('0x27')]=!![];_0x9b4586[_0x371b34][_0xfcfd('0x28')]=_0x5907cd[_0xfcfd('0x20')];_0x9b4586[_0x371b34][_0xfcfd('0x22')]=_[_0xfcfd('0x21')](_0x5907cd[_0xfcfd('0x22')])?util[_0xfcfd('0x29')]('SIP/%s',_0x5907cd[_0xfcfd('0x20')]):_0x5907cd[_0xfcfd('0x22')];if(_0x9b4586[_0x371b34][_0xfcfd('0x2a')]){_0x9b4586[_0x371b34][_0xfcfd('0x2b')]=moment()['format'](_0xfcfd('0x2c'));}if(_0x9b4586[_0x371b34][_0xfcfd('0x2d')]){_0x9b4586[_0x371b34][_0xfcfd('0x2e')]=moment()[_0xfcfd('0x29')](_0xfcfd('0x2c'));}RpcMemberReport[_0xfcfd('0x13')](_0x9b4586[_0x371b34]);}RpcVoiceQueueReport[_0xfcfd('0x2f')](_0x9b4586[_0x371b34]);}};function extractCalleridNumber(_0x323d79){var _0x113136=_0x323d79[_0xfcfd('0x30')](/<(.*?)>/);return _0x113136?_0x113136[0x1]:_0x323d79;}Report[_0xfcfd('0x24')][_0xfcfd('0x16')]=function(_0x3864fe){_0x3864fe[_0xfcfd('0x31')]=_0x3864fe[_0xfcfd('0x31')]||_0x3864fe['exten'];if(_0x3864fe[_0xfcfd('0x32')]==_0xfcfd('0x33')){_0x3864fe[_0xfcfd('0x34')]='queue';_0x3864fe['lastdata']=_0x3864fe[_0xfcfd('0x35')];if(_0x3864fe[_0xfcfd('0x36')]==_0xfcfd('0x37')){_0x3864fe[_0xfcfd('0x1f')]='';_0x3864fe[_0xfcfd('0x31')]=extractCalleridNumber(_0x3864fe['callerid']);}else if(_0x3864fe[_0xfcfd('0x36')]==_0xfcfd('0x38')){if(_0x3864fe[_0xfcfd('0x31')]==_0xfcfd('0x39')){_0x3864fe['destination']=extractCalleridNumber(_0x3864fe['calleridpreview']);_0x3864fe[_0xfcfd('0x3a')]=_0x3864fe[_0xfcfd('0x3b')];_0x3864fe[_0xfcfd('0x3c')]=[_0x3864fe[_0xfcfd('0x3d')],_0x3864fe['channel']=_0x3864fe[_0xfcfd('0x3c')]][0x0];_0x3864fe[_0xfcfd('0x3e')]=_0x3864fe[_0xfcfd('0x3f')];}else{_0x3864fe['destination']=_0x3864fe['calleridnum'];_0x3864fe['calleridnum']=_0x3864fe['originatecalleridnum'];if(_0x3864fe['disposition']=='ANSWERED'){_0x3864fe[_0xfcfd('0x1f')]=_0x3864fe[_0xfcfd('0x26')];}else{_0x3864fe[_0xfcfd('0x1f')]='';}}}}else{_0x3864fe[_0xfcfd('0x3e')]=util['format'](_0xfcfd('0x40'),_0x3864fe[_0xfcfd('0x41')],_0x3864fe[_0xfcfd('0x3a')]);}RpcVoiceCallReport['create'](_0x3864fe);if(_0x3864fe[_0xfcfd('0x42')]){for(var _0x27345e=0x0;_0x27345e<_0x3864fe[_0xfcfd('0x43')]['length'];_0x27345e+=0x1){_0x3864fe['monitorFilename']=_0x3864fe[_0xfcfd('0x43')][_0x27345e][_0xfcfd('0x44')];_0x3864fe[_0xfcfd('0x45')]=_0x3864fe[_0xfcfd('0x43')][_0x27345e]['createdAt'];if(_0x3864fe[_0xfcfd('0x46')]==_0xfcfd('0x39')){_0x3864fe[_0xfcfd('0x3a')]=_0x3864fe[_0xfcfd('0x26')];_0x3864fe[_0xfcfd('0x41')]=_0x3864fe[_0xfcfd('0x47')];_0x3864fe['connectedlinenum']=_0x3864fe[_0xfcfd('0x1f')];_0x3864fe['connectedlinename']=_0x3864fe[_0xfcfd('0x48')];_0x3864fe['exten']=_0x3864fe[_0xfcfd('0x3b')];}else if(_0x3864fe[_0xfcfd('0x46')]=='xcally-motion-dialer'){_0x3864fe['calleridnum']=_0x3864fe['destination'];_0x3864fe[_0xfcfd('0x46')]=_0x3864fe[_0xfcfd('0x3b')];}RpcVoiceRecording['create'](_0x3864fe);}}};Report['prototype'][_0xfcfd('0x49')]=function(_0xa1a568){if(_['isArray'](_0xa1a568)){_0xa1a568[_0xfcfd('0x4a')](function(_0x4ec26f){RpcVoiceAgentReport[_0xfcfd('0x2f')](_0x4ec26f);});}else{RpcVoiceAgentReport[_0xfcfd('0x2f')](_0xa1a568);}};Report[_0xfcfd('0x24')]['voiceDialReport']=function(_0x27cd68){RpcVoiceDialReport[_0xfcfd('0x2f')](_0x27cd68);var _0x92512b=undefined;var _0x2409f7=_0x27cd68[_0xfcfd('0x3d')];if(_['startsWith'](_0x2409f7,_0xfcfd('0x4b'))){var _0x145533=_0x2409f7[_0xfcfd('0x4c')](_0x2409f7[_0xfcfd('0x4d')]('/')+0x1,_0x2409f7['indexOf']('@'));_0x92512b=_['find'](this[_0xfcfd('0xd')],function(_0x426622){return _0x426622[_0xfcfd('0x4e')]==_0x145533||_0x426622[_0xfcfd('0x4f')]==_0x145533||_0x426622[_0xfcfd('0x1f')]==_0x145533;});}else{var _0x145533=_0x2409f7[_0xfcfd('0x4c')](_0x2409f7['indexOf']('/')+0x1,_0x2409f7[_0xfcfd('0x50')]('-'));_0x92512b=this[_0xfcfd('0x1d')](_0x145533);}if(_0x92512b){_0x27cd68[_0xfcfd('0x22')]=_[_0xfcfd('0x21')](_0x92512b[_0xfcfd('0x22')])?util[_0xfcfd('0x29')](_0xfcfd('0x23'),_0x92512b[_0xfcfd('0x20')]):_0x92512b[_0xfcfd('0x22')];_0x27cd68[_0xfcfd('0x48')]=_0x92512b[_0xfcfd('0x20')];_0x27cd68['accountcode']=_0x92512b[_0xfcfd('0x1f')];RpcMemberReport[_0xfcfd('0x18')](_0x27cd68);}};Report[_0xfcfd('0x24')][_0xfcfd('0x1a')]=function(_0x431c23){RpcVoiceTransferReport[_0xfcfd('0x1a')](_0x431c23);};Report[_0xfcfd('0x24')]['attendedTransfer']=function(_0x2b1a25){RpcVoiceTransferReport['attendedTransfer'](_0x2b1a25);};module[_0xfcfd('0x51')]=Report;