7943fb5cf7686d2f53a8fc80c9c81dc279a48048
[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 _0xb4fb=['[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested','updateAttributes','downloadTranscribe','fileText','root','/server/files/transcribes/transcribe_','.txt','Transcript\x20not\x20available','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','aws-sdk','uuid/v4','ioredis','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','then','error','stack','name','VoiceRecording','rawAttributes','type','key','differenceBy','map','format','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','options','find','create','body','catch','describe','download','../../components/encryptor','value','%s.cypher','existsSync','decryptFile','Sequelize','ValidationError','VoiceRecording\x20not\x20found','filename','unlink','message','send','Not\x20found','sequelize','MD5','col','uniqueid','token','$and','push','secrets','recording','Entity\x20not\x20found','cancellazione\x20fisica\x20documento\x20%s','isNil','info','unlinkSync','.cypher','File:\x20\x22','listBuckets','createBucket','upload','startTranscriptionJob','basename','[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','TranscriptionJobName','TranscriptionJob','TranscriptionJobStatus','Voice\x20Recording\x20not\x20found','Setting','findOne','transcribe','transcribeRegion','language','runSentiment','sentiment','sentimentAccountId','sentimentRegion','Sentiment\x20Analysis\x20not\x20configured','transcribeAccountId','Cloud\x20Provider\x20not\x20available','data1','data2','Buckets','Name','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','NEW'];(function(_0x1099f9,_0x59a040){var _0x46eae8=function(_0x1b2d1a){while(--_0x1b2d1a){_0x1099f9['push'](_0x1099f9['shift']());}};_0x46eae8(++_0x59a040);}(_0xb4fb,0x13a));var _0xbb4f=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0xb4fb[_0x20a584];return _0x4b41a8;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbb4f('0x0'));var zipdir=require(_0xbb4f('0x1'));var jsonpatch=require(_0xbb4f('0x2'));var rp=require('request-promise');var moment=require(_0xbb4f('0x3'));var BPromise=require(_0xbb4f('0x4'));var Mustache=require(_0xbb4f('0x5'));var util=require('util');var path=require(_0xbb4f('0x6'));var sox=require('sox');var csv=require(_0xbb4f('0x7'));var ejs=require(_0xbb4f('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xbb4f('0x9'));var squel=require(_0xbb4f('0xa'));var crypto=require(_0xbb4f('0xb'));var jsforce=require(_0xbb4f('0xc'));var deskjs=require(_0xbb4f('0xd'));var toCsv=require(_0xbb4f('0x7'));var querystring=require(_0xbb4f('0xe'));var Papa=require(_0xbb4f('0xf'));var AWS=require(_0xbb4f('0x10'));var uuidv4=require(_0xbb4f('0x11'));var Redis=require(_0xbb4f('0x12'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xbb4f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xbb4f('0x14'))(_0xbb4f('0x15'));var utils=require(_0xbb4f('0x16'));var config=require(_0xbb4f('0x17'));var licenseUtil=require(_0xbb4f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x334728,_0x1d116b){_0x1d116b=_0x1d116b||0xcc;return function(_0x1c546c){if(_0x1c546c){return _0x334728[_0xbb4f('0x19')](_0x1d116b);}return _0x334728[_0xbb4f('0x1a')](_0x1d116b)[_0xbb4f('0x1b')]();};}function respondWithResult(_0x2882b9,_0x382f6f){_0x382f6f=_0x382f6f||0xc8;return function(_0x1bc297){if(_0x1bc297){return _0x2882b9[_0xbb4f('0x1a')](_0x382f6f)[_0xbb4f('0x1c')](_0x1bc297);}};}function respondWithFilteredResult(_0x32aeb9,_0x3b75c2){return function(_0x2b14fb){if(_0x2b14fb){var _0x38de3f=typeof _0x3b75c2[_0xbb4f('0x1d')]===_0xbb4f('0x1e')&&typeof _0x3b75c2[_0xbb4f('0x1f')]===_0xbb4f('0x1e');var _0x127138=_0x2b14fb[_0xbb4f('0x20')];var _0x13fcb8=_0x38de3f?0x0:_0x3b75c2[_0xbb4f('0x1d')];var _0x1e42dc=_0x38de3f?_0x2b14fb[_0xbb4f('0x20')]:_0x3b75c2['offset']+_0x3b75c2[_0xbb4f('0x1f')];var _0x43ced2;if(_0x1e42dc>=_0x127138){_0x1e42dc=_0x127138;_0x43ced2=0xc8;}else{_0x43ced2=0xce;}_0x32aeb9['status'](_0x43ced2);return _0x32aeb9[_0xbb4f('0x21')](_0xbb4f('0x22'),_0x13fcb8+'-'+_0x1e42dc+'/'+_0x127138)[_0xbb4f('0x1c')](_0x2b14fb);}return null;};}function patchUpdates(_0x58725c){return function(_0x100ebe){try{jsonpatch[_0xbb4f('0x23')](_0x100ebe,_0x58725c,!![]);}catch(_0x11744a){return BPromise[_0xbb4f('0x24')](_0x11744a);}return _0x100ebe[_0xbb4f('0x25')]();};}function saveUpdates(_0xf61503,_0x2309aa){return function(_0x4a2737){if(_0x4a2737){return _0x4a2737[_0xbb4f('0x26')](_0xf61503)['then'](function(_0x55b654){return _0x55b654;});}return null;};}function removeEntity(_0x1b1125,_0x46137f){return function(_0x26873c){if(_0x26873c){return _0x26873c[_0xbb4f('0x27')]()[_0xbb4f('0x28')](function(){_0x1b1125['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0xd44573,_0x5c1dc){return function(_0x48d43b){if(!_0x48d43b){_0xd44573['sendStatus'](0x194);}return _0x48d43b;};}function handleError(_0x23bea8,_0x26a70c){_0x26a70c=_0x26a70c||0x1f4;return function(_0x5310df){logger[_0xbb4f('0x29')](_0x5310df[_0xbb4f('0x2a')]);if(_0x5310df[_0xbb4f('0x2b')]){delete _0x5310df[_0xbb4f('0x2b')];}_0x23bea8[_0xbb4f('0x1a')](_0x26a70c)['send'](_0x5310df);};}exports['index']=function(_0x4cdf0e,_0x479aad){var _0x21ab5a={},_0x13b784={},_0x1a2a8d={'count':0x0,'rows':[]};var _0x4d4a8=_['map'](db[_0xbb4f('0x2c')][_0xbb4f('0x2d')],function(_0x3d56c0){return{'name':_0x3d56c0['fieldName'],'type':_0x3d56c0[_0xbb4f('0x2e')][_0xbb4f('0x2f')]};});_0x13b784['model']=_[_0xbb4f('0x30')](_[_0xbb4f('0x31')](_0x4d4a8,'name'),[_0xbb4f('0x32')]);_0x13b784[_0xbb4f('0x33')]=_[_0xbb4f('0x34')](_0x4cdf0e['query']);_0x13b784['filters']=_[_0xbb4f('0x35')](_0x13b784[_0xbb4f('0x36')],_0x13b784[_0xbb4f('0x33')]);_0x21ab5a[_0xbb4f('0x37')]=_[_0xbb4f('0x35')](_0x13b784['model'],qs[_0xbb4f('0x38')](_0x4cdf0e['query'][_0xbb4f('0x38')]));_0x21ab5a['attributes']=_0x21ab5a[_0xbb4f('0x37')][_0xbb4f('0x39')]?_0x21ab5a[_0xbb4f('0x37')]:_0x13b784[_0xbb4f('0x36')];if(!_0x4cdf0e[_0xbb4f('0x33')][_0xbb4f('0x3a')](_0xbb4f('0x3b'))){_0x21ab5a[_0xbb4f('0x1f')]=qs[_0xbb4f('0x1f')](_0x4cdf0e['query']['limit']);_0x21ab5a['offset']=qs[_0xbb4f('0x1d')](_0x4cdf0e[_0xbb4f('0x33')][_0xbb4f('0x1d')]);}_0x21ab5a[_0xbb4f('0x3c')]=qs['sort'](_0x4cdf0e[_0xbb4f('0x33')][_0xbb4f('0x3d')]);_0x21ab5a[_0xbb4f('0x3e')]=qs[_0xbb4f('0x3f')](_[_0xbb4f('0x40')](_0x4cdf0e[_0xbb4f('0x33')],_0x13b784['filters']),_0x4d4a8);if(_0x4cdf0e[_0xbb4f('0x33')][_0xbb4f('0x41')]){_0x21ab5a[_0xbb4f('0x3e')]=_[_0xbb4f('0x42')](_0x21ab5a[_0xbb4f('0x3e')],{'$or':_['map'](_0x4d4a8,function(_0x4fbcec){if(_0x4fbcec[_0xbb4f('0x2e')]!==_0xbb4f('0x43')){var _0x3990f2={};_0x3990f2[_0x4fbcec['name']]={'$like':'%'+_0x4cdf0e[_0xbb4f('0x33')][_0xbb4f('0x41')]+'%'};return _0x3990f2;}})});}_0x21ab5a=_[_0xbb4f('0x42')]({},_0x21ab5a,_0x4cdf0e['options']);var _0x51dc2d={'where':_0x21ab5a['where']};return db['VoiceRecording']['count'](_0x51dc2d)[_0xbb4f('0x28')](function(_0xe59d9c){_0x1a2a8d[_0xbb4f('0x20')]=_0xe59d9c;if(_0x4cdf0e['query'][_0xbb4f('0x44')]){_0x21ab5a[_0xbb4f('0x45')]=[{'all':!![]}];}return db[_0xbb4f('0x2c')][_0xbb4f('0x46')](_0x21ab5a);})['then'](function(_0x4eb50b){_0x1a2a8d[_0xbb4f('0x47')]=_0x4eb50b;return _0x1a2a8d;})[_0xbb4f('0x28')](respondWithFilteredResult(_0x479aad,_0x21ab5a))['catch'](handleError(_0x479aad,null));};exports[_0xbb4f('0x48')]=function(_0x5edd27,_0x17599b){var _0xc42b0a={'raw':![],'where':{'id':_0x5edd27[_0xbb4f('0x49')]['id']}},_0x2d389b={};_0x2d389b[_0xbb4f('0x36')]=_['keys'](db['VoiceRecording'][_0xbb4f('0x2d')]);_0x2d389b[_0xbb4f('0x33')]=_[_0xbb4f('0x34')](_0x5edd27[_0xbb4f('0x33')]);_0x2d389b['filters']=_[_0xbb4f('0x35')](_0x2d389b['model'],_0x2d389b[_0xbb4f('0x33')]);_0xc42b0a[_0xbb4f('0x37')]=_[_0xbb4f('0x35')](_0x2d389b[_0xbb4f('0x36')],qs[_0xbb4f('0x38')](_0x5edd27[_0xbb4f('0x33')][_0xbb4f('0x38')]));_0xc42b0a[_0xbb4f('0x37')]=_0xc42b0a[_0xbb4f('0x37')][_0xbb4f('0x39')]?_0xc42b0a['attributes']:_0x2d389b[_0xbb4f('0x36')];if(_0x5edd27[_0xbb4f('0x33')][_0xbb4f('0x44')]){_0xc42b0a[_0xbb4f('0x45')]=[{'all':!![]}];}_0xc42b0a=_[_0xbb4f('0x42')]({},_0xc42b0a,_0x5edd27[_0xbb4f('0x4a')]);return db[_0xbb4f('0x2c')][_0xbb4f('0x4b')](_0xc42b0a)[_0xbb4f('0x28')](handleEntityNotFound(_0x17599b,null))[_0xbb4f('0x28')](respondWithResult(_0x17599b,null))['catch'](handleError(_0x17599b,null));};exports['create']=function(_0x39f8b5,_0x5c4c86){return db[_0xbb4f('0x2c')][_0xbb4f('0x4c')](_0x39f8b5[_0xbb4f('0x4d')],{})[_0xbb4f('0x28')](respondWithResult(_0x5c4c86,0xc9))[_0xbb4f('0x4e')](handleError(_0x5c4c86,null));};exports[_0xbb4f('0x26')]=function(_0x17cbe4,_0x113669){if(_0x17cbe4[_0xbb4f('0x4d')]['id']){delete _0x17cbe4[_0xbb4f('0x4d')]['id'];}return db[_0xbb4f('0x2c')][_0xbb4f('0x4b')]({'where':{'id':_0x17cbe4[_0xbb4f('0x49')]['id']}})[_0xbb4f('0x28')](handleEntityNotFound(_0x113669,null))[_0xbb4f('0x28')](saveUpdates(_0x17cbe4[_0xbb4f('0x4d')],null))[_0xbb4f('0x28')](respondWithResult(_0x113669,null))[_0xbb4f('0x4e')](handleError(_0x113669,null));};exports[_0xbb4f('0x4f')]=function(_0x5ebc9c,_0x8f992e){return db['VoiceRecording'][_0xbb4f('0x4f')]()['then'](respondWithResult(_0x8f992e,null))[_0xbb4f('0x4e')](handleError(_0x8f992e,null));};exports[_0xbb4f('0x50')]=function(_0x25c6b8,_0x552eca,_0x3dba56){var _0xb2ca94=require(_0xbb4f('0x51'));var _0xf11406=![];var _0x3a3a40={};if(_0x25c6b8[_0xbb4f('0x33')]['type']&&_0x25c6b8[_0xbb4f('0x33')][_0xbb4f('0x2e')]==='uniqueid'){_0x3a3a40['uniqueid']=_0x25c6b8[_0xbb4f('0x49')]['id'];}else{_0x3a3a40['id']=_0x25c6b8[_0xbb4f('0x49')]['id'];}return db[_0xbb4f('0x2c')]['find']({'where':_0x3a3a40,'attributes':['id',_0xbb4f('0x52')],'raw':!![]})[_0xbb4f('0x28')](handleEntityNotFound(_0x552eca,null))[_0xbb4f('0x28')](function(_0x4535a6){if(_0x4535a6){var _0x56bfe5=_0x4535a6[_0xbb4f('0x52')];var _0x4a90ce=util[_0xbb4f('0x32')](_0xbb4f('0x53'),_0x56bfe5);if(fs[_0xbb4f('0x54')](_0x4a90ce)){_0xf11406=!![];return _0xb2ca94[_0xbb4f('0x55')](_0x4a90ce,_0x56bfe5,config['secrets']['recording'])[_0xbb4f('0x28')](function(){return _0x4535a6;});}return _0x4535a6;}})[_0xbb4f('0x28')](function(_0x17ae40){if(_0x17ae40){var _0xc7a85b=_0x17ae40[_0xbb4f('0x52')];if(!fs[_0xbb4f('0x54')](_0xc7a85b)){throw new db[(_0xbb4f('0x56'))][(_0xbb4f('0x57'))](_0xbb4f('0x58'));}if(_0x17ae40[_0xbb4f('0x59')]){return _0x552eca[_0xbb4f('0x50')](_0xc7a85b,_0x17ae40[_0xbb4f('0x59')]+path['extname'](_0xc7a85b),function(){if(_0xf11406){fs['unlink'](_0xc7a85b);}});}else{return _0x552eca[_0xbb4f('0x50')](_0xc7a85b,function(_0x133a68){if(_0xf11406){fs[_0xbb4f('0x5a')](_0xc7a85b);}});}}})[_0xbb4f('0x4e')](function(_0x40df5d){if(_0x40df5d[_0xbb4f('0x5b')]==='VoiceRecording\x20not\x20found'){_0x552eca[_0xbb4f('0x1a')](0x194)[_0xbb4f('0x5c')](_0xbb4f('0x5d'));}else{return handleError(_0x552eca,null);}});};exports['downloads']=function(_0x1d5b76,_0x524917,_0x59bf9a){var _0x3e7743=require('../../components/encryptor');var _0x18940d=![];var _0x514e22={'$and':[db[_0xbb4f('0x5e')][_0xbb4f('0x3e')](db[_0xbb4f('0x5e')]['fn'](_0xbb4f('0x5f'),db[_0xbb4f('0x5e')][_0xbb4f('0x60')](_0xbb4f('0x61'))),_0x1d5b76[_0xbb4f('0x33')][_0xbb4f('0x62')])]};if(_0x1d5b76[_0xbb4f('0x33')][_0xbb4f('0x2e')]&&_0x1d5b76[_0xbb4f('0x33')][_0xbb4f('0x2e')]==='uniqueid'){_0x514e22[_0xbb4f('0x63')][_0xbb4f('0x64')]({'uniqueid':_0x1d5b76['params']['id']});}else{_0x514e22['$and'][_0xbb4f('0x64')]({'id':_0x1d5b76['params']['id']});}return db[_0xbb4f('0x2c')]['find']({'where':_0x514e22,'attributes':['id',_0xbb4f('0x52')],'raw':!![]})[_0xbb4f('0x28')](handleEntityNotFound(_0x524917,null))[_0xbb4f('0x28')](function(_0x2910bf){if(_0x2910bf){var _0x177457=util[_0xbb4f('0x32')](_0xbb4f('0x53'),_0x2910bf['value']);if(fs[_0xbb4f('0x54')](_0x177457)){_0x18940d=!![];return _0x3e7743[_0xbb4f('0x55')](_0x177457,_0x2910bf[_0xbb4f('0x52')],config[_0xbb4f('0x65')][_0xbb4f('0x66')])[_0xbb4f('0x28')](function(){return _0x2910bf;});}return _0x2910bf;}})[_0xbb4f('0x28')](function(_0x5a6a0f){if(_0x5a6a0f){if(!fs[_0xbb4f('0x54')](_0x5a6a0f[_0xbb4f('0x52')])){throw new db[(_0xbb4f('0x56'))][(_0xbb4f('0x57'))]('VoiceRecording\x20not\x20found');}if(_0x5a6a0f[_0xbb4f('0x59')]){return _0x524917[_0xbb4f('0x50')](_0x5a6a0f[_0xbb4f('0x52')],_0x5a6a0f[_0xbb4f('0x59')]+path['extname'](_0x5a6a0f[_0xbb4f('0x52')]),function(){if(_0x18940d){fs[_0xbb4f('0x5a')](_0x5a6a0f[_0xbb4f('0x52')]);}});}else{return _0x524917[_0xbb4f('0x50')](_0x5a6a0f['value'],function(_0x368bd3){if(_0x18940d){fs[_0xbb4f('0x5a')](_0x5a6a0f['value']);}});}}})[_0xbb4f('0x4e')](handleError(_0x524917,null));};exports[_0xbb4f('0x27')]=function(_0x579d41,_0x2c1595){return db[_0xbb4f('0x2c')][_0xbb4f('0x4b')]({'where':{'id':_0x579d41[_0xbb4f('0x49')]['id']}})[_0xbb4f('0x28')](function(_0x158bea){if(_['isNil'](_0x158bea)){throw new ReferenceError(_0xbb4f('0x67'));}return _0x158bea;})['then'](function(_0x3b50e7){var _0x1c5536=_0x3b50e7[_0xbb4f('0x52')];logger['info'](_0xbb4f('0x68'),_0x1c5536);if(!_[_0xbb4f('0x69')](_0x3b50e7[_0xbb4f('0x52')])&&fs[_0xbb4f('0x54')](_0x1c5536)){logger[_0xbb4f('0x6a')]('File:\x20\x22'+_0x1c5536+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs[_0xbb4f('0x6b')](_0x1c5536);}_0x1c5536=_0x1c5536+_0xbb4f('0x6c');if(!_[_0xbb4f('0x69')](_0x3b50e7[_0xbb4f('0x52')])&&fs[_0xbb4f('0x54')](_0x1c5536)){logger[_0xbb4f('0x6a')](_0xbb4f('0x6d')+_0x1c5536+'\x22\x20trovato\x20eseguo\x20la\x20cancellazione');fs['unlinkSync'](_0x1c5536);}return _0x3b50e7;})[_0xbb4f('0x28')](function(_0x3fcf30){if(!_0x3fcf30)throw new InternalError();return _0x3fcf30[_0xbb4f('0x27')]();})[_0xbb4f('0x28')](function(){_0x2c1595[_0xbb4f('0x1a')](0xcc)['end']();})['catch'](handleError(_0x2c1595,null));};function getBucketslist(_0x40aed0,_0x1babb0,_0x3045f6){return new Promise(function(_0x169fc2,_0xbcff7f){var _0x1d68ed=new AWS['S3']({'accessKeyId':_0x1babb0,'secretAccessKey':_0x40aed0,'region':_0x3045f6});_0x1d68ed[_0xbb4f('0x6e')]({},function(_0x56daa8,_0x25c22a){if(_0x56daa8){return _0xbcff7f(_0x56daa8);}else{return _0x169fc2(_0x25c22a);}});});}function createBucket(_0x800bf8,_0x30c6da,_0x96b46f,_0x50e15c){return new Promise(function(_0x2e20f0,_0x226bfa){var _0x4ae907=new AWS['S3']({'accessKeyId':_0x30c6da,'secretAccessKey':_0x800bf8,'region':_0x96b46f});_0x4ae907[_0xbb4f('0x6f')]({'Bucket':_0x50e15c},function(_0x24d66e,_0xaac51b){if(_0x24d66e){return _0x226bfa(_0x24d66e);}else{return _0x2e20f0(_0xaac51b);}});});}function uploadFile(_0x12a895,_0x1967ac,_0x10d0bf,_0x31a691,_0x1f5033,_0x43983e){return new Promise(function(_0x27927f,_0x1fbd7d){var _0x2f2396=new AWS['S3']({'accessKeyId':_0x1967ac,'secretAccessKey':_0x12a895,'region':_0x10d0bf});_0x2f2396[_0xbb4f('0x70')]({'Bucket':_0x31a691,'Key':_0x1f5033,'Body':_0x43983e},function(_0x32a519,_0x14ccea){if(_0x32a519){return _0x1fbd7d(_0x32a519);}else{return _0x27927f(_0x14ccea);}});});}function startTranscribe(_0x2bcd76,_0x3c3715,_0x2fed5f,_0x556f8d,_0x293953,_0x1b0c16){return new Promise(function(_0x1544cf,_0x3a467e){var _0x42f0aa=new AWS['TranscribeService']({'accessKeyId':_0x3c3715,'secretAccessKey':_0x2bcd76,'region':_0x2fed5f});_0x42f0aa[_0xbb4f('0x71')]({'TranscriptionJobName':_0x556f8d,'LanguageCode':_0x293953,'Media':{'MediaFileUri':_0x1b0c16}},function(_0x19de31,_0x41f65f){if(_0x19de31){return _0x3a467e(_0x19de31);}else{return _0x1544cf(_0x41f65f);}});});}function transcribe(_0x28c482,_0x5168b9,_0x3b1368,_0x17bd59,_0x144e46,_0x2120b4,_0x345a5a){return new Promise(function(_0x201479,_0x4f8fd0){var _0x2626f0={};logger[_0xbb4f('0x6a')](util[_0xbb4f('0x32')]('[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s',_0x28c482,_0x144e46));return uploadFile(_0x5168b9,_0x3b1368,_0x17bd59,_0x144e46,path[_0xbb4f('0x72')](_0x2120b4),fs['readFileSync'](_0x2120b4))['then'](function(_0x518d20){logger[_0xbb4f('0x6a')](util[_0xbb4f('0x32')](_0xbb4f('0x73'),_0x28c482,_0x144e46,_0x518d20[_0xbb4f('0x74')]));_0x2626f0[_0xbb4f('0x75')]=_0x518d20[_0xbb4f('0x76')];_0x2626f0[_0xbb4f('0x77')]=_0x518d20[_0xbb4f('0x74')];logger['info'](util[_0xbb4f('0x32')](_0xbb4f('0x78'),_0x28c482));return startTranscribe(_0x5168b9,_0x3b1368,_0x17bd59,uuidv4(),_0x345a5a,_0x518d20[_0xbb4f('0x74')]);})['then'](function(_0xdf510c){logger[_0xbb4f('0x6a')](util['format'](_0xbb4f('0x79'),_0x28c482,_0xdf510c['TranscriptionJob'][_0xbb4f('0x7a')]));_0x2626f0['transcribeName']=_0xdf510c[_0xbb4f('0x7b')]['TranscriptionJobName'];_0x2626f0['transcribeStatus']=_0xdf510c[_0xbb4f('0x7b')][_0xbb4f('0x7c')];return _0x201479(_0x2626f0);})[_0xbb4f('0x4e')](function(_0x49595d){return _0x4f8fd0(_0x49595d);});});}exports['runTranscribe']=function(_0x452a9f,_0x272205,_0x369ce6){var _0x1da5bb;var _0x146aaf;var _0x7f71f9;var _0x4463ec=require(_0xbb4f('0x51'));return db['VoiceRecording']['findOne']({'where':{'id':_0x452a9f[_0xbb4f('0x49')]['id']}})[_0xbb4f('0x28')](function(_0x367746){if(_0x367746){var _0x11dd8c=util[_0xbb4f('0x32')](_0xbb4f('0x53'),_0x367746[_0xbb4f('0x52')]);if(fs['existsSync'](_0x11dd8c)){cypher=!![];return _0x4463ec[_0xbb4f('0x55')](_0x11dd8c,_0x367746[_0xbb4f('0x52')],config[_0xbb4f('0x65')]['recording'])[_0xbb4f('0x28')](function(){return _0x367746;});}return _0x367746;}})['then'](function(_0x4042b3){if(!_0x4042b3){throw new db['Sequelize'][(_0xbb4f('0x57'))](_0xbb4f('0x7d'));}_0x146aaf=_0x4042b3;return db[_0xbb4f('0x7e')][_0xbb4f('0x7f')]({'where':{'id':0x1}});})[_0xbb4f('0x28')](handleEntityNotFound(_0x272205,null))[_0xbb4f('0x28')](function(_0x25a5ac){if(_0x25a5ac){_0x1da5bb=_0x25a5ac;if(!_0x1da5bb[_0xbb4f('0x80')]||!_0x1da5bb['transcribeAccountId']||!_0x1da5bb[_0xbb4f('0x81')]||!_0x1da5bb[_0xbb4f('0x82')]||!_0x1da5bb[_0xbb4f('0x75')]){throw new db[(_0xbb4f('0x56'))]['ValidationError']('Transcribe\x20not\x20configured');}if(_0x452a9f['body'][_0xbb4f('0x83')]&&(!_0x1da5bb[_0xbb4f('0x84')]||!_0x1da5bb[_0xbb4f('0x85')]||!_0x1da5bb[_0xbb4f('0x86')]||!_0x1da5bb[_0xbb4f('0x82')]||!_0x1da5bb[_0xbb4f('0x75')])){throw new db['Sequelize'][(_0xbb4f('0x57'))](_0xbb4f('0x87'));}return db['CloudProvider']['findOne']({'where':{'id':_0x1da5bb[_0xbb4f('0x88')]}});}})[_0xbb4f('0x28')](function(_0x105062){if(!_0x105062){throw new db[(_0xbb4f('0x56'))][(_0xbb4f('0x57'))](_0xbb4f('0x89'));}if(!_0x105062['data1']||!_0x105062['data2']){throw new db[(_0xbb4f('0x56'))][(_0xbb4f('0x57'))]('Cloud\x20Provider\x20not\x20configured');}_0x7f71f9=_0x105062;return getBucketslist(_0x7f71f9[_0xbb4f('0x8a')],_0x7f71f9[_0xbb4f('0x8b')],_0x1da5bb[_0xbb4f('0x81')]);})[_0xbb4f('0x28')](function(_0x14a87f){if(_0x14a87f&&_0x14a87f[_0xbb4f('0x8c')]){var _0x5a71dc=_[_0xbb4f('0x4b')](_0x14a87f[_0xbb4f('0x8c')],function(_0x295039){return _0x295039[_0xbb4f('0x8d')]===_0x1da5bb[_0xbb4f('0x75')];});if(!_0x5a71dc){logger[_0xbb4f('0x6a')](util[_0xbb4f('0x32')](_0xbb4f('0x8e'),_0x452a9f[_0xbb4f('0x49')]['id'],_0x1da5bb[_0xbb4f('0x75')]));return createBucket(_0x7f71f9[_0xbb4f('0x8a')],_0x7f71f9[_0xbb4f('0x8b')],_0x1da5bb[_0xbb4f('0x81')],_0x1da5bb[_0xbb4f('0x75')]);}logger[_0xbb4f('0x6a')](util[_0xbb4f('0x32')](_0xbb4f('0x8f'),_0x452a9f[_0xbb4f('0x49')]['id'],_0x1da5bb['bucket']));return;}})[_0xbb4f('0x28')](function(_0x4c8c07){if(_0x146aaf['transcribeStatus']===_0xbb4f('0x90')){return transcribe(_0x452a9f[_0xbb4f('0x49')]['id'],_0x7f71f9[_0xbb4f('0x8a')],_0x7f71f9[_0xbb4f('0x8b')],_0x1da5bb[_0xbb4f('0x81')],_0x1da5bb[_0xbb4f('0x75')],_0x146aaf[_0xbb4f('0x52')],_0x1da5bb[_0xbb4f('0x82')]);}else{logger[_0xbb4f('0x6a')](util[_0xbb4f('0x32')](_0xbb4f('0x91'),_0x452a9f[_0xbb4f('0x49')]['id']));return{'transcribeStatus':'IN_PROGRESS'};}})[_0xbb4f('0x28')](function(_0x1baa6d){if(_0x1baa6d){_0x1baa6d['tempSentiment']=_0x452a9f[_0xbb4f('0x4d')][_0xbb4f('0x83')];return _0x146aaf[_0xbb4f('0x92')](_0x1baa6d);}})[_0xbb4f('0x28')](respondWithResult(_0x272205,null))[_0xbb4f('0x4e')](handleError(_0x272205,null));};function writeFile(_0x168e4c,_0x261461){return new Promise(function(_0x444002,_0x200f89){fs['writeFile'](_0x261461,_0x168e4c,function(_0x145dc1,_0x3c8b63){if(_0x145dc1){return _0x200f89(_0x145dc1);}else{return _0x444002(_0x3c8b63);}});});}exports[_0xbb4f('0x93')]=function(_0x2b46ea,_0x461801,_0x5a560c){return db['VoiceRecording']['findOne']({'where':{'id':_0x2b46ea[_0xbb4f('0x49')]['id']}})[_0xbb4f('0x28')](handleEntityNotFound(_0x461801))['then'](function(_0x34b8a3){if(_0x34b8a3&&_0x34b8a3[_0xbb4f('0x94')]){var _0x191536=_0x34b8a3['fileText'];var _0x151751=config[_0xbb4f('0x95')]+_0xbb4f('0x96')+_0x34b8a3['id']+_0xbb4f('0x97');if(fs[_0xbb4f('0x54')](_0x151751)){return _0x151751;}return writeFile(_0x191536,_0x151751)[_0xbb4f('0x28')](function(){return _0x151751;});}else{throw new db[(_0xbb4f('0x56'))][(_0xbb4f('0x57'))](_0xbb4f('0x98'));}})[_0xbb4f('0x28')](function(_0x3a7686){return _0x461801[_0xbb4f('0x50')](_0x3a7686);})[_0xbb4f('0x4e')](handleError(_0x461801));};