I am using the Google Cloud API (dialogflow) with my NodeJS application, following the steps on google documentation, referencing a JSON file in a enviroment variable (using dotenv) I was able to use the API.
GOOGLE_APPLICATION_CREDENTIALS="./dialogflow_credentials.json"
But my actual project that I'm trying to implement the API are on Heroku, with automatic deploys based on my github repo. So, if I use the actual code, my JSON credentials will be visible on github.
Is there a way to put this JSON file direct on the ENV, as a string? (On heroku I can define the enviroment variables) or have a better way to do this?
I tried to use info from this question Is it possible to store a JSON file to an ENV variable with dotenv?, but doesn't work.
I'm testing with this example code on my index.js:
const dialogflow = require('dialogflow');
const uuid = require('uuid');
/**
* Send a query to the dialogflow agent, and return the query result.
* @param {string} projectId The project to be used
*/
async function runSample(projectId = 'your-project-id') {
// A unique identifier for the given session
const sessionId = uuid.v4();
// Create a new session
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: 'hello',
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
}