c8f97ee1914d4878f3efa7690101b2c567f999f9
[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 _0x68ff=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','../../mysqldb','sendStatus','status','json','count','offset','limit','Content-Range','apply','reject','update','destroy','then','error','name','VoiceRecording','rawAttributes','type','key','model','differenceBy','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','findAll','rows','catch','show','params','includeAll','include','create','body','find','describe','../../components/encryptor','uniqueid','value','format','%s.cypher','secrets','recording','existsSync','Sequelize','VoiceRecording\x20not\x20found','filename','extname','unlink','download','message','send','Not\x20found','MD5','col','token','$and','push','decryptFile','ValidationError','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','isNil','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','listBuckets','upload','TranscribeService','basename','readFileSync','[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)','Location','bucket','[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request','[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created','TranscriptionJob','TranscriptionJobName','transcribeStatus','TranscriptionJobStatus','runTranscribe','findOne','Setting','transcribe','transcribeRegion','runSentiment','sentiment','sentimentAccountId','Sentiment\x20Analysis\x20not\x20configured','CloudProvider','transcribeAccountId','Cloud\x20Provider\x20not\x20available','data2','Cloud\x20Provider\x20not\x20configured','Buckets','Name','data1','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','language','IN_PROGRESS','downloadTranscribe','fileText','root','/server/files/transcribes/transcribe_','.txt','Transcript\x20not\x20available','html-pdf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','uuid/v4','../../components/auth/service','../../components/parsers/qs'];(function(_0x580647,_0x43d2c3){var _0x5f0792=function(_0x386cef){while(--_0x386cef){_0x580647['push'](_0x580647['shift']());}};_0x5f0792(++_0x43d2c3);}(_0x68ff,0x10c));var _0xf68f=function(_0x5b3507,_0x3541ec){_0x5b3507=_0x5b3507-0x0;var _0x4cd24e=_0x68ff[_0x5b3507];return _0x4cd24e;};'use strict';var pdf=require(_0xf68f('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf68f('0x1'));var jsonpatch=require(_0xf68f('0x2'));var rp=require('request-promise');var moment=require(_0xf68f('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xf68f('0x4'));var util=require(_0xf68f('0x5'));var path=require(_0xf68f('0x6'));var sox=require(_0xf68f('0x7'));var csv=require('to-csv');var ejs=require(_0xf68f('0x8'));var fs=require('fs');var _=require(_0xf68f('0x9'));var squel=require('squel');var crypto=require(_0xf68f('0xa'));var jsforce=require(_0xf68f('0xb'));var deskjs=require(_0xf68f('0xc'));var toCsv=require('to-csv');var querystring=require(_0xf68f('0xd'));var Papa=require(_0xf68f('0xe'));var AWS=require('aws-sdk');var uuidv4=require(_0xf68f('0xf'));var Redis=require('ioredis');var authService=require(_0xf68f('0x10'));var qs=require(_0xf68f('0x11'));var as=require(_0xf68f('0x12'));var hardwareService=require(_0xf68f('0x13'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0xf68f('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0xf68f('0x15'))['db'];function respondWithStatusCode(_0x574e79,_0x16d6c5){_0x16d6c5=_0x16d6c5||0xcc;return function(_0x77b5ce){if(_0x77b5ce){return _0x574e79[_0xf68f('0x16')](_0x16d6c5);}return _0x574e79[_0xf68f('0x17')](_0x16d6c5)['end']();};}function respondWithResult(_0x19539d,_0x3a2352){_0x3a2352=_0x3a2352||0xc8;return function(_0x2c083a){if(_0x2c083a){return _0x19539d[_0xf68f('0x17')](_0x3a2352)[_0xf68f('0x18')](_0x2c083a);}};}function respondWithFilteredResult(_0x4dd17c,_0x38ee52){return function(_0x528ba0){if(_0x528ba0){var _0x3f19a6=_0x528ba0[_0xf68f('0x19')],_0x5bd388=_0x38ee52[_0xf68f('0x1a')],_0x50eb13=_0x38ee52[_0xf68f('0x1a')]+_0x38ee52[_0xf68f('0x1b')],_0x4bda68;if(_0x50eb13>=_0x3f19a6){_0x50eb13=_0x3f19a6;_0x4bda68=0xc8;}else{_0x4bda68=0xce;}_0x4dd17c[_0xf68f('0x17')](_0x4bda68);return _0x4dd17c['set'](_0xf68f('0x1c'),_0x5bd388+'-'+_0x50eb13+'/'+_0x3f19a6)['json'](_0x528ba0);}return null;};}function patchUpdates(_0x238000){return function(_0x368107){try{jsonpatch[_0xf68f('0x1d')](_0x368107,_0x238000,!![]);}catch(_0x3b751d){return BPromise[_0xf68f('0x1e')](_0x3b751d);}return _0x368107['save']();};}function saveUpdates(_0xfdefa9,_0x5173b1){return function(_0x3d9eb5){if(_0x3d9eb5){return _0x3d9eb5[_0xf68f('0x1f')](_0xfdefa9)['then'](function(_0x18438b){return _0x18438b;});}return null;};}function removeEntity(_0x39c29d,_0x5a6a36){return function(_0x4f79ed){if(_0x4f79ed){return _0x4f79ed[_0xf68f('0x20')]()[_0xf68f('0x21')](function(){_0x39c29d[_0xf68f('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0xfe78c6,_0x2180e1){return function(_0x37b170){if(!_0x37b170){_0xfe78c6[_0xf68f('0x16')](0x194);}return _0x37b170;};}function handleError(_0xbae0b8,_0x58d1d5){_0x58d1d5=_0x58d1d5||0x1f4;return function(_0x59b79c){logger[_0xf68f('0x22')](_0x59b79c['stack']);if(_0x59b79c['name']){delete _0x59b79c[_0xf68f('0x23')];}_0xbae0b8[_0xf68f('0x17')](_0x58d1d5)['send'](_0x59b79c);};}exports['index']=function(_0x498935,_0x2311c6){var _0x12050c={},_0x32839d={},_0x171091={'count':0x0,'rows':[]};var _0x106f51=_['map'](db[_0xf68f('0x24')][_0xf68f('0x25')],function(_0x2b8c63){return{'name':_0x2b8c63['fieldName'],'type':_0x2b8c63[_0xf68f('0x26')][_0xf68f('0x27')]};});_0x32839d[_0xf68f('0x28')]=_[_0xf68f('0x29')](_[_0xf68f('0x2a')](_0x106f51,'name'),['format']);_0x32839d[_0xf68f('0x2b')]=_[_0xf68f('0x2c')](_0x498935[_0xf68f('0x2b')]);_0x32839d[_0xf68f('0x2d')]=_[_0xf68f('0x2e')](_0x32839d['model'],_0x32839d[_0xf68f('0x2b')]);_0x12050c[_0xf68f('0x2f')]=_[_0xf68f('0x2e')](_0x32839d[_0xf68f('0x28')],qs[_0xf68f('0x30')](_0x498935[_0xf68f('0x2b')]['fields']));_0x12050c[_0xf68f('0x2f')]=_0x12050c['attributes'][_0xf68f('0x31')]?_0x12050c[_0xf68f('0x2f')]:_0x32839d[_0xf68f('0x28')];if(!_0x498935['query'][_0xf68f('0x32')](_0xf68f('0x33'))){_0x12050c['limit']=qs[_0xf68f('0x1b')](_0x498935[_0xf68f('0x2b')]['limit']);_0x12050c['offset']=qs[_0xf68f('0x1a')](_0x498935[_0xf68f('0x2b')]['offset']);}_0x12050c[_0xf68f('0x34')]=qs[_0xf68f('0x35')](_0x498935[_0xf68f('0x2b')][_0xf68f('0x35')]);_0x12050c[_0xf68f('0x36')]=qs[_0xf68f('0x2d')](_[_0xf68f('0x37')](_0x498935['query'],_0x32839d[_0xf68f('0x2d')]),_0x106f51);if(_0x498935[_0xf68f('0x2b')][_0xf68f('0x38')]){_0x12050c['where']=_[_0xf68f('0x39')](_0x12050c[_0xf68f('0x36')],{'$or':_[_0xf68f('0x2a')](_0x106f51,function(_0x195c1d){if(_0x195c1d[_0xf68f('0x26')]!==_0xf68f('0x3a')){var _0x229ce0={};_0x229ce0[_0x195c1d[_0xf68f('0x23')]]={'$like':'%'+_0x498935['query'][_0xf68f('0x38')]+'%'};return _0x229ce0;}})});}_0x12050c=_['merge']({},_0x12050c,_0x498935[_0xf68f('0x3b')]);var _0x9de7fc={'where':_0x12050c[_0xf68f('0x36')]};return db[_0xf68f('0x24')][_0xf68f('0x19')](_0x9de7fc)[_0xf68f('0x21')](function(_0x36061a){_0x171091[_0xf68f('0x19')]=_0x36061a;if(_0x498935[_0xf68f('0x2b')]['includeAll']){_0x12050c['include']=[{'all':!![]}];}return db[_0xf68f('0x24')][_0xf68f('0x3c')](_0x12050c);})[_0xf68f('0x21')](function(_0x250439){_0x171091[_0xf68f('0x3d')]=_0x250439;return _0x171091;})['then'](respondWithFilteredResult(_0x2311c6,_0x12050c))[_0xf68f('0x3e')](handleError(_0x2311c6,null));};exports[_0xf68f('0x3f')]=function(_0x84545,_0x4addc1){var _0x2ded2a={'raw':![],'where':{'id':_0x84545[_0xf68f('0x40')]['id']}},_0x5e12fd={};_0x5e12fd[_0xf68f('0x28')]=_[_0xf68f('0x2c')](db['VoiceRecording'][_0xf68f('0x25')]);_0x5e12fd[_0xf68f('0x2b')]=_[_0xf68f('0x2c')](_0x84545['query']);_0x5e12fd[_0xf68f('0x2d')]=_[_0xf68f('0x2e')](_0x5e12fd[_0xf68f('0x28')],_0x5e12fd[_0xf68f('0x2b')]);_0x2ded2a[_0xf68f('0x2f')]=_[_0xf68f('0x2e')](_0x5e12fd[_0xf68f('0x28')],qs['fields'](_0x84545[_0xf68f('0x2b')]['fields']));_0x2ded2a[_0xf68f('0x2f')]=_0x2ded2a[_0xf68f('0x2f')][_0xf68f('0x31')]?_0x2ded2a[_0xf68f('0x2f')]:_0x5e12fd[_0xf68f('0x28')];if(_0x84545[_0xf68f('0x2b')][_0xf68f('0x41')]){_0x2ded2a[_0xf68f('0x42')]=[{'all':!![]}];}_0x2ded2a=_[_0xf68f('0x39')]({},_0x2ded2a,_0x84545[_0xf68f('0x3b')]);return db['VoiceRecording']['find'](_0x2ded2a)['then'](handleEntityNotFound(_0x4addc1,null))[_0xf68f('0x21')](respondWithResult(_0x4addc1,null))[_0xf68f('0x3e')](handleError(_0x4addc1,null));};exports[_0xf68f('0x43')]=function(_0x57def2,_0x3905ff){return db['VoiceRecording'][_0xf68f('0x43')](_0x57def2[_0xf68f('0x44')],{})[_0xf68f('0x21')](respondWithResult(_0x3905ff,0xc9))[_0xf68f('0x3e')](handleError(_0x3905ff,null));};exports[_0xf68f('0x1f')]=function(_0x13d1ad,_0x125707){if(_0x13d1ad['body']['id']){delete _0x13d1ad['body']['id'];}return db[_0xf68f('0x24')][_0xf68f('0x45')]({'where':{'id':_0x13d1ad['params']['id']}})['then'](handleEntityNotFound(_0x125707,null))[_0xf68f('0x21')](saveUpdates(_0x13d1ad['body'],null))['then'](respondWithResult(_0x125707,null))[_0xf68f('0x3e')](handleError(_0x125707,null));};exports['describe']=function(_0x589189,_0x1de881){return db[_0xf68f('0x24')][_0xf68f('0x46')]()[_0xf68f('0x21')](respondWithResult(_0x1de881,null))[_0xf68f('0x3e')](handleError(_0x1de881,null));};exports['download']=function(_0x48e703,_0x2eae7a,_0xf0696b){var _0x1d9180=require(_0xf68f('0x47'));var _0x379cbd=![];var _0x954a0d={};if(_0x48e703[_0xf68f('0x2b')][_0xf68f('0x26')]&&_0x48e703[_0xf68f('0x2b')]['type']===_0xf68f('0x48')){_0x954a0d[_0xf68f('0x48')]=_0x48e703[_0xf68f('0x40')]['id'];}else{_0x954a0d['id']=_0x48e703[_0xf68f('0x40')]['id'];}return db[_0xf68f('0x24')][_0xf68f('0x45')]({'where':_0x954a0d,'attributes':['id',_0xf68f('0x49')],'raw':!![]})[_0xf68f('0x21')](handleEntityNotFound(_0x2eae7a,null))[_0xf68f('0x21')](function(_0x14585e){if(_0x14585e){var _0x5c3bc3=_0x14585e['value'];var _0x5235b8=util[_0xf68f('0x4a')](_0xf68f('0x4b'),_0x5c3bc3);if(fs['existsSync'](_0x5235b8)){_0x379cbd=!![];return _0x1d9180['decryptFile'](_0x5235b8,_0x5c3bc3,config[_0xf68f('0x4c')][_0xf68f('0x4d')])[_0xf68f('0x21')](function(){return _0x14585e;});}return _0x14585e;}})[_0xf68f('0x21')](function(_0xe2f88a){if(_0xe2f88a){var _0x9c534b=_0xe2f88a[_0xf68f('0x49')];if(!fs[_0xf68f('0x4e')](_0x9c534b)){throw new db[(_0xf68f('0x4f'))]['ValidationError'](_0xf68f('0x50'));}if(_0xe2f88a[_0xf68f('0x51')]){return _0x2eae7a['download'](_0x9c534b,_0xe2f88a[_0xf68f('0x51')]+path[_0xf68f('0x52')](_0x9c534b),function(){if(_0x379cbd){fs[_0xf68f('0x53')](_0x9c534b);}});}else{return _0x2eae7a[_0xf68f('0x54')](_0x9c534b,function(_0x387df9){if(_0x379cbd){fs['unlink'](_0x9c534b);}});}}})[_0xf68f('0x3e')](function(_0x49c2f7){if(_0x49c2f7[_0xf68f('0x55')]===_0xf68f('0x50')){_0x2eae7a[_0xf68f('0x17')](0x194)[_0xf68f('0x56')](_0xf68f('0x57'));}else{return handleError(_0x2eae7a,null);}});};exports['downloads']=function(_0x1a3f14,_0x4a61d3,_0x1786f7){var _0x42f860=require(_0xf68f('0x47'));var _0x55c2d3=![];var _0x3f3e58={'$and':[db['sequelize'][_0xf68f('0x36')](db['sequelize']['fn'](_0xf68f('0x58'),db['sequelize'][_0xf68f('0x59')](_0xf68f('0x48'))),_0x1a3f14[_0xf68f('0x2b')][_0xf68f('0x5a')])]};if(_0x1a3f14[_0xf68f('0x2b')][_0xf68f('0x26')]&&_0x1a3f14[_0xf68f('0x2b')][_0xf68f('0x26')]===_0xf68f('0x48')){_0x3f3e58[_0xf68f('0x5b')][_0xf68f('0x5c')]({'uniqueid':_0x1a3f14[_0xf68f('0x40')]['id']});}else{_0x3f3e58[_0xf68f('0x5b')][_0xf68f('0x5c')]({'id':_0x1a3f14[_0xf68f('0x40')]['id']});}return db['VoiceRecording'][_0xf68f('0x45')]({'where':_0x3f3e58,'attributes':['id','value'],'raw':!![]})[_0xf68f('0x21')](handleEntityNotFound(_0x4a61d3,null))['then'](function(_0x23fcaa){if(_0x23fcaa){var _0xa72dc9=util[_0xf68f('0x4a')](_0xf68f('0x4b'),_0x23fcaa[_0xf68f('0x49')]);if(fs[_0xf68f('0x4e')](_0xa72dc9)){_0x55c2d3=!![];return _0x42f860[_0xf68f('0x5d')](_0xa72dc9,_0x23fcaa[_0xf68f('0x49')],config[_0xf68f('0x4c')][_0xf68f('0x4d')])['then'](function(){return _0x23fcaa;});}return _0x23fcaa;}})[_0xf68f('0x21')](function(_0x3c66d9){if(_0x3c66d9){if(!fs[_0xf68f('0x4e')](_0x3c66d9['value'])){throw new db['Sequelize'][(_0xf68f('0x5e'))](_0xf68f('0x50'));}if(_0x3c66d9[_0xf68f('0x51')]){return _0x4a61d3['download'](_0x3c66d9[_0xf68f('0x49')],_0x3c66d9[_0xf68f('0x51')]+path[_0xf68f('0x52')](_0x3c66d9[_0xf68f('0x49')]),function(){if(_0x55c2d3){fs['unlink'](_0x3c66d9[_0xf68f('0x49')]);}});}else{return _0x4a61d3['download'](_0x3c66d9[_0xf68f('0x49')],function(_0x486d83){if(_0x55c2d3){fs[_0xf68f('0x53')](_0x3c66d9['value']);}});}}})[_0xf68f('0x3e')](handleError(_0x4a61d3,null));};exports[_0xf68f('0x20')]=function(_0x4dc6cf,_0x1eb7f3){return db[_0xf68f('0x24')][_0xf68f('0x45')]({'where':{'id':_0x4dc6cf[_0xf68f('0x40')]['id']}})['then'](function(_0x4bf155){if(!_0x4bf155)throw new ReferenceError(_0xf68f('0x5f'));return _0x4bf155;})[_0xf68f('0x21')](function(_0x512bf4){var _0x55e929=_0x512bf4[_0xf68f('0x49')];logger[_0xf68f('0x60')](_0xf68f('0x61'),_0x55e929);if(!_[_0xf68f('0x62')](_0x512bf4[_0xf68f('0x49')])&&fs[_0xf68f('0x4e')](_0x55e929)){logger['info'](_0xf68f('0x63')+_0x55e929+_0xf68f('0x64'));fs[_0xf68f('0x65')](_0x55e929);}_0x55e929=_0x55e929+_0xf68f('0x66');if(!_[_0xf68f('0x62')](_0x512bf4['value'])&&fs[_0xf68f('0x4e')](_0x55e929)){logger[_0xf68f('0x60')](_0xf68f('0x63')+_0x55e929+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs[_0xf68f('0x65')](_0x55e929);}return _0x512bf4;})['then'](function(_0xa63a5){if(!_0xa63a5)throw new InternalError();return _0xa63a5[_0xf68f('0x20')]();})[_0xf68f('0x21')](function(){_0x1eb7f3['status'](0xcc)['end']();})[_0xf68f('0x3e')](handleError(_0x1eb7f3,null));};function getBucketslist(_0x502d4a,_0x29f1a8,_0x313968){return new Promise(function(_0x41c935,_0x5e0dae){var _0x2ae84f=new AWS['S3']({'accessKeyId':_0x29f1a8,'secretAccessKey':_0x502d4a,'region':_0x313968});_0x2ae84f[_0xf68f('0x67')]({},function(_0x1d21b2,_0x6a5f6f){if(_0x1d21b2){return _0x5e0dae(_0x1d21b2);}else{return _0x41c935(_0x6a5f6f);}});});}function createBucket(_0x51ab51,_0x487b21,_0x466538,_0x57778b){return new Promise(function(_0x2fda7f,_0x1df0fa){var _0x2c2efa=new AWS['S3']({'accessKeyId':_0x487b21,'secretAccessKey':_0x51ab51,'region':_0x466538});_0x2c2efa['createBucket']({'Bucket':_0x57778b},function(_0x3f29f4,_0x3b3ed7){if(_0x3f29f4){return _0x1df0fa(_0x3f29f4);}else{return _0x2fda7f(_0x3b3ed7);}});});}function uploadFile(_0x50ee34,_0x377032,_0x2d3710,_0x202238,_0x2cca00,_0x240d33){return new Promise(function(_0x18134a,_0x35df5c){var _0x255778=new AWS['S3']({'accessKeyId':_0x377032,'secretAccessKey':_0x50ee34,'region':_0x2d3710});_0x255778[_0xf68f('0x68')]({'Bucket':_0x202238,'Key':_0x2cca00,'Body':_0x240d33},function(_0x483053,_0x25aba5){if(_0x483053){return _0x35df5c(_0x483053);}else{return _0x18134a(_0x25aba5);}});});}function startTranscribe(_0x12d398,_0x5e2a88,_0x34cc16,_0x39798b,_0x5ec5aa,_0x23df15){return new Promise(function(_0x4467c2,_0x538968){var _0x478dcb=new AWS[(_0xf68f('0x69'))]({'accessKeyId':_0x5e2a88,'secretAccessKey':_0x12d398,'region':_0x34cc16});_0x478dcb['startTranscriptionJob']({'TranscriptionJobName':_0x39798b,'LanguageCode':_0x5ec5aa,'Media':{'MediaFileUri':_0x23df15}},function(_0x218946,_0xa32c37){if(_0x218946){return _0x538968(_0x218946);}else{return _0x4467c2(_0xa32c37);}});});}function transcribe(_0x16b4f4,_0x20938e,_0x28ac5b,_0x42b9c5,_0x408ffa,_0x3dbfa1,_0x38e462){return new Promise(function(_0x22a8bc,_0x15d8b6){var _0x23d2f3={};logger[_0xf68f('0x60')](util[_0xf68f('0x4a')]('[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s',_0x16b4f4,_0x408ffa));return uploadFile(_0x20938e,_0x28ac5b,_0x42b9c5,_0x408ffa,path[_0xf68f('0x6a')](_0x3dbfa1),fs[_0xf68f('0x6b')](_0x3dbfa1))['then'](function(_0xd21e03){logger['info'](util['format'](_0xf68f('0x6c'),_0x16b4f4,_0x408ffa,_0xd21e03[_0xf68f('0x6d')]));_0x23d2f3[_0xf68f('0x6e')]=_0xd21e03['Bucket'];_0x23d2f3['location']=_0xd21e03[_0xf68f('0x6d')];logger[_0xf68f('0x60')](util[_0xf68f('0x4a')](_0xf68f('0x6f'),_0x16b4f4));return startTranscribe(_0x20938e,_0x28ac5b,_0x42b9c5,uuidv4(),_0x38e462,_0xd21e03[_0xf68f('0x6d')]);})[_0xf68f('0x21')](function(_0x18fd13){logger['info'](util[_0xf68f('0x4a')](_0xf68f('0x70'),_0x16b4f4,_0x18fd13[_0xf68f('0x71')][_0xf68f('0x72')]));_0x23d2f3['transcribeName']=_0x18fd13['TranscriptionJob'][_0xf68f('0x72')];_0x23d2f3[_0xf68f('0x73')]=_0x18fd13[_0xf68f('0x71')][_0xf68f('0x74')];return _0x22a8bc(_0x23d2f3);})['catch'](function(_0x142a46){return _0x15d8b6(_0x142a46);});});}exports[_0xf68f('0x75')]=function(_0x2a8e3a,_0x47fd8c,_0x206f7a){var _0x4e7aff;var _0x5bd49a;var _0x1dbab8;var _0x5c8e7b=require(_0xf68f('0x47'));return db[_0xf68f('0x24')][_0xf68f('0x76')]({'where':{'id':_0x2a8e3a['params']['id']}})['then'](function(_0x2d77f5){if(_0x2d77f5){var _0x1c9074=util[_0xf68f('0x4a')](_0xf68f('0x4b'),_0x2d77f5[_0xf68f('0x49')]);if(fs[_0xf68f('0x4e')](_0x1c9074)){cypher=!![];return _0x5c8e7b[_0xf68f('0x5d')](_0x1c9074,_0x2d77f5[_0xf68f('0x49')],config[_0xf68f('0x4c')][_0xf68f('0x4d')])['then'](function(){return _0x2d77f5;});}return _0x2d77f5;}})[_0xf68f('0x21')](function(_0x18fcc0){if(!_0x18fcc0){throw new db['Sequelize'][(_0xf68f('0x5e'))]('Voice\x20Recording\x20not\x20found');}_0x5bd49a=_0x18fcc0;return db[_0xf68f('0x77')][_0xf68f('0x76')]({'where':{'id':0x1}});})[_0xf68f('0x21')](handleEntityNotFound(_0x47fd8c,null))[_0xf68f('0x21')](function(_0x362289){if(_0x362289){_0x4e7aff=_0x362289;if(!_0x4e7aff[_0xf68f('0x78')]||!_0x4e7aff['transcribeAccountId']||!_0x4e7aff[_0xf68f('0x79')]||!_0x4e7aff['language']||!_0x4e7aff[_0xf68f('0x6e')]){throw new db['Sequelize'][(_0xf68f('0x5e'))]('Transcribe\x20not\x20configured');}if(_0x2a8e3a[_0xf68f('0x44')][_0xf68f('0x7a')]&&(!_0x4e7aff[_0xf68f('0x7b')]||!_0x4e7aff[_0xf68f('0x7c')]||!_0x4e7aff['sentimentRegion']||!_0x4e7aff['language']||!_0x4e7aff[_0xf68f('0x6e')])){throw new db['Sequelize'][(_0xf68f('0x5e'))](_0xf68f('0x7d'));}return db[_0xf68f('0x7e')][_0xf68f('0x76')]({'where':{'id':_0x4e7aff[_0xf68f('0x7f')]}});}})[_0xf68f('0x21')](function(_0x1750bc){if(!_0x1750bc){throw new db[(_0xf68f('0x4f'))][(_0xf68f('0x5e'))](_0xf68f('0x80'));}if(!_0x1750bc['data1']||!_0x1750bc[_0xf68f('0x81')]){throw new db['Sequelize']['ValidationError'](_0xf68f('0x82'));}_0x1dbab8=_0x1750bc;return getBucketslist(_0x1dbab8['data1'],_0x1dbab8[_0xf68f('0x81')],_0x4e7aff[_0xf68f('0x79')]);})[_0xf68f('0x21')](function(_0x6ed2ce){if(_0x6ed2ce&&_0x6ed2ce[_0xf68f('0x83')]){var _0x361ab5=_['find'](_0x6ed2ce[_0xf68f('0x83')],function(_0x33ab76){return _0x33ab76[_0xf68f('0x84')]===_0x4e7aff[_0xf68f('0x6e')];});if(!_0x361ab5){logger[_0xf68f('0x60')](util['format']('[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available',_0x2a8e3a[_0xf68f('0x40')]['id'],_0x4e7aff[_0xf68f('0x6e')]));return createBucket(_0x1dbab8[_0xf68f('0x85')],_0x1dbab8[_0xf68f('0x81')],_0x4e7aff[_0xf68f('0x79')],_0x4e7aff[_0xf68f('0x6e')]);}logger[_0xf68f('0x60')](util[_0xf68f('0x4a')](_0xf68f('0x86'),_0x2a8e3a[_0xf68f('0x40')]['id'],_0x4e7aff[_0xf68f('0x6e')]));return;}})['then'](function(_0x2b5da6){if(_0x5bd49a[_0xf68f('0x73')]==='NEW'){return transcribe(_0x2a8e3a[_0xf68f('0x40')]['id'],_0x1dbab8[_0xf68f('0x85')],_0x1dbab8[_0xf68f('0x81')],_0x4e7aff[_0xf68f('0x79')],_0x4e7aff[_0xf68f('0x6e')],_0x5bd49a[_0xf68f('0x49')],_0x4e7aff[_0xf68f('0x87')]);}else{logger[_0xf68f('0x60')](util[_0xf68f('0x4a')]('[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested',_0x2a8e3a[_0xf68f('0x40')]['id']));return{'transcribeStatus':_0xf68f('0x88')};}})[_0xf68f('0x21')](function(_0x58d5df){if(_0x58d5df){_0x58d5df['tempSentiment']=_0x2a8e3a[_0xf68f('0x44')][_0xf68f('0x7a')];return _0x5bd49a['updateAttributes'](_0x58d5df);}})['then'](respondWithResult(_0x47fd8c,null))[_0xf68f('0x3e')](handleError(_0x47fd8c,null));};function writeFile(_0x3edc11,_0x31a4ab){return new Promise(function(_0x315917,_0x2ca6c4){fs['writeFile'](_0x31a4ab,_0x3edc11,function(_0x52a1ea,_0x26acfa){if(_0x52a1ea){return _0x2ca6c4(_0x52a1ea);}else{return _0x315917(_0x26acfa);}});});}exports[_0xf68f('0x89')]=function(_0x54948d,_0x17bb36,_0x2d4535){return db[_0xf68f('0x24')][_0xf68f('0x76')]({'where':{'id':_0x54948d[_0xf68f('0x40')]['id']}})['then'](handleEntityNotFound(_0x17bb36))[_0xf68f('0x21')](function(_0xcd3cad){if(_0xcd3cad&&_0xcd3cad[_0xf68f('0x8a')]){var _0xd484ee=_0xcd3cad['fileText'];var _0x1d4024=config[_0xf68f('0x8b')]+_0xf68f('0x8c')+_0xcd3cad['id']+_0xf68f('0x8d');if(fs['existsSync'](_0x1d4024)){return _0x1d4024;}return writeFile(_0xd484ee,_0x1d4024)[_0xf68f('0x21')](function(){return _0x1d4024;});}else{throw new db['Sequelize'][(_0xf68f('0x5e'))](_0xf68f('0x8e'));}})['then'](function(_0x52e5bb){return _0x17bb36['download'](_0x52e5bb);})[_0xf68f('0x3e')](handleError(_0x17bb36));};