Built motion from commit (unavailable).|2.4.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 _0xcf0b=['findAgent','find','accountcode','name','isNil','interface','format','length','assigned','lastAssignedTo','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','match','destination','exten','type','queue','lastdata','callerid','from-sip','xcally-motion-preview','originatecalleridnum','destinationchannel','channel','calleridnum','disposition','ANSWERED','connectedlinenum','\x22%s\x22\x20<%s>','calleridname','monitor','monitorFilename','filename','createdAt','monitors','connectedlinename','membername','xcally-motion-dialer','isArray','forEach','voiceDialReport','Local','substring','indexOf','mobile','exports','bluebird','lodash','moment','../../../config/environment','../../../config/logger','../ami','../rpc/voiceCallReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceCallReport','./voiceAgentReport','./voiceDialReport','./userReport','realtime','agents','telephones','prototype','sync','xdr','disabled','custom:voiceQueueReport','voiceQueueReport','bind','custom:voiceCallReport','voiceCallReport','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','blindTransfer','attendedtransfer','attendedTransfer'];(function(_0x4c440b,_0x3ea627){var _0x2d48cf=function(_0x56bac7){while(--_0x56bac7){_0x4c440b['push'](_0x4c440b['shift']());}};_0x2d48cf(++_0x3ea627);}(_0xcf0b,0x182));var _0xbcf0=function(_0x254bc4,_0x95004f){_0x254bc4=_0x254bc4-0x0;var _0x2f89d6=_0xcf0b[_0x254bc4];return _0x2f89d6;};'use strict';var BPromise=require(_0xbcf0('0x0'));var _=require(_0xbcf0('0x1'));var moment=require(_0xbcf0('0x2'));var util=require('util');var config=require(_0xbcf0('0x3'));var logger=require(_0xbcf0('0x4'))('ami');var ami=require(_0xbcf0('0x5'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');var RpcVoiceCallReport=require(_0xbcf0('0x6'));var RpcVoiceDialReport=require('../rpc/voiceDialReport');var RpcMemberReport=require(_0xbcf0('0x7'));var RpcVoiceQueueReport=require(_0xbcf0('0x8'));var RpcVoiceRecording=require(_0xbcf0('0x9'));var RpcVoiceTransferReport=require(_0xbcf0('0xa'));var VoiceQueueReport=require(_0xbcf0('0xb'));var VoiceCallReport=require(_0xbcf0('0xc'));var VoiceAgentReport=require(_0xbcf0('0xd'));var VoiceDialReport=require(_0xbcf0('0xe'));var UserReport=require(_0xbcf0('0xf'));function Report(_0x368d75){this[_0xbcf0('0x10')]=_0x368d75;this[_0xbcf0('0x11')]=_0x368d75[_0xbcf0('0x11')];this['telephones']=_0x368d75[_0xbcf0('0x12')];}Report[_0xbcf0('0x13')][_0xbcf0('0x14')]=function(_0x347cdd){var _0x5d9faa=new VoiceQueueReport(this['realtime']);var _0x389244=new VoiceAgentReport(this[_0xbcf0('0x10')]);var _0xb71c61=new VoiceDialReport(this[_0xbcf0('0x10')]);var _0x27e4f9=new VoiceCallReport(this[_0xbcf0('0x10')]);var _0x271a08=new UserReport(this[_0xbcf0('0x10')]);if(config['xdr']&&config[_0xbcf0('0x15')][_0xbcf0('0x16')]){ami['on'](_0xbcf0('0x17'),this[_0xbcf0('0x18')][_0xbcf0('0x19')](this));ami['on'](_0xbcf0('0x1a'),this[_0xbcf0('0x1b')][_0xbcf0('0x19')](this));ami['on'](_0xbcf0('0x1c'),this[_0xbcf0('0x1d')]['bind'](this));ami['on'](_0xbcf0('0x1e'),this['voiceDialReport'][_0xbcf0('0x19')](this));ami['on']('blindtransfer',this[_0xbcf0('0x1f')][_0xbcf0('0x19')](this));ami['on'](_0xbcf0('0x20'),this[_0xbcf0('0x21')][_0xbcf0('0x19')](this));}};Report['prototype'][_0xbcf0('0x22')]=function(_0x32b2d2){var _0x36a05e=undefined;_0x36a05e=_[_0xbcf0('0x23')](this[_0xbcf0('0x11')],function(_0x34794d){return _0x34794d[_0xbcf0('0x24')]==_0x32b2d2||_0x34794d[_0xbcf0('0x25')]==_0x32b2d2;});if(_[_0xbcf0('0x26')](_0x36a05e)){var _0x2c8e5f=_[_0xbcf0('0x23')](this[_0xbcf0('0x12')],function(_0xf14b2e){return _0xf14b2e[_0xbcf0('0x24')]==_0x32b2d2||_0xf14b2e['name']==_0x32b2d2;});if(_0x2c8e5f){_0x36a05e=_[_0xbcf0('0x23')](this[_0xbcf0('0x11')],function(_0x2f00aa){return _0x2f00aa[_0xbcf0('0x27')]==util[_0xbcf0('0x28')]('SIP/%s',_0x2c8e5f[_0xbcf0('0x25')]);});}}return _0x36a05e;};Report[_0xbcf0('0x13')][_0xbcf0('0x18')]=function(_0x185708){for(var _0x178e16=0x0;_0x178e16<_0x185708[_0xbcf0('0x29')];_0x178e16+=0x1){var _0x56ac14=this[_0xbcf0('0x22')](_0x185708[_0x178e16]['connectedlinenum']);if(_0x56ac14){_0x185708[_0x178e16][_0xbcf0('0x24')]=_0x56ac14[_0xbcf0('0x24')];_0x185708[_0x178e16][_0xbcf0('0x2a')]=!![];_0x185708[_0x178e16][_0xbcf0('0x2b')]=_0x56ac14[_0xbcf0('0x25')];_0x185708[_0x178e16]['interface']=_[_0xbcf0('0x26')](_0x56ac14[_0xbcf0('0x27')])?util[_0xbcf0('0x28')]('SIP/%s',_0x56ac14[_0xbcf0('0x25')]):_0x56ac14['interface'];if(_0x185708[_0x178e16][_0xbcf0('0x2c')]){_0x185708[_0x178e16][_0xbcf0('0x2d')]=moment()[_0xbcf0('0x28')](_0xbcf0('0x2e'));}if(_0x185708[_0x178e16][_0xbcf0('0x2f')]){_0x185708[_0x178e16][_0xbcf0('0x30')]=moment()['format'](_0xbcf0('0x2e'));}RpcMemberReport[_0xbcf0('0x18')](_0x185708[_0x178e16]);}RpcVoiceQueueReport[_0xbcf0('0x31')](_0x185708[_0x178e16]);}};function extractCalleridNumber(_0x41aca5){var _0x20c7fd=_0x41aca5[_0xbcf0('0x32')](/<(.*?)>/);return _0x20c7fd?_0x20c7fd[0x1]:_0x41aca5;}Report['prototype']['voiceCallReport']=function(_0x60bc62){_0x60bc62[_0xbcf0('0x33')]=_0x60bc62['destination']||_0x60bc62[_0xbcf0('0x34')];if(_0x60bc62[_0xbcf0('0x35')]=='dialer'){_0x60bc62['lastapplication']=_0xbcf0('0x36');_0x60bc62[_0xbcf0('0x37')]=_0x60bc62[_0xbcf0('0x36')];if(_0x60bc62['context']=='from-voip-provider'){_0x60bc62[_0xbcf0('0x24')]='';_0x60bc62[_0xbcf0('0x33')]=extractCalleridNumber(_0x60bc62[_0xbcf0('0x38')]);}else if(_0x60bc62['context']==_0xbcf0('0x39')){if(_0x60bc62[_0xbcf0('0x33')]==_0xbcf0('0x3a')){_0x60bc62[_0xbcf0('0x33')]=extractCalleridNumber(_0x60bc62['calleridpreview']);_0x60bc62['calleridnum']=_0x60bc62[_0xbcf0('0x3b')];_0x60bc62[_0xbcf0('0x3c')]=[_0x60bc62[_0xbcf0('0x3d')],_0x60bc62['channel']=_0x60bc62[_0xbcf0('0x3c')]][0x0];_0x60bc62[_0xbcf0('0x38')]=_0x60bc62['calleridpreview'];}else{_0x60bc62[_0xbcf0('0x33')]=_0x60bc62[_0xbcf0('0x3e')];_0x60bc62[_0xbcf0('0x3e')]=_0x60bc62[_0xbcf0('0x3b')];if(_0x60bc62[_0xbcf0('0x3f')]==_0xbcf0('0x40')){_0x60bc62[_0xbcf0('0x24')]=_0x60bc62[_0xbcf0('0x41')];}else{_0x60bc62[_0xbcf0('0x24')]='';}}}}else{_0x60bc62['callerid']=util[_0xbcf0('0x28')](_0xbcf0('0x42'),_0x60bc62[_0xbcf0('0x43')],_0x60bc62[_0xbcf0('0x3e')]);}RpcVoiceCallReport[_0xbcf0('0x31')](_0x60bc62);if(_0x60bc62[_0xbcf0('0x44')]){for(var _0x2e0ca1=0x0;_0x2e0ca1<_0x60bc62['monitors']['length'];_0x2e0ca1+=0x1){_0x60bc62[_0xbcf0('0x45')]=_0x60bc62['monitors'][_0x2e0ca1][_0xbcf0('0x46')];_0x60bc62[_0xbcf0('0x47')]=_0x60bc62[_0xbcf0('0x48')][_0x2e0ca1][_0xbcf0('0x47')];if(_0x60bc62[_0xbcf0('0x34')]==_0xbcf0('0x3a')){_0x60bc62[_0xbcf0('0x3e')]=_0x60bc62[_0xbcf0('0x41')];_0x60bc62[_0xbcf0('0x43')]=_0x60bc62[_0xbcf0('0x49')];_0x60bc62[_0xbcf0('0x41')]=_0x60bc62[_0xbcf0('0x24')];_0x60bc62[_0xbcf0('0x49')]=_0x60bc62[_0xbcf0('0x4a')];_0x60bc62[_0xbcf0('0x34')]=_0x60bc62[_0xbcf0('0x3b')];}else if(_0x60bc62[_0xbcf0('0x34')]==_0xbcf0('0x4b')){_0x60bc62[_0xbcf0('0x3e')]=_0x60bc62[_0xbcf0('0x33')];_0x60bc62[_0xbcf0('0x34')]=_0x60bc62['originatecalleridnum'];}RpcVoiceRecording['create'](_0x60bc62);}}};Report['prototype'][_0xbcf0('0x1d')]=function(_0x36c51d){if(_[_0xbcf0('0x4c')](_0x36c51d)){_0x36c51d[_0xbcf0('0x4d')](function(_0x4e735e){RpcVoiceAgentReport[_0xbcf0('0x31')](_0x4e735e);});}else{RpcVoiceAgentReport[_0xbcf0('0x31')](_0x36c51d);}};Report['prototype'][_0xbcf0('0x4e')]=function(_0x1057f2){RpcVoiceDialReport[_0xbcf0('0x31')](_0x1057f2);var _0x2df302=undefined;var _0x4d27ad=_0x1057f2['channel'];if(_['startsWith'](_0x4d27ad,_0xbcf0('0x4f'))){var _0x5668b7=_0x4d27ad[_0xbcf0('0x50')](_0x4d27ad['indexOf']('/')+0x1,_0x4d27ad[_0xbcf0('0x51')]('@'));_0x2df302=_[_0xbcf0('0x23')](this[_0xbcf0('0x11')],function(_0x3d060a){return _0x3d060a[_0xbcf0('0x52')]==_0x5668b7||_0x3d060a['phone']==_0x5668b7||_0x3d060a[_0xbcf0('0x24')]==_0x5668b7;});}else{var _0x5668b7=_0x4d27ad[_0xbcf0('0x50')](_0x4d27ad[_0xbcf0('0x51')]('/')+0x1,_0x4d27ad['lastIndexOf']('-'));_0x2df302=this[_0xbcf0('0x22')](_0x5668b7);}if(_0x2df302){_0x1057f2['interface']=_['isNil'](_0x2df302[_0xbcf0('0x27')])?util['format']('SIP/%s',_0x2df302[_0xbcf0('0x25')]):_0x2df302[_0xbcf0('0x27')];_0x1057f2[_0xbcf0('0x4a')]=_0x2df302[_0xbcf0('0x25')];_0x1057f2[_0xbcf0('0x24')]=_0x2df302[_0xbcf0('0x24')];RpcMemberReport['voiceDialReport'](_0x1057f2);}};Report[_0xbcf0('0x13')][_0xbcf0('0x1f')]=function(_0xdeef22){RpcVoiceTransferReport[_0xbcf0('0x1f')](_0xdeef22);};Report['prototype']['attendedTransfer']=function(_0x20fd00){RpcVoiceTransferReport['attendedTransfer'](_0x20fd00);};module[_0xbcf0('0x53')]=Report;