Built motion from commit (unavailable).|2.5.4
[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 _0x79a3=['disabled','voiceQueueReport','voiceCallReport','bind','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindtransfer','blindTransfer','attendedtransfer','attendedTransfer','findAgent','find','accountcode','name','isNil','interface','format','SIP/%s','connectedlinenum','assigned','lastAssignedTo','queuecallercomplete','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','destination','exten','dialer','lastapplication','lastdata','queue','context','from-voip-provider','callerid','from-sip','xcally-motion-preview','calleridpreview','originatecalleridnum','destinationchannel','channel','calleridnum','ANSWERED','calleridname','monitor','length','monitorFilename','createdAt','monitors','connectedlinename','membername','xcally-motion-dialer','isArray','forEach','indexOf','mobile','phone','substring','lastIndexOf','exports','bluebird','lodash','moment','../../../config/environment','../../../config/logger','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceAgentReport','./voiceDialReport','./userReport','realtime','agents','telephones','prototype','sync','xdr'];(function(_0xdc356f,_0x3003d0){var _0x339eaa=function(_0xc2283e){while(--_0xc2283e){_0xdc356f['push'](_0xdc356f['shift']());}};_0x339eaa(++_0x3003d0);}(_0x79a3,0x137));var _0x379a=function(_0x5e76be,_0x260463){_0x5e76be=_0x5e76be-0x0;var _0x51cb9c=_0x79a3[_0x5e76be];return _0x51cb9c;};'use strict';var BPromise=require(_0x379a('0x0'));var _=require(_0x379a('0x1'));var moment=require(_0x379a('0x2'));var util=require('util');var config=require(_0x379a('0x3'));var logger=require(_0x379a('0x4'))('ami');var ami=require(_0x379a('0x5'));var RpcVoiceAgentReport=require(_0x379a('0x6'));var RpcVoiceCallReport=require(_0x379a('0x7'));var RpcVoiceDialReport=require('../rpc/voiceDialReport');var RpcMemberReport=require('../rpc/memberReport');var RpcVoiceQueueReport=require(_0x379a('0x8'));var RpcVoiceRecording=require(_0x379a('0x9'));var RpcVoiceTransferReport=require(_0x379a('0xa'));var VoiceQueueReport=require(_0x379a('0xb'));var VoiceCallReport=require('./voiceCallReport');var VoiceAgentReport=require(_0x379a('0xc'));var VoiceDialReport=require(_0x379a('0xd'));var UserReport=require(_0x379a('0xe'));function Report(_0x497bdd){this[_0x379a('0xf')]=_0x497bdd;this[_0x379a('0x10')]=_0x497bdd['agents'];this['telephones']=_0x497bdd[_0x379a('0x11')];}Report[_0x379a('0x12')][_0x379a('0x13')]=function(_0x3afbf7){var _0x34bee5=new VoiceQueueReport(this[_0x379a('0xf')]);var _0x4a11ff=new VoiceAgentReport(this[_0x379a('0xf')]);var _0x13945b=new VoiceDialReport(this[_0x379a('0xf')]);var _0x4fad10=new VoiceCallReport(this[_0x379a('0xf')]);var _0x258fd6=new UserReport(this[_0x379a('0xf')]);if(config['xdr']&&config[_0x379a('0x14')][_0x379a('0x15')]){ami['on']('custom:voiceQueueReport',this[_0x379a('0x16')]['bind'](this));ami['on']('custom:voiceCallReport',this[_0x379a('0x17')][_0x379a('0x18')](this));ami['on'](_0x379a('0x19'),this[_0x379a('0x1a')][_0x379a('0x18')](this));ami['on'](_0x379a('0x1b'),this[_0x379a('0x1c')][_0x379a('0x18')](this));ami['on'](_0x379a('0x1d'),this[_0x379a('0x1e')][_0x379a('0x18')](this));ami['on'](_0x379a('0x1f'),this[_0x379a('0x20')][_0x379a('0x18')](this));}};Report['prototype'][_0x379a('0x21')]=function(_0x43228b){var _0x21dae4=undefined;_0x21dae4=_[_0x379a('0x22')](this[_0x379a('0x10')],function(_0x15f57b){return _0x15f57b[_0x379a('0x23')]==_0x43228b||_0x15f57b[_0x379a('0x24')]==_0x43228b;});if(_[_0x379a('0x25')](_0x21dae4)){var _0x1763a2=_[_0x379a('0x22')](this[_0x379a('0x11')],function(_0x5024ff){return _0x5024ff['accountcode']==_0x43228b||_0x5024ff[_0x379a('0x24')]==_0x43228b;});if(_0x1763a2){_0x21dae4=_['find'](this[_0x379a('0x10')],function(_0x5eed14){return _0x5eed14[_0x379a('0x26')]==util[_0x379a('0x27')](_0x379a('0x28'),_0x1763a2[_0x379a('0x24')]);});}}return _0x21dae4;};Report[_0x379a('0x12')]['voiceQueueReport']=function(_0x33290c){for(var _0xf0b34b=0x0;_0xf0b34b<_0x33290c['length'];_0xf0b34b+=0x1){var _0x4cb7e0=this[_0x379a('0x21')](_0x33290c[_0xf0b34b][_0x379a('0x29')]);if(_0x4cb7e0){_0x33290c[_0xf0b34b][_0x379a('0x23')]=_0x4cb7e0[_0x379a('0x23')];_0x33290c[_0xf0b34b][_0x379a('0x2a')]=!![];_0x33290c[_0xf0b34b][_0x379a('0x2b')]=_0x4cb7e0['name'];_0x33290c[_0xf0b34b][_0x379a('0x26')]=_[_0x379a('0x25')](_0x4cb7e0[_0x379a('0x26')])?util[_0x379a('0x27')](_0x379a('0x28'),_0x4cb7e0['name']):_0x4cb7e0[_0x379a('0x26')];if(_0x33290c[_0xf0b34b][_0x379a('0x2c')]){_0x33290c[_0xf0b34b]['queuecallercompleteAt']=moment()[_0x379a('0x27')](_0x379a('0x2d'));}if(_0x33290c[_0xf0b34b][_0x379a('0x2e')]){_0x33290c[_0xf0b34b][_0x379a('0x2f')]=moment()[_0x379a('0x27')](_0x379a('0x2d'));}RpcMemberReport[_0x379a('0x16')](_0x33290c[_0xf0b34b]);}RpcVoiceQueueReport[_0x379a('0x30')](_0x33290c[_0xf0b34b]);}};function extractCalleridNumber(_0x568ba3){var _0x56e1e5=_0x568ba3['match'](/<(.*?)>/);return _0x56e1e5?_0x56e1e5[0x1]:_0x568ba3;}Report[_0x379a('0x12')]['voiceCallReport']=function(_0x11eba1){_0x11eba1[_0x379a('0x31')]=_0x11eba1[_0x379a('0x31')]||_0x11eba1[_0x379a('0x32')];if(_0x11eba1['type']==_0x379a('0x33')){_0x11eba1[_0x379a('0x34')]='queue';_0x11eba1[_0x379a('0x35')]=_0x11eba1[_0x379a('0x36')];if(_0x11eba1[_0x379a('0x37')]==_0x379a('0x38')){_0x11eba1['accountcode']='';_0x11eba1[_0x379a('0x31')]=extractCalleridNumber(_0x11eba1[_0x379a('0x39')]);}else if(_0x11eba1[_0x379a('0x37')]==_0x379a('0x3a')){if(_0x11eba1[_0x379a('0x31')]==_0x379a('0x3b')){_0x11eba1['destination']=extractCalleridNumber(_0x11eba1[_0x379a('0x3c')]);_0x11eba1['calleridnum']=_0x11eba1[_0x379a('0x3d')];_0x11eba1[_0x379a('0x3e')]=[_0x11eba1[_0x379a('0x3f')],_0x11eba1[_0x379a('0x3f')]=_0x11eba1[_0x379a('0x3e')]][0x0];_0x11eba1['callerid']=_0x11eba1[_0x379a('0x3c')];}else{_0x11eba1['destination']=_0x11eba1['calleridnum'];_0x11eba1[_0x379a('0x40')]=_0x11eba1[_0x379a('0x3d')];if(_0x11eba1['disposition']==_0x379a('0x41')){_0x11eba1[_0x379a('0x23')]=_0x11eba1[_0x379a('0x29')];}else{_0x11eba1[_0x379a('0x23')]='';}}}}else{_0x11eba1[_0x379a('0x39')]=util[_0x379a('0x27')]('\x22%s\x22\x20<%s>',_0x11eba1[_0x379a('0x42')],_0x11eba1[_0x379a('0x40')]);}RpcVoiceCallReport[_0x379a('0x30')](_0x11eba1);if(_0x11eba1[_0x379a('0x43')]){for(var _0x50910a=0x0;_0x50910a<_0x11eba1['monitors'][_0x379a('0x44')];_0x50910a+=0x1){_0x11eba1[_0x379a('0x45')]=_0x11eba1['monitors'][_0x50910a]['filename'];_0x11eba1[_0x379a('0x46')]=_0x11eba1[_0x379a('0x47')][_0x50910a][_0x379a('0x46')];if(_0x11eba1[_0x379a('0x32')]==_0x379a('0x3b')){_0x11eba1[_0x379a('0x40')]=_0x11eba1[_0x379a('0x29')];_0x11eba1[_0x379a('0x42')]=_0x11eba1['connectedlinename'];_0x11eba1['connectedlinenum']=_0x11eba1[_0x379a('0x23')];_0x11eba1[_0x379a('0x48')]=_0x11eba1[_0x379a('0x49')];_0x11eba1[_0x379a('0x32')]=_0x11eba1[_0x379a('0x3d')];}else if(_0x11eba1[_0x379a('0x32')]==_0x379a('0x4a')){_0x11eba1[_0x379a('0x40')]=_0x11eba1[_0x379a('0x31')];_0x11eba1[_0x379a('0x32')]=_0x11eba1[_0x379a('0x3d')];}RpcVoiceRecording[_0x379a('0x30')](_0x11eba1);}}};Report[_0x379a('0x12')][_0x379a('0x1a')]=function(_0x25ff66){if(_[_0x379a('0x4b')](_0x25ff66)){_0x25ff66[_0x379a('0x4c')](function(_0x5b31aa){RpcVoiceAgentReport[_0x379a('0x30')](_0x5b31aa);});}else{RpcVoiceAgentReport[_0x379a('0x30')](_0x25ff66);}};Report[_0x379a('0x12')]['voiceDialReport']=function(_0x3be311){RpcVoiceDialReport[_0x379a('0x30')](_0x3be311);var _0x454967=undefined;var _0xdeb235=_0x3be311['channel'];if(_['startsWith'](_0xdeb235,'Local')){var _0x142952=_0xdeb235['substring'](_0xdeb235[_0x379a('0x4d')]('/')+0x1,_0xdeb235[_0x379a('0x4d')]('@'));_0x454967=_['find'](this[_0x379a('0x10')],function(_0x516a92){return _0x516a92[_0x379a('0x4e')]==_0x142952||_0x516a92[_0x379a('0x4f')]==_0x142952||_0x516a92['accountcode']==_0x142952;});}else{var _0x142952=_0xdeb235[_0x379a('0x50')](_0xdeb235[_0x379a('0x4d')]('/')+0x1,_0xdeb235[_0x379a('0x51')]('-'));_0x454967=this[_0x379a('0x21')](_0x142952);}if(_0x454967){_0x3be311[_0x379a('0x26')]=_[_0x379a('0x25')](_0x454967['interface'])?util[_0x379a('0x27')](_0x379a('0x28'),_0x454967[_0x379a('0x24')]):_0x454967[_0x379a('0x26')];_0x3be311['membername']=_0x454967[_0x379a('0x24')];_0x3be311[_0x379a('0x23')]=_0x454967['accountcode'];RpcMemberReport['voiceDialReport'](_0x3be311);}};Report[_0x379a('0x12')][_0x379a('0x1e')]=function(_0x2465b9){RpcVoiceTransferReport[_0x379a('0x1e')](_0x2465b9);};Report['prototype'][_0x379a('0x20')]=function(_0x4923c3){RpcVoiceTransferReport['attendedTransfer'](_0x4923c3);};module[_0x379a('0x52')]=Report;