Built motion from commit (unavailable).|2.5.31
[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 _0x7e97=['clone','newexten','[%s][recordings][newexten]','[%s][recordings][newexten]\x20application:%s\x20appdata:%s','application','appdata','toLowerCase','set','startsWith','cdr','split','substring','lastIndexOf','queuecallerjoin','[%s][recordings][queuecallerjoin]','[%s][recordings][queuecallerjoin]\x20queue:%s','queue','util','./utils','info','format','[%s][recordings][writeDB]','accountcode','name','UserId','request','CreateVoiceRecording','newchannel','debug','[%s][recordings][newchannel]','uniqueid','[%s][recordings][newchannel]\x20context:%s\x20exten:%s','context','exten','channel','error','isNil','channelstate','[%s][recordings][newstate]\x20context:%s\x20channel:%s','transfer','[%s][recordings][newstate]\x20linkedid:%s\x20context:%s\x20channel:%s','[%s][recordings][newstate]','varset','variable','mixmonitor_filename','[%s][recordings][varset]','value','.wav49','replace','.WAV','linkedid','monitors','push','hangup','[%s][recordings][hangup]','[%s][recordings][hangup]\x20calleridnum:%s\x20calleridname:%s\x20reason:%s','calleridnum','calleridname','connectedlinenum','connectedlinename','type','outbound','forEach'];(function(_0x29f002,_0x59eac3){var _0x224699=function(_0x1bc579){while(--_0x1bc579){_0x29f002['push'](_0x29f002['shift']());}};_0x224699(++_0x59eac3);}(_0x7e97,0xce));var _0x77e9=function(_0x5b7c6e,_0x32bc51){_0x5b7c6e=_0x5b7c6e-0x0;var _0x4108ac=_0x7e97[_0x5b7c6e];return _0x4108ac;};'use strict';var _=require('lodash');var util=require(_0x77e9('0x0'));var utils=require(_0x77e9('0x1'));var recordings={};function writeDB(_0x23ec7b){utils[_0x77e9('0x2')](util[_0x77e9('0x3')](_0x77e9('0x4'),_0x23ec7b['uniqueid']));if(_0x23ec7b[_0x77e9('0x5')]){utils['getUserByInternal'](_0x23ec7b[_0x77e9('0x5')])['then'](function(_0x24998b){if(_0x24998b){_0x23ec7b['membername']=_0x24998b[_0x77e9('0x6')];_0x23ec7b[_0x77e9('0x7')]=_0x24998b['id'];}utils[_0x77e9('0x8')](_0x77e9('0x9'),_0x23ec7b);});}else{utils[_0x77e9('0x8')](_0x77e9('0x9'),_0x23ec7b);}}exports[_0x77e9('0xa')]=function(_0x54bb5d){try{utils[_0x77e9('0xb')](util[_0x77e9('0x3')](_0x77e9('0xc'),_0x54bb5d['uniqueid']),_0x54bb5d);if(_0x54bb5d[_0x77e9('0xd')]==_0x54bb5d['linkedid']){utils[_0x77e9('0x2')](util[_0x77e9('0x3')](_0x77e9('0xe'),_0x54bb5d[_0x77e9('0xd')],_0x54bb5d[_0x77e9('0xf')],_0x54bb5d[_0x77e9('0x10')]));recordings[_0x54bb5d['uniqueid']]={'uniqueid':_0x54bb5d['uniqueid'],'accountcode':_0x54bb5d[_0x77e9('0x5')],'exten':_0x54bb5d['exten'],'context':_0x54bb5d['context'],'channel':_0x54bb5d[_0x77e9('0x11')],'monitors':[]};}}catch(_0x437075){utils[_0x77e9('0x12')](util[_0x77e9('0x3')](_0x77e9('0xc'),_0x54bb5d[_0x77e9('0xd')]),_0x437075);}};exports['newstate']=function(_0x5897fa){try{utils['debug'](util[_0x77e9('0x3')]('[%s][recordings][newstate]',_0x5897fa[_0x77e9('0xd')]),_0x5897fa);if(!_[_0x77e9('0x13')](recordings[_0x5897fa[_0x77e9('0xd')]])&&_0x5897fa[_0x77e9('0x14')]==0x6){utils[_0x77e9('0x2')](util['format'](_0x77e9('0x15'),_0x5897fa['uniqueid'],_0x5897fa[_0x77e9('0xf')],_0x5897fa[_0x77e9('0x11')]));}else if(!_[_0x77e9('0x13')](recordings[_0x5897fa['linkedid']])&&_0x5897fa['channelstate']==0x6&&_0x5897fa[_0x77e9('0xf')]!=_0x77e9('0x16')){utils[_0x77e9('0x2')](util[_0x77e9('0x3')](_0x77e9('0x17'),_0x5897fa['uniqueid'],_0x5897fa['linkedid'],_0x5897fa[_0x77e9('0xf')],_0x5897fa[_0x77e9('0x11')]));recordings[_0x5897fa['linkedid']]['accountcode']=_0x5897fa[_0x77e9('0x5')];}}catch(_0x4e949b){utils['error'](util[_0x77e9('0x3')](_0x77e9('0x18'),_0x5897fa[_0x77e9('0xd')]),_0x4e949b);}};exports[_0x77e9('0x19')]=function(_0xbe6a4b){try{if(!_[_0x77e9('0x13')](_0xbe6a4b[_0x77e9('0x1a')])&&!_[_0x77e9('0x13')](_0xbe6a4b[_0x77e9('0x1a')][_0x77e9('0x1b')])){utils[_0x77e9('0xb')](util[_0x77e9('0x3')](_0x77e9('0x1c'),_0xbe6a4b['uniqueid']),_0xbe6a4b);utils[_0x77e9('0x2')](util[_0x77e9('0x3')]('[%s][recordings][varset]\x20variable:%s\x20value:%s',_0xbe6a4b['uniqueid'],_0xbe6a4b['variable'],_0xbe6a4b[_0x77e9('0x1d')]));if(_['endsWith'](_0xbe6a4b[_0x77e9('0x1d')],_0x77e9('0x1e'))){_0xbe6a4b[_0x77e9('0x1d')]=_0xbe6a4b[_0x77e9('0x1d')][_0x77e9('0x1f')](_0x77e9('0x1e'),_0x77e9('0x20'));}if(recordings[_0xbe6a4b[_0x77e9('0x21')]]){var _0x51ae0d=_['find'](recordings[_0xbe6a4b[_0x77e9('0x21')]][_0x77e9('0x22')],{'value':_0xbe6a4b[_0x77e9('0x1d')]});if(_[_0x77e9('0x13')](_0x51ae0d)){recordings[_0xbe6a4b[_0x77e9('0x21')]][_0x77e9('0x22')][_0x77e9('0x23')]({'value':_0xbe6a4b[_0x77e9('0x1d')]});}}}}catch(_0x442ca7){utils[_0x77e9('0x12')](util[_0x77e9('0x3')](_0x77e9('0x1c'),_0xbe6a4b[_0x77e9('0xd')]),_0x442ca7);}};exports[_0x77e9('0x24')]=function(_0x2c0222){try{if(!_[_0x77e9('0x13')](recordings[_0x2c0222[_0x77e9('0xd')]])){utils[_0x77e9('0xb')](util[_0x77e9('0x3')](_0x77e9('0x25'),_0x2c0222[_0x77e9('0xd')]),_0x2c0222);utils[_0x77e9('0x2')](util[_0x77e9('0x3')](_0x77e9('0x26'),_0x2c0222[_0x77e9('0xd')],_0x2c0222[_0x77e9('0x27')],_0x2c0222[_0x77e9('0x28')],_0x2c0222['cause-txt']));recordings[_0x2c0222[_0x77e9('0xd')]]['calleridnum']=_0x2c0222['calleridnum'];recordings[_0x2c0222[_0x77e9('0xd')]][_0x77e9('0x28')]=_0x2c0222['calleridname'];recordings[_0x2c0222[_0x77e9('0xd')]][_0x77e9('0x29')]=_0x2c0222[_0x77e9('0x29')];recordings[_0x2c0222['uniqueid']][_0x77e9('0x2a')]=_0x2c0222[_0x77e9('0x2a')];if(recordings[_0x2c0222[_0x77e9('0xd')]][_0x77e9('0x2b')]==_0x77e9('0x2c')&&recordings[_0x2c0222['uniqueid']][_0x77e9('0x5')]){recordings[_0x2c0222[_0x77e9('0xd')]]['connectedlinenum']=recordings[_0x2c0222[_0x77e9('0xd')]][_0x77e9('0x5')];recordings[_0x2c0222[_0x77e9('0xd')]][_0x77e9('0x2a')]='';}recordings[_0x2c0222['uniqueid']][_0x77e9('0x22')][_0x77e9('0x2d')](function(_0x5c77ee){var _0x1a7105=_[_0x77e9('0x2e')](recordings[_0x2c0222[_0x77e9('0xd')]]);_0x1a7105[_0x77e9('0x1d')]=_0x5c77ee[_0x77e9('0x1d')];writeDB(_0x1a7105);});delete recordings[_0x2c0222[_0x77e9('0xd')]];}}catch(_0x2d2356){utils[_0x77e9('0x12')](util[_0x77e9('0x3')]('[%s][recordings][hangup]',_0x2c0222[_0x77e9('0xd')]),_0x2d2356);}};exports[_0x77e9('0x2f')]=function(_0x57a5cc){try{if(!_[_0x77e9('0x13')](recordings[_0x57a5cc['uniqueid']])){utils[_0x77e9('0xb')](util[_0x77e9('0x3')](_0x77e9('0x30'),_0x57a5cc[_0x77e9('0xd')]),_0x57a5cc);utils[_0x77e9('0x2')](util[_0x77e9('0x3')](_0x77e9('0x31'),_0x57a5cc[_0x77e9('0xd')],_0x57a5cc[_0x77e9('0x32')],_0x57a5cc[_0x77e9('0x33')]));if(_0x57a5cc[_0x77e9('0x32')][_0x77e9('0x34')]()==_0x77e9('0x35')&&_[_0x77e9('0x36')](_0x57a5cc[_0x77e9('0x33')][_0x77e9('0x34')](),_0x77e9('0x37'))){var _0x4aab9d=_0x57a5cc['appdata'][_0x77e9('0x38')]('=');var _0x157749=_0x4aab9d[0x0][_0x77e9('0x39')](_0x4aab9d[0x0][_0x77e9('0x3a')]('(')+0x1,_0x4aab9d[0x0][_0x77e9('0x3a')](')'));var _0x15eb54=_0x4aab9d[0x1];recordings[_0x57a5cc[_0x77e9('0xd')]][_0x157749]=_0x15eb54;}}}catch(_0xd5e067){utils['error'](util[_0x77e9('0x3')]('[%s][recordings][newexten]',_0x57a5cc[_0x77e9('0xd')]),_0xd5e067);}};exports[_0x77e9('0x3b')]=function(_0x276346){try{if(!_[_0x77e9('0x13')](recordings[_0x276346['uniqueid']])){utils[_0x77e9('0xb')](util[_0x77e9('0x3')](_0x77e9('0x3c'),_0x276346[_0x77e9('0xd')]),_0x276346);utils[_0x77e9('0x2')](util[_0x77e9('0x3')](_0x77e9('0x3d'),_0x276346[_0x77e9('0xd')],_0x276346[_0x77e9('0x3e')]));recordings[_0x276346['uniqueid']][_0x77e9('0x3e')]=_0x276346[_0x77e9('0x3e')];}}catch(_0x4d1337){utils[_0x77e9('0x12')](util[_0x77e9('0x3')](_0x77e9('0x3c'),_0x276346[_0x77e9('0xd')]),_0x4d1337);}};