Built motion from commit (unavailable).|2.6.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 _0x3542=['find','accountcode','name','interface','format','SIP/%s','voiceQueueReport','length','connectedlinenum','assigned','lastAssignedTo','isNil','queuecallercompleteAt','YYYY-MM-DD\x20HH:mm:ss','queuecallerexit','queuecallerexitAt','create','match','destination','exten','lastapplication','queue','lastdata','from-voip-provider','context','xcally-motion-preview','calleridpreview','calleridnum','originatecalleridnum','destinationchannel','channel','callerid','\x22%s\x22\x20<%s>','calleridname','transfers','linkedid','transfereelinkedid','uniqueid','monitor','monitors','filename','createdAt','connectedlinename','membername','xcally-motion-dialer','forEach','startsWith','indexOf','mobile','phone','substring','lastIndexOf','transfererlinkedid','exports','lodash','moment','../../../config/environment','../ami','../rpc/voiceAgentReport','../rpc/voiceCallReport','../rpc/voiceDialReport','../rpc/memberReport','../rpc/voiceTransferReport','./voiceCallReport','./voiceAgentReport','./userReport','realtime','agents','telephones','prototype','sync','xdr','disabled','custom:voiceQueueReport','bind','custom:voiceCallReport','voiceCallReport','voiceAgentReport','custom:voiceDialReport','voiceDialReport','blindTransfer','attendedtransfer','attendedTransfer','findAgent'];(function(_0x12cdae,_0x245ec6){var _0x5494ec=function(_0x441d9c){while(--_0x441d9c){_0x12cdae['push'](_0x12cdae['shift']());}};_0x5494ec(++_0x245ec6);}(_0x3542,0x8a));var _0x2354=function(_0x329421,_0x414a49){_0x329421=_0x329421-0x0;var _0x5b31e8=_0x3542[_0x329421];return _0x5b31e8;};'use strict';var _=require(_0x2354('0x0'));var moment=require(_0x2354('0x1'));var util=require('util');var config=require(_0x2354('0x2'));var ami=require(_0x2354('0x3'));var RpcVoiceAgentReport=require(_0x2354('0x4'));var RpcVoiceCallReport=require(_0x2354('0x5'));var RpcVoiceDialReport=require(_0x2354('0x6'));var RpcMemberReport=require(_0x2354('0x7'));var RpcVoiceQueueReport=require('../rpc/voiceQueueReport');var RpcVoiceRecording=require('../rpc/voiceRecording');var RpcVoiceTransferReport=require(_0x2354('0x8'));var VoiceQueueReport=require('./voiceQueueReport');var VoiceCallReport=require(_0x2354('0x9'));var VoiceAgentReport=require(_0x2354('0xa'));var VoiceDialReport=require('./voiceDialReport');var UserReport=require(_0x2354('0xb'));function Report(_0x50aa21){this[_0x2354('0xc')]=_0x50aa21;this[_0x2354('0xd')]=_0x50aa21['agents'];this[_0x2354('0xe')]=_0x50aa21[_0x2354('0xe')];}Report[_0x2354('0xf')][_0x2354('0x10')]=function(_0x5ba510){var _0x2f9a21=new VoiceQueueReport(this[_0x2354('0xc')]);var _0x4701f1=new VoiceAgentReport(this[_0x2354('0xc')]);var _0x1e11f2=new VoiceDialReport(this['realtime']);var _0x2582e5=new VoiceCallReport(this[_0x2354('0xc')]);var _0x1f3d09=new UserReport(this['realtime']);if(config[_0x2354('0x11')]&&config['xdr'][_0x2354('0x12')]){ami['on'](_0x2354('0x13'),this['voiceQueueReport'][_0x2354('0x14')](this));ami['on'](_0x2354('0x15'),this[_0x2354('0x16')][_0x2354('0x14')](this));ami['on']('custom:voiceAgentReport',this[_0x2354('0x17')][_0x2354('0x14')](this));ami['on'](_0x2354('0x18'),this[_0x2354('0x19')][_0x2354('0x14')](this));ami['on']('blindtransfer',this[_0x2354('0x1a')][_0x2354('0x14')](this));ami['on'](_0x2354('0x1b'),this[_0x2354('0x1c')][_0x2354('0x14')](this));}};Report[_0x2354('0xf')][_0x2354('0x1d')]=function(_0x51b437){var _0x56914f;_0x56914f=_[_0x2354('0x1e')](this[_0x2354('0xd')],function(_0x1a2f1c){return _0x1a2f1c[_0x2354('0x1f')]==_0x51b437||_0x1a2f1c[_0x2354('0x20')]==_0x51b437;});if(_['isNil'](_0x56914f)){var _0x90e84c=_[_0x2354('0x1e')](this[_0x2354('0xe')],function(_0x1f3486){return _0x1f3486[_0x2354('0x1f')]==_0x51b437||_0x1f3486['name']==_0x51b437;});if(_0x90e84c){_0x56914f=_[_0x2354('0x1e')](this['agents'],function(_0x5e12d5){return _0x5e12d5[_0x2354('0x21')]==util[_0x2354('0x22')](_0x2354('0x23'),_0x90e84c[_0x2354('0x20')]);});}}return _0x56914f;};Report[_0x2354('0xf')][_0x2354('0x24')]=function(_0x4746ba){for(var _0x3f0e10=0x0;_0x3f0e10<_0x4746ba[_0x2354('0x25')];_0x3f0e10+=0x1){var _0x2b36be=this[_0x2354('0x1d')](_0x4746ba[_0x3f0e10][_0x2354('0x26')]);if(_0x2b36be){_0x4746ba[_0x3f0e10][_0x2354('0x1f')]=_0x2b36be['accountcode'];_0x4746ba[_0x3f0e10][_0x2354('0x27')]=!![];_0x4746ba[_0x3f0e10][_0x2354('0x28')]=_0x2b36be[_0x2354('0x20')];_0x4746ba[_0x3f0e10]['interface']=_[_0x2354('0x29')](_0x2b36be[_0x2354('0x21')])?util[_0x2354('0x22')](_0x2354('0x23'),_0x2b36be[_0x2354('0x20')]):_0x2b36be[_0x2354('0x21')];if(_0x4746ba[_0x3f0e10]['queuecallercomplete']){_0x4746ba[_0x3f0e10][_0x2354('0x2a')]=moment()[_0x2354('0x22')](_0x2354('0x2b'));}if(_0x4746ba[_0x3f0e10][_0x2354('0x2c')]){_0x4746ba[_0x3f0e10][_0x2354('0x2d')]=moment()[_0x2354('0x22')](_0x2354('0x2b'));}RpcMemberReport[_0x2354('0x24')](_0x4746ba[_0x3f0e10]);}RpcVoiceQueueReport[_0x2354('0x2e')](_0x4746ba[_0x3f0e10]);}};function extractCalleridNumber(_0xc7752d){var _0x684382=_0xc7752d[_0x2354('0x2f')](/<(.*?)>/);return _0x684382?_0x684382[0x1]:_0xc7752d;}Report[_0x2354('0xf')][_0x2354('0x16')]=function(_0x5cab24){_0x5cab24[_0x2354('0x30')]=_0x5cab24[_0x2354('0x30')]||_0x5cab24[_0x2354('0x31')];if(_0x5cab24['type']=='dialer'){_0x5cab24[_0x2354('0x32')]=_0x2354('0x33');_0x5cab24[_0x2354('0x34')]=_0x5cab24[_0x2354('0x33')];if(_0x5cab24['context']==_0x2354('0x35')){_0x5cab24[_0x2354('0x1f')]='';_0x5cab24['destination']=extractCalleridNumber(_0x5cab24['callerid']);}else if(_0x5cab24[_0x2354('0x36')]=='from-sip'){if(_0x5cab24[_0x2354('0x30')]==_0x2354('0x37')){_0x5cab24['destination']=extractCalleridNumber(_0x5cab24[_0x2354('0x38')]);_0x5cab24[_0x2354('0x39')]=_0x5cab24[_0x2354('0x3a')];_0x5cab24[_0x2354('0x3b')]=[_0x5cab24[_0x2354('0x3c')],_0x5cab24[_0x2354('0x3c')]=_0x5cab24['destinationchannel']][0x0];_0x5cab24[_0x2354('0x3d')]=_0x5cab24[_0x2354('0x38')];}else{_0x5cab24[_0x2354('0x30')]=_0x5cab24['calleridnum'];_0x5cab24[_0x2354('0x39')]=_0x5cab24[_0x2354('0x3a')];if(_0x5cab24['disposition']=='ANSWERED'){_0x5cab24[_0x2354('0x1f')]=_0x5cab24[_0x2354('0x26')];}else{_0x5cab24[_0x2354('0x1f')]='';}}}}else{_0x5cab24[_0x2354('0x3d')]=util[_0x2354('0x22')](_0x2354('0x3e'),_0x5cab24[_0x2354('0x3f')],_0x5cab24[_0x2354('0x39')]);}if(RpcVoiceTransferReport[_0x2354('0x40')][_0x5cab24[_0x2354('0x41')]]){var _0x4dffdf=RpcVoiceTransferReport['transfers'][_0x5cab24[_0x2354('0x41')]];_0x4dffdf[_0x2354('0x42')]=_0x5cab24[_0x2354('0x43')];RpcVoiceTransferReport[_0x2354('0x1a')](_0x4dffdf);delete RpcVoiceTransferReport['transfers'][_0x5cab24[_0x2354('0x41')]];}RpcVoiceCallReport[_0x2354('0x2e')](_0x5cab24);if(_0x5cab24[_0x2354('0x44')]){for(var _0x37d77e=0x0;_0x37d77e<_0x5cab24[_0x2354('0x45')][_0x2354('0x25')];_0x37d77e+=0x1){_0x5cab24['monitorFilename']=_0x5cab24[_0x2354('0x45')][_0x37d77e][_0x2354('0x46')];_0x5cab24['createdAt']=_0x5cab24['monitors'][_0x37d77e][_0x2354('0x47')];if(_0x5cab24[_0x2354('0x31')]==_0x2354('0x37')){_0x5cab24['calleridnum']=_0x5cab24[_0x2354('0x26')];_0x5cab24[_0x2354('0x3f')]=_0x5cab24[_0x2354('0x48')];_0x5cab24['connectedlinenum']=_0x5cab24['accountcode'];_0x5cab24[_0x2354('0x48')]=_0x5cab24[_0x2354('0x49')];_0x5cab24[_0x2354('0x31')]=_0x5cab24[_0x2354('0x3a')];}else if(_0x5cab24[_0x2354('0x31')]==_0x2354('0x4a')){_0x5cab24[_0x2354('0x39')]=_0x5cab24['destination'];_0x5cab24['exten']=_0x5cab24[_0x2354('0x3a')];}RpcVoiceRecording[_0x2354('0x2e')](_0x5cab24);}}};Report[_0x2354('0xf')][_0x2354('0x17')]=function(_0x447d9f){if(_['isArray'](_0x447d9f)){_0x447d9f[_0x2354('0x4b')](function(_0x57c41d){RpcVoiceAgentReport['create'](_0x57c41d);});}else{RpcVoiceAgentReport[_0x2354('0x2e')](_0x447d9f);}};Report[_0x2354('0xf')]['voiceDialReport']=function(_0x3d7c0b){RpcVoiceDialReport[_0x2354('0x2e')](_0x3d7c0b);var _0x15d30d;var _0x1d785b;var _0x4eafab=_0x3d7c0b[_0x2354('0x3c')];if(_[_0x2354('0x4c')](_0x4eafab,'Local')){_0x1d785b=_0x4eafab['substring'](_0x4eafab['indexOf']('/')+0x1,_0x4eafab[_0x2354('0x4d')]('@'));_0x15d30d=_[_0x2354('0x1e')](this['agents'],function(_0x279679){return _0x279679[_0x2354('0x4e')]==_0x1d785b||_0x279679[_0x2354('0x4f')]==_0x1d785b||_0x279679[_0x2354('0x1f')]==_0x1d785b;});}else{_0x1d785b=_0x4eafab[_0x2354('0x50')](_0x4eafab[_0x2354('0x4d')]('/')+0x1,_0x4eafab[_0x2354('0x51')]('-'));_0x15d30d=this[_0x2354('0x1d')](_0x1d785b);}if(_0x15d30d){_0x3d7c0b[_0x2354('0x21')]=_[_0x2354('0x29')](_0x15d30d[_0x2354('0x21')])?util[_0x2354('0x22')](_0x2354('0x23'),_0x15d30d[_0x2354('0x20')]):_0x15d30d[_0x2354('0x21')];_0x3d7c0b[_0x2354('0x49')]=_0x15d30d['name'];_0x3d7c0b[_0x2354('0x1f')]=_0x15d30d[_0x2354('0x1f')];RpcMemberReport[_0x2354('0x19')](_0x3d7c0b);}};Report[_0x2354('0xf')]['blindTransfer']=function(_0x97dca8){RpcVoiceTransferReport['transfers'][_0x97dca8[_0x2354('0x52')]]=_0x97dca8;};Report[_0x2354('0xf')][_0x2354('0x1c')]=function(_0x41e8df){RpcVoiceTransferReport[_0x2354('0x1c')](_0x41e8df);};module[_0x2354('0x53')]=Report;