83be7fe68d7e4cf7fdfc0e6c9bbd9740c8be5c32
[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 _0x9f15=['info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','isNil','listBuckets','createBucket','upload','TranscribeService','[RUNTRANSCRIPT][%d]\x20Starting\x20voice\x20recording\x20upload\x20in\x20bucket\x20%s','basename','readFileSync','bucket','Bucket','location','Location','TranscriptionJob','TranscriptionJobName','transcribeName','TranscriptionJobStatus','findOne','Voice\x20Recording\x20not\x20found','Setting','transcribe','transcribeRegion','language','Transcribe\x20not\x20configured','runSentiment','sentimentAccountId','sentimentRegion','CloudProvider','transcribeAccountId','Cloud\x20Provider\x20not\x20available','data1','data2','Cloud\x20Provider\x20not\x20configured','Buckets','Name','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20not\x20available','[RUNTRANSCRIPT][%d]\x20Bucket\x20%s\x20available','transcribeStatus','IN_PROGRESS','tempSentiment','writeFile','downloadTranscribe','fileText','root','/server/files/transcribes/transcribe_','.txt','Transcript\x20not\x20available','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','path','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','aws-sdk','uuid/v4','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','destroy','error','stack','name','send','render','merge','body','message','agent','interaction','account','index','VoiceRecording','rawAttributes','fieldName','type','model','differenceBy','format','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','where','filters','pick','filter','VIRTUAL','options','includeAll','include','rows','catch','show','find','create','describe','../../components/encryptor','uniqueid','params','value','%s.cypher','existsSync','decryptFile','Sequelize','ValidationError','VoiceRecording\x20not\x20found','filename','extname','unlink','download','Not\x20found','downloads','sequelize','col','token','$and','push','secrets','recording','Entity\x20not\x20found'];(function(_0x4c321c,_0x3e9da0){var _0x25accb=function(_0x21bf7a){while(--_0x21bf7a){_0x4c321c['push'](_0x4c321c['shift']());}};_0x25accb(++_0x3e9da0);}(_0x9f15,0x16e));var _0x59f1=function(_0x44ca6e,_0x5e2c91){_0x44ca6e=_0x44ca6e-0x0;var _0x2edab2=_0x9f15[_0x44ca6e];return _0x2edab2;};'use strict';var emlformat=require(_0x59f1('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x59f1('0x1'));var jsonpatch=require(_0x59f1('0x2'));var rp=require(_0x59f1('0x3'));var moment=require('moment');var BPromise=require(_0x59f1('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0x59f1('0x5'));var sox=require('sox');var csv=require(_0x59f1('0x6'));var ejs=require(_0x59f1('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x59f1('0x8'));var squel=require(_0x59f1('0x9'));var crypto=require(_0x59f1('0xa'));var jsforce=require(_0x59f1('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x59f1('0xc'));var Papa=require(_0x59f1('0xd'));var AWS=require(_0x59f1('0xe'));var uuidv4=require(_0x59f1('0xf'));var Redis=require(_0x59f1('0x10'));var authService=require(_0x59f1('0x11'));var qs=require(_0x59f1('0x12'));var as=require(_0x59f1('0x13'));var hardwareService=require(_0x59f1('0x14'));var logger=require('../../config/logger')(_0x59f1('0x15'));var utils=require(_0x59f1('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x59f1('0x17'));var db=require(_0x59f1('0x18'))['db'];function respondWithStatusCode(_0x5541eb,_0x552ec2){_0x552ec2=_0x552ec2||0xcc;return function(_0x46bf82){if(_0x46bf82){return _0x5541eb[_0x59f1('0x19')](_0x552ec2);}return _0x5541eb[_0x59f1('0x1a')](_0x552ec2)[_0x59f1('0x1b')]();};}function respondWithResult(_0x120023,_0x1a7b01){_0x1a7b01=_0x1a7b01||0xc8;return function(_0x3b753d){if(_0x3b753d){return _0x120023[_0x59f1('0x1a')](_0x1a7b01)[_0x59f1('0x1c')](_0x3b753d);}};}function respondWithFilteredResult(_0x26c8c0,_0x4546d8){return function(_0x2e0612){if(_0x2e0612){var _0x19c75d=typeof _0x4546d8[_0x59f1('0x1d')]===_0x59f1('0x1e')&&typeof _0x4546d8[_0x59f1('0x1f')]===_0x59f1('0x1e');var _0x2fa856=_0x2e0612[_0x59f1('0x20')];var _0x15674a=_0x19c75d?0x0:_0x4546d8[_0x59f1('0x1d')];var _0x1458f4=_0x19c75d?_0x2e0612[_0x59f1('0x20')]:_0x4546d8[_0x59f1('0x1d')]+_0x4546d8[_0x59f1('0x1f')];var _0x1c5d97;if(_0x1458f4>=_0x2fa856){_0x1458f4=_0x2fa856;_0x1c5d97=0xc8;}else{_0x1c5d97=0xce;}_0x26c8c0[_0x59f1('0x1a')](_0x1c5d97);return _0x26c8c0[_0x59f1('0x21')](_0x59f1('0x22'),_0x15674a+'-'+_0x1458f4+'/'+_0x2fa856)[_0x59f1('0x1c')](_0x2e0612);}return null;};}function patchUpdates(_0x19fe3a){return function(_0x42ac33){try{jsonpatch['apply'](_0x42ac33,_0x19fe3a,!![]);}catch(_0x4e1fe9){return BPromise[_0x59f1('0x23')](_0x4e1fe9);}return _0x42ac33[_0x59f1('0x24')]();};}function saveUpdates(_0x439cb2,_0x1862b3){return function(_0x597c1c){if(_0x597c1c){return _0x597c1c[_0x59f1('0x25')](_0x439cb2)[_0x59f1('0x26')](function(_0x4477f9){return _0x4477f9;});}return null;};}function removeEntity(_0x5c7f6a,_0x11fd22){return function(_0x5c9525){if(_0x5c9525){return _0x5c9525[_0x59f1('0x27')]()[_0x59f1('0x26')](function(){_0x5c7f6a[_0x59f1('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2d537a,_0x1df61c){return function(_0x3e1087){if(!_0x3e1087){_0x2d537a[_0x59f1('0x19')](0x194);}return _0x3e1087;};}function handleError(_0x1b4831,_0x31e7e6){_0x31e7e6=_0x31e7e6||0x1f4;return function(_0x28a11c){logger[_0x59f1('0x28')](_0x28a11c[_0x59f1('0x29')]);if(_0x28a11c[_0x59f1('0x2a')]){delete _0x28a11c[_0x59f1('0x2a')];}_0x1b4831[_0x59f1('0x1a')](_0x31e7e6)[_0x59f1('0x2b')](_0x28a11c);};}function getMustacheRender(_0x508606,_0x56adb6){return Mustache[_0x59f1('0x2c')](_0x508606,_[_0x59f1('0x2d')](_0x56adb6[_0x59f1('0x2e')],{'contact':_0x56adb6['contact'],'message':_0x56adb6[_0x59f1('0x2f')],'agent':_0x56adb6[_0x59f1('0x30')],'interaction':_0x56adb6[_0x59f1('0x31')],'account':_0x56adb6[_0x59f1('0x32')]}))||'';}exports[_0x59f1('0x33')]=function(_0x52697c,_0x473b63){var _0x331abd={},_0x2e3e39={},_0x4c614e={'count':0x0,'rows':[]};var _0x1a223d=_['map'](db[_0x59f1('0x34')][_0x59f1('0x35')],function(_0x3f395c){return{'name':_0x3f395c[_0x59f1('0x36')],'type':_0x3f395c[_0x59f1('0x37')]['key']};});_0x2e3e39[_0x59f1('0x38')]=_[_0x59f1('0x39')](_['map'](_0x1a223d,_0x59f1('0x2a')),[_0x59f1('0x3a')]);_0x2e3e39[_0x59f1('0x3b')]=_[_0x59f1('0x3c')](_0x52697c[_0x59f1('0x3b')]);_0x2e3e39['filters']=_[_0x59f1('0x3d')](_0x2e3e39[_0x59f1('0x38')],_0x2e3e39['query']);_0x331abd[_0x59f1('0x3e')]=_[_0x59f1('0x3d')](_0x2e3e39[_0x59f1('0x38')],qs[_0x59f1('0x3f')](_0x52697c[_0x59f1('0x3b')][_0x59f1('0x3f')]));_0x331abd['attributes']=_0x331abd[_0x59f1('0x3e')][_0x59f1('0x40')]?_0x331abd['attributes']:_0x2e3e39[_0x59f1('0x38')];if(!_0x52697c[_0x59f1('0x3b')][_0x59f1('0x41')](_0x59f1('0x42'))){_0x331abd['limit']=qs[_0x59f1('0x1f')](_0x52697c[_0x59f1('0x3b')][_0x59f1('0x1f')]);_0x331abd[_0x59f1('0x1d')]=qs[_0x59f1('0x1d')](_0x52697c[_0x59f1('0x3b')][_0x59f1('0x1d')]);}_0x331abd['order']=qs['sort'](_0x52697c['query']['sort']);_0x331abd[_0x59f1('0x43')]=qs[_0x59f1('0x44')](_[_0x59f1('0x45')](_0x52697c[_0x59f1('0x3b')],_0x2e3e39[_0x59f1('0x44')]),_0x1a223d);if(_0x52697c['query'][_0x59f1('0x46')]){_0x331abd[_0x59f1('0x43')]=_[_0x59f1('0x2d')](_0x331abd[_0x59f1('0x43')],{'$or':_['map'](_0x1a223d,function(_0x4846ff){if(_0x4846ff[_0x59f1('0x37')]!==_0x59f1('0x47')){var _0x2d9620={};_0x2d9620[_0x4846ff[_0x59f1('0x2a')]]={'$like':'%'+_0x52697c[_0x59f1('0x3b')][_0x59f1('0x46')]+'%'};return _0x2d9620;}})});}_0x331abd=_['merge']({},_0x331abd,_0x52697c[_0x59f1('0x48')]);var _0x220793={'where':_0x331abd[_0x59f1('0x43')]};return db['VoiceRecording'][_0x59f1('0x20')](_0x220793)[_0x59f1('0x26')](function(_0x5a1f1e){_0x4c614e[_0x59f1('0x20')]=_0x5a1f1e;if(_0x52697c[_0x59f1('0x3b')][_0x59f1('0x49')]){_0x331abd[_0x59f1('0x4a')]=[{'all':!![]}];}return db[_0x59f1('0x34')]['findAll'](_0x331abd);})['then'](function(_0x360566){_0x4c614e[_0x59f1('0x4b')]=_0x360566;return _0x4c614e;})[_0x59f1('0x26')](respondWithFilteredResult(_0x473b63,_0x331abd))[_0x59f1('0x4c')](handleError(_0x473b63,null));};exports[_0x59f1('0x4d')]=function(_0x48cb23,_0x145886){var _0x5473bf={'raw':![],'where':{'id':_0x48cb23['params']['id']}},_0x3ecbd6={};_0x3ecbd6[_0x59f1('0x38')]=_['keys'](db['VoiceRecording'][_0x59f1('0x35')]);_0x3ecbd6[_0x59f1('0x3b')]=_[_0x59f1('0x3c')](_0x48cb23[_0x59f1('0x3b')]);_0x3ecbd6['filters']=_['intersection'](_0x3ecbd6['model'],_0x3ecbd6['query']);_0x5473bf[_0x59f1('0x3e')]=_[_0x59f1('0x3d')](_0x3ecbd6[_0x59f1('0x38')],qs[_0x59f1('0x3f')](_0x48cb23[_0x59f1('0x3b')][_0x59f1('0x3f')]));_0x5473bf[_0x59f1('0x3e')]=_0x5473bf[_0x59f1('0x3e')][_0x59f1('0x40')]?_0x5473bf[_0x59f1('0x3e')]:_0x3ecbd6[_0x59f1('0x38')];if(_0x48cb23[_0x59f1('0x3b')][_0x59f1('0x49')]){_0x5473bf[_0x59f1('0x4a')]=[{'all':!![]}];}_0x5473bf=_[_0x59f1('0x2d')]({},_0x5473bf,_0x48cb23[_0x59f1('0x48')]);return db[_0x59f1('0x34')][_0x59f1('0x4e')](_0x5473bf)[_0x59f1('0x26')](handleEntityNotFound(_0x145886,null))[_0x59f1('0x26')](respondWithResult(_0x145886,null))[_0x59f1('0x4c')](handleError(_0x145886,null));};exports[_0x59f1('0x4f')]=function(_0x4f556a,_0xea2029){return db['VoiceRecording'][_0x59f1('0x4f')](_0x4f556a[_0x59f1('0x2e')],{})[_0x59f1('0x26')](respondWithResult(_0xea2029,0xc9))['catch'](handleError(_0xea2029,null));};exports['update']=function(_0x22e3ff,_0x38d238){if(_0x22e3ff[_0x59f1('0x2e')]['id']){delete _0x22e3ff[_0x59f1('0x2e')]['id'];}return db[_0x59f1('0x34')][_0x59f1('0x4e')]({'where':{'id':_0x22e3ff['params']['id']}})[_0x59f1('0x26')](handleEntityNotFound(_0x38d238,null))[_0x59f1('0x26')](saveUpdates(_0x22e3ff[_0x59f1('0x2e')],null))['then'](respondWithResult(_0x38d238,null))['catch'](handleError(_0x38d238,null));};exports[_0x59f1('0x50')]=function(_0x37b417,_0x2adc11){return db[_0x59f1('0x34')][_0x59f1('0x50')]()[_0x59f1('0x26')](respondWithResult(_0x2adc11,null))[_0x59f1('0x4c')](handleError(_0x2adc11,null));};exports['download']=function(_0x305c85,_0x75f5ed,_0x409eea){var _0x2c0af2=require(_0x59f1('0x51'));var _0x32553b=![];var _0x556b7b={};if(_0x305c85[_0x59f1('0x3b')][_0x59f1('0x37')]&&_0x305c85[_0x59f1('0x3b')][_0x59f1('0x37')]===_0x59f1('0x52')){_0x556b7b[_0x59f1('0x52')]=_0x305c85[_0x59f1('0x53')]['id'];}else{_0x556b7b['id']=_0x305c85[_0x59f1('0x53')]['id'];}return db['VoiceRecording']['find']({'where':_0x556b7b,'attributes':['id',_0x59f1('0x54')],'raw':!![]})[_0x59f1('0x26')](handleEntityNotFound(_0x75f5ed,null))[_0x59f1('0x26')](function(_0x55525e){if(_0x55525e){var _0x10d906=_0x55525e[_0x59f1('0x54')];var _0x2b87d1=util[_0x59f1('0x3a')](_0x59f1('0x55'),_0x10d906);if(fs[_0x59f1('0x56')](_0x2b87d1)){_0x32553b=!![];return _0x2c0af2[_0x59f1('0x57')](_0x2b87d1,_0x10d906,config['secrets']['recording'])[_0x59f1('0x26')](function(){return _0x55525e;});}return _0x55525e;}})[_0x59f1('0x26')](function(_0x265d5e){if(_0x265d5e){var _0x2fa948=_0x265d5e[_0x59f1('0x54')];if(!fs['existsSync'](_0x2fa948)){throw new db[(_0x59f1('0x58'))][(_0x59f1('0x59'))](_0x59f1('0x5a'));}if(_0x265d5e[_0x59f1('0x5b')]){return _0x75f5ed['download'](_0x2fa948,_0x265d5e[_0x59f1('0x5b')]+path[_0x59f1('0x5c')](_0x2fa948),function(){if(_0x32553b){fs[_0x59f1('0x5d')](_0x2fa948);}});}else{return _0x75f5ed[_0x59f1('0x5e')](_0x2fa948,function(_0x403eae){if(_0x32553b){fs[_0x59f1('0x5d')](_0x2fa948);}});}}})['catch'](function(_0xa3b928){if(_0xa3b928[_0x59f1('0x2f')]===_0x59f1('0x5a')){_0x75f5ed['status'](0x194)[_0x59f1('0x2b')](_0x59f1('0x5f'));}else{return handleError(_0x75f5ed,null);}});};exports[_0x59f1('0x60')]=function(_0x508e40,_0x40c8ca,_0x39a0d2){var _0x2a631e=require(_0x59f1('0x51'));var _0x233d1b=![];var _0x437f4f={'$and':[db[_0x59f1('0x61')][_0x59f1('0x43')](db[_0x59f1('0x61')]['fn']('MD5',db[_0x59f1('0x61')][_0x59f1('0x62')](_0x59f1('0x52'))),_0x508e40['query'][_0x59f1('0x63')])]};if(_0x508e40['query'][_0x59f1('0x37')]&&_0x508e40[_0x59f1('0x3b')]['type']===_0x59f1('0x52')){_0x437f4f[_0x59f1('0x64')][_0x59f1('0x65')]({'uniqueid':_0x508e40['params']['id']});}else{_0x437f4f['$and'][_0x59f1('0x65')]({'id':_0x508e40[_0x59f1('0x53')]['id']});}return db[_0x59f1('0x34')][_0x59f1('0x4e')]({'where':_0x437f4f,'attributes':['id',_0x59f1('0x54')],'raw':!![]})[_0x59f1('0x26')](handleEntityNotFound(_0x40c8ca,null))[_0x59f1('0x26')](function(_0x4050af){if(_0x4050af){var _0x55b688=util['format'](_0x59f1('0x55'),_0x4050af[_0x59f1('0x54')]);if(fs[_0x59f1('0x56')](_0x55b688)){_0x233d1b=!![];return _0x2a631e['decryptFile'](_0x55b688,_0x4050af[_0x59f1('0x54')],config[_0x59f1('0x66')][_0x59f1('0x67')])[_0x59f1('0x26')](function(){return _0x4050af;});}return _0x4050af;}})['then'](function(_0x1b3921){if(_0x1b3921){if(!fs['existsSync'](_0x1b3921[_0x59f1('0x54')])){throw new db[(_0x59f1('0x58'))][(_0x59f1('0x59'))](_0x59f1('0x5a'));}if(_0x1b3921[_0x59f1('0x5b')]){return _0x40c8ca[_0x59f1('0x5e')](_0x1b3921[_0x59f1('0x54')],_0x1b3921[_0x59f1('0x5b')]+path[_0x59f1('0x5c')](_0x1b3921[_0x59f1('0x54')]),function(){if(_0x233d1b){fs[_0x59f1('0x5d')](_0x1b3921[_0x59f1('0x54')]);}});}else{return _0x40c8ca[_0x59f1('0x5e')](_0x1b3921[_0x59f1('0x54')],function(_0x227b1f){if(_0x233d1b){fs[_0x59f1('0x5d')](_0x1b3921[_0x59f1('0x54')]);}});}}})[_0x59f1('0x4c')](handleError(_0x40c8ca,null));};exports[_0x59f1('0x27')]=function(_0x3fa305,_0x29c629){return db[_0x59f1('0x34')][_0x59f1('0x4e')]({'where':{'id':_0x3fa305[_0x59f1('0x53')]['id']}})[_0x59f1('0x26')](function(_0x36597e){if(_['isNil'](_0x36597e)){throw new ReferenceError(_0x59f1('0x68'));}return _0x36597e;})['then'](function(_0x4d2608){var _0x1e192e=_0x4d2608[_0x59f1('0x54')];logger[_0x59f1('0x69')](_0x59f1('0x6a'),_0x1e192e);if(!_['isNil'](_0x4d2608[_0x59f1('0x54')])&&fs[_0x59f1('0x56')](_0x1e192e)){logger[_0x59f1('0x69')](_0x59f1('0x6b')+_0x1e192e+_0x59f1('0x6c'));fs[_0x59f1('0x6d')](_0x1e192e);}_0x1e192e=_0x1e192e+_0x59f1('0x6e');if(!_[_0x59f1('0x6f')](_0x4d2608['value'])&&fs[_0x59f1('0x56')](_0x1e192e)){logger['info'](_0x59f1('0x6b')+_0x1e192e+_0x59f1('0x6c'));fs['unlinkSync'](_0x1e192e);}return _0x4d2608;})[_0x59f1('0x26')](function(_0x18cdfd){if(!_0x18cdfd)throw new InternalError();return _0x18cdfd[_0x59f1('0x27')]();})[_0x59f1('0x26')](function(){_0x29c629[_0x59f1('0x1a')](0xcc)[_0x59f1('0x1b')]();})[_0x59f1('0x4c')](handleError(_0x29c629,null));};function getBucketslist(_0x8d800e,_0x54da6a,_0x50d227){return new Promise(function(_0x464498,_0x17a654){var _0x43a21f=new AWS['S3']({'accessKeyId':_0x54da6a,'secretAccessKey':_0x8d800e,'region':_0x50d227});_0x43a21f[_0x59f1('0x70')]({},function(_0x23ad3f,_0x23a7e8){if(_0x23ad3f){return _0x17a654(_0x23ad3f);}else{return _0x464498(_0x23a7e8);}});});}function createBucket(_0xeeff15,_0x1fadd1,_0x2e76b7,_0x5222cc){return new Promise(function(_0x513855,_0x3a7056){var _0x3f7958=new AWS['S3']({'accessKeyId':_0x1fadd1,'secretAccessKey':_0xeeff15,'region':_0x2e76b7});_0x3f7958[_0x59f1('0x71')]({'Bucket':_0x5222cc},function(_0x2b9a4f,_0x3ae342){if(_0x2b9a4f){return _0x3a7056(_0x2b9a4f);}else{return _0x513855(_0x3ae342);}});});}function uploadFile(_0x3951f2,_0x4c1d8b,_0xff116d,_0x4c713f,_0x1a1bf7,_0x2180e8){return new Promise(function(_0x3c9e21,_0x40e767){var _0xec2b13=new AWS['S3']({'accessKeyId':_0x4c1d8b,'secretAccessKey':_0x3951f2,'region':_0xff116d});_0xec2b13[_0x59f1('0x72')]({'Bucket':_0x4c713f,'Key':_0x1a1bf7,'Body':_0x2180e8},function(_0x230442,_0x4cd54b){if(_0x230442){return _0x40e767(_0x230442);}else{return _0x3c9e21(_0x4cd54b);}});});}function startTranscribe(_0x536b62,_0x4f0b9d,_0x5c9851,_0x38fb34,_0x5cb5ec,_0x9d011d){return new Promise(function(_0x462284,_0x2c12cb){var _0x69668a=new AWS[(_0x59f1('0x73'))]({'accessKeyId':_0x4f0b9d,'secretAccessKey':_0x536b62,'region':_0x5c9851});_0x69668a['startTranscriptionJob']({'TranscriptionJobName':_0x38fb34,'LanguageCode':_0x5cb5ec,'Media':{'MediaFileUri':_0x9d011d}},function(_0x41c132,_0x12854b){if(_0x41c132){return _0x2c12cb(_0x41c132);}else{return _0x462284(_0x12854b);}});});}function transcribe(_0x37dad5,_0x2627e1,_0x1c80d2,_0x36bc3a,_0x3bdc29,_0x3daf6f,_0x58316c){return new Promise(function(_0x105516,_0x2bbfe8){var _0x52234b={};logger['info'](util[_0x59f1('0x3a')](_0x59f1('0x74'),_0x37dad5,_0x3bdc29));return uploadFile(_0x2627e1,_0x1c80d2,_0x36bc3a,_0x3bdc29,path[_0x59f1('0x75')](_0x3daf6f),fs[_0x59f1('0x76')](_0x3daf6f))[_0x59f1('0x26')](function(_0x549469){logger[_0x59f1('0x69')](util[_0x59f1('0x3a')]('[RUNTRANSCRIPT][%d]\x20Voice\x20recording\x20uploaded\x20in\x20bucket\x20%s\x20(%s)',_0x37dad5,_0x3bdc29,_0x549469['Location']));_0x52234b[_0x59f1('0x77')]=_0x549469[_0x59f1('0x78')];_0x52234b[_0x59f1('0x79')]=_0x549469[_0x59f1('0x7a')];logger['info'](util[_0x59f1('0x3a')]('[RUNTRANSCRIPT][%d]\x20Sending\x20transcribe\x20request',_0x37dad5));return startTranscribe(_0x2627e1,_0x1c80d2,_0x36bc3a,uuidv4(),_0x58316c,_0x549469[_0x59f1('0x7a')]);})[_0x59f1('0x26')](function(_0x95b40f){logger[_0x59f1('0x69')](util[_0x59f1('0x3a')]('[RUNTRANSCRIPT][%d]\x20Transcription\x20job\x20%s\x20created',_0x37dad5,_0x95b40f[_0x59f1('0x7b')][_0x59f1('0x7c')]));_0x52234b[_0x59f1('0x7d')]=_0x95b40f[_0x59f1('0x7b')][_0x59f1('0x7c')];_0x52234b['transcribeStatus']=_0x95b40f[_0x59f1('0x7b')][_0x59f1('0x7e')];return _0x105516(_0x52234b);})[_0x59f1('0x4c')](function(_0x3b5f80){return _0x2bbfe8(_0x3b5f80);});});}exports['runTranscribe']=function(_0x112eb2,_0x26c64f,_0x3d8083){var _0xb4600d;var _0x59ee9a;var _0x26710f;var _0x5eb2c8=require(_0x59f1('0x51'));return db['VoiceRecording'][_0x59f1('0x7f')]({'where':{'id':_0x112eb2[_0x59f1('0x53')]['id']}})[_0x59f1('0x26')](function(_0x1ca2a9){if(_0x1ca2a9){var _0x35c086=util[_0x59f1('0x3a')](_0x59f1('0x55'),_0x1ca2a9[_0x59f1('0x54')]);if(fs['existsSync'](_0x35c086)){cypher=!![];return _0x5eb2c8[_0x59f1('0x57')](_0x35c086,_0x1ca2a9[_0x59f1('0x54')],config[_0x59f1('0x66')][_0x59f1('0x67')])[_0x59f1('0x26')](function(){return _0x1ca2a9;});}return _0x1ca2a9;}})[_0x59f1('0x26')](function(_0x5f55cf){if(!_0x5f55cf){throw new db[(_0x59f1('0x58'))][(_0x59f1('0x59'))](_0x59f1('0x80'));}_0x59ee9a=_0x5f55cf;return db[_0x59f1('0x81')][_0x59f1('0x7f')]({'where':{'id':0x1}});})['then'](handleEntityNotFound(_0x26c64f,null))[_0x59f1('0x26')](function(_0x38c0e5){if(_0x38c0e5){_0xb4600d=_0x38c0e5;if(!_0xb4600d[_0x59f1('0x82')]||!_0xb4600d['transcribeAccountId']||!_0xb4600d[_0x59f1('0x83')]||!_0xb4600d[_0x59f1('0x84')]||!_0xb4600d['bucket']){throw new db[(_0x59f1('0x58'))]['ValidationError'](_0x59f1('0x85'));}if(_0x112eb2[_0x59f1('0x2e')][_0x59f1('0x86')]&&(!_0xb4600d['sentiment']||!_0xb4600d[_0x59f1('0x87')]||!_0xb4600d[_0x59f1('0x88')]||!_0xb4600d[_0x59f1('0x84')]||!_0xb4600d[_0x59f1('0x77')])){throw new db['Sequelize'][(_0x59f1('0x59'))]('Sentiment\x20Analysis\x20not\x20configured');}return db[_0x59f1('0x89')][_0x59f1('0x7f')]({'where':{'id':_0xb4600d[_0x59f1('0x8a')]}});}})['then'](function(_0x55cf19){if(!_0x55cf19){throw new db[(_0x59f1('0x58'))][(_0x59f1('0x59'))](_0x59f1('0x8b'));}if(!_0x55cf19[_0x59f1('0x8c')]||!_0x55cf19[_0x59f1('0x8d')]){throw new db[(_0x59f1('0x58'))][(_0x59f1('0x59'))](_0x59f1('0x8e'));}_0x26710f=_0x55cf19;return getBucketslist(_0x26710f['data1'],_0x26710f[_0x59f1('0x8d')],_0xb4600d[_0x59f1('0x83')]);})['then'](function(_0xa3fb13){if(_0xa3fb13&&_0xa3fb13[_0x59f1('0x8f')]){var _0x3ddcdf=_[_0x59f1('0x4e')](_0xa3fb13[_0x59f1('0x8f')],function(_0x463c7d){return _0x463c7d[_0x59f1('0x90')]===_0xb4600d['bucket'];});if(!_0x3ddcdf){logger[_0x59f1('0x69')](util[_0x59f1('0x3a')](_0x59f1('0x91'),_0x112eb2[_0x59f1('0x53')]['id'],_0xb4600d[_0x59f1('0x77')]));return createBucket(_0x26710f[_0x59f1('0x8c')],_0x26710f[_0x59f1('0x8d')],_0xb4600d[_0x59f1('0x83')],_0xb4600d[_0x59f1('0x77')]);}logger[_0x59f1('0x69')](util[_0x59f1('0x3a')](_0x59f1('0x92'),_0x112eb2[_0x59f1('0x53')]['id'],_0xb4600d[_0x59f1('0x77')]));return;}})[_0x59f1('0x26')](function(_0x4f6ae9){if(_0x59ee9a[_0x59f1('0x93')]==='NEW'){return transcribe(_0x112eb2['params']['id'],_0x26710f[_0x59f1('0x8c')],_0x26710f[_0x59f1('0x8d')],_0xb4600d[_0x59f1('0x83')],_0xb4600d['bucket'],_0x59ee9a[_0x59f1('0x54')],_0xb4600d[_0x59f1('0x84')]);}else{logger['info'](util[_0x59f1('0x3a')]('[RUNTRANSCRIPT][%d]\x20Transcript\x20action\x20already\x20requested',_0x112eb2['params']['id']));return{'transcribeStatus':_0x59f1('0x94')};}})[_0x59f1('0x26')](function(_0x8238c1){if(_0x8238c1){_0x8238c1[_0x59f1('0x95')]=_0x112eb2[_0x59f1('0x2e')][_0x59f1('0x86')];return _0x59ee9a['updateAttributes'](_0x8238c1);}})[_0x59f1('0x26')](respondWithResult(_0x26c64f,null))[_0x59f1('0x4c')](handleError(_0x26c64f,null));};function writeFile(_0x524fdb,_0x350649){return new Promise(function(_0x533cb8,_0x173d03){fs[_0x59f1('0x96')](_0x350649,_0x524fdb,function(_0x41be4a,_0x33e253){if(_0x41be4a){return _0x173d03(_0x41be4a);}else{return _0x533cb8(_0x33e253);}});});}exports[_0x59f1('0x97')]=function(_0x329b44,_0x2cb951,_0x29b7c8){return db[_0x59f1('0x34')][_0x59f1('0x7f')]({'where':{'id':_0x329b44[_0x59f1('0x53')]['id']}})[_0x59f1('0x26')](handleEntityNotFound(_0x2cb951))[_0x59f1('0x26')](function(_0x38e96a){if(_0x38e96a&&_0x38e96a[_0x59f1('0x98')]){var _0x5b2384=_0x38e96a['fileText'];var _0x77b283=config[_0x59f1('0x99')]+_0x59f1('0x9a')+_0x38e96a['id']+_0x59f1('0x9b');if(fs[_0x59f1('0x56')](_0x77b283)){return _0x77b283;}return writeFile(_0x5b2384,_0x77b283)['then'](function(){return _0x77b283;});}else{throw new db['Sequelize'][(_0x59f1('0x59'))](_0x59f1('0x9c'));}})[_0x59f1('0x26')](function(_0x34fae0){return _0x2cb951[_0x59f1('0x5e')](_0x34fae0);})[_0x59f1('0x4c')](handleError(_0x2cb951));};