Built motion from commit (unavailable).|2.5.1
[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 _0xdc5e=['Positive','Mixed','name','SequelizeValidationError','inspect','VoiceRecording','IN_PROGRESS','No\x20transcribe\x20job\x20to\x20check','Settings\x20not\x20available','transcribeAccountId','Transcribe\x20not\x20configured','forEach','push','all','catch','error','start','lodash','aws-sdk','util','bluebird','../../mysqldb','transcribe','getTranscriptionJob','Comprehend','detectSentiment','substring','info','format','[RECORDING:%d]\x20Get\x20status\x20for\x20transcript\x20job\x20(%s)','transcribeName','data1','data2','transcribeRegion','then','TranscriptionJobStatus','fileText','TranscriptionJob','COMPLETED','Transcript','TranscriptFileUri','[RECORDING:%d]\x20Get\x20transcript','[RECORDING:%d]\x20Transcript\x20downloaded','results','transcripts','length','transcript','update','[RECORDING:%d]\x20Voice\x20Recording\x20entry\x20updated','tempSentiment','Sequelize','ValidationError','Sentiment\x20Analysis\x20not\x20requested','sentiment','sentimentRegion','language','bucket','Sentiment\x20Analysis\x20not\x20configured','sentimentAccountId','CloudProvider','findOne','Cloud\x20Provider\x20not\x20available','[RECORDING:%d]\x20Requesting\x20sentiment\x20analysis','[RECORDING:%d]\x20Sentiment\x20Analysis\x20available','Sentiment','SentimentScore','Negative','Neutral','FAILED','FailureReason','Transcript\x20not\x20available','Cloud\x20Provider\x20not\x20configured'];(function(_0x3947c9,_0x4d6c97){var _0x2e7871=function(_0x1236cc){while(--_0x1236cc){_0x3947c9['push'](_0x3947c9['shift']());}};_0x2e7871(++_0x4d6c97);}(_0xdc5e,0x1c1));var _0xedc5=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xdc5e[_0x321bb2];return _0x9c12ed;};var _=require(_0xedc5('0x0'));var AWS=require(_0xedc5('0x1'));var rp=require('request-promise');var util=require(_0xedc5('0x2'));var BPromise=require(_0xedc5('0x3'));var db=require(_0xedc5('0x4'))['db'];var logger=require('../../config/logger')(_0xedc5('0x5'));function getTranscriptionJob(_0x580703,_0x26a6f7,_0x49559b,_0x4650be){return new Promise(function(_0x1b417e,_0x4aee33){var _0x4b876e=new AWS['TranscribeService']({'accessKeyId':_0x26a6f7,'secretAccessKey':_0x580703,'region':_0x49559b});_0x4b876e[_0xedc5('0x6')]({'TranscriptionJobName':_0x4650be},function(_0x2c6bab,_0x11b08c){if(_0x2c6bab){return _0x4aee33(_0x2c6bab);}else{return _0x1b417e(_0x11b08c);}});});}function sentiment(_0x441814,_0x4e65c2,_0x460877,_0x52ce44,_0x335825){return new Promise(function(_0x58b01d,_0x5efc9d){var _0x1fbce5=new AWS[(_0xedc5('0x7'))]({'accessKeyId':_0x4e65c2,'secretAccessKey':_0x441814,'region':_0x460877});_0x1fbce5[_0xedc5('0x8')]({'Text':_0x52ce44,'LanguageCode':_0x335825[_0xedc5('0x9')](0x0,0x2)},function(_0x2bc02e,_0x145ad8){if(_0x2bc02e){return _0x5efc9d(_0x2bc02e);}else{return _0x58b01d(_0x145ad8);}});});}function checkTranscribeJob(_0x44d3c8,_0x5d7151,_0x5c7634){var _0x49d78c;return new BPromise(function(_0x3941a5,_0x20987f){logger[_0xedc5('0xa')](util[_0xedc5('0xb')](_0xedc5('0xc'),_0x44d3c8['id'],_0x44d3c8[_0xedc5('0xd')]));return getTranscriptionJob(_0x5c7634[_0xedc5('0xe')],_0x5c7634[_0xedc5('0xf')],_0x5d7151[_0xedc5('0x10')],_0x44d3c8[_0xedc5('0xd')])[_0xedc5('0x11')](function(_0x427c82){logger[_0xedc5('0xa')](util[_0xedc5('0xb')]('[RECORDING:%d]\x20Status\x20of\x20transcript\x20job\x20(%s):\x20%s',_0x44d3c8['id'],_0x44d3c8['transcribeName'],_0x427c82['TranscriptionJob'][_0xedc5('0x12')]));if(!_0x44d3c8[_0xedc5('0x13')]){switch(_0x427c82[_0xedc5('0x14')][_0xedc5('0x12')]){case _0xedc5('0x15'):var _0x34aeb9={'transcribeStatus':_0x427c82[_0xedc5('0x14')]['TranscriptionJobStatus'],'fileUri':_0x427c82[_0xedc5('0x14')][_0xedc5('0x16')][_0xedc5('0x17')]};logger[_0xedc5('0xa')](util[_0xedc5('0xb')](_0xedc5('0x18'),_0x44d3c8['id']));return rp({'uri':_0x427c82[_0xedc5('0x14')][_0xedc5('0x16')][_0xedc5('0x17')],'json':!![]})['then'](function(_0x2081c7){logger['info'](util[_0xedc5('0xb')](_0xedc5('0x19'),_0x44d3c8['id']));if(_0x2081c7&&_0x2081c7[_0xedc5('0x1a')]&&_0x2081c7[_0xedc5('0x1a')][_0xedc5('0x1b')]&&_0x2081c7['results'][_0xedc5('0x1b')][_0xedc5('0x1c')]){_0x34aeb9[_0xedc5('0x13')]='';for(var _0x2bfa01=0x0;_0x2bfa01<_0x2081c7[_0xedc5('0x1a')]['transcripts']['length'];_0x2bfa01++){_0x34aeb9[_0xedc5('0x13')]+=_0x2081c7[_0xedc5('0x1a')][_0xedc5('0x1b')][_0x2bfa01][_0xedc5('0x1d')]+'';}}return _0x44d3c8[_0xedc5('0x1e')](_0x34aeb9);})['then'](function(){logger[_0xedc5('0xa')](util[_0xedc5('0xb')](_0xedc5('0x1f'),_0x44d3c8['id']));if(!_0x44d3c8[_0xedc5('0x20')]){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x23'));}if(!_0x5d7151[_0xedc5('0x24')]||!_0x5d7151['sentimentAccountId']||!_0x5d7151[_0xedc5('0x25')]||!_0x5d7151[_0xedc5('0x26')]||!_0x5d7151[_0xedc5('0x27')]){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x28'));}if(!_0x34aeb9[_0xedc5('0x13')]){throw new Error('Transcript\x20not\x20available');}if(_0x5d7151[_0xedc5('0x29')]===_0x5c7634['id']){return _0x5c7634;}else{return db[_0xedc5('0x2a')][_0xedc5('0x2b')]({'where':{'id':_settings[_0xedc5('0x29')]}});}})[_0xedc5('0x11')](function(_0x2ce4cd){if(!_0x2ce4cd){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x2c'));}if(!_0x2ce4cd['data1']||!_0x2ce4cd['data2']){throw new db[(_0xedc5('0x21'))]['ValidationError']('Cloud\x20Provider\x20not\x20configured');}_0x49d78c=_0x2ce4cd;logger['info'](util[_0xedc5('0xb')](_0xedc5('0x2d'),_0x44d3c8['id']));return sentiment(_0x49d78c[_0xedc5('0xe')],_0x49d78c[_0xedc5('0xf')],_0x5d7151['sentimentRegion'],_0x34aeb9[_0xedc5('0x13')],_0x5d7151[_0xedc5('0x26')]);})[_0xedc5('0x11')](function(_0x1cf569){logger[_0xedc5('0xa')](util[_0xedc5('0xb')](_0xedc5('0x2e'),_0x44d3c8['id']));return _0x44d3c8[_0xedc5('0x1e')]({'sentiment':_0x1cf569[_0xedc5('0x2f')],'sPositive':_0x1cf569[_0xedc5('0x30')]['Positive'],'sNegative':_0x1cf569[_0xedc5('0x30')][_0xedc5('0x31')],'sMixed':_0x1cf569[_0xedc5('0x30')]['Mixed'],'sNeutral':_0x1cf569[_0xedc5('0x30')][_0xedc5('0x32')]});})[_0xedc5('0x11')](function(){logger[_0xedc5('0xa')](util[_0xedc5('0xb')](_0xedc5('0x1f'),_0x44d3c8['id']));_0x3941a5();});case _0xedc5('0x33'):return _0x44d3c8[_0xedc5('0x1e')]({'transcribeStatus':_0xedc5('0x33'),'failureReason':_0x427c82[_0xedc5('0x14')][_0xedc5('0x34')]})[_0xedc5('0x11')](function(){logger[_0xedc5('0xa')](util[_0xedc5('0xb')](_0xedc5('0x1f'),_0x44d3c8['id']));_0x3941a5();});default:logger['info'](util[_0xedc5('0xb')]('[RECORDING:%d]\x20Transcript\x20Job\x20status\x20not\x20managed',_0x44d3c8['id']));break;}}else{return BPromise['resolve']()['then'](function(){if(!_0x44d3c8[_0xedc5('0x20')]){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))]('Sentiment\x20Analysis\x20not\x20requested');}if(!_0x5d7151[_0xedc5('0x24')]||!_0x5d7151[_0xedc5('0x29')]||!_0x5d7151[_0xedc5('0x25')]||!_0x5d7151[_0xedc5('0x26')]||!_0x5d7151[_0xedc5('0x27')]){throw new db[(_0xedc5('0x21'))]['ValidationError'](_0xedc5('0x28'));}if(!_0x44d3c8['fileText']){throw new Error(_0xedc5('0x35'));}if(_0x5d7151[_0xedc5('0x29')]===_0x5c7634['id']){return _0x5c7634;}else{return db['CloudProvider'][_0xedc5('0x2b')]({'where':{'id':_settings[_0xedc5('0x29')]}});}})['then'](function(_0x2e2b6f){if(!_0x2e2b6f){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x2c'));}if(!_0x2e2b6f[_0xedc5('0xe')]||!_0x2e2b6f[_0xedc5('0xf')]){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x36'));}_0x49d78c=_0x2e2b6f;logger['info'](util[_0xedc5('0xb')](_0xedc5('0x2d'),_0x44d3c8['id']));return sentiment(_0x49d78c[_0xedc5('0xe')],_0x49d78c[_0xedc5('0xf')],_0x5d7151[_0xedc5('0x25')],_0x44d3c8[_0xedc5('0x13')],_0x5d7151[_0xedc5('0x26')]);})[_0xedc5('0x11')](function(_0x119450){logger[_0xedc5('0xa')](util[_0xedc5('0xb')](_0xedc5('0x2e'),_0x44d3c8['id']));return _0x44d3c8[_0xedc5('0x1e')]({'sentiment':_0x119450['Sentiment'],'sPositive':_0x119450[_0xedc5('0x30')][_0xedc5('0x37')],'sNegative':_0x119450[_0xedc5('0x30')]['Negative'],'sMixed':_0x119450['SentimentScore'][_0xedc5('0x38')],'sNeutral':_0x119450[_0xedc5('0x30')][_0xedc5('0x32')],'transcribeStatus':_0xedc5('0x15')});})[_0xedc5('0x11')](function(){logger[_0xedc5('0xa')](util[_0xedc5('0xb')](_0xedc5('0x1f'),_0x44d3c8['id']));_0x3941a5();});}})['catch'](function(_0x27a097){if(_0x27a097){if(!_0x27a097[_0xedc5('0x39')]||_0x27a097[_0xedc5('0x39')]!==_0xedc5('0x3a')){logger['error'](util[_0xedc5('0xb')]('[RECORDING:%d]\x20Error\x20running\x20Transcribe\x20&\x20Sentiment\x20Analysis',_0x44d3c8['id']),util[_0xedc5('0x3b')](_0x27a097,{'showHidden':![],'depth':null}));}}_0x3941a5();});});}function checkTranscribe(){var _0x2b8ccf;var _0x346bbc;var _0x53f45;return db[_0xedc5('0x3c')]['findAll']({'where':{'transcribeStatus':_0xedc5('0x3d')}})[_0xedc5('0x11')](function(_0xa21683){if(!_0xa21683||!_0xa21683[_0xedc5('0x1c')]){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x3e'));}_0x2b8ccf=_0xa21683;return db['Setting'][_0xedc5('0x2b')]({'where':{'id':0x1}});})[_0xedc5('0x11')](function(_0x4fca04){if(!_0x4fca04){throw new db['Sequelize'][(_0xedc5('0x22'))](_0xedc5('0x3f'));}_0x346bbc=_0x4fca04;if(!_0x346bbc[_0xedc5('0x5')]||!_0x346bbc[_0xedc5('0x40')]||!_0x346bbc[_0xedc5('0x10')]||!_0x346bbc[_0xedc5('0x26')]||!_0x346bbc[_0xedc5('0x27')]){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x41'));}return db[_0xedc5('0x2a')][_0xedc5('0x2b')]({'where':{'id':_0x346bbc[_0xedc5('0x40')]}});})[_0xedc5('0x11')](function(_0x4ced15){if(!_0x4ced15){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x2c'));}if(!_0x4ced15['data1']||!_0x4ced15[_0xedc5('0xf')]){throw new db[(_0xedc5('0x21'))][(_0xedc5('0x22'))](_0xedc5('0x36'));}_0x53f45=_0x4ced15;var _0x301118=[];_0x2b8ccf[_0xedc5('0x42')](function(_0x3a6041){_0x301118[_0xedc5('0x43')](checkTranscribeJob(_0x3a6041,_0x346bbc,_0x53f45));});return BPromise[_0xedc5('0x44')](_0x301118);})[_0xedc5('0x45')](function(_0x4133f8){if(_0x4133f8){if(!_0x4133f8[_0xedc5('0x39')]||_0x4133f8['name']!==_0xedc5('0x3a')){logger[_0xedc5('0x46')](util[_0xedc5('0x3b')](_0x4133f8,{'showHidden':![],'depth':null}));}}});}exports[_0xedc5('0x47')]=function(){setInterval(function(){return checkTranscribe();},0x3c*0x3e8);return checkTranscribe();};