5cc2cd51a051c636fd491a6c858ef7db431e197f
[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 _0x0f21=['./voiceAgentReport','./voiceDialReport','./userReport','agents','telephones','prototype','sync','realtime','xdr','disabled','voiceQueueReport','custom:voiceCallReport','voiceCallReport','bind','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindtransfer','blindTransfer','attendedtransfer','findAgent','isNil','find','accountcode','name','format','SIP/%s','length','connectedlinenum','lastAssignedTo','interface','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','destination','exten','type','dialer','lastapplication','queue','lastdata','callerid','context','from-sip','calleridpreview','calleridnum','originatecalleridnum','destinationchannel','channel','disposition','\x22%s\x22\x20<%s>','calleridname','monitor','monitors','monitorFilename','createdAt','xcally-motion-preview','connectedlinename','xcally-motion-dialer','isArray','substring','indexOf','mobile','phone','lastIndexOf','membername','attendedTransfer','bluebird','lodash','moment','../../../config/environment','../../../config/logger','ami','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceCallReport'];(function(_0x5c2e3e,_0x26ecd3){var _0x53f64a=function(_0x2b5df8){while(--_0x2b5df8){_0x5c2e3e['push'](_0x5c2e3e['shift']());}};_0x53f64a(++_0x26ecd3);}(_0x0f21,0x14c));var _0x10f2=function(_0x34df56,_0x52a58f){_0x34df56=_0x34df56-0x0;var _0x520f88=_0x0f21[_0x34df56];return _0x520f88;};'use strict';var BPromise=require(_0x10f2('0x0'));var _=require(_0x10f2('0x1'));var moment=require(_0x10f2('0x2'));var util=require('util');var config=require(_0x10f2('0x3'));var logger=require(_0x10f2('0x4'))(_0x10f2('0x5'));var ami=require(_0x10f2('0x6'));var RpcVoiceAgentReport=require(_0x10f2('0x7'));var RpcVoiceCallReport=require(_0x10f2('0x8'));var RpcVoiceDialReport=require(_0x10f2('0x9'));var RpcMemberReport=require(_0x10f2('0xa'));var RpcVoiceQueueReport=require(_0x10f2('0xb'));var RpcVoiceRecording=require(_0x10f2('0xc'));var RpcVoiceTransferReport=require(_0x10f2('0xd'));var VoiceQueueReport=require(_0x10f2('0xe'));var VoiceCallReport=require(_0x10f2('0xf'));var VoiceAgentReport=require(_0x10f2('0x10'));var VoiceDialReport=require(_0x10f2('0x11'));var UserReport=require(_0x10f2('0x12'));function Report(_0x45fb36){this['realtime']=_0x45fb36;this[_0x10f2('0x13')]=_0x45fb36[_0x10f2('0x13')];this[_0x10f2('0x14')]=_0x45fb36[_0x10f2('0x14')];}Report[_0x10f2('0x15')][_0x10f2('0x16')]=function(_0x2bf64b){var _0xa6a910=new VoiceQueueReport(this['realtime']);var _0x64386=new VoiceAgentReport(this[_0x10f2('0x17')]);var _0x190686=new VoiceDialReport(this[_0x10f2('0x17')]);var _0x307986=new VoiceCallReport(this[_0x10f2('0x17')]);var _0xbddef9=new UserReport(this['realtime']);if(config[_0x10f2('0x18')]&&config[_0x10f2('0x18')][_0x10f2('0x19')]){ami['on']('custom:voiceQueueReport',this[_0x10f2('0x1a')]['bind'](this));ami['on'](_0x10f2('0x1b'),this[_0x10f2('0x1c')][_0x10f2('0x1d')](this));ami['on'](_0x10f2('0x1e'),this[_0x10f2('0x1f')]['bind'](this));ami['on'](_0x10f2('0x20'),this[_0x10f2('0x21')][_0x10f2('0x1d')](this));ami['on'](_0x10f2('0x22'),this[_0x10f2('0x23')][_0x10f2('0x1d')](this));ami['on'](_0x10f2('0x24'),this['attendedTransfer'][_0x10f2('0x1d')](this));}};Report['prototype'][_0x10f2('0x25')]=function(_0x5e2eed){var _0x28e5b6=undefined;_0x28e5b6=_['find'](this[_0x10f2('0x13')],function(_0x437821){return _0x437821['accountcode']==_0x5e2eed||_0x437821['name']==_0x5e2eed;});if(_[_0x10f2('0x26')](_0x28e5b6)){var _0x30c628=_[_0x10f2('0x27')](this['telephones'],function(_0x5cee9f){return _0x5cee9f[_0x10f2('0x28')]==_0x5e2eed||_0x5cee9f[_0x10f2('0x29')]==_0x5e2eed;});if(_0x30c628){_0x28e5b6=_[_0x10f2('0x27')](this[_0x10f2('0x13')],function(_0x482e43){return _0x482e43['interface']==util[_0x10f2('0x2a')](_0x10f2('0x2b'),_0x30c628[_0x10f2('0x29')]);});}}return _0x28e5b6;};Report[_0x10f2('0x15')][_0x10f2('0x1a')]=function(_0x1127bb){for(var _0xaaee1f=0x0;_0xaaee1f<_0x1127bb[_0x10f2('0x2c')];_0xaaee1f+=0x1){var _0x43bc02=this[_0x10f2('0x25')](_0x1127bb[_0xaaee1f][_0x10f2('0x2d')]);if(_0x43bc02){_0x1127bb[_0xaaee1f][_0x10f2('0x28')]=_0x43bc02[_0x10f2('0x28')];_0x1127bb[_0xaaee1f]['assigned']=!![];_0x1127bb[_0xaaee1f][_0x10f2('0x2e')]=_0x43bc02[_0x10f2('0x29')];_0x1127bb[_0xaaee1f][_0x10f2('0x2f')]=_['isNil'](_0x43bc02[_0x10f2('0x2f')])?util[_0x10f2('0x2a')](_0x10f2('0x2b'),_0x43bc02[_0x10f2('0x29')]):_0x43bc02['interface'];if(_0x1127bb[_0xaaee1f][_0x10f2('0x30')]){_0x1127bb[_0xaaee1f][_0x10f2('0x31')]=moment()[_0x10f2('0x2a')](_0x10f2('0x32'));}if(_0x1127bb[_0xaaee1f][_0x10f2('0x33')]){_0x1127bb[_0xaaee1f][_0x10f2('0x34')]=moment()[_0x10f2('0x2a')]('YYYY-MM-DD\x20HH:mm:ss');}RpcMemberReport[_0x10f2('0x1a')](_0x1127bb[_0xaaee1f]);}RpcVoiceQueueReport[_0x10f2('0x35')](_0x1127bb[_0xaaee1f]);}};function extractCalleridNumber(_0x68f194){var _0x323c49=_0x68f194['match'](/<(.*?)>/);return _0x323c49?_0x323c49[0x1]:_0x68f194;}Report[_0x10f2('0x15')][_0x10f2('0x1c')]=function(_0x534f2a){_0x534f2a[_0x10f2('0x36')]=_0x534f2a[_0x10f2('0x36')]||_0x534f2a[_0x10f2('0x37')];if(_0x534f2a[_0x10f2('0x38')]==_0x10f2('0x39')){_0x534f2a[_0x10f2('0x3a')]=_0x10f2('0x3b');_0x534f2a[_0x10f2('0x3c')]=_0x534f2a['queue'];if(_0x534f2a['context']=='from-voip-provider'){_0x534f2a[_0x10f2('0x28')]='';_0x534f2a[_0x10f2('0x36')]=extractCalleridNumber(_0x534f2a[_0x10f2('0x3d')]);}else if(_0x534f2a[_0x10f2('0x3e')]==_0x10f2('0x3f')){if(_0x534f2a['destination']=='xcally-motion-preview'){_0x534f2a[_0x10f2('0x36')]=extractCalleridNumber(_0x534f2a[_0x10f2('0x40')]);_0x534f2a[_0x10f2('0x41')]=_0x534f2a[_0x10f2('0x42')];_0x534f2a[_0x10f2('0x43')]=[_0x534f2a[_0x10f2('0x44')],_0x534f2a[_0x10f2('0x44')]=_0x534f2a[_0x10f2('0x43')]][0x0];_0x534f2a[_0x10f2('0x3d')]=_0x534f2a['calleridpreview'];}else{_0x534f2a[_0x10f2('0x36')]=_0x534f2a['calleridnum'];_0x534f2a[_0x10f2('0x41')]=_0x534f2a[_0x10f2('0x42')];if(_0x534f2a[_0x10f2('0x45')]=='ANSWERED'){_0x534f2a[_0x10f2('0x28')]=_0x534f2a['connectedlinenum'];}else{_0x534f2a[_0x10f2('0x28')]='';}}}}else{_0x534f2a['callerid']=util[_0x10f2('0x2a')](_0x10f2('0x46'),_0x534f2a[_0x10f2('0x47')],_0x534f2a[_0x10f2('0x41')]);}RpcVoiceCallReport[_0x10f2('0x35')](_0x534f2a);if(_0x534f2a[_0x10f2('0x48')]){for(var _0x215b1b=0x0;_0x215b1b<_0x534f2a[_0x10f2('0x49')]['length'];_0x215b1b+=0x1){_0x534f2a[_0x10f2('0x4a')]=_0x534f2a[_0x10f2('0x49')][_0x215b1b]['filename'];_0x534f2a[_0x10f2('0x4b')]=_0x534f2a[_0x10f2('0x49')][_0x215b1b][_0x10f2('0x4b')];if(_0x534f2a[_0x10f2('0x37')]==_0x10f2('0x4c')){_0x534f2a[_0x10f2('0x41')]=_0x534f2a['connectedlinenum'];_0x534f2a[_0x10f2('0x47')]=_0x534f2a[_0x10f2('0x4d')];_0x534f2a[_0x10f2('0x2d')]=_0x534f2a[_0x10f2('0x28')];_0x534f2a[_0x10f2('0x4d')]=_0x534f2a['membername'];_0x534f2a['exten']=_0x534f2a['originatecalleridnum'];}else if(_0x534f2a[_0x10f2('0x37')]==_0x10f2('0x4e')){_0x534f2a[_0x10f2('0x41')]=_0x534f2a[_0x10f2('0x36')];_0x534f2a[_0x10f2('0x37')]=_0x534f2a['originatecalleridnum'];}RpcVoiceRecording[_0x10f2('0x35')](_0x534f2a);}}};Report[_0x10f2('0x15')]['voiceAgentReport']=function(_0x355a05){if(_[_0x10f2('0x4f')](_0x355a05)){_0x355a05['forEach'](function(_0x5d78da){RpcVoiceAgentReport[_0x10f2('0x35')](_0x5d78da);});}else{RpcVoiceAgentReport[_0x10f2('0x35')](_0x355a05);}};Report[_0x10f2('0x15')][_0x10f2('0x21')]=function(_0x37ab8e){RpcVoiceDialReport['create'](_0x37ab8e);var _0x1d5c07=undefined;var _0x1bc10f=_0x37ab8e['channel'];if(_['startsWith'](_0x1bc10f,'Local')){var _0x9672d3=_0x1bc10f[_0x10f2('0x50')](_0x1bc10f[_0x10f2('0x51')]('/')+0x1,_0x1bc10f[_0x10f2('0x51')]('@'));_0x1d5c07=_[_0x10f2('0x27')](this['agents'],function(_0x54d097){return _0x54d097[_0x10f2('0x52')]==_0x9672d3||_0x54d097[_0x10f2('0x53')]==_0x9672d3||_0x54d097['accountcode']==_0x9672d3;});}else{var _0x9672d3=_0x1bc10f[_0x10f2('0x50')](_0x1bc10f[_0x10f2('0x51')]('/')+0x1,_0x1bc10f[_0x10f2('0x54')]('-'));_0x1d5c07=this['findAgent'](_0x9672d3);}if(_0x1d5c07){_0x37ab8e[_0x10f2('0x2f')]=_[_0x10f2('0x26')](_0x1d5c07[_0x10f2('0x2f')])?util[_0x10f2('0x2a')](_0x10f2('0x2b'),_0x1d5c07[_0x10f2('0x29')]):_0x1d5c07[_0x10f2('0x2f')];_0x37ab8e[_0x10f2('0x55')]=_0x1d5c07['name'];_0x37ab8e[_0x10f2('0x28')]=_0x1d5c07['accountcode'];RpcMemberReport[_0x10f2('0x21')](_0x37ab8e);}};Report[_0x10f2('0x15')][_0x10f2('0x23')]=function(_0x306a9f){RpcVoiceTransferReport[_0x10f2('0x23')](_0x306a9f);};Report[_0x10f2('0x15')][_0x10f2('0x56')]=function(_0x1f3ec4){RpcVoiceTransferReport['attendedTransfer'](_0x1f3ec4);};module['exports']=Report;