f08bad4ae8690791a0b2d7709fffba75bd895104
[motion2.git] / server / services / xdr / recordings.controller.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 _0xc283=['endsWith','value','.wav49','replace','find','monitors','push','error','[%s][recordings][hangup]','[%s][recordings][hangup]\x20calleridnum:%s\x20calleridname:%s\x20reason:%s','calleridnum','calleridname','connectedlinenum','connectedlinename','type','forEach','newexten','[%s][recordings][newexten]','[%s][recordings][newexten]\x20application:%s\x20appdata:%s','application','appdata','toLowerCase','set','startsWith','cdr','split','substring','lastIndexOf','[%s][recordings][queuecallerjoin]','[%s][recordings][queuecallerjoin]\x20queue:%s','queue','lodash','util','./utils','format','uniqueid','accountcode','getUserByInternal','name','request','CreateVoiceRecording','debug','linkedid','info','context','exten','channel','[%s][recordings][newchannel]','[%s][recordings][newstate]','isNil','channelstate','transfer','varset','variable','mixmonitor_filename','[%s][recordings][varset]','[%s][recordings][varset]\x20variable:%s\x20value:%s'];(function(_0x12d033,_0x25fa2f){var _0x3b4e80=function(_0x46c1f4){while(--_0x46c1f4){_0x12d033['push'](_0x12d033['shift']());}};_0x3b4e80(++_0x25fa2f);}(_0xc283,0x103));var _0x3c28=function(_0x5844f0,_0x4bd3f1){_0x5844f0=_0x5844f0-0x0;var _0x38cfc6=_0xc283[_0x5844f0];return _0x38cfc6;};'use strict';var _=require(_0x3c28('0x0'));var util=require(_0x3c28('0x1'));var utils=require(_0x3c28('0x2'));var recordings={};function writeDB(_0x26bb31){utils['info'](util[_0x3c28('0x3')]('[%s][recordings][writeDB]',_0x26bb31[_0x3c28('0x4')]));if(_0x26bb31[_0x3c28('0x5')]){utils[_0x3c28('0x6')](_0x26bb31[_0x3c28('0x5')])['then'](function(_0x19fa76){if(_0x19fa76){_0x26bb31['membername']=_0x19fa76[_0x3c28('0x7')];_0x26bb31['UserId']=_0x19fa76['id'];}utils[_0x3c28('0x8')](_0x3c28('0x9'),_0x26bb31);});}else{utils[_0x3c28('0x8')](_0x3c28('0x9'),_0x26bb31);}}exports['newchannel']=function(_0x3aeff9){try{utils[_0x3c28('0xa')](util[_0x3c28('0x3')]('[%s][recordings][newchannel]',_0x3aeff9[_0x3c28('0x4')]),_0x3aeff9);if(_0x3aeff9[_0x3c28('0x4')]==_0x3aeff9[_0x3c28('0xb')]){utils[_0x3c28('0xc')](util[_0x3c28('0x3')]('[%s][recordings][newchannel]\x20context:%s\x20exten:%s',_0x3aeff9[_0x3c28('0x4')],_0x3aeff9[_0x3c28('0xd')],_0x3aeff9[_0x3c28('0xe')]));recordings[_0x3aeff9[_0x3c28('0x4')]]={'uniqueid':_0x3aeff9[_0x3c28('0x4')],'accountcode':_0x3aeff9[_0x3c28('0x5')],'exten':_0x3aeff9[_0x3c28('0xe')],'context':_0x3aeff9['context'],'channel':_0x3aeff9[_0x3c28('0xf')],'monitors':[]};}}catch(_0xfc860f){utils['error'](util[_0x3c28('0x3')](_0x3c28('0x10'),_0x3aeff9[_0x3c28('0x4')]),_0xfc860f);}};exports['newstate']=function(_0x5e0875){try{utils['debug'](util[_0x3c28('0x3')](_0x3c28('0x11'),_0x5e0875['uniqueid']),_0x5e0875);if(!_[_0x3c28('0x12')](recordings[_0x5e0875[_0x3c28('0x4')]])&&_0x5e0875[_0x3c28('0x13')]==0x6){utils[_0x3c28('0xc')](util['format']('[%s][recordings][newstate]\x20context:%s\x20channel:%s',_0x5e0875[_0x3c28('0x4')],_0x5e0875[_0x3c28('0xd')],_0x5e0875['channel']));}else if(!_[_0x3c28('0x12')](recordings[_0x5e0875[_0x3c28('0xb')]])&&_0x5e0875[_0x3c28('0x13')]==0x6&&_0x5e0875[_0x3c28('0xd')]!=_0x3c28('0x14')){utils[_0x3c28('0xc')](util[_0x3c28('0x3')]('[%s][recordings][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x5e0875[_0x3c28('0x4')],_0x5e0875['linkedid'],_0x5e0875['context'],_0x5e0875[_0x3c28('0xf')]));recordings[_0x5e0875[_0x3c28('0xb')]][_0x3c28('0x5')]=_0x5e0875[_0x3c28('0x5')];}}catch(_0x3c47a4){utils['error'](util['format'](_0x3c28('0x11'),_0x5e0875[_0x3c28('0x4')]),_0x3c47a4);}};exports[_0x3c28('0x15')]=function(_0x8814f6){try{if(!_['isNil'](_0x8814f6[_0x3c28('0x16')])&&!_['isNil'](_0x8814f6[_0x3c28('0x16')][_0x3c28('0x17')])){utils['debug'](util['format'](_0x3c28('0x18'),_0x8814f6[_0x3c28('0x4')]),_0x8814f6);utils[_0x3c28('0xc')](util[_0x3c28('0x3')](_0x3c28('0x19'),_0x8814f6[_0x3c28('0x4')],_0x8814f6[_0x3c28('0x16')],_0x8814f6['value']));if(_[_0x3c28('0x1a')](_0x8814f6[_0x3c28('0x1b')],_0x3c28('0x1c'))){_0x8814f6['value']=_0x8814f6[_0x3c28('0x1b')][_0x3c28('0x1d')]('.wav49','.WAV');}if(recordings[_0x8814f6[_0x3c28('0xb')]]){var _0x478c5c=_[_0x3c28('0x1e')](recordings[_0x8814f6['linkedid']][_0x3c28('0x1f')],{'value':_0x8814f6[_0x3c28('0x1b')]});if(_[_0x3c28('0x12')](_0x478c5c)){recordings[_0x8814f6[_0x3c28('0xb')]][_0x3c28('0x1f')][_0x3c28('0x20')]({'value':_0x8814f6[_0x3c28('0x1b')]});}}}}catch(_0x58d06e){utils[_0x3c28('0x21')](util[_0x3c28('0x3')](_0x3c28('0x18'),_0x8814f6[_0x3c28('0x4')]),_0x58d06e);}};exports['hangup']=function(_0x29f4a0){try{if(!_[_0x3c28('0x12')](recordings[_0x29f4a0[_0x3c28('0x4')]])){utils[_0x3c28('0xa')](util[_0x3c28('0x3')](_0x3c28('0x22'),_0x29f4a0[_0x3c28('0x4')]),_0x29f4a0);utils[_0x3c28('0xc')](util['format'](_0x3c28('0x23'),_0x29f4a0[_0x3c28('0x4')],_0x29f4a0[_0x3c28('0x24')],_0x29f4a0[_0x3c28('0x25')],_0x29f4a0['cause-txt']));recordings[_0x29f4a0[_0x3c28('0x4')]][_0x3c28('0x24')]=_0x29f4a0['calleridnum'];recordings[_0x29f4a0[_0x3c28('0x4')]][_0x3c28('0x25')]=_0x29f4a0[_0x3c28('0x25')];recordings[_0x29f4a0['uniqueid']][_0x3c28('0x26')]=_0x29f4a0[_0x3c28('0x26')];recordings[_0x29f4a0['uniqueid']][_0x3c28('0x27')]=_0x29f4a0[_0x3c28('0x27')];if(recordings[_0x29f4a0[_0x3c28('0x4')]][_0x3c28('0x28')]=='outbound'&&recordings[_0x29f4a0['uniqueid']][_0x3c28('0x5')]){recordings[_0x29f4a0[_0x3c28('0x4')]][_0x3c28('0x26')]=recordings[_0x29f4a0[_0x3c28('0x4')]]['accountcode'];recordings[_0x29f4a0[_0x3c28('0x4')]][_0x3c28('0x27')]='';}recordings[_0x29f4a0[_0x3c28('0x4')]][_0x3c28('0x1f')][_0x3c28('0x29')](function(_0x16aa70){var _0x1fb4e3=_['clone'](recordings[_0x29f4a0['uniqueid']]);_0x1fb4e3[_0x3c28('0x1b')]=_0x16aa70[_0x3c28('0x1b')];writeDB(_0x1fb4e3);});delete recordings[_0x29f4a0[_0x3c28('0x4')]];}}catch(_0x44ea2e){utils['error'](util[_0x3c28('0x3')]('[%s][recordings][hangup]',_0x29f4a0[_0x3c28('0x4')]),_0x44ea2e);}};exports[_0x3c28('0x2a')]=function(_0x1d3fa6){try{if(!_['isNil'](recordings[_0x1d3fa6[_0x3c28('0x4')]])){utils['debug'](util['format'](_0x3c28('0x2b'),_0x1d3fa6[_0x3c28('0x4')]),_0x1d3fa6);utils[_0x3c28('0xc')](util[_0x3c28('0x3')](_0x3c28('0x2c'),_0x1d3fa6[_0x3c28('0x4')],_0x1d3fa6[_0x3c28('0x2d')],_0x1d3fa6[_0x3c28('0x2e')]));if(_0x1d3fa6[_0x3c28('0x2d')][_0x3c28('0x2f')]()==_0x3c28('0x30')&&_[_0x3c28('0x31')](_0x1d3fa6[_0x3c28('0x2e')][_0x3c28('0x2f')](),_0x3c28('0x32'))){var _0x2fb397=_0x1d3fa6['appdata'][_0x3c28('0x33')]('=');var _0x3cec8a=_0x2fb397[0x0][_0x3c28('0x34')](_0x2fb397[0x0][_0x3c28('0x35')]('(')+0x1,_0x2fb397[0x0][_0x3c28('0x35')](')'));var _0x58ccab=_0x2fb397[0x1];recordings[_0x1d3fa6['uniqueid']][_0x3cec8a]=_0x58ccab;}}}catch(_0x23ff40){utils[_0x3c28('0x21')](util[_0x3c28('0x3')](_0x3c28('0x2b'),_0x1d3fa6['uniqueid']),_0x23ff40);}};exports['queuecallerjoin']=function(_0x5e42b7){try{if(!_['isNil'](recordings[_0x5e42b7[_0x3c28('0x4')]])){utils[_0x3c28('0xa')](util[_0x3c28('0x3')](_0x3c28('0x36'),_0x5e42b7['uniqueid']),_0x5e42b7);utils['info'](util['format'](_0x3c28('0x37'),_0x5e42b7[_0x3c28('0x4')],_0x5e42b7['queue']));recordings[_0x5e42b7[_0x3c28('0x4')]]['queue']=_0x5e42b7[_0x3c28('0x38')];}}catch(_0xbd4815){utils[_0x3c28('0x21')](util['format'](_0x3c28('0x36'),_0x5e42b7[_0x3c28('0x4')]),_0xbd4815);}};