fix check file

This commit is contained in:
Leifer Mendez
2022-01-16 21:26:32 +01:00
parent 982df6184e
commit a21f70af1f

View File

@@ -4,19 +4,28 @@ const nanoid = require('nanoid')
/**
* Debes de tener tu archivo con el nombre "chatbot-account.json" en la raíz del proyecto
*/
const CREDENTIALS = JSON.parse(fs.readFileSync(`${__dirname}/../chatbot-account.json`));
let PROJECID;
let CONFIGURATION;
let sessionClient;
const PROJECID = CREDENTIALS.project_id;
const CONFIGURATION = {
credentials: {
private_key: CREDENTIALS['private_key'],
client_email: CREDENTIALS['client_email']
const checkFileCredentials = () => {
if(!fs.existsSync(`${__dirname}/../chatbot-account.json`)){
return false
}
const parseCredentials = JSON.parse(fs.readFileSync(`${__dirname}/../chatbot-account.json`));
PROJECID = parseCredentials.project_id;
CONFIGURATION = {
credentials: {
private_key: parseCredentials['private_key'],
client_email: parseCredentials['client_email']
}
}
sessionClient = new dialogflow.SessionsClient(CONFIGURATION);
}
// Create a new session
const sessionClient = new dialogflow.SessionsClient(CONFIGURATION);
// Detect intent method
const detectIntent = async (queryText) => {
@@ -61,4 +70,6 @@ const getDataIa = (message = '', cb = () => { }) => {
})
}
checkFileCredentials();
module.exports = { getDataIa }