Built motion from commit (unavailable).|2.5.0
[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 _0x84ae=['exten','dialer','lastapplication','queue','context','from-voip-provider','callerid','xcally-motion-preview','calleridnum','originatecalleridnum','channel','destinationchannel','calleridpreview','ANSWERED','\x22%s\x22\x20<%s>','monitor','monitors','monitorFilename','createdAt','calleridname','membername','voiceAgentReport','forEach','startsWith','Local','substring','indexOf','phone','lastIndexOf','blindTransfer','exports','lodash','moment','util','../../../config/environment','../../../config/logger','ami','../ami','../rpc/voiceAgentReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceQueueReport','./voiceCallReport','./voiceAgentReport','./voiceDialReport','./userReport','realtime','agents','telephones','prototype','xdr','disabled','custom:voiceQueueReport','voiceQueueReport','bind','custom:voiceCallReport','custom:voiceAgentReport','voiceDialReport','blindtransfer','attendedtransfer','attendedTransfer','findAgent','find','accountcode','name','interface','format','length','connectedlinenum','assigned','lastAssignedTo','isNil','SIP/%s','queuecallercomplete','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','match','voiceCallReport','destination'];(function(_0x3868ff,_0x350373){var _0x444aee=function(_0x3df0d0){while(--_0x3df0d0){_0x3868ff['push'](_0x3868ff['shift']());}};_0x444aee(++_0x350373);}(_0x84ae,0x1be));var _0xe84a=function(_0x210b8c,_0xd76f59){_0x210b8c=_0x210b8c-0x0;var _0xf39efa=_0x84ae[_0x210b8c];return _0xf39efa;};'use strict';var BPromise=require('bluebird');var _=require(_0xe84a('0x0'));var moment=require(_0xe84a('0x1'));var util=require(_0xe84a('0x2'));var config=require(_0xe84a('0x3'));var logger=require(_0xe84a('0x4'))(_0xe84a('0x5'));var ami=require(_0xe84a('0x6'));var RpcVoiceAgentReport=require(_0xe84a('0x7'));var RpcVoiceCallReport=require('../rpc/voiceCallReport');var RpcVoiceDialReport=require('../rpc/voiceDialReport');var RpcMemberReport=require(_0xe84a('0x8'));var RpcVoiceQueueReport=require(_0xe84a('0x9'));var RpcVoiceRecording=require(_0xe84a('0xa'));var RpcVoiceTransferReport=require(_0xe84a('0xb'));var VoiceQueueReport=require(_0xe84a('0xc'));var VoiceCallReport=require(_0xe84a('0xd'));var VoiceAgentReport=require(_0xe84a('0xe'));var VoiceDialReport=require(_0xe84a('0xf'));var UserReport=require(_0xe84a('0x10'));function Report(_0x3a0389){this[_0xe84a('0x11')]=_0x3a0389;this['agents']=_0x3a0389[_0xe84a('0x12')];this['telephones']=_0x3a0389[_0xe84a('0x13')];}Report[_0xe84a('0x14')]['sync']=function(_0x2a88b9){var _0x522a87=new VoiceQueueReport(this[_0xe84a('0x11')]);var _0x233554=new VoiceAgentReport(this[_0xe84a('0x11')]);var _0x436c0f=new VoiceDialReport(this[_0xe84a('0x11')]);var _0x55dab7=new VoiceCallReport(this[_0xe84a('0x11')]);var _0x9af1c7=new UserReport(this[_0xe84a('0x11')]);if(config[_0xe84a('0x15')]&&config['xdr'][_0xe84a('0x16')]){ami['on'](_0xe84a('0x17'),this[_0xe84a('0x18')][_0xe84a('0x19')](this));ami['on'](_0xe84a('0x1a'),this['voiceCallReport']['bind'](this));ami['on'](_0xe84a('0x1b'),this['voiceAgentReport'][_0xe84a('0x19')](this));ami['on']('custom:voiceDialReport',this[_0xe84a('0x1c')][_0xe84a('0x19')](this));ami['on'](_0xe84a('0x1d'),this['blindTransfer'][_0xe84a('0x19')](this));ami['on'](_0xe84a('0x1e'),this[_0xe84a('0x1f')]['bind'](this));}};Report['prototype'][_0xe84a('0x20')]=function(_0x73dceb){var _0x1f9a6a=undefined;_0x1f9a6a=_[_0xe84a('0x21')](this[_0xe84a('0x12')],function(_0x23b6a6){return _0x23b6a6[_0xe84a('0x22')]==_0x73dceb||_0x23b6a6['name']==_0x73dceb;});if(_['isNil'](_0x1f9a6a)){var _0x1bf229=_[_0xe84a('0x21')](this[_0xe84a('0x13')],function(_0x35ffc8){return _0x35ffc8[_0xe84a('0x22')]==_0x73dceb||_0x35ffc8[_0xe84a('0x23')]==_0x73dceb;});if(_0x1bf229){_0x1f9a6a=_['find'](this[_0xe84a('0x12')],function(_0xf3662f){return _0xf3662f[_0xe84a('0x24')]==util[_0xe84a('0x25')]('SIP/%s',_0x1bf229[_0xe84a('0x23')]);});}}return _0x1f9a6a;};Report[_0xe84a('0x14')][_0xe84a('0x18')]=function(_0x2f68ac){for(var _0x5b54cf=0x0;_0x5b54cf<_0x2f68ac[_0xe84a('0x26')];_0x5b54cf+=0x1){var _0x1799ca=this['findAgent'](_0x2f68ac[_0x5b54cf][_0xe84a('0x27')]);if(_0x1799ca){_0x2f68ac[_0x5b54cf]['accountcode']=_0x1799ca[_0xe84a('0x22')];_0x2f68ac[_0x5b54cf][_0xe84a('0x28')]=!![];_0x2f68ac[_0x5b54cf][_0xe84a('0x29')]=_0x1799ca[_0xe84a('0x23')];_0x2f68ac[_0x5b54cf]['interface']=_[_0xe84a('0x2a')](_0x1799ca[_0xe84a('0x24')])?util[_0xe84a('0x25')](_0xe84a('0x2b'),_0x1799ca[_0xe84a('0x23')]):_0x1799ca['interface'];if(_0x2f68ac[_0x5b54cf][_0xe84a('0x2c')]){_0x2f68ac[_0x5b54cf]['queuecallercompleteAt']=moment()[_0xe84a('0x25')](_0xe84a('0x2d'));}if(_0x2f68ac[_0x5b54cf][_0xe84a('0x2e')]){_0x2f68ac[_0x5b54cf][_0xe84a('0x2f')]=moment()[_0xe84a('0x25')](_0xe84a('0x2d'));}RpcMemberReport[_0xe84a('0x18')](_0x2f68ac[_0x5b54cf]);}RpcVoiceQueueReport[_0xe84a('0x30')](_0x2f68ac[_0x5b54cf]);}};function extractCalleridNumber(_0x5f4553){var _0x498152=_0x5f4553[_0xe84a('0x31')](/<(.*?)>/);return _0x498152?_0x498152[0x1]:_0x5f4553;}Report[_0xe84a('0x14')][_0xe84a('0x32')]=function(_0x20cf78){_0x20cf78[_0xe84a('0x33')]=_0x20cf78[_0xe84a('0x33')]||_0x20cf78[_0xe84a('0x34')];if(_0x20cf78['type']==_0xe84a('0x35')){_0x20cf78[_0xe84a('0x36')]=_0xe84a('0x37');_0x20cf78['lastdata']=_0x20cf78['queue'];if(_0x20cf78[_0xe84a('0x38')]==_0xe84a('0x39')){_0x20cf78[_0xe84a('0x22')]='';_0x20cf78[_0xe84a('0x33')]=extractCalleridNumber(_0x20cf78[_0xe84a('0x3a')]);}else if(_0x20cf78[_0xe84a('0x38')]=='from-sip'){if(_0x20cf78['destination']==_0xe84a('0x3b')){_0x20cf78['destination']=extractCalleridNumber(_0x20cf78['calleridpreview']);_0x20cf78[_0xe84a('0x3c')]=_0x20cf78[_0xe84a('0x3d')];_0x20cf78['destinationchannel']=[_0x20cf78[_0xe84a('0x3e')],_0x20cf78['channel']=_0x20cf78[_0xe84a('0x3f')]][0x0];_0x20cf78[_0xe84a('0x3a')]=_0x20cf78[_0xe84a('0x40')];}else{_0x20cf78[_0xe84a('0x33')]=_0x20cf78[_0xe84a('0x3c')];_0x20cf78['calleridnum']=_0x20cf78[_0xe84a('0x3d')];if(_0x20cf78['disposition']==_0xe84a('0x41')){_0x20cf78['accountcode']=_0x20cf78[_0xe84a('0x27')];}else{_0x20cf78[_0xe84a('0x22')]='';}}}}else{_0x20cf78[_0xe84a('0x3a')]=util[_0xe84a('0x25')](_0xe84a('0x42'),_0x20cf78['calleridname'],_0x20cf78[_0xe84a('0x3c')]);}RpcVoiceCallReport[_0xe84a('0x30')](_0x20cf78);if(_0x20cf78[_0xe84a('0x43')]){for(var _0x3eb0cb=0x0;_0x3eb0cb<_0x20cf78[_0xe84a('0x44')][_0xe84a('0x26')];_0x3eb0cb+=0x1){_0x20cf78[_0xe84a('0x45')]=_0x20cf78[_0xe84a('0x44')][_0x3eb0cb]['filename'];_0x20cf78[_0xe84a('0x46')]=_0x20cf78[_0xe84a('0x44')][_0x3eb0cb][_0xe84a('0x46')];if(_0x20cf78[_0xe84a('0x34')]=='xcally-motion-preview'){_0x20cf78[_0xe84a('0x3c')]=_0x20cf78[_0xe84a('0x27')];_0x20cf78[_0xe84a('0x47')]=_0x20cf78['connectedlinename'];_0x20cf78[_0xe84a('0x27')]=_0x20cf78[_0xe84a('0x22')];_0x20cf78['connectedlinename']=_0x20cf78[_0xe84a('0x48')];_0x20cf78['exten']=_0x20cf78[_0xe84a('0x3d')];}else if(_0x20cf78[_0xe84a('0x34')]=='xcally-motion-dialer'){_0x20cf78[_0xe84a('0x3c')]=_0x20cf78[_0xe84a('0x33')];_0x20cf78[_0xe84a('0x34')]=_0x20cf78[_0xe84a('0x3d')];}RpcVoiceRecording[_0xe84a('0x30')](_0x20cf78);}}};Report[_0xe84a('0x14')][_0xe84a('0x49')]=function(_0x4901fb){if(_['isArray'](_0x4901fb)){_0x4901fb[_0xe84a('0x4a')](function(_0x268a9d){RpcVoiceAgentReport[_0xe84a('0x30')](_0x268a9d);});}else{RpcVoiceAgentReport[_0xe84a('0x30')](_0x4901fb);}};Report[_0xe84a('0x14')][_0xe84a('0x1c')]=function(_0x349984){RpcVoiceDialReport[_0xe84a('0x30')](_0x349984);var _0x4d055b=undefined;var _0x28168b=_0x349984[_0xe84a('0x3e')];if(_[_0xe84a('0x4b')](_0x28168b,_0xe84a('0x4c'))){var _0x5a1aed=_0x28168b[_0xe84a('0x4d')](_0x28168b[_0xe84a('0x4e')]('/')+0x1,_0x28168b[_0xe84a('0x4e')]('@'));_0x4d055b=_[_0xe84a('0x21')](this['agents'],function(_0x55586a){return _0x55586a['mobile']==_0x5a1aed||_0x55586a[_0xe84a('0x4f')]==_0x5a1aed||_0x55586a[_0xe84a('0x22')]==_0x5a1aed;});}else{var _0x5a1aed=_0x28168b['substring'](_0x28168b[_0xe84a('0x4e')]('/')+0x1,_0x28168b[_0xe84a('0x50')]('-'));_0x4d055b=this[_0xe84a('0x20')](_0x5a1aed);}if(_0x4d055b){_0x349984[_0xe84a('0x24')]=_[_0xe84a('0x2a')](_0x4d055b[_0xe84a('0x24')])?util[_0xe84a('0x25')]('SIP/%s',_0x4d055b['name']):_0x4d055b[_0xe84a('0x24')];_0x349984[_0xe84a('0x48')]=_0x4d055b[_0xe84a('0x23')];_0x349984[_0xe84a('0x22')]=_0x4d055b[_0xe84a('0x22')];RpcMemberReport[_0xe84a('0x1c')](_0x349984);}};Report[_0xe84a('0x14')][_0xe84a('0x51')]=function(_0x59ee48){RpcVoiceTransferReport['blindTransfer'](_0x59ee48);};Report[_0xe84a('0x14')][_0xe84a('0x1f')]=function(_0x25e193){RpcVoiceTransferReport[_0xe84a('0x1f')](_0x25e193);};module[_0xe84a('0x52')]=Report;