Built motion from commit (unavailable).|2.4.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 _0x9d2b=['voiceQueueReport','custom:voiceCallReport','voiceCallReport','bind','custom:voiceAgentReport','voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindtransfer','attendedtransfer','attendedTransfer','findAgent','find','accountcode','isNil','interface','format','name','length','assigned','lastAssignedTo','SIP/%s','queuecallercomplete','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','match','destination','dialer','lastapplication','queue','context','from-voip-provider','callerid','xcally-motion-preview','originatecalleridnum','destinationchannel','channel','calleridpreview','calleridnum','disposition','ANSWERED','calleridname','create','monitor','monitors','monitorFilename','filename','connectedlinename','connectedlinenum','membername','exten','xcally-motion-dialer','isArray','forEach','Local','indexOf','mobile','phone','substring','lastIndexOf','blindTransfer','exports','bluebird','lodash','moment','util','../../../config/environment','../../../config/logger','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','./voiceQueueReport','./voiceCallReport','./voiceAgentReport','./voiceDialReport','./userReport','realtime','agents','telephones','prototype','sync','xdr','custom:voiceQueueReport'];(function(_0x3aba7d,_0x13e136){var _0x7b0814=function(_0x163f04){while(--_0x163f04){_0x3aba7d['push'](_0x3aba7d['shift']());}};_0x7b0814(++_0x13e136);}(_0x9d2b,0x1a0));var _0xb9d2=function(_0x47568e,_0x5ccdaf){_0x47568e=_0x47568e-0x0;var _0x33815b=_0x9d2b[_0x47568e];return _0x33815b;};'use strict';var BPromise=require(_0xb9d2('0x0'));var _=require(_0xb9d2('0x1'));var moment=require(_0xb9d2('0x2'));var util=require(_0xb9d2('0x3'));var config=require(_0xb9d2('0x4'));var logger=require(_0xb9d2('0x5'))('ami');var ami=require('../ami');var RpcVoiceAgentReport=require(_0xb9d2('0x6'));var RpcVoiceCallReport=require(_0xb9d2('0x7'));var RpcVoiceDialReport=require(_0xb9d2('0x8'));var RpcMemberReport=require(_0xb9d2('0x9'));var RpcVoiceQueueReport=require(_0xb9d2('0xa'));var RpcVoiceRecording=require(_0xb9d2('0xb'));var RpcVoiceTransferReport=require('../rpc/voiceTransferReport');var VoiceQueueReport=require(_0xb9d2('0xc'));var VoiceCallReport=require(_0xb9d2('0xd'));var VoiceAgentReport=require(_0xb9d2('0xe'));var VoiceDialReport=require(_0xb9d2('0xf'));var UserReport=require(_0xb9d2('0x10'));function Report(_0x4af16c){this[_0xb9d2('0x11')]=_0x4af16c;this[_0xb9d2('0x12')]=_0x4af16c[_0xb9d2('0x12')];this[_0xb9d2('0x13')]=_0x4af16c[_0xb9d2('0x13')];}Report[_0xb9d2('0x14')][_0xb9d2('0x15')]=function(_0x182f6f){var _0x3a2b30=new VoiceQueueReport(this[_0xb9d2('0x11')]);var _0xcbe8e=new VoiceAgentReport(this[_0xb9d2('0x11')]);var _0x2ffeeb=new VoiceDialReport(this[_0xb9d2('0x11')]);var _0x840ced=new VoiceCallReport(this[_0xb9d2('0x11')]);var _0x299c18=new UserReport(this['realtime']);if(config[_0xb9d2('0x16')]&&config[_0xb9d2('0x16')]['disabled']){ami['on'](_0xb9d2('0x17'),this[_0xb9d2('0x18')]['bind'](this));ami['on'](_0xb9d2('0x19'),this[_0xb9d2('0x1a')][_0xb9d2('0x1b')](this));ami['on'](_0xb9d2('0x1c'),this[_0xb9d2('0x1d')][_0xb9d2('0x1b')](this));ami['on'](_0xb9d2('0x1e'),this[_0xb9d2('0x1f')][_0xb9d2('0x1b')](this));ami['on'](_0xb9d2('0x20'),this['blindTransfer'][_0xb9d2('0x1b')](this));ami['on'](_0xb9d2('0x21'),this[_0xb9d2('0x22')]['bind'](this));}};Report[_0xb9d2('0x14')][_0xb9d2('0x23')]=function(_0x45df3d){var _0xa465f=undefined;_0xa465f=_[_0xb9d2('0x24')](this['agents'],function(_0x2954f4){return _0x2954f4[_0xb9d2('0x25')]==_0x45df3d||_0x2954f4['name']==_0x45df3d;});if(_[_0xb9d2('0x26')](_0xa465f)){var _0x3b01d1=_[_0xb9d2('0x24')](this['telephones'],function(_0x33b6c7){return _0x33b6c7[_0xb9d2('0x25')]==_0x45df3d||_0x33b6c7['name']==_0x45df3d;});if(_0x3b01d1){_0xa465f=_[_0xb9d2('0x24')](this[_0xb9d2('0x12')],function(_0x238dbe){return _0x238dbe[_0xb9d2('0x27')]==util[_0xb9d2('0x28')]('SIP/%s',_0x3b01d1[_0xb9d2('0x29')]);});}}return _0xa465f;};Report[_0xb9d2('0x14')][_0xb9d2('0x18')]=function(_0x599b22){for(var _0x554e52=0x0;_0x554e52<_0x599b22[_0xb9d2('0x2a')];_0x554e52+=0x1){var _0x4c1b34=this[_0xb9d2('0x23')](_0x599b22[_0x554e52]['connectedlinenum']);if(_0x4c1b34){_0x599b22[_0x554e52][_0xb9d2('0x25')]=_0x4c1b34[_0xb9d2('0x25')];_0x599b22[_0x554e52][_0xb9d2('0x2b')]=!![];_0x599b22[_0x554e52][_0xb9d2('0x2c')]=_0x4c1b34[_0xb9d2('0x29')];_0x599b22[_0x554e52][_0xb9d2('0x27')]=_[_0xb9d2('0x26')](_0x4c1b34['interface'])?util['format'](_0xb9d2('0x2d'),_0x4c1b34[_0xb9d2('0x29')]):_0x4c1b34[_0xb9d2('0x27')];if(_0x599b22[_0x554e52][_0xb9d2('0x2e')]){_0x599b22[_0x554e52][_0xb9d2('0x2f')]=moment()['format'](_0xb9d2('0x30'));}if(_0x599b22[_0x554e52][_0xb9d2('0x31')]){_0x599b22[_0x554e52][_0xb9d2('0x32')]=moment()[_0xb9d2('0x28')](_0xb9d2('0x30'));}RpcMemberReport[_0xb9d2('0x18')](_0x599b22[_0x554e52]);}RpcVoiceQueueReport['create'](_0x599b22[_0x554e52]);}};function extractCalleridNumber(_0x368cf2){var _0x16d742=_0x368cf2[_0xb9d2('0x33')](/<(.*?)>/);return _0x16d742?_0x16d742[0x1]:_0x368cf2;}Report[_0xb9d2('0x14')][_0xb9d2('0x1a')]=function(_0x4d9afc){_0x4d9afc['destination']=_0x4d9afc[_0xb9d2('0x34')]||_0x4d9afc['exten'];if(_0x4d9afc['type']==_0xb9d2('0x35')){_0x4d9afc[_0xb9d2('0x36')]=_0xb9d2('0x37');_0x4d9afc['lastdata']=_0x4d9afc['queue'];if(_0x4d9afc[_0xb9d2('0x38')]==_0xb9d2('0x39')){_0x4d9afc[_0xb9d2('0x25')]='';_0x4d9afc[_0xb9d2('0x34')]=extractCalleridNumber(_0x4d9afc[_0xb9d2('0x3a')]);}else if(_0x4d9afc[_0xb9d2('0x38')]=='from-sip'){if(_0x4d9afc['destination']==_0xb9d2('0x3b')){_0x4d9afc[_0xb9d2('0x34')]=extractCalleridNumber(_0x4d9afc['calleridpreview']);_0x4d9afc['calleridnum']=_0x4d9afc[_0xb9d2('0x3c')];_0x4d9afc[_0xb9d2('0x3d')]=[_0x4d9afc[_0xb9d2('0x3e')],_0x4d9afc[_0xb9d2('0x3e')]=_0x4d9afc[_0xb9d2('0x3d')]][0x0];_0x4d9afc['callerid']=_0x4d9afc[_0xb9d2('0x3f')];}else{_0x4d9afc[_0xb9d2('0x34')]=_0x4d9afc[_0xb9d2('0x40')];_0x4d9afc[_0xb9d2('0x40')]=_0x4d9afc[_0xb9d2('0x3c')];if(_0x4d9afc[_0xb9d2('0x41')]==_0xb9d2('0x42')){_0x4d9afc[_0xb9d2('0x25')]=_0x4d9afc['connectedlinenum'];}else{_0x4d9afc[_0xb9d2('0x25')]='';}}}}else{_0x4d9afc['callerid']=util[_0xb9d2('0x28')]('\x22%s\x22\x20<%s>',_0x4d9afc[_0xb9d2('0x43')],_0x4d9afc[_0xb9d2('0x40')]);}RpcVoiceCallReport[_0xb9d2('0x44')](_0x4d9afc);if(_0x4d9afc[_0xb9d2('0x45')]){for(var _0x516566=0x0;_0x516566<_0x4d9afc[_0xb9d2('0x46')][_0xb9d2('0x2a')];_0x516566+=0x1){_0x4d9afc[_0xb9d2('0x47')]=_0x4d9afc[_0xb9d2('0x46')][_0x516566][_0xb9d2('0x48')];_0x4d9afc['createdAt']=_0x4d9afc[_0xb9d2('0x46')][_0x516566]['createdAt'];if(_0x4d9afc['exten']==_0xb9d2('0x3b')){_0x4d9afc['calleridnum']=_0x4d9afc['connectedlinenum'];_0x4d9afc[_0xb9d2('0x43')]=_0x4d9afc[_0xb9d2('0x49')];_0x4d9afc[_0xb9d2('0x4a')]=_0x4d9afc[_0xb9d2('0x25')];_0x4d9afc[_0xb9d2('0x49')]=_0x4d9afc[_0xb9d2('0x4b')];_0x4d9afc[_0xb9d2('0x4c')]=_0x4d9afc['originatecalleridnum'];}else if(_0x4d9afc['exten']==_0xb9d2('0x4d')){_0x4d9afc[_0xb9d2('0x40')]=_0x4d9afc[_0xb9d2('0x34')];_0x4d9afc[_0xb9d2('0x4c')]=_0x4d9afc['originatecalleridnum'];}RpcVoiceRecording['create'](_0x4d9afc);}}};Report[_0xb9d2('0x14')][_0xb9d2('0x1d')]=function(_0x481bea){if(_[_0xb9d2('0x4e')](_0x481bea)){_0x481bea[_0xb9d2('0x4f')](function(_0x194815){RpcVoiceAgentReport['create'](_0x194815);});}else{RpcVoiceAgentReport[_0xb9d2('0x44')](_0x481bea);}};Report['prototype'][_0xb9d2('0x1f')]=function(_0x29e494){RpcVoiceDialReport[_0xb9d2('0x44')](_0x29e494);var _0x5d50bb=undefined;var _0x21dc6b=_0x29e494['channel'];if(_['startsWith'](_0x21dc6b,_0xb9d2('0x50'))){var _0x4d163e=_0x21dc6b['substring'](_0x21dc6b[_0xb9d2('0x51')]('/')+0x1,_0x21dc6b[_0xb9d2('0x51')]('@'));_0x5d50bb=_['find'](this[_0xb9d2('0x12')],function(_0x433878){return _0x433878[_0xb9d2('0x52')]==_0x4d163e||_0x433878[_0xb9d2('0x53')]==_0x4d163e||_0x433878[_0xb9d2('0x25')]==_0x4d163e;});}else{var _0x4d163e=_0x21dc6b[_0xb9d2('0x54')](_0x21dc6b['indexOf']('/')+0x1,_0x21dc6b[_0xb9d2('0x55')]('-'));_0x5d50bb=this[_0xb9d2('0x23')](_0x4d163e);}if(_0x5d50bb){_0x29e494[_0xb9d2('0x27')]=_[_0xb9d2('0x26')](_0x5d50bb['interface'])?util[_0xb9d2('0x28')](_0xb9d2('0x2d'),_0x5d50bb[_0xb9d2('0x29')]):_0x5d50bb[_0xb9d2('0x27')];_0x29e494[_0xb9d2('0x4b')]=_0x5d50bb[_0xb9d2('0x29')];_0x29e494[_0xb9d2('0x25')]=_0x5d50bb[_0xb9d2('0x25')];RpcMemberReport[_0xb9d2('0x1f')](_0x29e494);}};Report[_0xb9d2('0x14')]['blindTransfer']=function(_0x463e22){RpcVoiceTransferReport[_0xb9d2('0x56')](_0x463e22);};Report['prototype'][_0xb9d2('0x22')]=function(_0x725371){RpcVoiceTransferReport[_0xb9d2('0x22')](_0x725371);};module[_0xb9d2('0x57')]=Report;