18 var _0xb234=['randomstring','url','./aws','./google','./tilde','../../../config/logger','https://api.ispeech.org/api/rest','protocol','https:','host','WHAT_EVER','get','statusCode','error','request\x20to\x20','\x20failed,\x20status\x20code\x20=\x20','statusMessage','finish','info','close','unlink','download\x20error','pipe','path','data','end','wav','error\x20convert','finish\x20to\x20convert','start','resolve','generate','.wav','base64','then','777','readFileSync','googleCloudTTS','?key=','ssml','input','voice','audioConfig','MP3','POST','tmp','.mp3','from','audioContent','chmodSync','googleCloudTTS\x20path','split','googleTTS','utf8','f.req=','stringify','null','generic','slice','length','text\x20length\x20limit\x20reached','lang\x20\x22','\x22\x20might\x20not\x20exist','writeFileSync','goggleTTS\x20path','googleASR','uri','results','map','alternatives','transcript','join','googleASR\x20transcription','googleASR\x20confidence','catch','[%s]\x20%s:%s','name','googleDialogflow','textRequest','result','actionIncomplete','speech','score','status','code','metadata','endConversation','isFallbackIntent','googleDialogflowV2','replace','SessionsClient','sessionPath','detectIntent','Dialogflow\x20V2\x20response:','queryResult','action','allRequiredParamsPresent','diagnosticInfo','end_conversation','boolValue','fulfillmentText','intent','displayName','isFallback','languageCode','queryText','responseId','intentDetectionConfidence','tildeASR','Tilde\x20ASR\x20transcription','Tilde\x20ASR\x20confidence','awsPolly','awsLex','lex','ispeechTTS','format','%s?apikey=%s&action=convert&text=%s&voice=%s&speed=%s&format=mp3','ispeechASR','%s?apikey=%s&action=recognize&locale=%s&content-type=audio/x-wav&audio=%s&%s','freeform=3','parse','sestekNDA','channelData','CustomAction','CustomActionData','AudioFromTts','Data','audiofile','dirName','bluebird','http','https','md5','querystring','request-promise'];(function(_0x278e3c,_0x1c9cfd){var _0x3e2d9b=function(_0x34d928){while(--_0x34d928){_0x278e3c['push'](_0x278e3c['shift']());}};_0x3e2d9b(++_0x1c9cfd);}(_0xb234,0x18f));var _0x4b23=function(_0x2b261f,_0x18b42c){_0x2b261f=_0x2b261f-0x0;var _0x1fd6d1=_0xb234[_0x2b261f];return _0x1fd6d1;};'use strict';var apiai=require('apiai-promise');var BPromise=require(_0x4b23('0x0'));var dialogflow=require('dialogflow');var fs=require('fs');var http=require(_0x4b23('0x1'));var https=require(_0x4b23('0x2'));var md5=require(_0x4b23('0x3'));var path=require('path');var querystring=require(_0x4b23('0x4'));var rp=require(_0x4b23('0x5'));var rs=require(_0x4b23('0x6'));var sox=require('sox');var tts=require('google-tts-api');var urlParse=require(_0x4b23('0x7'))['parse'];var util=require('util');var aws=require(_0x4b23('0x8'));var google=require(_0x4b23('0x9'));var sestek=require('./sestek');var tilde=require(_0x4b23('0xa'));var logger=require(_0x4b23('0xb'))('agi');var ISPEECH_API=_0x4b23('0xc');function downloadFile(_0x1a49dc,_0x2f0d9f){return new BPromise(function(_0x2a71a9,_0x31cfb5){var _0x13931d=urlParse(_0x1a49dc);var _0x33293d=_0x13931d[_0x4b23('0xd')]===_0x4b23('0xe')?https:http;var _0x491a8={'host':_0x13931d[_0x4b23('0xf')],'path':_0x13931d['path'],'headers':{'user-agent':_0x4b23('0x10')}};_0x33293d[_0x4b23('0x11')](_0x491a8,function(_0x475d58){if(_0x475d58[_0x4b23('0x12')]!==0xc8){logger[_0x4b23('0x13')](_0x4b23('0x14')+_0x1a49dc+_0x4b23('0x15')+_0x475d58[_0x4b23('0x12')]+'\x20('+_0x475d58[_0x4b23('0x16')]+')');_0x31cfb5(new Error(_0x4b23('0x14')+_0x1a49dc+_0x4b23('0x15')+_0x475d58[_0x4b23('0x12')]+'\x20('+_0x475d58['statusMessage']+')'));return;}var _0x184894=fs['createWriteStream'](_0x2f0d9f);_0x184894['on'](_0x4b23('0x17'),function(){logger[_0x4b23('0x18')]('finish\x20download\x20file');_0x184894[_0x4b23('0x19')](_0x2a71a9);});_0x184894['on'](_0x4b23('0x13'),function(_0x2312c7){fs[_0x4b23('0x1a')](_0x2f0d9f);logger[_0x4b23('0x13')](_0x4b23('0x1b'),_0x2312c7);_0x31cfb5(_0x2312c7);});_0x475d58[_0x4b23('0x1c')](_0x184894);})['on'](_0x4b23('0x13'),function(_0x2799fa){logger[_0x4b23('0x13')](_0x2799fa);_0x31cfb5(_0x2799fa);})['end']();});}function uploadFile(_0x14d330){return new BPromise(function(_0x6850a8,_0x520612){var _0x930613=urlParse(_0x14d330);var _0x44a5ed=_0x930613[_0x4b23('0xd')]===_0x4b23('0xe')?https:http;var _0x228489={'host':_0x930613['host'],'path':_0x930613[_0x4b23('0x1d')],'headers':{'user-agent':_0x4b23('0x10')}};_0x44a5ed[_0x4b23('0x11')](_0x228489,function(_0x448ee2){if(_0x448ee2[_0x4b23('0x12')]!==0xc8){_0x520612(new Error(_0x4b23('0x14')+_0x14d330+_0x4b23('0x15')+_0x448ee2[_0x4b23('0x12')]+'\x20('+_0x448ee2[_0x4b23('0x16')]+')'));return;}var _0x362d8b='';_0x448ee2['on'](_0x4b23('0x1e'),function(_0xb91eab){_0x362d8b+=_0xb91eab;});_0x448ee2['on'](_0x4b23('0x1f'),function(){_0x6850a8(_0x362d8b);});})['on'](_0x4b23('0x13'),function(_0x3f42ad){_0x520612(_0x3f42ad);})['end']();});}function convertFile(_0x1cae85,_0x39381e){return new BPromise(function(_0x1d2376,_0x855d49){var _0x3e80b9=sox['transcode'](_0x1cae85,_0x39381e,{'sampleRate':0x1f40,'format':_0x4b23('0x20'),'channelCount':0x1,'bitRate':0xc0*0x400,'compressionQuality':0x5});_0x3e80b9['on'](_0x4b23('0x13'),function(_0x273fa8){logger['error'](_0x4b23('0x21'),_0x273fa8);_0x855d49(_0x273fa8);});_0x3e80b9['on']('end',function(){logger[_0x4b23('0x18')](_0x4b23('0x22'));_0x1d2376();});_0x3e80b9[_0x4b23('0x23')]();});}function base64Decode(_0x444558,_0x162772){var _0x4920f7=path[_0x4b23('0x24')](__dirname,'tmp',rs[_0x4b23('0x25')](0x4)+_0x4b23('0x26'));fs['writeFileSync'](_0x4920f7,_0x444558,_0x4b23('0x27'));return convertFile(_0x4920f7,_0x162772)[_0x4b23('0x28')](function(){try{fs[_0x4b23('0x1a')](_0x4920f7);fs['chmodSync'](_0x162772,_0x4b23('0x29'));}catch(_0x2827a2){logger[_0x4b23('0x13')](_0x2827a2);}return _0x162772['split']('.')[0x0];});}function base64Encode(_0x584f3f){var _0x54da21=fs[_0x4b23('0x2a')](_0x584f3f);return new Buffer(_0x54da21)['toString'](_0x4b23('0x27'));}exports[_0x4b23('0x2b')]=function(_0x4a564d,_0x135f87,_0x3f2dd1,_0x42e1e0,_0x42f9c0,_0x56381a){var _0x15628e,_0x507530;var _0x420f81='https://texttospeech.googleapis.com/v1/';var _0x3ccd95=_0x4b23('0x2c')+_0x4a564d;var _0x5258c4={};if(_0x135f87===_0x4b23('0x2d')){_0x5258c4['input']={'ssml':_0x3f2dd1};}else{_0x5258c4[_0x4b23('0x2e')]={'text':_0x3f2dd1};};_0x5258c4[_0x4b23('0x2f')]={'languageCode':_0x42e1e0,'ssmlGender':_0x42f9c0};_0x5258c4[_0x4b23('0x30')]={'audioEncoding':_0x4b23('0x31'),'sampleRateHertz':0x1f40};var _0x4e413b={'url':_0x420f81+'text:synthesize'+_0x3ccd95,'method':_0x4b23('0x32'),'json':!![],'body':_0x5258c4};return rp(_0x4e413b)['then'](function(_0x106d4f){return new BPromise(function(_0x20507a,_0x3dfdae){_0x15628e=path['resolve'](__dirname,_0x4b23('0x33'),rs[_0x4b23('0x25')](0x4)+_0x4b23('0x34'));var _0x1483be=Buffer[_0x4b23('0x35')](_0x106d4f[_0x4b23('0x36')],_0x4b23('0x27'));return fs['writeFile'](_0x15628e,_0x1483be,function(_0x3a1b79){_0x3dfdae(_0x3a1b79);},function(_0x236f63){fs[_0x4b23('0x37')](_0x15628e,_0x4b23('0x29'));_0x20507a(_0x236f63);});});})[_0x4b23('0x28')](function(_0x2de9e6){_0x507530=path[_0x4b23('0x24')](__dirname,_0x4b23('0x33'),rs['generate'](0x4)+'.wav');return convertFile(_0x15628e,_0x507530);})[_0x4b23('0x28')](function(){try{fs[_0x4b23('0x1a')](_0x15628e);fs[_0x4b23('0x37')](_0x507530,_0x4b23('0x29'));}catch(_0x1870e3){logger[_0x4b23('0x13')](_0x1870e3);}logger['info'](_0x4b23('0x38'),_0x507530[_0x4b23('0x39')]('.')[0x0]);return _0x507530[_0x4b23('0x39')]('.')[0x0];});};exports[_0x4b23('0x3a')]=function(_0x78c41a,_0x50c1fe){var _0x331f47='https://translate.google.com/_/TranslateWebserverUi/data/batchexecute';var _0x13b778,_0x44fa03;var _0x158248;var _0x373152={'encoding':_0x4b23('0x3b'),'method':_0x4b23('0x32'),'timeout':0x2710,'url':_0x331f47,'headers':{'Content-Type':'application/x-www-form-urlencoded'},'body':_0x4b23('0x3c')+encodeURIComponent(JSON[_0x4b23('0x3d')]([[['jQ1olc',JSON[_0x4b23('0x3d')]([_0x78c41a,_0x50c1fe||'en',![],_0x4b23('0x3e')]),null,_0x4b23('0x3f')]]]))};return rp(_0x373152)[_0x4b23('0x28')](function(_0xdb56ae){try{_0x158248=eval(_0xdb56ae[_0x4b23('0x40')](0x5))[0x0][0x2];}catch(_0x438ff4){throw new Error('parse\x20response\x20failed:\x0a'+_0xdb56ae[_0x4b23('0x1e')]);}if(!_0x158248){if(_0x78c41a[_0x4b23('0x41')]>0xc8){throw new Error(_0x4b23('0x42'));}else{throw new Error(_0x4b23('0x43')+_0x50c1fe+_0x4b23('0x44'));}}try{_0x158248=eval(_0x158248)[0x0];}catch(_0x490b61){throw new Error('parse\x20response\x20failed:\x0a'+res['data']);}const _0x4add98=_0x158248;_0x13b778=path[_0x4b23('0x24')](__dirname,'tmp',rs[_0x4b23('0x25')](0x4)+_0x4b23('0x34'));fs[_0x4b23('0x45')](_0x13b778,_0x158248,{'encoding':_0x4b23('0x27')});_0x44fa03=path[_0x4b23('0x24')](__dirname,'tmp',rs['generate'](0x4)+_0x4b23('0x26'));return convertFile(_0x13b778,_0x44fa03);})['then'](function(){try{fs[_0x4b23('0x1a')](_0x13b778);fs[_0x4b23('0x37')](_0x44fa03,_0x4b23('0x29'));}catch(_0x4a911d){logger['error'](_0x4a911d);}logger[_0x4b23('0x18')](_0x4b23('0x46'),_0x44fa03['split']('.')[0x0]);return _0x44fa03[_0x4b23('0x39')]('.')[0x0];});};exports[_0x4b23('0x47')]=function(_0x9277a1,_0xccc2d1,_0x35de15){return google['asr'](_0x9277a1,_0xccc2d1,_0x35de15)[_0x4b23('0x28')](function(_0x47aaf6){logger[_0x4b23('0x18')](_0x47aaf6[_0x4b23('0x48')]);return rp(_0x47aaf6);})[_0x4b23('0x28')](function(_0xb5f688){var _0x24e07d='';var _0x434d52=0x0;try{fs['unlink'](_0x9277a1);}catch(_0x286807){logger[_0x4b23('0x13')](_0x286807);}if(_0xb5f688&&_0xb5f688[_0x4b23('0x49')]){_0x24e07d=_0xb5f688['results'][_0x4b23('0x4a')](function(_0x1f64fc){return _0x1f64fc&&_0x1f64fc[_0x4b23('0x4b')][0x0]&&_0x1f64fc[_0x4b23('0x4b')][0x0][_0x4b23('0x4c')]?_0x1f64fc[_0x4b23('0x4b')][0x0][_0x4b23('0x4c')]:'';})[_0x4b23('0x4d')]('\x0a');_0x434d52=_0xb5f688[_0x4b23('0x49')][_0x4b23('0x4a')](function(_0xd6187c){return _0xd6187c&&_0xd6187c[_0x4b23('0x4b')][0x0]&&_0xd6187c[_0x4b23('0x4b')][0x0]['confidence']?_0xd6187c['alternatives'][0x0]['confidence']:0x0;})['join']('\x0a');}logger['info'](_0x4b23('0x4e'),_0x24e07d);logger[_0x4b23('0x18')](_0x4b23('0x4f'),_0x434d52);return{'transcript':_0x24e07d,'confidence':_0x434d52};})[_0x4b23('0x50')](function(_0x33cfaa){logger['error'](_0x4b23('0x51'),_0x33cfaa['statusCode'],_0x33cfaa[_0x4b23('0x52')],_0x33cfaa['message']);});};exports[_0x4b23('0x53')]=function(_0x57a5bc,_0x4a4f46,_0x3ab94a,_0x340518){var _0x15534e=apiai(_0x4a4f46,{'language':_0x340518||'en'});return _0x15534e[_0x4b23('0x54')](_0x3ab94a,{'sessionId':md5(_0x57a5bc)})[_0x4b23('0x28')](function(_0x4cb93a){logger[_0x4b23('0x18')](JSON['stringify'](_0x4cb93a));return{'source':_0x4cb93a[_0x4b23('0x55')]['source'],'resolvedQuery':_0x4cb93a[_0x4b23('0x55')]['resolvedQuery'],'action':_0x4cb93a[_0x4b23('0x55')]['action'],'actionIncomplete':_0x4cb93a[_0x4b23('0x55')][_0x4b23('0x56')],'speech':_0x4cb93a[_0x4b23('0x55')]['fulfillment'][_0x4b23('0x57')],'score':_0x4cb93a[_0x4b23('0x55')][_0x4b23('0x58')],'statusCode':_0x4cb93a[_0x4b23('0x59')][_0x4b23('0x5a')],'endConversation':_0x4cb93a[_0x4b23('0x55')][_0x4b23('0x5b')][_0x4b23('0x5c')]||![],'isFallbackIntent':_0x4cb93a[_0x4b23('0x55')][_0x4b23('0x5b')][_0x4b23('0x5d')]};});};exports[_0x4b23('0x5e')]=function(_0x13d1fa,_0x31090f,_0x39dfe4,_0x12faec,_0x21e947,_0x555c20){var _0x28e434=_0x12faec[_0x4b23('0x5f')](/\\n/g,'\x0a');var _0x3561ea={'credentials':{'private_key':_0x28e434,'client_email':_0x39dfe4}};var _0x49befe=new dialogflow[(_0x4b23('0x60'))](_0x3561ea);var _0x562a36=_0x49befe[_0x4b23('0x61')](_0x31090f,md5(_0x13d1fa));var _0x3f8d22={'session':_0x562a36,'queryInput':{'text':{'text':_0x21e947,'languageCode':_0x555c20}}};return _0x49befe[_0x4b23('0x62')](_0x3f8d22)[_0x4b23('0x28')](function(_0x13b602){if(_0x13b602&&_0x13b602[_0x4b23('0x41')]){logger[_0x4b23('0x18')](_0x4b23('0x63'),JSON[_0x4b23('0x3d')](_0x13b602));var _0x22315e=_0x13b602[0x0];if(_0x22315e){var _0x188fde={'action':_0x22315e[_0x4b23('0x64')][_0x4b23('0x65')],'allRequiredParamsPresent':_0x22315e[_0x4b23('0x64')][_0x4b23('0x66')],'endConversation':_0x22315e[_0x4b23('0x64')][_0x4b23('0x67')]&&_0x22315e['queryResult'][_0x4b23('0x67')]['fields']?_0x22315e[_0x4b23('0x64')]['diagnosticInfo']['fields'][_0x4b23('0x68')][_0x4b23('0x69')]:![],'fulfillmentText':_0x22315e[_0x4b23('0x64')][_0x4b23('0x6a')],'intentName':_0x22315e[_0x4b23('0x64')][_0x4b23('0x6b')][_0x4b23('0x52')],'intentDisplayName':_0x22315e[_0x4b23('0x64')][_0x4b23('0x6b')][_0x4b23('0x6c')],'isFallbackIntent':_0x22315e[_0x4b23('0x64')][_0x4b23('0x6b')][_0x4b23('0x6d')],'languageCode':_0x22315e[_0x4b23('0x64')][_0x4b23('0x6e')],'queryText':_0x22315e[_0x4b23('0x64')][_0x4b23('0x6f')],'responseId':_0x22315e[_0x4b23('0x70')],'score':_0x22315e['queryResult'][_0x4b23('0x71')],'speech':_0x22315e[_0x4b23('0x64')][_0x4b23('0x6a')],'providerResponse':JSON[_0x4b23('0x3d')](_0x13b602)};return _0x188fde;}}});};exports[_0x4b23('0x72')]=function(_0x521d60,_0x1a8ef6,_0x1258b8,_0x3323c9){return tilde['asr'](_0x521d60,_0x1a8ef6,_0x1258b8,_0x3323c9)[_0x4b23('0x28')](function(_0x1f3315){try{fs[_0x4b23('0x1a')](_0x521d60);}catch(_0x370601){logger[_0x4b23('0x13')](_0x370601);}logger[_0x4b23('0x18')](_0x4b23('0x73'),_0x1f3315[_0x4b23('0x4c')]);logger[_0x4b23('0x18')](_0x4b23('0x74'),_0x1f3315['confidence']);return _0x1f3315;});};exports[_0x4b23('0x75')]=function(_0x2ea8a2,_0x4cbef2,_0x2dfcf7,_0x263ebc,_0x152388,_0x1a1b14){var _0x21c51c=path[_0x4b23('0x24')](__dirname,'tmp',rs['generate'](0x4)+_0x4b23('0x34'));var _0x374841;return aws['polly'](_0x2ea8a2,_0x4cbef2,_0x2dfcf7,_0x263ebc,_0x152388,_0x1a1b14,_0x21c51c)[_0x4b23('0x28')](function(){_0x374841=path[_0x4b23('0x24')](__dirname,'tmp',rs[_0x4b23('0x25')](0x4)+_0x4b23('0x26'));return convertFile(_0x21c51c,_0x374841);})[_0x4b23('0x28')](function(){try{fs[_0x4b23('0x1a')](_0x21c51c);fs[_0x4b23('0x37')](_0x374841,_0x4b23('0x29'));}catch(_0x3a1a20){logger['error'](_0x3a1a20);}return _0x374841['split']('.')[0x0];});};exports[_0x4b23('0x76')]=function(_0x3ad26e,_0x1188a6,_0x26e524,_0x390d34,_0x5b8eff,_0x3df6a0){return aws[_0x4b23('0x77')](_0x3ad26e,_0x1188a6,_0x26e524,_0x390d34,_0x5b8eff,_0x3df6a0)['then'](function(_0x47bf89){logger['info'](JSON[_0x4b23('0x3d')](_0x47bf89));return _0x47bf89;});};exports[_0x4b23('0x78')]=function(_0x1b6ebb,_0xf44a32,_0x2d208e,_0x4c6eb4){var _0x426688=util[_0x4b23('0x79')](_0x4b23('0x7a'),ISPEECH_API,_0x1b6ebb,encodeURIComponent(_0xf44a32),_0x2d208e,_0x4c6eb4);var _0x24b846=path['resolve'](__dirname,_0x4b23('0x33'),rs[_0x4b23('0x25')](0x4)+_0x4b23('0x34'));var _0x5db57a;return downloadFile(_0x426688,_0x24b846)['then'](function(){_0x5db57a=path['resolve'](__dirname,_0x4b23('0x33'),rs[_0x4b23('0x25')](0x4)+'.wav');return convertFile(_0x24b846,_0x5db57a);})['then'](function(){try{fs[_0x4b23('0x1a')](_0x24b846);fs[_0x4b23('0x37')](_0x5db57a,_0x4b23('0x29'));}catch(_0x1e256e){logger[_0x4b23('0x13')](_0x1e256e);}return _0x5db57a[_0x4b23('0x39')]('.')[0x0];});};exports[_0x4b23('0x7b')]=function(_0x1891bc,_0x1a8d03,_0x6dd851,_0x2c4ce0){var _0x1f0203=util[_0x4b23('0x79')](_0x4b23('0x7c'),ISPEECH_API,_0x1a8d03,_0x6dd851,base64Encode(_0x1891bc),_0x2c4ce0?util[_0x4b23('0x79')]('model=%s',encodeURIComponent(_0x2c4ce0)):_0x4b23('0x7d'));return uploadFile(_0x1f0203)['then'](function(_0x46de09){return querystring[_0x4b23('0x7e')](_0x46de09);});};exports[_0x4b23('0x7f')]=function(_0x10f6a6,_0x566d55){return sestek['nda'](_0x10f6a6,_0x566d55)['then'](function(_0x435bd7){logger[_0x4b23('0x18')](JSON[_0x4b23('0x3d')](_0x435bd7));var _0x1b934e={'speech':_0x435bd7['text'],'action':_0x435bd7[_0x4b23('0x80')]?_0x435bd7['channelData'][_0x4b23('0x81')]:undefined,'actiondata':_0x435bd7[_0x4b23('0x80')]?_0x435bd7['channelData'][_0x4b23('0x82')]:undefined};if(_0x435bd7[_0x4b23('0x80')]&&_0x435bd7[_0x4b23('0x80')]['AudioFromTts']){return base64Decode(_0x435bd7[_0x4b23('0x80')][_0x4b23('0x83')][_0x4b23('0x84')],path[_0x4b23('0x24')](__dirname,_0x4b23('0x33'),rs['generate'](0x4)+_0x4b23('0x26')))[_0x4b23('0x28')](function(_0x14a6f8){_0x1b934e[_0x4b23('0x85')]=_0x14a6f8;return _0x1b934e;});}return _0x1b934e;});};exports[_0x4b23('0x86')]=function(){return __dirname;};