Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / config / schedule / transcribe.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 _0xf677=['update','tempSentiment','Sequelize','ValidationError','Sentiment\x20Analysis\x20not\x20requested','sentiment','sentimentAccountId','language','bucket','Transcript\x20not\x20available','CloudProvider','findOne','Cloud\x20Provider\x20not\x20available','Cloud\x20Provider\x20not\x20configured','[RECORDING:%d]\x20Sentiment\x20Analysis\x20available','Sentiment','SentimentScore','Negative','Neutral','FAILED','FailureReason','[RECORDING:%d]\x20Voice\x20Recording\x20entry\x20updated','[RECORDING:%d]\x20Transcript\x20Job\x20status\x20not\x20managed','resolve','[RECORDING:%d]\x20Requesting\x20sentiment\x20analysis','sentimentRegion','Positive','catch','name','SequelizeValidationError','error','[RECORDING:%d]\x20Error\x20running\x20Transcribe\x20&\x20Sentiment\x20Analysis','inspect','VoiceRecording','findAll','No\x20transcribe\x20job\x20to\x20check','transcribeAccountId','forEach','push','all','start','aws-sdk','request-promise','util','../../mysqldb','../../config/logger','transcribe','TranscribeService','detectSentiment','info','format','[RECORDING:%d]\x20Get\x20status\x20for\x20transcript\x20job\x20(%s)','transcribeName','data1','data2','transcribeRegion','then','TranscriptionJob','TranscriptionJobStatus','fileText','COMPLETED','Transcript','[RECORDING:%d]\x20Get\x20transcript','TranscriptFileUri','[RECORDING:%d]\x20Transcript\x20downloaded','results','transcripts','length','transcript'];(function(_0x18c8b5,_0x2a15d3){var _0x358984=function(_0xf5461){while(--_0xf5461){_0x18c8b5['push'](_0x18c8b5['shift']());}};_0x358984(++_0x2a15d3);}(_0xf677,0xb3));var _0x7f67=function(_0x4ee8f2,_0x341ceb){_0x4ee8f2=_0x4ee8f2-0x0;var _0x59d6c8=_0xf677[_0x4ee8f2];return _0x59d6c8;};var _=require('lodash');var AWS=require(_0x7f67('0x0'));var rp=require(_0x7f67('0x1'));var util=require(_0x7f67('0x2'));var BPromise=require('bluebird');var db=require(_0x7f67('0x3'))['db'];var logger=require(_0x7f67('0x4'))(_0x7f67('0x5'));function getTranscriptionJob(_0x37ff1d,_0xf4e4,_0x82ab01,_0x5d35e8){return new Promise(function(_0x285aa1,_0x5ada61){var _0x684a3a=new AWS[(_0x7f67('0x6'))]({'accessKeyId':_0xf4e4,'secretAccessKey':_0x37ff1d,'region':_0x82ab01});_0x684a3a['getTranscriptionJob']({'TranscriptionJobName':_0x5d35e8},function(_0x220695,_0x436ffc){if(_0x220695){return _0x5ada61(_0x220695);}else{return _0x285aa1(_0x436ffc);}});});}function sentiment(_0x5a018a,_0x4a9bf9,_0x28b581,_0x40933f,_0x5b090c){return new Promise(function(_0x324424,_0x85dbef){var _0x5e1e8b=new AWS['Comprehend']({'accessKeyId':_0x4a9bf9,'secretAccessKey':_0x5a018a,'region':_0x28b581});_0x5e1e8b[_0x7f67('0x7')]({'Text':_0x40933f,'LanguageCode':_0x5b090c['substring'](0x0,0x2)},function(_0x5f40b9,_0x1f91cc){if(_0x5f40b9){return _0x85dbef(_0x5f40b9);}else{return _0x324424(_0x1f91cc);}});});}function checkTranscribeJob(_0x4658d2,_0xc991f3,_0x599059){var _0x54aa57;return new BPromise(function(_0x1550a7,_0x27239f){logger[_0x7f67('0x8')](util[_0x7f67('0x9')](_0x7f67('0xa'),_0x4658d2['id'],_0x4658d2[_0x7f67('0xb')]));return getTranscriptionJob(_0x599059[_0x7f67('0xc')],_0x599059[_0x7f67('0xd')],_0xc991f3[_0x7f67('0xe')],_0x4658d2[_0x7f67('0xb')])[_0x7f67('0xf')](function(_0x5452c9){logger[_0x7f67('0x8')](util[_0x7f67('0x9')]('[RECORDING:%d]\x20Status\x20of\x20transcript\x20job\x20(%s):\x20%s',_0x4658d2['id'],_0x4658d2[_0x7f67('0xb')],_0x5452c9[_0x7f67('0x10')][_0x7f67('0x11')]));if(!_0x4658d2[_0x7f67('0x12')]){switch(_0x5452c9[_0x7f67('0x10')][_0x7f67('0x11')]){case _0x7f67('0x13'):var _0x1399b5={'transcribeStatus':_0x5452c9['TranscriptionJob'][_0x7f67('0x11')],'fileUri':_0x5452c9['TranscriptionJob'][_0x7f67('0x14')]['TranscriptFileUri']};logger[_0x7f67('0x8')](util['format'](_0x7f67('0x15'),_0x4658d2['id']));return rp({'uri':_0x5452c9[_0x7f67('0x10')][_0x7f67('0x14')][_0x7f67('0x16')],'json':!![]})[_0x7f67('0xf')](function(_0x346690){logger[_0x7f67('0x8')](util['format'](_0x7f67('0x17'),_0x4658d2['id']));if(_0x346690&&_0x346690[_0x7f67('0x18')]&&_0x346690[_0x7f67('0x18')][_0x7f67('0x19')]&&_0x346690[_0x7f67('0x18')]['transcripts'][_0x7f67('0x1a')]){_0x1399b5['fileText']='';for(var _0x24dc70=0x0;_0x24dc70<_0x346690[_0x7f67('0x18')][_0x7f67('0x19')][_0x7f67('0x1a')];_0x24dc70++){_0x1399b5[_0x7f67('0x12')]+=_0x346690[_0x7f67('0x18')][_0x7f67('0x19')][_0x24dc70][_0x7f67('0x1b')]+'';}}return _0x4658d2[_0x7f67('0x1c')](_0x1399b5);})[_0x7f67('0xf')](function(){logger['info'](util['format']('[RECORDING:%d]\x20Voice\x20Recording\x20entry\x20updated',_0x4658d2['id']));if(!_0x4658d2[_0x7f67('0x1d')]){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))](_0x7f67('0x20'));}if(!_0xc991f3[_0x7f67('0x21')]||!_0xc991f3[_0x7f67('0x22')]||!_0xc991f3['sentimentRegion']||!_0xc991f3[_0x7f67('0x23')]||!_0xc991f3[_0x7f67('0x24')]){throw new db['Sequelize']['ValidationError']('Sentiment\x20Analysis\x20not\x20configured');}if(!_0x1399b5[_0x7f67('0x12')]){throw new Error(_0x7f67('0x25'));}if(_0xc991f3[_0x7f67('0x22')]===_0x599059['id']){return _0x599059;}else{return db[_0x7f67('0x26')][_0x7f67('0x27')]({'where':{'id':_settings[_0x7f67('0x22')]}});}})[_0x7f67('0xf')](function(_0x28e028){if(!_0x28e028){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))](_0x7f67('0x28'));}if(!_0x28e028['data1']||!_0x28e028['data2']){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))](_0x7f67('0x29'));}_0x54aa57=_0x28e028;logger[_0x7f67('0x8')](util[_0x7f67('0x9')]('[RECORDING:%d]\x20Requesting\x20sentiment\x20analysis',_0x4658d2['id']));return sentiment(_0x54aa57[_0x7f67('0xc')],_0x54aa57['data2'],_0xc991f3['sentimentRegion'],_0x1399b5[_0x7f67('0x12')],_0xc991f3[_0x7f67('0x23')]);})[_0x7f67('0xf')](function(_0x38dd73){logger[_0x7f67('0x8')](util['format'](_0x7f67('0x2a'),_0x4658d2['id']));return _0x4658d2['update']({'sentiment':_0x38dd73[_0x7f67('0x2b')],'sPositive':_0x38dd73[_0x7f67('0x2c')]['Positive'],'sNegative':_0x38dd73[_0x7f67('0x2c')][_0x7f67('0x2d')],'sMixed':_0x38dd73[_0x7f67('0x2c')]['Mixed'],'sNeutral':_0x38dd73[_0x7f67('0x2c')][_0x7f67('0x2e')]});})['then'](function(){logger[_0x7f67('0x8')](util[_0x7f67('0x9')]('[RECORDING:%d]\x20Voice\x20Recording\x20entry\x20updated',_0x4658d2['id']));_0x1550a7();});case _0x7f67('0x2f'):return _0x4658d2[_0x7f67('0x1c')]({'transcribeStatus':_0x7f67('0x2f'),'failureReason':_0x5452c9['TranscriptionJob'][_0x7f67('0x30')]})[_0x7f67('0xf')](function(){logger[_0x7f67('0x8')](util['format'](_0x7f67('0x31'),_0x4658d2['id']));_0x1550a7();});default:logger[_0x7f67('0x8')](util[_0x7f67('0x9')](_0x7f67('0x32'),_0x4658d2['id']));break;}}else{return BPromise[_0x7f67('0x33')]()['then'](function(){if(!_0x4658d2[_0x7f67('0x1d')]){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))](_0x7f67('0x20'));}if(!_0xc991f3[_0x7f67('0x21')]||!_0xc991f3[_0x7f67('0x22')]||!_0xc991f3['sentimentRegion']||!_0xc991f3['language']||!_0xc991f3[_0x7f67('0x24')]){throw new db['Sequelize'][(_0x7f67('0x1f'))]('Sentiment\x20Analysis\x20not\x20configured');}if(!_0x4658d2[_0x7f67('0x12')]){throw new Error(_0x7f67('0x25'));}if(_0xc991f3['sentimentAccountId']===_0x599059['id']){return _0x599059;}else{return db['CloudProvider'][_0x7f67('0x27')]({'where':{'id':_settings[_0x7f67('0x22')]}});}})[_0x7f67('0xf')](function(_0x4fda36){if(!_0x4fda36){throw new db[(_0x7f67('0x1e'))]['ValidationError']('Cloud\x20Provider\x20not\x20available');}if(!_0x4fda36['data1']||!_0x4fda36[_0x7f67('0xd')]){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))](_0x7f67('0x29'));}_0x54aa57=_0x4fda36;logger[_0x7f67('0x8')](util[_0x7f67('0x9')](_0x7f67('0x34'),_0x4658d2['id']));return sentiment(_0x54aa57[_0x7f67('0xc')],_0x54aa57[_0x7f67('0xd')],_0xc991f3[_0x7f67('0x35')],_0x4658d2['fileText'],_0xc991f3[_0x7f67('0x23')]);})[_0x7f67('0xf')](function(_0x54d58c){logger[_0x7f67('0x8')](util[_0x7f67('0x9')](_0x7f67('0x2a'),_0x4658d2['id']));return _0x4658d2[_0x7f67('0x1c')]({'sentiment':_0x54d58c[_0x7f67('0x2b')],'sPositive':_0x54d58c['SentimentScore'][_0x7f67('0x36')],'sNegative':_0x54d58c[_0x7f67('0x2c')][_0x7f67('0x2d')],'sMixed':_0x54d58c['SentimentScore']['Mixed'],'sNeutral':_0x54d58c[_0x7f67('0x2c')]['Neutral'],'transcribeStatus':'COMPLETED'});})[_0x7f67('0xf')](function(){logger[_0x7f67('0x8')](util[_0x7f67('0x9')]('[RECORDING:%d]\x20Voice\x20Recording\x20entry\x20updated',_0x4658d2['id']));_0x1550a7();});}})[_0x7f67('0x37')](function(_0x1db09f){if(_0x1db09f){if(!_0x1db09f[_0x7f67('0x38')]||_0x1db09f[_0x7f67('0x38')]!==_0x7f67('0x39')){logger[_0x7f67('0x3a')](util[_0x7f67('0x9')](_0x7f67('0x3b'),_0x4658d2['id']),util[_0x7f67('0x3c')](_0x1db09f,{'showHidden':![],'depth':null}));}}_0x1550a7();});});}function checkTranscribe(){var _0x4e41fb;var _0x4680bf;var _0x396d46;return db[_0x7f67('0x3d')][_0x7f67('0x3e')]({'where':{'transcribeStatus':'IN_PROGRESS'}})[_0x7f67('0xf')](function(_0xf22456){if(!_0xf22456||!_0xf22456[_0x7f67('0x1a')]){throw new db['Sequelize'][(_0x7f67('0x1f'))](_0x7f67('0x3f'));}_0x4e41fb=_0xf22456;return db['Setting'][_0x7f67('0x27')]({'where':{'id':0x1}});})[_0x7f67('0xf')](function(_0x1f1928){if(!_0x1f1928){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))]('Settings\x20not\x20available');}_0x4680bf=_0x1f1928;if(!_0x4680bf[_0x7f67('0x5')]||!_0x4680bf[_0x7f67('0x40')]||!_0x4680bf[_0x7f67('0xe')]||!_0x4680bf[_0x7f67('0x23')]||!_0x4680bf[_0x7f67('0x24')]){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))]('Transcribe\x20not\x20configured');}return db[_0x7f67('0x26')][_0x7f67('0x27')]({'where':{'id':_0x4680bf['transcribeAccountId']}});})[_0x7f67('0xf')](function(_0xfce8d4){if(!_0xfce8d4){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))](_0x7f67('0x28'));}if(!_0xfce8d4['data1']||!_0xfce8d4[_0x7f67('0xd')]){throw new db[(_0x7f67('0x1e'))][(_0x7f67('0x1f'))](_0x7f67('0x29'));}_0x396d46=_0xfce8d4;var _0x4f1dde=[];_0x4e41fb[_0x7f67('0x41')](function(_0x258061){_0x4f1dde[_0x7f67('0x42')](checkTranscribeJob(_0x258061,_0x4680bf,_0x396d46));});return BPromise[_0x7f67('0x43')](_0x4f1dde);})[_0x7f67('0x37')](function(_0x1fd17f){if(_0x1fd17f){if(!_0x1fd17f['name']||_0x1fd17f[_0x7f67('0x38')]!=='SequelizeValidationError'){logger[_0x7f67('0x3a')](util[_0x7f67('0x3c')](_0x1fd17f,{'showHidden':![],'depth':null}));}}});}exports[_0x7f67('0x44')]=function(){setInterval(function(){return checkTranscribe();},0x3c*0x3e8);return checkTranscribe();};