Built motion from commit (unavailable).|2.4.21
[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 _0x3add=['custom:voiceCallReport','voiceCallReport','custom:voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindTransfer','attendedtransfer','attendedTransfer','findAgent','accountcode','name','isNil','find','interface','format','SIP/%s','connectedlinenum','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexitAt','create','match','destination','exten','lastdata','queue','context','from-voip-provider','callerid','xcally-motion-preview','calleridpreview','calleridnum','originatecalleridnum','channel','destinationchannel','ANSWERED','\x22%s\x22\x20<%s>','calleridname','monitor','monitors','filename','createdAt','connectedlinename','voiceAgentReport','isArray','forEach','startsWith','Local','substring','indexOf','mobile','phone','membername','lodash','util','../../../config/environment','../../../config/logger','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','./voiceQueueReport','./voiceAgentReport','./userReport','realtime','agents','telephones','prototype','sync','xdr','disabled','custom:voiceQueueReport','voiceQueueReport','bind'];(function(_0x52096b,_0x20bab4){var _0x2b1cc7=function(_0x3f7021){while(--_0x3f7021){_0x52096b['push'](_0x52096b['shift']());}};_0x2b1cc7(++_0x20bab4);}(_0x3add,0x82));var _0xd3ad=function(_0x623e7,_0x1bef7d){_0x623e7=_0x623e7-0x0;var _0x121131=_0x3add[_0x623e7];return _0x121131;};'use strict';var BPromise=require('bluebird');var _=require(_0xd3ad('0x0'));var moment=require('moment');var util=require(_0xd3ad('0x1'));var config=require(_0xd3ad('0x2'));var logger=require(_0xd3ad('0x3'))('ami');var ami=require(_0xd3ad('0x4'));var RpcVoiceAgentReport=require(_0xd3ad('0x5'));var RpcVoiceCallReport=require(_0xd3ad('0x6'));var RpcVoiceDialReport=require(_0xd3ad('0x7'));var RpcMemberReport=require(_0xd3ad('0x8'));var RpcVoiceQueueReport=require(_0xd3ad('0x9'));var RpcVoiceRecording=require(_0xd3ad('0xa'));var RpcVoiceTransferReport=require('../rpc/voiceTransferReport');var VoiceQueueReport=require(_0xd3ad('0xb'));var VoiceCallReport=require('./voiceCallReport');var VoiceAgentReport=require(_0xd3ad('0xc'));var VoiceDialReport=require('./voiceDialReport');var UserReport=require(_0xd3ad('0xd'));function Report(_0x403b55){this[_0xd3ad('0xe')]=_0x403b55;this[_0xd3ad('0xf')]=_0x403b55[_0xd3ad('0xf')];this[_0xd3ad('0x10')]=_0x403b55['telephones'];}Report[_0xd3ad('0x11')][_0xd3ad('0x12')]=function(_0xe5bcf2){var _0x4a7a19=new VoiceQueueReport(this['realtime']);var _0x2de06a=new VoiceAgentReport(this[_0xd3ad('0xe')]);var _0x47e169=new VoiceDialReport(this[_0xd3ad('0xe')]);var _0x33adae=new VoiceCallReport(this['realtime']);var _0x5d7af8=new UserReport(this[_0xd3ad('0xe')]);if(config[_0xd3ad('0x13')]&&config[_0xd3ad('0x13')][_0xd3ad('0x14')]){ami['on'](_0xd3ad('0x15'),this[_0xd3ad('0x16')][_0xd3ad('0x17')](this));ami['on'](_0xd3ad('0x18'),this[_0xd3ad('0x19')][_0xd3ad('0x17')](this));ami['on'](_0xd3ad('0x1a'),this['voiceAgentReport'][_0xd3ad('0x17')](this));ami['on'](_0xd3ad('0x1b'),this[_0xd3ad('0x1c')]['bind'](this));ami['on']('blindtransfer',this[_0xd3ad('0x1d')][_0xd3ad('0x17')](this));ami['on'](_0xd3ad('0x1e'),this[_0xd3ad('0x1f')][_0xd3ad('0x17')](this));}};Report[_0xd3ad('0x11')][_0xd3ad('0x20')]=function(_0x6104a4){var _0x10b5f7=undefined;_0x10b5f7=_['find'](this[_0xd3ad('0xf')],function(_0x54f639){return _0x54f639[_0xd3ad('0x21')]==_0x6104a4||_0x54f639[_0xd3ad('0x22')]==_0x6104a4;});if(_[_0xd3ad('0x23')](_0x10b5f7)){var _0x20c125=_[_0xd3ad('0x24')](this[_0xd3ad('0x10')],function(_0x5db662){return _0x5db662[_0xd3ad('0x21')]==_0x6104a4||_0x5db662[_0xd3ad('0x22')]==_0x6104a4;});if(_0x20c125){_0x10b5f7=_[_0xd3ad('0x24')](this['agents'],function(_0x22c85a){return _0x22c85a[_0xd3ad('0x25')]==util[_0xd3ad('0x26')](_0xd3ad('0x27'),_0x20c125[_0xd3ad('0x22')]);});}}return _0x10b5f7;};Report[_0xd3ad('0x11')][_0xd3ad('0x16')]=function(_0x112e71){for(var _0x5279e8=0x0;_0x5279e8<_0x112e71['length'];_0x5279e8+=0x1){var _0x541ee1=this[_0xd3ad('0x20')](_0x112e71[_0x5279e8][_0xd3ad('0x28')]);if(_0x541ee1){_0x112e71[_0x5279e8][_0xd3ad('0x21')]=_0x541ee1['accountcode'];_0x112e71[_0x5279e8]['assigned']=!![];_0x112e71[_0x5279e8]['lastAssignedTo']=_0x541ee1[_0xd3ad('0x22')];_0x112e71[_0x5279e8][_0xd3ad('0x25')]=_[_0xd3ad('0x23')](_0x541ee1[_0xd3ad('0x25')])?util['format'](_0xd3ad('0x27'),_0x541ee1[_0xd3ad('0x22')]):_0x541ee1[_0xd3ad('0x25')];if(_0x112e71[_0x5279e8]['queuecallercomplete']){_0x112e71[_0x5279e8][_0xd3ad('0x29')]=moment()['format'](_0xd3ad('0x2a'));}if(_0x112e71[_0x5279e8]['queuecallerexit']){_0x112e71[_0x5279e8][_0xd3ad('0x2b')]=moment()[_0xd3ad('0x26')](_0xd3ad('0x2a'));}RpcMemberReport[_0xd3ad('0x16')](_0x112e71[_0x5279e8]);}RpcVoiceQueueReport[_0xd3ad('0x2c')](_0x112e71[_0x5279e8]);}};function extractCalleridNumber(_0x1cd429){var _0xcf5871=_0x1cd429[_0xd3ad('0x2d')](/<(.*?)>/);return _0xcf5871?_0xcf5871[0x1]:_0x1cd429;}Report['prototype'][_0xd3ad('0x19')]=function(_0x539e47){_0x539e47[_0xd3ad('0x2e')]=_0x539e47[_0xd3ad('0x2e')]||_0x539e47[_0xd3ad('0x2f')];if(_0x539e47['type']=='dialer'){_0x539e47['lastapplication']='queue';_0x539e47[_0xd3ad('0x30')]=_0x539e47[_0xd3ad('0x31')];if(_0x539e47[_0xd3ad('0x32')]==_0xd3ad('0x33')){_0x539e47[_0xd3ad('0x21')]='';_0x539e47[_0xd3ad('0x2e')]=extractCalleridNumber(_0x539e47[_0xd3ad('0x34')]);}else if(_0x539e47[_0xd3ad('0x32')]=='from-sip'){if(_0x539e47[_0xd3ad('0x2e')]==_0xd3ad('0x35')){_0x539e47[_0xd3ad('0x2e')]=extractCalleridNumber(_0x539e47[_0xd3ad('0x36')]);_0x539e47[_0xd3ad('0x37')]=_0x539e47[_0xd3ad('0x38')];_0x539e47['destinationchannel']=[_0x539e47[_0xd3ad('0x39')],_0x539e47['channel']=_0x539e47[_0xd3ad('0x3a')]][0x0];_0x539e47['callerid']=_0x539e47[_0xd3ad('0x36')];}else{_0x539e47[_0xd3ad('0x2e')]=_0x539e47[_0xd3ad('0x37')];_0x539e47[_0xd3ad('0x37')]=_0x539e47[_0xd3ad('0x38')];if(_0x539e47['disposition']==_0xd3ad('0x3b')){_0x539e47[_0xd3ad('0x21')]=_0x539e47[_0xd3ad('0x28')];}else{_0x539e47['accountcode']='';}}}}else{_0x539e47[_0xd3ad('0x34')]=util['format'](_0xd3ad('0x3c'),_0x539e47[_0xd3ad('0x3d')],_0x539e47[_0xd3ad('0x37')]);}RpcVoiceCallReport[_0xd3ad('0x2c')](_0x539e47);if(_0x539e47[_0xd3ad('0x3e')]){for(var _0x3e9b7a=0x0;_0x3e9b7a<_0x539e47[_0xd3ad('0x3f')]['length'];_0x3e9b7a+=0x1){_0x539e47['monitorFilename']=_0x539e47['monitors'][_0x3e9b7a][_0xd3ad('0x40')];_0x539e47[_0xd3ad('0x41')]=_0x539e47[_0xd3ad('0x3f')][_0x3e9b7a][_0xd3ad('0x41')];if(_0x539e47[_0xd3ad('0x2f')]==_0xd3ad('0x35')){_0x539e47[_0xd3ad('0x37')]=_0x539e47['connectedlinenum'];_0x539e47['calleridname']=_0x539e47[_0xd3ad('0x42')];_0x539e47[_0xd3ad('0x28')]=_0x539e47[_0xd3ad('0x21')];_0x539e47['connectedlinename']=_0x539e47['membername'];_0x539e47[_0xd3ad('0x2f')]=_0x539e47['originatecalleridnum'];}else if(_0x539e47['exten']=='xcally-motion-dialer'){_0x539e47['calleridnum']=_0x539e47[_0xd3ad('0x2e')];_0x539e47['exten']=_0x539e47[_0xd3ad('0x38')];}RpcVoiceRecording[_0xd3ad('0x2c')](_0x539e47);}}};Report[_0xd3ad('0x11')][_0xd3ad('0x43')]=function(_0x391907){if(_[_0xd3ad('0x44')](_0x391907)){_0x391907[_0xd3ad('0x45')](function(_0x3ff355){RpcVoiceAgentReport[_0xd3ad('0x2c')](_0x3ff355);});}else{RpcVoiceAgentReport['create'](_0x391907);}};Report[_0xd3ad('0x11')]['voiceDialReport']=function(_0x868825){RpcVoiceDialReport[_0xd3ad('0x2c')](_0x868825);var _0x4e3196=undefined;var _0x409ee7=_0x868825[_0xd3ad('0x39')];if(_[_0xd3ad('0x46')](_0x409ee7,_0xd3ad('0x47'))){var _0x230c44=_0x409ee7[_0xd3ad('0x48')](_0x409ee7[_0xd3ad('0x49')]('/')+0x1,_0x409ee7['indexOf']('@'));_0x4e3196=_[_0xd3ad('0x24')](this[_0xd3ad('0xf')],function(_0xb483d){return _0xb483d[_0xd3ad('0x4a')]==_0x230c44||_0xb483d[_0xd3ad('0x4b')]==_0x230c44||_0xb483d[_0xd3ad('0x21')]==_0x230c44;});}else{var _0x230c44=_0x409ee7[_0xd3ad('0x48')](_0x409ee7['indexOf']('/')+0x1,_0x409ee7['lastIndexOf']('-'));_0x4e3196=this[_0xd3ad('0x20')](_0x230c44);}if(_0x4e3196){_0x868825[_0xd3ad('0x25')]=_[_0xd3ad('0x23')](_0x4e3196[_0xd3ad('0x25')])?util[_0xd3ad('0x26')](_0xd3ad('0x27'),_0x4e3196[_0xd3ad('0x22')]):_0x4e3196[_0xd3ad('0x25')];_0x868825[_0xd3ad('0x4c')]=_0x4e3196['name'];_0x868825[_0xd3ad('0x21')]=_0x4e3196[_0xd3ad('0x21')];RpcMemberReport[_0xd3ad('0x1c')](_0x868825);}};Report['prototype'][_0xd3ad('0x1d')]=function(_0x220ac2){RpcVoiceTransferReport[_0xd3ad('0x1d')](_0x220ac2);};Report[_0xd3ad('0x11')][_0xd3ad('0x1f')]=function(_0x849057){RpcVoiceTransferReport[_0xd3ad('0x1f')](_0x849057);};module['exports']=Report;