Built motion from commit a61a4a20.|2.5.46
[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 _0xf3b9=['../../components/encryptor','uniqueid','value','%s.cypher','existsSync','secrets','recording','Sequelize','ValidationError','VoiceRecording\x20not\x20found','filename','extname','unlink','message','Not\x20found','downloads','sequelize','MD5','col','token','$and','push','decryptFile','destroy','isNil','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','listBuckets','upload','TranscribeService','startTranscriptionJob','[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s','basename','readFileSync','Location','Bucket','location','[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request','[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created','TranscriptionJob','TranscriptionJobName','transcribeName','transcribeStatus','TranscriptionJobStatus','findOne','Voice\x20Recording\x20not\x20found','Setting','transcribe','transcribeAccountId','language','bucket','Transcribe\x20not\x20configured','runSentiment','sentiment','sentimentAccountId','sentimentRegion','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','Cloud\x20Provider\x20not\x20available','data1','data2','Cloud\x20Provider\x20not\x20configured','transcribeRegion','Buckets','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','NEW','IN_PROGRESS','tempSentiment','downloadTranscribe','fileText','root','/server/files/transcribes/transcribe_','.txt','Transcript\x20not\x20available','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','aws-sdk','uuid/v4','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','end','offset','undefined','limit','count','status','Content-Range','json','apply','reject','save','update','then','error','stack','name','send','index','map','VoiceRecording','rawAttributes','type','key','model','differenceBy','format','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','sort','where','pick','filter','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','describe','download'];(function(_0x3c8533,_0x2517ef){var _0x3305a7=function(_0x1d4842){while(--_0x1d4842){_0x3c8533['push'](_0x3c8533['shift']());}};_0x3305a7(++_0x2517ef);}(_0xf3b9,0x190));var _0x9f3b=function(_0x13f83f,_0x44e4b6){_0x13f83f=_0x13f83f-0x0;var _0x5648f5=_0xf3b9[_0x13f83f];return _0x5648f5;};'use strict';var emlformat=require(_0x9f3b('0x0'));var rimraf=require(_0x9f3b('0x1'));var zipdir=require(_0x9f3b('0x2'));var jsonpatch=require(_0x9f3b('0x3'));var rp=require(_0x9f3b('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x9f3b('0x5'));var util=require(_0x9f3b('0x6'));var path=require(_0x9f3b('0x7'));var sox=require(_0x9f3b('0x8'));var csv=require(_0x9f3b('0x9'));var ejs=require(_0x9f3b('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x9f3b('0xb'));var squel=require(_0x9f3b('0xc'));var crypto=require(_0x9f3b('0xd'));var jsforce=require(_0x9f3b('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x9f3b('0x9'));var querystring=require(_0x9f3b('0xf'));var Papa=require(_0x9f3b('0x10'));var AWS=require(_0x9f3b('0x11'));var uuidv4=require(_0x9f3b('0x12'));var Redis=require(_0x9f3b('0x13'));var authService=require(_0x9f3b('0x14'));var qs=require(_0x9f3b('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9f3b('0x16'));var logger=require(_0x9f3b('0x17'))(_0x9f3b('0x18'));var utils=require(_0x9f3b('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0x9f3b('0x1a'));var db=require(_0x9f3b('0x1b'))['db'];function respondWithStatusCode(_0x51dbe3,_0x3f1009){_0x3f1009=_0x3f1009||0xcc;return function(_0x414e13){if(_0x414e13){return _0x51dbe3['sendStatus'](_0x3f1009);}return _0x51dbe3['status'](_0x3f1009)[_0x9f3b('0x1c')]();};}function respondWithResult(_0x4ef862,_0x5c4e4f){_0x5c4e4f=_0x5c4e4f||0xc8;return function(_0x4e5274){if(_0x4e5274){return _0x4ef862['status'](_0x5c4e4f)['json'](_0x4e5274);}};}function respondWithFilteredResult(_0x11fa81,_0x58dba9){return function(_0x84e11f){if(_0x84e11f){var _0x2c9bcb=typeof _0x58dba9[_0x9f3b('0x1d')]===_0x9f3b('0x1e')&&typeof _0x58dba9[_0x9f3b('0x1f')]===_0x9f3b('0x1e');var _0x2d609f=_0x84e11f[_0x9f3b('0x20')];var _0x4c5ad6=_0x2c9bcb?0x0:_0x58dba9[_0x9f3b('0x1d')];var _0x5014a8=_0x2c9bcb?_0x84e11f[_0x9f3b('0x20')]:_0x58dba9[_0x9f3b('0x1d')]+_0x58dba9[_0x9f3b('0x1f')];var _0x485a7c;if(_0x5014a8>=_0x2d609f){_0x5014a8=_0x2d609f;_0x485a7c=0xc8;}else{_0x485a7c=0xce;}_0x11fa81[_0x9f3b('0x21')](_0x485a7c);return _0x11fa81['set'](_0x9f3b('0x22'),_0x4c5ad6+'-'+_0x5014a8+'/'+_0x2d609f)[_0x9f3b('0x23')](_0x84e11f);}return null;};}function patchUpdates(_0x553b41){return function(_0x38cd73){try{jsonpatch[_0x9f3b('0x24')](_0x38cd73,_0x553b41,!![]);}catch(_0x3e646d){return BPromise[_0x9f3b('0x25')](_0x3e646d);}return _0x38cd73[_0x9f3b('0x26')]();};}function saveUpdates(_0x12b7ff,_0x2e61e1){return function(_0x2a97c7){if(_0x2a97c7){return _0x2a97c7[_0x9f3b('0x27')](_0x12b7ff)[_0x9f3b('0x28')](function(_0x4448d1){return _0x4448d1;});}return null;};}function removeEntity(_0x4cddd1,_0x3cc08b){return function(_0x32db9b){if(_0x32db9b){return _0x32db9b['destroy']()[_0x9f3b('0x28')](function(){_0x4cddd1[_0x9f3b('0x21')](0xcc)['end']();});}};}function handleEntityNotFound(_0x583ff4,_0x1920a1){return function(_0x20c9fb){if(!_0x20c9fb){_0x583ff4['sendStatus'](0x194);}return _0x20c9fb;};}function handleError(_0x264a25,_0x336b86){_0x336b86=_0x336b86||0x1f4;return function(_0x173132){logger[_0x9f3b('0x29')](_0x173132[_0x9f3b('0x2a')]);if(_0x173132[_0x9f3b('0x2b')]){delete _0x173132['name'];}_0x264a25[_0x9f3b('0x21')](_0x336b86)[_0x9f3b('0x2c')](_0x173132);};}exports[_0x9f3b('0x2d')]=function(_0x147847,_0x50f923){var _0x52c478={},_0x454e2a={},_0x4ea89e={'count':0x0,'rows':[]};var _0x434c76=_[_0x9f3b('0x2e')](db[_0x9f3b('0x2f')][_0x9f3b('0x30')],function(_0x2f5f32){return{'name':_0x2f5f32['fieldName'],'type':_0x2f5f32[_0x9f3b('0x31')][_0x9f3b('0x32')]};});_0x454e2a[_0x9f3b('0x33')]=_[_0x9f3b('0x34')](_['map'](_0x434c76,_0x9f3b('0x2b')),[_0x9f3b('0x35')]);_0x454e2a['query']=_[_0x9f3b('0x36')](_0x147847[_0x9f3b('0x37')]);_0x454e2a[_0x9f3b('0x38')]=_['intersection'](_0x454e2a['model'],_0x454e2a[_0x9f3b('0x37')]);_0x52c478[_0x9f3b('0x39')]=_[_0x9f3b('0x3a')](_0x454e2a['model'],qs[_0x9f3b('0x3b')](_0x147847[_0x9f3b('0x37')][_0x9f3b('0x3b')]));_0x52c478[_0x9f3b('0x39')]=_0x52c478[_0x9f3b('0x39')][_0x9f3b('0x3c')]?_0x52c478[_0x9f3b('0x39')]:_0x454e2a['model'];if(!_0x147847[_0x9f3b('0x37')][_0x9f3b('0x3d')]('nolimit')){_0x52c478[_0x9f3b('0x1f')]=qs[_0x9f3b('0x1f')](_0x147847[_0x9f3b('0x37')]['limit']);_0x52c478['offset']=qs[_0x9f3b('0x1d')](_0x147847[_0x9f3b('0x37')][_0x9f3b('0x1d')]);}_0x52c478['order']=qs['sort'](_0x147847[_0x9f3b('0x37')][_0x9f3b('0x3e')]);_0x52c478[_0x9f3b('0x3f')]=qs[_0x9f3b('0x38')](_[_0x9f3b('0x40')](_0x147847[_0x9f3b('0x37')],_0x454e2a[_0x9f3b('0x38')]),_0x434c76);if(_0x147847[_0x9f3b('0x37')][_0x9f3b('0x41')]){_0x52c478[_0x9f3b('0x3f')]=_['merge'](_0x52c478[_0x9f3b('0x3f')],{'$or':_[_0x9f3b('0x2e')](_0x434c76,function(_0x2eea35){if(_0x2eea35[_0x9f3b('0x31')]!==_0x9f3b('0x42')){var _0x383606={};_0x383606[_0x2eea35[_0x9f3b('0x2b')]]={'$like':'%'+_0x147847[_0x9f3b('0x37')][_0x9f3b('0x41')]+'%'};return _0x383606;}})});}_0x52c478=_['merge']({},_0x52c478,_0x147847[_0x9f3b('0x43')]);var _0xb7109e={'where':_0x52c478['where']};return db[_0x9f3b('0x2f')]['count'](_0xb7109e)['then'](function(_0x3ced71){_0x4ea89e[_0x9f3b('0x20')]=_0x3ced71;if(_0x147847[_0x9f3b('0x37')][_0x9f3b('0x44')]){_0x52c478[_0x9f3b('0x45')]=[{'all':!![]}];}return db[_0x9f3b('0x2f')][_0x9f3b('0x46')](_0x52c478);})[_0x9f3b('0x28')](function(_0xed65b5){_0x4ea89e[_0x9f3b('0x47')]=_0xed65b5;return _0x4ea89e;})[_0x9f3b('0x28')](respondWithFilteredResult(_0x50f923,_0x52c478))[_0x9f3b('0x48')](handleError(_0x50f923,null));};exports[_0x9f3b('0x49')]=function(_0x55bee8,_0x460178){var _0x56b7fe={'raw':![],'where':{'id':_0x55bee8[_0x9f3b('0x4a')]['id']}},_0x5e713f={};_0x5e713f[_0x9f3b('0x33')]=_[_0x9f3b('0x36')](db[_0x9f3b('0x2f')][_0x9f3b('0x30')]);_0x5e713f['query']=_['keys'](_0x55bee8['query']);_0x5e713f['filters']=_[_0x9f3b('0x3a')](_0x5e713f[_0x9f3b('0x33')],_0x5e713f[_0x9f3b('0x37')]);_0x56b7fe['attributes']=_['intersection'](_0x5e713f[_0x9f3b('0x33')],qs[_0x9f3b('0x3b')](_0x55bee8['query'][_0x9f3b('0x3b')]));_0x56b7fe[_0x9f3b('0x39')]=_0x56b7fe[_0x9f3b('0x39')][_0x9f3b('0x3c')]?_0x56b7fe[_0x9f3b('0x39')]:_0x5e713f[_0x9f3b('0x33')];if(_0x55bee8[_0x9f3b('0x37')][_0x9f3b('0x44')]){_0x56b7fe[_0x9f3b('0x45')]=[{'all':!![]}];}_0x56b7fe=_['merge']({},_0x56b7fe,_0x55bee8[_0x9f3b('0x43')]);return db[_0x9f3b('0x2f')][_0x9f3b('0x4b')](_0x56b7fe)[_0x9f3b('0x28')](handleEntityNotFound(_0x460178,null))[_0x9f3b('0x28')](respondWithResult(_0x460178,null))['catch'](handleError(_0x460178,null));};exports[_0x9f3b('0x4c')]=function(_0x2b6b57,_0x1dd67f){return db[_0x9f3b('0x2f')]['create'](_0x2b6b57[_0x9f3b('0x4d')],{})['then'](respondWithResult(_0x1dd67f,0xc9))[_0x9f3b('0x48')](handleError(_0x1dd67f,null));};exports[_0x9f3b('0x27')]=function(_0x2310e8,_0x46da54){if(_0x2310e8['body']['id']){delete _0x2310e8[_0x9f3b('0x4d')]['id'];}return db[_0x9f3b('0x2f')][_0x9f3b('0x4b')]({'where':{'id':_0x2310e8[_0x9f3b('0x4a')]['id']}})[_0x9f3b('0x28')](handleEntityNotFound(_0x46da54,null))['then'](saveUpdates(_0x2310e8[_0x9f3b('0x4d')],null))['then'](respondWithResult(_0x46da54,null))[_0x9f3b('0x48')](handleError(_0x46da54,null));};exports[_0x9f3b('0x4e')]=function(_0x582cf7,_0x33e698){return db[_0x9f3b('0x2f')]['describe']()[_0x9f3b('0x28')](respondWithResult(_0x33e698,null))['catch'](handleError(_0x33e698,null));};exports[_0x9f3b('0x4f')]=function(_0x44d81f,_0x491b33,_0x28763d){var _0x32969d=require(_0x9f3b('0x50'));var _0x3f66bb=![];var _0x40c437={};if(_0x44d81f[_0x9f3b('0x37')][_0x9f3b('0x31')]&&_0x44d81f[_0x9f3b('0x37')][_0x9f3b('0x31')]===_0x9f3b('0x51')){_0x40c437['uniqueid']=_0x44d81f[_0x9f3b('0x4a')]['id'];}else{_0x40c437['id']=_0x44d81f['params']['id'];}return db[_0x9f3b('0x2f')][_0x9f3b('0x4b')]({'where':_0x40c437,'attributes':['id',_0x9f3b('0x52')],'raw':!![]})[_0x9f3b('0x28')](handleEntityNotFound(_0x491b33,null))[_0x9f3b('0x28')](function(_0x56fc5c){if(_0x56fc5c){var _0x41a855=_0x56fc5c[_0x9f3b('0x52')];var _0xbfc3dd=util['format'](_0x9f3b('0x53'),_0x41a855);if(fs[_0x9f3b('0x54')](_0xbfc3dd)){_0x3f66bb=!![];return _0x32969d['decryptFile'](_0xbfc3dd,_0x41a855,config[_0x9f3b('0x55')][_0x9f3b('0x56')])[_0x9f3b('0x28')](function(){return _0x56fc5c;});}return _0x56fc5c;}})['then'](function(_0x26aa80){if(_0x26aa80){var _0x194965=_0x26aa80['value'];if(!fs[_0x9f3b('0x54')](_0x194965)){throw new db[(_0x9f3b('0x57'))][(_0x9f3b('0x58'))](_0x9f3b('0x59'));}if(_0x26aa80[_0x9f3b('0x5a')]){return _0x491b33[_0x9f3b('0x4f')](_0x194965,_0x26aa80[_0x9f3b('0x5a')]+path[_0x9f3b('0x5b')](_0x194965),function(){if(_0x3f66bb){fs[_0x9f3b('0x5c')](_0x194965);}});}else{return _0x491b33[_0x9f3b('0x4f')](_0x194965,function(_0xa1ce8f){if(_0x3f66bb){fs[_0x9f3b('0x5c')](_0x194965);}});}}})[_0x9f3b('0x48')](function(_0x18bebe){if(_0x18bebe[_0x9f3b('0x5d')]==='VoiceRecording\x20not\x20found'){_0x491b33[_0x9f3b('0x21')](0x194)[_0x9f3b('0x2c')](_0x9f3b('0x5e'));}else{return handleError(_0x491b33,null);}});};exports[_0x9f3b('0x5f')]=function(_0x55c92d,_0x31541c,_0x4ca180){var _0x6c6189=require(_0x9f3b('0x50'));var _0x41f173=![];var _0x58e398={'$and':[db[_0x9f3b('0x60')][_0x9f3b('0x3f')](db[_0x9f3b('0x60')]['fn'](_0x9f3b('0x61'),db[_0x9f3b('0x60')][_0x9f3b('0x62')]('uniqueid')),_0x55c92d[_0x9f3b('0x37')][_0x9f3b('0x63')])]};if(_0x55c92d['query'][_0x9f3b('0x31')]&&_0x55c92d[_0x9f3b('0x37')][_0x9f3b('0x31')]===_0x9f3b('0x51')){_0x58e398[_0x9f3b('0x64')][_0x9f3b('0x65')]({'uniqueid':_0x55c92d[_0x9f3b('0x4a')]['id']});}else{_0x58e398['$and'][_0x9f3b('0x65')]({'id':_0x55c92d[_0x9f3b('0x4a')]['id']});}return db[_0x9f3b('0x2f')]['find']({'where':_0x58e398,'attributes':['id','value'],'raw':!![]})[_0x9f3b('0x28')](handleEntityNotFound(_0x31541c,null))[_0x9f3b('0x28')](function(_0x4dd579){if(_0x4dd579){var _0x18f26a=util[_0x9f3b('0x35')]('%s.cypher',_0x4dd579[_0x9f3b('0x52')]);if(fs['existsSync'](_0x18f26a)){_0x41f173=!![];return _0x6c6189[_0x9f3b('0x66')](_0x18f26a,_0x4dd579['value'],config['secrets']['recording'])['then'](function(){return _0x4dd579;});}return _0x4dd579;}})[_0x9f3b('0x28')](function(_0x2f39b7){if(_0x2f39b7){if(!fs[_0x9f3b('0x54')](_0x2f39b7[_0x9f3b('0x52')])){throw new db[(_0x9f3b('0x57'))][(_0x9f3b('0x58'))](_0x9f3b('0x59'));}if(_0x2f39b7[_0x9f3b('0x5a')]){return _0x31541c[_0x9f3b('0x4f')](_0x2f39b7[_0x9f3b('0x52')],_0x2f39b7[_0x9f3b('0x5a')]+path[_0x9f3b('0x5b')](_0x2f39b7[_0x9f3b('0x52')]),function(){if(_0x41f173){fs[_0x9f3b('0x5c')](_0x2f39b7['value']);}});}else{return _0x31541c[_0x9f3b('0x4f')](_0x2f39b7[_0x9f3b('0x52')],function(_0x142785){if(_0x41f173){fs[_0x9f3b('0x5c')](_0x2f39b7[_0x9f3b('0x52')]);}});}}})['catch'](handleError(_0x31541c,null));};exports[_0x9f3b('0x67')]=function(_0x5aaf9a,_0x4057f0){return db['VoiceRecording'][_0x9f3b('0x4b')]({'where':{'id':_0x5aaf9a[_0x9f3b('0x4a')]['id']}})[_0x9f3b('0x28')](function(_0x35ec7e){if(_[_0x9f3b('0x68')](_0x35ec7e)){throw new ReferenceError(_0x9f3b('0x69'));}return _0x35ec7e;})['then'](function(_0x11e57d){var _0x12d0aa=_0x11e57d[_0x9f3b('0x52')];logger[_0x9f3b('0x6a')](_0x9f3b('0x6b'),_0x12d0aa);if(!_[_0x9f3b('0x68')](_0x11e57d[_0x9f3b('0x52')])&&fs[_0x9f3b('0x54')](_0x12d0aa)){logger[_0x9f3b('0x6a')](_0x9f3b('0x6c')+_0x12d0aa+_0x9f3b('0x6d'));fs[_0x9f3b('0x6e')](_0x12d0aa);}_0x12d0aa=_0x12d0aa+_0x9f3b('0x6f');if(!_[_0x9f3b('0x68')](_0x11e57d[_0x9f3b('0x52')])&&fs[_0x9f3b('0x54')](_0x12d0aa)){logger[_0x9f3b('0x6a')](_0x9f3b('0x6c')+_0x12d0aa+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs[_0x9f3b('0x6e')](_0x12d0aa);}return _0x11e57d;})[_0x9f3b('0x28')](function(_0x45a963){if(!_0x45a963)throw new InternalError();return _0x45a963[_0x9f3b('0x67')]();})[_0x9f3b('0x28')](function(){_0x4057f0[_0x9f3b('0x21')](0xcc)[_0x9f3b('0x1c')]();})[_0x9f3b('0x48')](handleError(_0x4057f0,null));};function getBucketslist(_0x194ad1,_0x2ddc67,_0x9ec8f0){return new Promise(function(_0x3adf12,_0x7fde2c){var _0x294eec=new AWS['S3']({'accessKeyId':_0x2ddc67,'secretAccessKey':_0x194ad1,'region':_0x9ec8f0});_0x294eec[_0x9f3b('0x70')]({},function(_0x1d5a3d,_0x510a08){if(_0x1d5a3d){return _0x7fde2c(_0x1d5a3d);}else{return _0x3adf12(_0x510a08);}});});}function createBucket(_0x34182e,_0x31dbcb,_0x28efb0,_0x13b286){return new Promise(function(_0x5c1790,_0x21bdec){var _0x3d2079=new AWS['S3']({'accessKeyId':_0x31dbcb,'secretAccessKey':_0x34182e,'region':_0x28efb0});_0x3d2079['createBucket']({'Bucket':_0x13b286},function(_0x3d6096,_0x1daed1){if(_0x3d6096){return _0x21bdec(_0x3d6096);}else{return _0x5c1790(_0x1daed1);}});});}function uploadFile(_0x371b4e,_0x72b2e8,_0x13ea3d,_0x253dc5,_0x50c422,_0x3c724b){return new Promise(function(_0x3e6127,_0x186987){var _0x414e71=new AWS['S3']({'accessKeyId':_0x72b2e8,'secretAccessKey':_0x371b4e,'region':_0x13ea3d});_0x414e71[_0x9f3b('0x71')]({'Bucket':_0x253dc5,'Key':_0x50c422,'Body':_0x3c724b},function(_0x2f4282,_0x2b8da9){if(_0x2f4282){return _0x186987(_0x2f4282);}else{return _0x3e6127(_0x2b8da9);}});});}function startTranscribe(_0x5da079,_0x1cb179,_0x5637a8,_0x47d5ee,_0x590997,_0x1122e3){return new Promise(function(_0x267111,_0x4047fa){var _0x1ce0c9=new AWS[(_0x9f3b('0x72'))]({'accessKeyId':_0x1cb179,'secretAccessKey':_0x5da079,'region':_0x5637a8});_0x1ce0c9[_0x9f3b('0x73')]({'TranscriptionJobName':_0x47d5ee,'LanguageCode':_0x590997,'Media':{'MediaFileUri':_0x1122e3}},function(_0x588af3,_0x1c0cbf){if(_0x588af3){return _0x4047fa(_0x588af3);}else{return _0x267111(_0x1c0cbf);}});});}function transcribe(_0x55fbe4,_0xc1dac9,_0x457ce6,_0xcdbaf8,_0x20d9ba,_0xeac4f8,_0x1affd6){return new Promise(function(_0x4efaeb,_0x238eea){var _0x2e3212={};logger[_0x9f3b('0x6a')](util['format'](_0x9f3b('0x74'),_0x55fbe4,_0x20d9ba));return uploadFile(_0xc1dac9,_0x457ce6,_0xcdbaf8,_0x20d9ba,path[_0x9f3b('0x75')](_0xeac4f8),fs[_0x9f3b('0x76')](_0xeac4f8))[_0x9f3b('0x28')](function(_0xc48b70){logger['info'](util[_0x9f3b('0x35')]('[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)',_0x55fbe4,_0x20d9ba,_0xc48b70[_0x9f3b('0x77')]));_0x2e3212['bucket']=_0xc48b70[_0x9f3b('0x78')];_0x2e3212[_0x9f3b('0x79')]=_0xc48b70['Location'];logger[_0x9f3b('0x6a')](util[_0x9f3b('0x35')](_0x9f3b('0x7a'),_0x55fbe4));return startTranscribe(_0xc1dac9,_0x457ce6,_0xcdbaf8,uuidv4(),_0x1affd6,_0xc48b70[_0x9f3b('0x77')]);})[_0x9f3b('0x28')](function(_0x93a97a){logger[_0x9f3b('0x6a')](util[_0x9f3b('0x35')](_0x9f3b('0x7b'),_0x55fbe4,_0x93a97a[_0x9f3b('0x7c')][_0x9f3b('0x7d')]));_0x2e3212[_0x9f3b('0x7e')]=_0x93a97a[_0x9f3b('0x7c')][_0x9f3b('0x7d')];_0x2e3212[_0x9f3b('0x7f')]=_0x93a97a[_0x9f3b('0x7c')][_0x9f3b('0x80')];return _0x4efaeb(_0x2e3212);})['catch'](function(_0x5ec1ff){return _0x238eea(_0x5ec1ff);});});}exports['runTranscribe']=function(_0x188c94,_0x2c1ed8,_0x1444fc){var _0x911607;var _0x152009;var _0x4f327b;var _0x1868ae=require('../../components/encryptor');return db[_0x9f3b('0x2f')][_0x9f3b('0x81')]({'where':{'id':_0x188c94[_0x9f3b('0x4a')]['id']}})['then'](function(_0x45797a){if(_0x45797a){var _0x1604da=util[_0x9f3b('0x35')](_0x9f3b('0x53'),_0x45797a['value']);if(fs[_0x9f3b('0x54')](_0x1604da)){cypher=!![];return _0x1868ae[_0x9f3b('0x66')](_0x1604da,_0x45797a[_0x9f3b('0x52')],config[_0x9f3b('0x55')][_0x9f3b('0x56')])[_0x9f3b('0x28')](function(){return _0x45797a;});}return _0x45797a;}})[_0x9f3b('0x28')](function(_0x16af8e){if(!_0x16af8e){throw new db[(_0x9f3b('0x57'))][(_0x9f3b('0x58'))](_0x9f3b('0x82'));}_0x152009=_0x16af8e;return db[_0x9f3b('0x83')][_0x9f3b('0x81')]({'where':{'id':0x1}});})[_0x9f3b('0x28')](handleEntityNotFound(_0x2c1ed8,null))[_0x9f3b('0x28')](function(_0x327a2f){if(_0x327a2f){_0x911607=_0x327a2f;if(!_0x911607[_0x9f3b('0x84')]||!_0x911607[_0x9f3b('0x85')]||!_0x911607['transcribeRegion']||!_0x911607[_0x9f3b('0x86')]||!_0x911607[_0x9f3b('0x87')]){throw new db[(_0x9f3b('0x57'))]['ValidationError'](_0x9f3b('0x88'));}if(_0x188c94[_0x9f3b('0x4d')][_0x9f3b('0x89')]&&(!_0x911607[_0x9f3b('0x8a')]||!_0x911607[_0x9f3b('0x8b')]||!_0x911607[_0x9f3b('0x8c')]||!_0x911607[_0x9f3b('0x86')]||!_0x911607['bucket'])){throw new db[(_0x9f3b('0x57'))][(_0x9f3b('0x58'))](_0x9f3b('0x8d'));}return db[_0x9f3b('0x8e')][_0x9f3b('0x81')]({'where':{'id':_0x911607[_0x9f3b('0x85')]}});}})[_0x9f3b('0x28')](function(_0x8d07f8){if(!_0x8d07f8){throw new db[(_0x9f3b('0x57'))][(_0x9f3b('0x58'))](_0x9f3b('0x8f'));}if(!_0x8d07f8[_0x9f3b('0x90')]||!_0x8d07f8[_0x9f3b('0x91')]){throw new db[(_0x9f3b('0x57'))][(_0x9f3b('0x58'))](_0x9f3b('0x92'));}_0x4f327b=_0x8d07f8;return getBucketslist(_0x4f327b['data1'],_0x4f327b[_0x9f3b('0x91')],_0x911607[_0x9f3b('0x93')]);})[_0x9f3b('0x28')](function(_0x1065bb){if(_0x1065bb&&_0x1065bb['Buckets']){var _0x25de77=_[_0x9f3b('0x4b')](_0x1065bb[_0x9f3b('0x94')],function(_0x15432c){return _0x15432c['Name']===_0x911607[_0x9f3b('0x87')];});if(!_0x25de77){logger['info'](util[_0x9f3b('0x35')](_0x9f3b('0x95'),_0x188c94[_0x9f3b('0x4a')]['id'],_0x911607[_0x9f3b('0x87')]));return createBucket(_0x4f327b[_0x9f3b('0x90')],_0x4f327b['data2'],_0x911607[_0x9f3b('0x93')],_0x911607[_0x9f3b('0x87')]);}logger['info'](util[_0x9f3b('0x35')](_0x9f3b('0x96'),_0x188c94[_0x9f3b('0x4a')]['id'],_0x911607[_0x9f3b('0x87')]));return;}})['then'](function(_0x585e22){if(_0x152009[_0x9f3b('0x7f')]===_0x9f3b('0x97')){return transcribe(_0x188c94[_0x9f3b('0x4a')]['id'],_0x4f327b['data1'],_0x4f327b['data2'],_0x911607['transcribeRegion'],_0x911607[_0x9f3b('0x87')],_0x152009[_0x9f3b('0x52')],_0x911607[_0x9f3b('0x86')]);}else{logger[_0x9f3b('0x6a')](util[_0x9f3b('0x35')]('[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested',_0x188c94[_0x9f3b('0x4a')]['id']));return{'transcribeStatus':_0x9f3b('0x98')};}})['then'](function(_0x4a2bf7){if(_0x4a2bf7){_0x4a2bf7[_0x9f3b('0x99')]=_0x188c94[_0x9f3b('0x4d')]['runSentiment'];return _0x152009['updateAttributes'](_0x4a2bf7);}})[_0x9f3b('0x28')](respondWithResult(_0x2c1ed8,null))['catch'](handleError(_0x2c1ed8,null));};function writeFile(_0x112d93,_0x2a8dbb){return new Promise(function(_0x37a288,_0x44d720){fs['writeFile'](_0x2a8dbb,_0x112d93,function(_0x3c581c,_0x5e96aa){if(_0x3c581c){return _0x44d720(_0x3c581c);}else{return _0x37a288(_0x5e96aa);}});});}exports[_0x9f3b('0x9a')]=function(_0x4d66c0,_0x4ad38a,_0x202499){return db[_0x9f3b('0x2f')]['findOne']({'where':{'id':_0x4d66c0[_0x9f3b('0x4a')]['id']}})['then'](handleEntityNotFound(_0x4ad38a))[_0x9f3b('0x28')](function(_0x39d294){if(_0x39d294&&_0x39d294['fileText']){var _0x2390aa=_0x39d294[_0x9f3b('0x9b')];var _0x18cae5=config[_0x9f3b('0x9c')]+_0x9f3b('0x9d')+_0x39d294['id']+_0x9f3b('0x9e');if(fs[_0x9f3b('0x54')](_0x18cae5)){return _0x18cae5;}return writeFile(_0x2390aa,_0x18cae5)['then'](function(){return _0x18cae5;});}else{throw new db['Sequelize'][(_0x9f3b('0x58'))](_0x9f3b('0x9f'));}})[_0x9f3b('0x28')](function(_0x5b8c4e){return _0x4ad38a[_0x9f3b('0x4f')](_0x5b8c4e);})[_0x9f3b('0x48')](handleError(_0x4ad38a));};