0f939d09ac4575d538e1eeb4da13ac2f0e831e86
[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 _0x5133=['debug','[%s][recordings][newchannel]','linkedid','[%s][recordings][newchannel]\x20context:%s\x20exten:%s','accountcode','exten','context','channel','error','[%s][recordings][newstate]','isNil','[%s][recordings][newstate]\x20context:%s\x20channel:%s','channelstate','transfer','varset','variable','mixmonitor_filename','[%s][recordings][varset]','[%s][recordings][varset]\x20variable:%s\x20value:%s','value','.wav49','replace','find','monitors','push','[%s][recordings][hangup]\x20calleridnum:%s\x20calleridname:%s\x20reason:%s','calleridnum','calleridname','cause-txt','connectedlinenum','connectedlinename','type','clone','[%s][recordings][hangup]','newexten','[%s][recordings][newexten]','[%s][recordings][newexten]\x20application:%s\x20appdata:%s','application','toLowerCase','startsWith','appdata','cdr','split','lastIndexOf','queuecallerjoin','queue','[%s][recordings][queuecallerjoin]','[%s][recordings][blindtransfer]','[%s][recordings][blindtransfer]\x20transferercalleridnum:%s\x20transferercalleridname:%s\x20transfereecalleridnum:%s\x20transfereecalleridname:%s','transferercalleridname','transfereecalleridnum','transfereecalleridname','transfereruniqueid','recording','util','./transfers.controller','info','format','[%s][recordings][writeDB]','uniqueid','then','membername','request','CreateVoiceRecording','blinds','newchannel'];(function(_0x24c606,_0x105207){var _0x4868d4=function(_0x2e7e53){while(--_0x2e7e53){_0x24c606['push'](_0x24c606['shift']());}};_0x4868d4(++_0x105207);}(_0x5133,0x1c2));var _0x3513=function(_0x9c098d,_0x981406){_0x9c098d=_0x9c098d-0x0;var _0x23fa83=_0x5133[_0x9c098d];return _0x23fa83;};'use strict';var _=require('lodash');var util=require(_0x3513('0x0'));var utils=require('./utils');var transfers=require(_0x3513('0x1'));var recordings={};function writeDB(_0x5891db){var _0x34b735;utils[_0x3513('0x2')](util[_0x3513('0x3')](_0x3513('0x4'),_0x5891db[_0x3513('0x5')]));if(transfers['blinds'][_0x5891db[_0x3513('0x5')]]){_0x34b735=_0x5891db['uniqueid'];_0x5891db['uniqueid']=transfers['blinds'][_0x5891db[_0x3513('0x5')]]['transfereeuniqueid'];}if(_0x5891db['accountcode']){utils['getUserByInternal'](_0x5891db['accountcode'])[_0x3513('0x6')](function(_0xe6103a){if(_0xe6103a){_0x5891db[_0x3513('0x7')]=_0xe6103a['name'];_0x5891db['UserId']=_0xe6103a['id'];}utils[_0x3513('0x8')](_0x3513('0x9'),_0x5891db);});}else{utils[_0x3513('0x8')](_0x3513('0x9'),_0x5891db);}if(_0x34b735)delete transfers[_0x3513('0xa')][_0x34b735];}exports[_0x3513('0xb')]=function(_0x17eefb){try{utils[_0x3513('0xc')](util[_0x3513('0x3')](_0x3513('0xd'),_0x17eefb[_0x3513('0x5')]),_0x17eefb);if(_0x17eefb[_0x3513('0x5')]==_0x17eefb[_0x3513('0xe')]){utils[_0x3513('0x2')](util[_0x3513('0x3')](_0x3513('0xf'),_0x17eefb['uniqueid'],_0x17eefb['context'],_0x17eefb['exten']));recordings[_0x17eefb[_0x3513('0x5')]]={'uniqueid':_0x17eefb['uniqueid'],'accountcode':_0x17eefb[_0x3513('0x10')],'exten':_0x17eefb[_0x3513('0x11')],'context':_0x17eefb[_0x3513('0x12')],'channel':_0x17eefb[_0x3513('0x13')],'monitors':[]};}}catch(_0x29ac12){utils[_0x3513('0x14')](util['format'](_0x3513('0xd'),_0x17eefb[_0x3513('0x5')]),_0x29ac12);}};exports['newstate']=function(_0x3d8f49){try{utils[_0x3513('0xc')](util[_0x3513('0x3')](_0x3513('0x15'),_0x3d8f49[_0x3513('0x5')]),_0x3d8f49);if(!_[_0x3513('0x16')](recordings[_0x3d8f49[_0x3513('0x5')]])&&_0x3d8f49['channelstate']==0x6){utils['info'](util[_0x3513('0x3')](_0x3513('0x17'),_0x3d8f49[_0x3513('0x5')],_0x3d8f49['context'],_0x3d8f49[_0x3513('0x13')]));}else if(!_[_0x3513('0x16')](recordings[_0x3d8f49[_0x3513('0xe')]])&&_0x3d8f49[_0x3513('0x18')]==0x6&&_0x3d8f49[_0x3513('0x12')]!=_0x3513('0x19')){utils[_0x3513('0x2')](util[_0x3513('0x3')]('[%s][recordings][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s',_0x3d8f49['uniqueid'],_0x3d8f49['linkedid'],_0x3d8f49[_0x3513('0x12')],_0x3d8f49[_0x3513('0x13')]));recordings[_0x3d8f49[_0x3513('0xe')]][_0x3513('0x10')]=_0x3d8f49[_0x3513('0x10')];}}catch(_0x22db1a){utils[_0x3513('0x14')](util[_0x3513('0x3')]('[%s][recordings][newstate]',_0x3d8f49[_0x3513('0x5')]),_0x22db1a);}};exports[_0x3513('0x1a')]=function(_0xc823c4){try{if(!_[_0x3513('0x16')](_0xc823c4[_0x3513('0x1b')])&&!_[_0x3513('0x16')](_0xc823c4[_0x3513('0x1b')][_0x3513('0x1c')])){utils['debug'](util[_0x3513('0x3')](_0x3513('0x1d'),_0xc823c4[_0x3513('0x5')]),_0xc823c4);utils[_0x3513('0x2')](util['format'](_0x3513('0x1e'),_0xc823c4[_0x3513('0x5')],_0xc823c4[_0x3513('0x1b')],_0xc823c4[_0x3513('0x1f')]));if(_['endsWith'](_0xc823c4[_0x3513('0x1f')],_0x3513('0x20'))){_0xc823c4[_0x3513('0x1f')]=_0xc823c4[_0x3513('0x1f')][_0x3513('0x21')](_0x3513('0x20'),'.WAV');}if(recordings[_0xc823c4['linkedid']]){var _0x3f5e30=_[_0x3513('0x22')](recordings[_0xc823c4['linkedid']][_0x3513('0x23')],{'value':_0xc823c4[_0x3513('0x1f')]});if(_['isNil'](_0x3f5e30)){recordings[_0xc823c4[_0x3513('0xe')]][_0x3513('0x23')][_0x3513('0x24')]({'value':_0xc823c4[_0x3513('0x1f')]});}}}}catch(_0xd44aa3){utils[_0x3513('0x14')](util[_0x3513('0x3')](_0x3513('0x1d'),_0xc823c4[_0x3513('0x5')]),_0xd44aa3);}};exports['hangup']=function(_0x5a24c1){try{if(!_[_0x3513('0x16')](recordings[_0x5a24c1[_0x3513('0x5')]])){utils[_0x3513('0xc')](util[_0x3513('0x3')]('[%s][recordings][hangup]',_0x5a24c1['uniqueid']),_0x5a24c1);utils[_0x3513('0x2')](util[_0x3513('0x3')](_0x3513('0x25'),_0x5a24c1[_0x3513('0x5')],_0x5a24c1[_0x3513('0x26')],_0x5a24c1[_0x3513('0x27')],_0x5a24c1[_0x3513('0x28')]));recordings[_0x5a24c1[_0x3513('0x5')]]['calleridnum']=_0x5a24c1['calleridnum'];recordings[_0x5a24c1['uniqueid']][_0x3513('0x27')]=_0x5a24c1[_0x3513('0x27')];recordings[_0x5a24c1[_0x3513('0x5')]]['connectedlinenum']=_0x5a24c1[_0x3513('0x29')];recordings[_0x5a24c1[_0x3513('0x5')]]['connectedlinename']=_0x5a24c1[_0x3513('0x2a')];if(recordings[_0x5a24c1[_0x3513('0x5')]][_0x3513('0x2b')]=='outbound'&&recordings[_0x5a24c1['uniqueid']]['accountcode']){recordings[_0x5a24c1[_0x3513('0x5')]][_0x3513('0x29')]=recordings[_0x5a24c1[_0x3513('0x5')]][_0x3513('0x10')];recordings[_0x5a24c1[_0x3513('0x5')]][_0x3513('0x2a')]='';}recordings[_0x5a24c1[_0x3513('0x5')]][_0x3513('0x23')]['forEach'](function(_0x298804){var _0x4e3bf=_[_0x3513('0x2c')](recordings[_0x5a24c1[_0x3513('0x5')]]);_0x4e3bf['value']=_0x298804[_0x3513('0x1f')];writeDB(_0x4e3bf);});delete recordings[_0x5a24c1[_0x3513('0x5')]];}}catch(_0x4f69ca){utils[_0x3513('0x14')](util[_0x3513('0x3')](_0x3513('0x2d'),_0x5a24c1['uniqueid']),_0x4f69ca);}};exports[_0x3513('0x2e')]=function(_0x480ab3){try{if(!_[_0x3513('0x16')](recordings[_0x480ab3['uniqueid']])){utils[_0x3513('0xc')](util[_0x3513('0x3')](_0x3513('0x2f'),_0x480ab3[_0x3513('0x5')]),_0x480ab3);utils[_0x3513('0x2')](util['format'](_0x3513('0x30'),_0x480ab3[_0x3513('0x5')],_0x480ab3[_0x3513('0x31')],_0x480ab3['appdata']));if(_0x480ab3[_0x3513('0x31')][_0x3513('0x32')]()=='set'&&_[_0x3513('0x33')](_0x480ab3[_0x3513('0x34')]['toLowerCase'](),_0x3513('0x35'))){var _0x451090=_0x480ab3[_0x3513('0x34')][_0x3513('0x36')]('=');var _0x224bfe=_0x451090[0x0]['substring'](_0x451090[0x0][_0x3513('0x37')]('(')+0x1,_0x451090[0x0][_0x3513('0x37')](')'));var _0x354a57=_0x451090[0x1];recordings[_0x480ab3[_0x3513('0x5')]][_0x224bfe]=_0x354a57;}}}catch(_0x3e305e){utils[_0x3513('0x14')](util[_0x3513('0x3')](_0x3513('0x2f'),_0x480ab3[_0x3513('0x5')]),_0x3e305e);}};exports[_0x3513('0x38')]=function(_0x365110){try{if(!_['isNil'](recordings[_0x365110['uniqueid']])){utils[_0x3513('0xc')](util[_0x3513('0x3')]('[%s][recordings][queuecallerjoin]',_0x365110[_0x3513('0x5')]),_0x365110);utils[_0x3513('0x2')](util[_0x3513('0x3')]('[%s][recordings][queuecallerjoin]\x20queue:%s',_0x365110[_0x3513('0x5')],_0x365110[_0x3513('0x39')]));recordings[_0x365110[_0x3513('0x5')]]['queue']=_0x365110[_0x3513('0x39')];}}catch(_0xeb5504){utils['error'](util[_0x3513('0x3')](_0x3513('0x3a'),_0x365110['uniqueid']),_0xeb5504);}};exports['blindtransfer']=function(_0x530abd){try{utils[_0x3513('0xc')](util['format'](_0x3513('0x3b'),_0x530abd[_0x3513('0x5')]),_0x530abd);utils['info'](util[_0x3513('0x3')](_0x3513('0x3c'),_0x530abd[_0x3513('0x5')],_0x530abd['transferercalleridnum'],_0x530abd[_0x3513('0x3d')],_0x530abd[_0x3513('0x3e')],_0x530abd[_0x3513('0x3f')]));if(recordings[_0x530abd[_0x3513('0x40')]]&&transfers['blinds'][_0x530abd[_0x3513('0x40')]]){transfers[_0x3513('0xa')][_0x530abd[_0x3513('0x40')]][_0x3513('0x41')]=!![];}}catch(_0x4eca9f){utils['error'](util[_0x3513('0x3')](_0x3513('0x3b'),_0x530abd[_0x3513('0x5')]),_0x4eca9f);}};