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 _0xfa79=['exten','type','dialer','queue','lastdata','context','from-sip','xcally-motion-preview','calleridpreview','calleridnum','originatecalleridnum','destinationchannel','channel','callerid','disposition','ANSWERED','calleridname','monitor','monitors','monitorFilename','filename','createdAt','membername','isArray','forEach','voiceDialReport','startsWith','Local','substring','indexOf','mobile','phone','exports','bluebird','lodash','moment','util','../../../config/environment','../../../config/logger','ami','../ami','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceQueueReport','../rpc/voiceRecording','../rpc/voiceTransferReport','./voiceCallReport','./voiceDialReport','./userReport','realtime','agents','telephones','prototype','sync','xdr','disabled','custom:voiceQueueReport','custom:voiceCallReport','voiceCallReport','bind','voiceAgentReport','custom:voiceDialReport','blindTransfer','attendedtransfer','attendedTransfer','findAgent','find','accountcode','name','isNil','interface','format','SIP/%s','length','connectedlinenum','assigned','lastAssignedTo','queuecallercompleteAt','queuecallerexit','queuecallerexitAt','YYYY-MM-DD\x20HH:mm:ss','voiceQueueReport','create','match','destination'];(function(_0x52ba49,_0x928968){var _0x1a5618=function(_0x4e2db1){while(--_0x4e2db1){_0x52ba49['push'](_0x52ba49['shift']());}};_0x1a5618(++_0x928968);}(_0xfa79,0x175));var _0x9fa7=function(_0x20a9bc,_0x91481c){_0x20a9bc=_0x20a9bc-0x0;var _0x4897aa=_0xfa79[_0x20a9bc];return _0x4897aa;};'use strict';var BPromise=require(_0x9fa7('0x0'));var _=require(_0x9fa7('0x1'));var moment=require(_0x9fa7('0x2'));var util=require(_0x9fa7('0x3'));var config=require(_0x9fa7('0x4'));var logger=require(_0x9fa7('0x5'))(_0x9fa7('0x6'));var ami=require(_0x9fa7('0x7'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');var RpcVoiceCallReport=require('../rpc/voiceCallReport');var RpcVoiceDialReport=require(_0x9fa7('0x8'));var RpcMemberReport=require(_0x9fa7('0x9'));var RpcVoiceQueueReport=require(_0x9fa7('0xa'));var RpcVoiceRecording=require(_0x9fa7('0xb'));var RpcVoiceTransferReport=require(_0x9fa7('0xc'));var VoiceQueueReport=require('./voiceQueueReport');var VoiceCallReport=require(_0x9fa7('0xd'));var VoiceAgentReport=require('./voiceAgentReport');var VoiceDialReport=require(_0x9fa7('0xe'));var UserReport=require(_0x9fa7('0xf'));function Report(_0x8a44a3){this[_0x9fa7('0x10')]=_0x8a44a3;this[_0x9fa7('0x11')]=_0x8a44a3[_0x9fa7('0x11')];this[_0x9fa7('0x12')]=_0x8a44a3[_0x9fa7('0x12')];}Report[_0x9fa7('0x13')][_0x9fa7('0x14')]=function(_0x1029e7){var _0x14c369=new VoiceQueueReport(this[_0x9fa7('0x10')]);var _0x189b52=new VoiceAgentReport(this[_0x9fa7('0x10')]);var _0x29db2c=new VoiceDialReport(this['realtime']);var _0x726267=new VoiceCallReport(this[_0x9fa7('0x10')]);var _0x40fbcf=new UserReport(this[_0x9fa7('0x10')]);if(config[_0x9fa7('0x15')]&&config[_0x9fa7('0x15')][_0x9fa7('0x16')]){ami['on'](_0x9fa7('0x17'),this['voiceQueueReport']['bind'](this));ami['on'](_0x9fa7('0x18'),this[_0x9fa7('0x19')][_0x9fa7('0x1a')](this));ami['on']('custom:voiceAgentReport',this[_0x9fa7('0x1b')]['bind'](this));ami['on'](_0x9fa7('0x1c'),this['voiceDialReport']['bind'](this));ami['on']('blindtransfer',this[_0x9fa7('0x1d')][_0x9fa7('0x1a')](this));ami['on'](_0x9fa7('0x1e'),this[_0x9fa7('0x1f')][_0x9fa7('0x1a')](this));}};Report[_0x9fa7('0x13')][_0x9fa7('0x20')]=function(_0x208f07){var _0x526f55=undefined;_0x526f55=_[_0x9fa7('0x21')](this[_0x9fa7('0x11')],function(_0x330f02){return _0x330f02[_0x9fa7('0x22')]==_0x208f07||_0x330f02[_0x9fa7('0x23')]==_0x208f07;});if(_[_0x9fa7('0x24')](_0x526f55)){var _0x208db9=_[_0x9fa7('0x21')](this[_0x9fa7('0x12')],function(_0x20a4be){return _0x20a4be[_0x9fa7('0x22')]==_0x208f07||_0x20a4be[_0x9fa7('0x23')]==_0x208f07;});if(_0x208db9){_0x526f55=_[_0x9fa7('0x21')](this['agents'],function(_0x40b4a5){return _0x40b4a5[_0x9fa7('0x25')]==util[_0x9fa7('0x26')](_0x9fa7('0x27'),_0x208db9[_0x9fa7('0x23')]);});}}return _0x526f55;};Report[_0x9fa7('0x13')]['voiceQueueReport']=function(_0x45723e){for(var _0x36ff84=0x0;_0x36ff84<_0x45723e[_0x9fa7('0x28')];_0x36ff84+=0x1){var _0xd2af2=this['findAgent'](_0x45723e[_0x36ff84][_0x9fa7('0x29')]);if(_0xd2af2){_0x45723e[_0x36ff84][_0x9fa7('0x22')]=_0xd2af2[_0x9fa7('0x22')];_0x45723e[_0x36ff84][_0x9fa7('0x2a')]=!![];_0x45723e[_0x36ff84][_0x9fa7('0x2b')]=_0xd2af2['name'];_0x45723e[_0x36ff84]['interface']=_[_0x9fa7('0x24')](_0xd2af2[_0x9fa7('0x25')])?util[_0x9fa7('0x26')](_0x9fa7('0x27'),_0xd2af2[_0x9fa7('0x23')]):_0xd2af2[_0x9fa7('0x25')];if(_0x45723e[_0x36ff84]['queuecallercomplete']){_0x45723e[_0x36ff84][_0x9fa7('0x2c')]=moment()[_0x9fa7('0x26')]('YYYY-MM-DD\x20HH:mm:ss');}if(_0x45723e[_0x36ff84][_0x9fa7('0x2d')]){_0x45723e[_0x36ff84][_0x9fa7('0x2e')]=moment()[_0x9fa7('0x26')](_0x9fa7('0x2f'));}RpcMemberReport[_0x9fa7('0x30')](_0x45723e[_0x36ff84]);}RpcVoiceQueueReport[_0x9fa7('0x31')](_0x45723e[_0x36ff84]);}};function extractCalleridNumber(_0x253063){var _0x3f867c=_0x253063[_0x9fa7('0x32')](/<(.*?)>/);return _0x3f867c?_0x3f867c[0x1]:_0x253063;}Report[_0x9fa7('0x13')][_0x9fa7('0x19')]=function(_0x1f9434){_0x1f9434[_0x9fa7('0x33')]=_0x1f9434[_0x9fa7('0x33')]||_0x1f9434[_0x9fa7('0x34')];if(_0x1f9434[_0x9fa7('0x35')]==_0x9fa7('0x36')){_0x1f9434['lastapplication']=_0x9fa7('0x37');_0x1f9434[_0x9fa7('0x38')]=_0x1f9434[_0x9fa7('0x37')];if(_0x1f9434['context']=='from-voip-provider'){_0x1f9434[_0x9fa7('0x22')]='';_0x1f9434['destination']=extractCalleridNumber(_0x1f9434['callerid']);}else if(_0x1f9434[_0x9fa7('0x39')]==_0x9fa7('0x3a')){if(_0x1f9434[_0x9fa7('0x33')]==_0x9fa7('0x3b')){_0x1f9434[_0x9fa7('0x33')]=extractCalleridNumber(_0x1f9434[_0x9fa7('0x3c')]);_0x1f9434[_0x9fa7('0x3d')]=_0x1f9434[_0x9fa7('0x3e')];_0x1f9434[_0x9fa7('0x3f')]=[_0x1f9434[_0x9fa7('0x40')],_0x1f9434[_0x9fa7('0x40')]=_0x1f9434['destinationchannel']][0x0];_0x1f9434[_0x9fa7('0x41')]=_0x1f9434[_0x9fa7('0x3c')];}else{_0x1f9434[_0x9fa7('0x33')]=_0x1f9434[_0x9fa7('0x3d')];_0x1f9434[_0x9fa7('0x3d')]=_0x1f9434[_0x9fa7('0x3e')];if(_0x1f9434[_0x9fa7('0x42')]==_0x9fa7('0x43')){_0x1f9434[_0x9fa7('0x22')]=_0x1f9434[_0x9fa7('0x29')];}else{_0x1f9434['accountcode']='';}}}}else{_0x1f9434[_0x9fa7('0x41')]=util[_0x9fa7('0x26')]('\x22%s\x22\x20<%s>',_0x1f9434[_0x9fa7('0x44')],_0x1f9434[_0x9fa7('0x3d')]);}RpcVoiceCallReport['create'](_0x1f9434);if(_0x1f9434[_0x9fa7('0x45')]){for(var _0x14284f=0x0;_0x14284f<_0x1f9434[_0x9fa7('0x46')]['length'];_0x14284f+=0x1){_0x1f9434[_0x9fa7('0x47')]=_0x1f9434[_0x9fa7('0x46')][_0x14284f][_0x9fa7('0x48')];_0x1f9434['createdAt']=_0x1f9434['monitors'][_0x14284f][_0x9fa7('0x49')];if(_0x1f9434[_0x9fa7('0x34')]==_0x9fa7('0x3b')){_0x1f9434[_0x9fa7('0x3d')]=_0x1f9434[_0x9fa7('0x29')];_0x1f9434[_0x9fa7('0x44')]=_0x1f9434['connectedlinename'];_0x1f9434['connectedlinenum']=_0x1f9434[_0x9fa7('0x22')];_0x1f9434['connectedlinename']=_0x1f9434[_0x9fa7('0x4a')];_0x1f9434[_0x9fa7('0x34')]=_0x1f9434[_0x9fa7('0x3e')];}else if(_0x1f9434[_0x9fa7('0x34')]=='xcally-motion-dialer'){_0x1f9434['calleridnum']=_0x1f9434[_0x9fa7('0x33')];_0x1f9434[_0x9fa7('0x34')]=_0x1f9434[_0x9fa7('0x3e')];}RpcVoiceRecording[_0x9fa7('0x31')](_0x1f9434);}}};Report[_0x9fa7('0x13')][_0x9fa7('0x1b')]=function(_0x24a14b){if(_[_0x9fa7('0x4b')](_0x24a14b)){_0x24a14b[_0x9fa7('0x4c')](function(_0x533277){RpcVoiceAgentReport[_0x9fa7('0x31')](_0x533277);});}else{RpcVoiceAgentReport[_0x9fa7('0x31')](_0x24a14b);}};Report[_0x9fa7('0x13')][_0x9fa7('0x4d')]=function(_0x352cc1){RpcVoiceDialReport[_0x9fa7('0x31')](_0x352cc1);var _0x441b1a=undefined;var _0x8257f4=_0x352cc1[_0x9fa7('0x40')];if(_[_0x9fa7('0x4e')](_0x8257f4,_0x9fa7('0x4f'))){var _0x3faba4=_0x8257f4[_0x9fa7('0x50')](_0x8257f4[_0x9fa7('0x51')]('/')+0x1,_0x8257f4['indexOf']('@'));_0x441b1a=_[_0x9fa7('0x21')](this['agents'],function(_0x41701d){return _0x41701d[_0x9fa7('0x52')]==_0x3faba4||_0x41701d[_0x9fa7('0x53')]==_0x3faba4||_0x41701d[_0x9fa7('0x22')]==_0x3faba4;});}else{var _0x3faba4=_0x8257f4[_0x9fa7('0x50')](_0x8257f4[_0x9fa7('0x51')]('/')+0x1,_0x8257f4['lastIndexOf']('-'));_0x441b1a=this[_0x9fa7('0x20')](_0x3faba4);}if(_0x441b1a){_0x352cc1['interface']=_[_0x9fa7('0x24')](_0x441b1a['interface'])?util[_0x9fa7('0x26')](_0x9fa7('0x27'),_0x441b1a[_0x9fa7('0x23')]):_0x441b1a[_0x9fa7('0x25')];_0x352cc1['membername']=_0x441b1a[_0x9fa7('0x23')];_0x352cc1[_0x9fa7('0x22')]=_0x441b1a[_0x9fa7('0x22')];RpcMemberReport[_0x9fa7('0x4d')](_0x352cc1);}};Report[_0x9fa7('0x13')][_0x9fa7('0x1d')]=function(_0x5d15b2){RpcVoiceTransferReport['blindTransfer'](_0x5d15b2);};Report[_0x9fa7('0x13')][_0x9fa7('0x1f')]=function(_0x170768){RpcVoiceTransferReport['attendedTransfer'](_0x170768);};module[_0x9fa7('0x54')]=Report;