diff --git a/adapter/diaglogflow.js b/adapter/diaglogflow.js index 44b6987..c042b8c 100644 --- a/adapter/diaglogflow.js +++ b/adapter/diaglogflow.js @@ -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 } \ No newline at end of file