dfbadc5bb1c9736ca52b9aba978bbee9cc611042
[motion2.git] / server / api / voiceRecording / voiceRecording.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 _0x4334=['ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','status','end','json','offset','limit','set','Content-Range','apply','reject','update','destroy','sendStatus','name','map','VoiceRecording','rawAttributes','fieldName','type','model','differenceBy','format','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','count','then','includeAll','include','rows','catch','keys','length','options','find','create','body','params','describe','download','../../components/encryptor','uniqueid','value','existsSync','decryptFile','secrets','recording','Sequelize','ValidationError','filename','extname','unlink','message','send','Not\x20found','downloads','sequelize','MD5','col','token','$and','push','%s.cypher','VoiceRecording\x20not\x20found','Entity\x20not\x20found','cancellazione\x20fisica\x20documento\x20%s','isNil','info','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','listBuckets','createBucket','upload','TranscribeService','startTranscriptionJob','[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s','basename','readFileSync','[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)','Location','bucket','Bucket','location','[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request','[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created','TranscriptionJob','TranscriptionJobName','transcribeName','transcribeStatus','TranscriptionJobStatus','runTranscribe','findOne','Setting','transcribe','transcribeAccountId','transcribeRegion','language','sentiment','sentimentRegion','Cloud\x20Provider\x20not\x20available','data2','Cloud\x20Provider\x20not\x20configured','data1','Buckets','Name','NEW','[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested','IN_PROGRESS','tempSentiment','runSentiment','updateAttributes','writeFile','downloadTranscribe','fileText','root','/server/files/transcribes/transcribe_','.txt','html-pdf','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','aws-sdk','uuid/v4'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x4334,0x88));var _0x4433=function(_0x3ae885,_0x30a66c){_0x3ae885=_0x3ae885-0x0;var _0x47571e=_0x4334[_0x3ae885];return _0x47571e;};'use strict';var pdf=require(_0x4433('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x4433('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x4433('0x2'));var rp=require(_0x4433('0x3'));var moment=require(_0x4433('0x4'));var BPromise=require(_0x4433('0x5'));var Mustache=require('mustache');var util=require(_0x4433('0x6'));var path=require(_0x4433('0x7'));var sox=require('sox');var csv=require(_0x4433('0x8'));var ejs=require(_0x4433('0x9'));var fs=require('fs');var _=require(_0x4433('0xa'));var squel=require(_0x4433('0xb'));var crypto=require(_0x4433('0xc'));var jsforce=require(_0x4433('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x4433('0x8'));var querystring=require(_0x4433('0xe'));var Papa=require(_0x4433('0xf'));var AWS=require(_0x4433('0x10'));var uuidv4=require(_0x4433('0x11'));var Redis=require(_0x4433('0x12'));var authService=require(_0x4433('0x13'));var qs=require(_0x4433('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4433('0x15'));var logger=require(_0x4433('0x16'))(_0x4433('0x17'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x4433('0x18'));var db=require(_0x4433('0x19'))['db'];function respondWithStatusCode(_0x5504c0,_0x1a0a79){_0x1a0a79=_0x1a0a79||0xcc;return function(_0x5b74dc){if(_0x5b74dc){return _0x5504c0['sendStatus'](_0x1a0a79);}return _0x5504c0[_0x4433('0x1a')](_0x1a0a79)[_0x4433('0x1b')]();};}function respondWithResult(_0x169506,_0x2dff87){_0x2dff87=_0x2dff87||0xc8;return function(_0x4c36f9){if(_0x4c36f9){return _0x169506[_0x4433('0x1a')](_0x2dff87)[_0x4433('0x1c')](_0x4c36f9);}};}function respondWithFilteredResult(_0x166da8,_0x36c10b){return function(_0x5391a7){if(_0x5391a7){var _0xaa9b1b=_0x5391a7['count'],_0xc70f1d=_0x36c10b['offset'],_0xe061d0=_0x36c10b[_0x4433('0x1d')]+_0x36c10b[_0x4433('0x1e')],_0x403928;if(_0xe061d0>=_0xaa9b1b){_0xe061d0=_0xaa9b1b;_0x403928=0xc8;}else{_0x403928=0xce;}_0x166da8[_0x4433('0x1a')](_0x403928);return _0x166da8[_0x4433('0x1f')](_0x4433('0x20'),_0xc70f1d+'-'+_0xe061d0+'/'+_0xaa9b1b)[_0x4433('0x1c')](_0x5391a7);}return null;};}function patchUpdates(_0x242b53){return function(_0x5da19e){try{jsonpatch[_0x4433('0x21')](_0x5da19e,_0x242b53,!![]);}catch(_0x31c695){return BPromise[_0x4433('0x22')](_0x31c695);}return _0x5da19e['save']();};}function saveUpdates(_0x3ecbb9,_0x5d5c71){return function(_0x3f43cf){if(_0x3f43cf){return _0x3f43cf[_0x4433('0x23')](_0x3ecbb9)['then'](function(_0x371ee9){return _0x371ee9;});}return null;};}function removeEntity(_0x5ab86a,_0x2ec11e){return function(_0x1f33e4){if(_0x1f33e4){return _0x1f33e4[_0x4433('0x24')]()['then'](function(){_0x5ab86a[_0x4433('0x1a')](0xcc)[_0x4433('0x1b')]();});}};}function handleEntityNotFound(_0x26e143,_0x46f751){return function(_0x32d6fe){if(!_0x32d6fe){_0x26e143[_0x4433('0x25')](0x194);}return _0x32d6fe;};}function handleError(_0x2fdade,_0x52724a){_0x52724a=_0x52724a||0x1f4;return function(_0x4ad75f){logger['error'](_0x4ad75f['stack']);if(_0x4ad75f['name']){delete _0x4ad75f[_0x4433('0x26')];}_0x2fdade[_0x4433('0x1a')](_0x52724a)['send'](_0x4ad75f);};}exports['index']=function(_0x31a006,_0xdb3ae8){var _0x4a922a={},_0x367dda={},_0x215da6={'count':0x0,'rows':[]};var _0x575bf9=_[_0x4433('0x27')](db[_0x4433('0x28')][_0x4433('0x29')],function(_0x4f8d7d){return{'name':_0x4f8d7d[_0x4433('0x2a')],'type':_0x4f8d7d[_0x4433('0x2b')]['key']};});_0x367dda[_0x4433('0x2c')]=_[_0x4433('0x2d')](_[_0x4433('0x27')](_0x575bf9,_0x4433('0x26')),[_0x4433('0x2e')]);_0x367dda[_0x4433('0x2f')]=_['keys'](_0x31a006[_0x4433('0x2f')]);_0x367dda[_0x4433('0x30')]=_[_0x4433('0x31')](_0x367dda[_0x4433('0x2c')],_0x367dda['query']);_0x4a922a[_0x4433('0x32')]=_[_0x4433('0x31')](_0x367dda[_0x4433('0x2c')],qs[_0x4433('0x33')](_0x31a006[_0x4433('0x2f')][_0x4433('0x33')]));_0x4a922a[_0x4433('0x32')]=_0x4a922a[_0x4433('0x32')]['length']?_0x4a922a[_0x4433('0x32')]:_0x367dda[_0x4433('0x2c')];if(!_0x31a006['query'][_0x4433('0x34')](_0x4433('0x35'))){_0x4a922a[_0x4433('0x1e')]=qs[_0x4433('0x1e')](_0x31a006[_0x4433('0x2f')][_0x4433('0x1e')]);_0x4a922a['offset']=qs[_0x4433('0x1d')](_0x31a006['query'][_0x4433('0x1d')]);}_0x4a922a['order']=qs['sort'](_0x31a006['query'][_0x4433('0x36')]);_0x4a922a[_0x4433('0x37')]=qs[_0x4433('0x30')](_[_0x4433('0x38')](_0x31a006[_0x4433('0x2f')],_0x367dda[_0x4433('0x30')]),_0x575bf9);if(_0x31a006[_0x4433('0x2f')][_0x4433('0x39')]){_0x4a922a[_0x4433('0x37')]=_[_0x4433('0x3a')](_0x4a922a['where'],{'$or':_[_0x4433('0x27')](_0x575bf9,function(_0x639c6){if(_0x639c6['type']!==_0x4433('0x3b')){var _0x391803={};_0x391803[_0x639c6[_0x4433('0x26')]]={'$like':'%'+_0x31a006[_0x4433('0x2f')][_0x4433('0x39')]+'%'};return _0x391803;}})});}_0x4a922a=_[_0x4433('0x3a')]({},_0x4a922a,_0x31a006['options']);var _0x68c297={'where':_0x4a922a[_0x4433('0x37')]};return db[_0x4433('0x28')][_0x4433('0x3c')](_0x68c297)[_0x4433('0x3d')](function(_0x17e99d){_0x215da6['count']=_0x17e99d;if(_0x31a006['query'][_0x4433('0x3e')]){_0x4a922a[_0x4433('0x3f')]=[{'all':!![]}];}return db[_0x4433('0x28')]['findAll'](_0x4a922a);})[_0x4433('0x3d')](function(_0x4bc39d){_0x215da6[_0x4433('0x40')]=_0x4bc39d;return _0x215da6;})['then'](respondWithFilteredResult(_0xdb3ae8,_0x4a922a))[_0x4433('0x41')](handleError(_0xdb3ae8,null));};exports['show']=function(_0x5a9c6e,_0x52496e){var _0x5a9f7c={'raw':![],'where':{'id':_0x5a9c6e['params']['id']}},_0x1f4e22={};_0x1f4e22['model']=_['keys'](db[_0x4433('0x28')][_0x4433('0x29')]);_0x1f4e22[_0x4433('0x2f')]=_[_0x4433('0x42')](_0x5a9c6e[_0x4433('0x2f')]);_0x1f4e22['filters']=_[_0x4433('0x31')](_0x1f4e22[_0x4433('0x2c')],_0x1f4e22['query']);_0x5a9f7c[_0x4433('0x32')]=_['intersection'](_0x1f4e22[_0x4433('0x2c')],qs[_0x4433('0x33')](_0x5a9c6e[_0x4433('0x2f')]['fields']));_0x5a9f7c[_0x4433('0x32')]=_0x5a9f7c[_0x4433('0x32')][_0x4433('0x43')]?_0x5a9f7c[_0x4433('0x32')]:_0x1f4e22[_0x4433('0x2c')];if(_0x5a9c6e[_0x4433('0x2f')]['includeAll']){_0x5a9f7c[_0x4433('0x3f')]=[{'all':!![]}];}_0x5a9f7c=_[_0x4433('0x3a')]({},_0x5a9f7c,_0x5a9c6e[_0x4433('0x44')]);return db[_0x4433('0x28')][_0x4433('0x45')](_0x5a9f7c)[_0x4433('0x3d')](handleEntityNotFound(_0x52496e,null))[_0x4433('0x3d')](respondWithResult(_0x52496e,null))[_0x4433('0x41')](handleError(_0x52496e,null));};exports['create']=function(_0x4779a3,_0x442238){return db[_0x4433('0x28')][_0x4433('0x46')](_0x4779a3['body'],{})[_0x4433('0x3d')](respondWithResult(_0x442238,0xc9))['catch'](handleError(_0x442238,null));};exports[_0x4433('0x23')]=function(_0x5cfc44,_0x5d1368){if(_0x5cfc44[_0x4433('0x47')]['id']){delete _0x5cfc44[_0x4433('0x47')]['id'];}return db['VoiceRecording'][_0x4433('0x45')]({'where':{'id':_0x5cfc44[_0x4433('0x48')]['id']}})['then'](handleEntityNotFound(_0x5d1368,null))[_0x4433('0x3d')](saveUpdates(_0x5cfc44[_0x4433('0x47')],null))[_0x4433('0x3d')](respondWithResult(_0x5d1368,null))[_0x4433('0x41')](handleError(_0x5d1368,null));};exports[_0x4433('0x49')]=function(_0x44d284,_0x4e31de){return db[_0x4433('0x28')][_0x4433('0x49')]()['then'](respondWithResult(_0x4e31de,null))['catch'](handleError(_0x4e31de,null));};exports[_0x4433('0x4a')]=function(_0x44816f,_0x14d02e,_0x21939b){var _0x253735=require(_0x4433('0x4b'));var _0x2f8c17=![];var _0x24a9a3={};if(_0x44816f[_0x4433('0x2f')][_0x4433('0x2b')]&&_0x44816f[_0x4433('0x2f')][_0x4433('0x2b')]===_0x4433('0x4c')){_0x24a9a3[_0x4433('0x4c')]=_0x44816f[_0x4433('0x48')]['id'];}else{_0x24a9a3['id']=_0x44816f['params']['id'];}return db[_0x4433('0x28')][_0x4433('0x45')]({'where':_0x24a9a3,'attributes':['id',_0x4433('0x4d')],'raw':!![]})['then'](handleEntityNotFound(_0x14d02e,null))['then'](function(_0x331863){if(_0x331863){var _0x1e051a=_0x331863[_0x4433('0x4d')];var _0x348c1f=util[_0x4433('0x2e')]('%s.cypher',_0x1e051a);if(fs[_0x4433('0x4e')](_0x348c1f)){_0x2f8c17=!![];return _0x253735[_0x4433('0x4f')](_0x348c1f,_0x1e051a,config[_0x4433('0x50')][_0x4433('0x51')])[_0x4433('0x3d')](function(){return _0x331863;});}return _0x331863;}})[_0x4433('0x3d')](function(_0x2d772d){if(_0x2d772d){var _0x13ffc5=_0x2d772d[_0x4433('0x4d')];if(!fs['existsSync'](_0x13ffc5)){throw new db[(_0x4433('0x52'))][(_0x4433('0x53'))]('VoiceRecording\x20not\x20found');}if(_0x2d772d['filename']){return _0x14d02e['download'](_0x13ffc5,_0x2d772d[_0x4433('0x54')]+path[_0x4433('0x55')](_0x13ffc5),function(){if(_0x2f8c17){fs[_0x4433('0x56')](_0x13ffc5);}});}else{return _0x14d02e['download'](_0x13ffc5,function(_0x17f427){if(_0x2f8c17){fs[_0x4433('0x56')](_0x13ffc5);}});}}})[_0x4433('0x41')](function(_0x334c8f){if(_0x334c8f[_0x4433('0x57')]==='VoiceRecording\x20not\x20found'){_0x14d02e[_0x4433('0x1a')](0x194)[_0x4433('0x58')](_0x4433('0x59'));}else{return handleError(_0x14d02e,null);}});};exports[_0x4433('0x5a')]=function(_0x4bcbaa,_0x172ea8,_0x4e0658){var _0x4f436f=require(_0x4433('0x4b'));var _0x3e40c6=![];var _0x10aa4a={'$and':[db[_0x4433('0x5b')][_0x4433('0x37')](db['sequelize']['fn'](_0x4433('0x5c'),db['sequelize'][_0x4433('0x5d')](_0x4433('0x4c'))),_0x4bcbaa['query'][_0x4433('0x5e')])]};if(_0x4bcbaa['query'][_0x4433('0x2b')]&&_0x4bcbaa[_0x4433('0x2f')][_0x4433('0x2b')]==='uniqueid'){_0x10aa4a[_0x4433('0x5f')]['push']({'uniqueid':_0x4bcbaa[_0x4433('0x48')]['id']});}else{_0x10aa4a['$and'][_0x4433('0x60')]({'id':_0x4bcbaa[_0x4433('0x48')]['id']});}return db[_0x4433('0x28')][_0x4433('0x45')]({'where':_0x10aa4a,'attributes':['id',_0x4433('0x4d')],'raw':!![]})[_0x4433('0x3d')](handleEntityNotFound(_0x172ea8,null))[_0x4433('0x3d')](function(_0x202ab9){if(_0x202ab9){var _0x4ea1fa=util[_0x4433('0x2e')](_0x4433('0x61'),_0x202ab9[_0x4433('0x4d')]);if(fs['existsSync'](_0x4ea1fa)){_0x3e40c6=!![];return _0x4f436f[_0x4433('0x4f')](_0x4ea1fa,_0x202ab9[_0x4433('0x4d')],config[_0x4433('0x50')][_0x4433('0x51')])[_0x4433('0x3d')](function(){return _0x202ab9;});}return _0x202ab9;}})['then'](function(_0x34e7c7){if(_0x34e7c7){if(!fs['existsSync'](_0x34e7c7[_0x4433('0x4d')])){throw new db[(_0x4433('0x52'))][(_0x4433('0x53'))](_0x4433('0x62'));}if(_0x34e7c7['filename']){return _0x172ea8[_0x4433('0x4a')](_0x34e7c7[_0x4433('0x4d')],_0x34e7c7['filename']+path[_0x4433('0x55')](_0x34e7c7[_0x4433('0x4d')]),function(){if(_0x3e40c6){fs['unlink'](_0x34e7c7[_0x4433('0x4d')]);}});}else{return _0x172ea8[_0x4433('0x4a')](_0x34e7c7[_0x4433('0x4d')],function(_0x1f51fc){if(_0x3e40c6){fs['unlink'](_0x34e7c7['value']);}});}}})['catch'](handleError(_0x172ea8,null));};exports['destroy']=function(_0x4d7eb2,_0x4e143d){return db['VoiceRecording']['find']({'where':{'id':_0x4d7eb2['params']['id']}})[_0x4433('0x3d')](function(_0x568f5e){if(!_0x568f5e)throw new ReferenceError(_0x4433('0x63'));return _0x568f5e;})['then'](function(_0x22d94a){var _0x3d7377=_0x22d94a[_0x4433('0x4d')];logger['info'](_0x4433('0x64'),_0x3d7377);if(!_[_0x4433('0x65')](_0x22d94a[_0x4433('0x4d')])&&fs['existsSync'](_0x3d7377)){logger[_0x4433('0x66')](_0x4433('0x67')+_0x3d7377+_0x4433('0x68'));fs[_0x4433('0x69')](_0x3d7377);}_0x3d7377=_0x3d7377+_0x4433('0x6a');if(!_[_0x4433('0x65')](_0x22d94a[_0x4433('0x4d')])&&fs[_0x4433('0x4e')](_0x3d7377)){logger[_0x4433('0x66')](_0x4433('0x67')+_0x3d7377+_0x4433('0x68'));fs['unlinkSync'](_0x3d7377);}return _0x22d94a;})['then'](function(_0x19c909){if(!_0x19c909)throw new InternalError();return _0x19c909[_0x4433('0x24')]();})[_0x4433('0x3d')](function(){_0x4e143d['status'](0xcc)['end']();})[_0x4433('0x41')](handleError(_0x4e143d,null));};function getBucketslist(_0xcb540c,_0x21aae7,_0x378ad8){return new Promise(function(_0xde377e,_0xaf1467){var _0x360874=new AWS['S3']({'accessKeyId':_0x21aae7,'secretAccessKey':_0xcb540c,'region':_0x378ad8});_0x360874[_0x4433('0x6b')]({},function(_0x252c62,_0xf4d255){if(_0x252c62){return _0xaf1467(_0x252c62);}else{return _0xde377e(_0xf4d255);}});});}function createBucket(_0x4d3fa6,_0x3df669,_0x844dc0,_0x29507a){return new Promise(function(_0x1098bc,_0x567b03){var _0x118bdb=new AWS['S3']({'accessKeyId':_0x3df669,'secretAccessKey':_0x4d3fa6,'region':_0x844dc0});_0x118bdb[_0x4433('0x6c')]({'Bucket':_0x29507a},function(_0x1b5f48,_0x47f5f4){if(_0x1b5f48){return _0x567b03(_0x1b5f48);}else{return _0x1098bc(_0x47f5f4);}});});}function uploadFile(_0x5e1bff,_0x10cc35,_0x516a2e,_0x21f6dd,_0x3038d1,_0x680d5d){return new Promise(function(_0x3a3c64,_0x2e1606){var _0x4a3b5a=new AWS['S3']({'accessKeyId':_0x10cc35,'secretAccessKey':_0x5e1bff,'region':_0x516a2e});_0x4a3b5a[_0x4433('0x6d')]({'Bucket':_0x21f6dd,'Key':_0x3038d1,'Body':_0x680d5d},function(_0x5a6e6e,_0xc50e14){if(_0x5a6e6e){return _0x2e1606(_0x5a6e6e);}else{return _0x3a3c64(_0xc50e14);}});});}function startTranscribe(_0x33da92,_0xf375cf,_0x449098,_0x1f657c,_0x44911b,_0x4a2133){return new Promise(function(_0x3cd489,_0x967064){var _0x572ed9=new AWS[(_0x4433('0x6e'))]({'accessKeyId':_0xf375cf,'secretAccessKey':_0x33da92,'region':_0x449098});_0x572ed9[_0x4433('0x6f')]({'TranscriptionJobName':_0x1f657c,'LanguageCode':_0x44911b,'Media':{'MediaFileUri':_0x4a2133}},function(_0x2b0ba0,_0x34df06){if(_0x2b0ba0){return _0x967064(_0x2b0ba0);}else{return _0x3cd489(_0x34df06);}});});}function transcribe(_0x4e3c9d,_0x535f1d,_0x4e24ae,_0xd4f10f,_0xc55038,_0x53fb0a,_0x5afd1f){return new Promise(function(_0x24e251,_0x1fde29){var _0x25ebdb={};logger[_0x4433('0x66')](util['format'](_0x4433('0x70'),_0x4e3c9d,_0xc55038));return uploadFile(_0x535f1d,_0x4e24ae,_0xd4f10f,_0xc55038,path[_0x4433('0x71')](_0x53fb0a),fs[_0x4433('0x72')](_0x53fb0a))[_0x4433('0x3d')](function(_0x337954){logger[_0x4433('0x66')](util[_0x4433('0x2e')](_0x4433('0x73'),_0x4e3c9d,_0xc55038,_0x337954[_0x4433('0x74')]));_0x25ebdb[_0x4433('0x75')]=_0x337954[_0x4433('0x76')];_0x25ebdb[_0x4433('0x77')]=_0x337954[_0x4433('0x74')];logger[_0x4433('0x66')](util['format'](_0x4433('0x78'),_0x4e3c9d));return startTranscribe(_0x535f1d,_0x4e24ae,_0xd4f10f,uuidv4(),_0x5afd1f,_0x337954[_0x4433('0x74')]);})[_0x4433('0x3d')](function(_0xe64345){logger[_0x4433('0x66')](util[_0x4433('0x2e')](_0x4433('0x79'),_0x4e3c9d,_0xe64345[_0x4433('0x7a')][_0x4433('0x7b')]));_0x25ebdb[_0x4433('0x7c')]=_0xe64345[_0x4433('0x7a')][_0x4433('0x7b')];_0x25ebdb[_0x4433('0x7d')]=_0xe64345[_0x4433('0x7a')][_0x4433('0x7e')];return _0x24e251(_0x25ebdb);})['catch'](function(_0x91e041){return _0x1fde29(_0x91e041);});});}exports[_0x4433('0x7f')]=function(_0x3a2f69,_0x36d872,_0x224486){var _0x2e53ae;var _0x16b432;var _0x48c35b;var _0x43b25f=require(_0x4433('0x4b'));return db[_0x4433('0x28')][_0x4433('0x80')]({'where':{'id':_0x3a2f69[_0x4433('0x48')]['id']}})[_0x4433('0x3d')](function(_0x210326){if(_0x210326){var _0x20e94f=util[_0x4433('0x2e')](_0x4433('0x61'),_0x210326[_0x4433('0x4d')]);if(fs[_0x4433('0x4e')](_0x20e94f)){cypher=!![];return _0x43b25f[_0x4433('0x4f')](_0x20e94f,_0x210326[_0x4433('0x4d')],config[_0x4433('0x50')][_0x4433('0x51')])[_0x4433('0x3d')](function(){return _0x210326;});}return _0x210326;}})['then'](function(_0x78b3af){if(!_0x78b3af){throw new db[(_0x4433('0x52'))][(_0x4433('0x53'))]('Voice\x20Recording\x20not\x20found');}_0x16b432=_0x78b3af;return db[_0x4433('0x81')][_0x4433('0x80')]({'where':{'id':0x1}});})['then'](handleEntityNotFound(_0x36d872,null))['then'](function(_0x31c1c9){if(_0x31c1c9){_0x2e53ae=_0x31c1c9;if(!_0x2e53ae[_0x4433('0x82')]||!_0x2e53ae[_0x4433('0x83')]||!_0x2e53ae[_0x4433('0x84')]||!_0x2e53ae[_0x4433('0x85')]||!_0x2e53ae[_0x4433('0x75')]){throw new db[(_0x4433('0x52'))][(_0x4433('0x53'))]('Transcribe\x20not\x20configured');}if(_0x3a2f69['body']['runSentiment']&&(!_0x2e53ae[_0x4433('0x86')]||!_0x2e53ae['sentimentAccountId']||!_0x2e53ae[_0x4433('0x87')]||!_0x2e53ae[_0x4433('0x85')]||!_0x2e53ae['bucket'])){throw new db[(_0x4433('0x52'))][(_0x4433('0x53'))]('Sentiment\x20Analysis\x20not\x20configured');}return db['CloudProvider'][_0x4433('0x80')]({'where':{'id':_0x2e53ae[_0x4433('0x83')]}});}})[_0x4433('0x3d')](function(_0xdc500e){if(!_0xdc500e){throw new db[(_0x4433('0x52'))][(_0x4433('0x53'))](_0x4433('0x88'));}if(!_0xdc500e['data1']||!_0xdc500e[_0x4433('0x89')]){throw new db[(_0x4433('0x52'))][(_0x4433('0x53'))](_0x4433('0x8a'));}_0x48c35b=_0xdc500e;return getBucketslist(_0x48c35b[_0x4433('0x8b')],_0x48c35b[_0x4433('0x89')],_0x2e53ae[_0x4433('0x84')]);})[_0x4433('0x3d')](function(_0x3e225d){if(_0x3e225d&&_0x3e225d[_0x4433('0x8c')]){var _0x5deae6=_['find'](_0x3e225d[_0x4433('0x8c')],function(_0x3f36e9){return _0x3f36e9[_0x4433('0x8d')]===_0x2e53ae[_0x4433('0x75')];});if(!_0x5deae6){logger[_0x4433('0x66')](util['format']('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available',_0x3a2f69[_0x4433('0x48')]['id'],_0x2e53ae[_0x4433('0x75')]));return createBucket(_0x48c35b[_0x4433('0x8b')],_0x48c35b[_0x4433('0x89')],_0x2e53ae[_0x4433('0x84')],_0x2e53ae[_0x4433('0x75')]);}logger[_0x4433('0x66')](util[_0x4433('0x2e')]('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available',_0x3a2f69[_0x4433('0x48')]['id'],_0x2e53ae[_0x4433('0x75')]));return;}})['then'](function(_0x501b1c){if(_0x16b432[_0x4433('0x7d')]===_0x4433('0x8e')){return transcribe(_0x3a2f69[_0x4433('0x48')]['id'],_0x48c35b[_0x4433('0x8b')],_0x48c35b[_0x4433('0x89')],_0x2e53ae[_0x4433('0x84')],_0x2e53ae[_0x4433('0x75')],_0x16b432['value'],_0x2e53ae[_0x4433('0x85')]);}else{logger[_0x4433('0x66')](util[_0x4433('0x2e')](_0x4433('0x8f'),_0x3a2f69[_0x4433('0x48')]['id']));return{'transcribeStatus':_0x4433('0x90')};}})[_0x4433('0x3d')](function(_0x2c9800){if(_0x2c9800){_0x2c9800[_0x4433('0x91')]=_0x3a2f69[_0x4433('0x47')][_0x4433('0x92')];return _0x16b432[_0x4433('0x93')](_0x2c9800);}})[_0x4433('0x3d')](respondWithResult(_0x36d872,null))[_0x4433('0x41')](handleError(_0x36d872,null));};function writeFile(_0x4016b1,_0x55c066){return new Promise(function(_0x228d3a,_0x23a479){fs[_0x4433('0x94')](_0x55c066,_0x4016b1,function(_0x3f19fa,_0xfd23c7){if(_0x3f19fa){return _0x23a479(_0x3f19fa);}else{return _0x228d3a(_0xfd23c7);}});});}exports[_0x4433('0x95')]=function(_0x4eaad6,_0x11aea9,_0x164f58){return db['VoiceRecording']['findOne']({'where':{'id':_0x4eaad6[_0x4433('0x48')]['id']}})[_0x4433('0x3d')](handleEntityNotFound(_0x11aea9))['then'](function(_0x9b21ff){if(_0x9b21ff&&_0x9b21ff[_0x4433('0x96')]){var _0x5f028d=_0x9b21ff[_0x4433('0x96')];var _0x54bf6c=config[_0x4433('0x97')]+_0x4433('0x98')+_0x9b21ff['id']+_0x4433('0x99');if(fs['existsSync'](_0x54bf6c)){return _0x54bf6c;}return writeFile(_0x5f028d,_0x54bf6c)['then'](function(){return _0x54bf6c;});}else{throw new db[(_0x4433('0x52'))][(_0x4433('0x53'))]('Transcript\x20not\x20available');}})[_0x4433('0x3d')](function(_0x57c019){return _0x11aea9[_0x4433('0x4a')](_0x57c019);})[_0x4433('0x41')](handleError(_0x11aea9));};