Reputation: 1086
i am trying to implement a chat bot application with google dialog flow. i was fallowing this github tutorial https://github.com/dialogflow/dialogflow-nodejs-client-v2 to implement api. this is my code
var express = require('express');
var router = express.Router();
const projectId = 'my-project-id'; //https://dialogflow.com/docs/agents#settings
const sessionId = 'random no';
const query = 'hello';
const languageCode = 'en-US';
// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient();
// // Define session path
// const sessionPath = sessionClient.sessionPath(projectId, sessionId);
/* GET home page. */
router.get('/', function(req, res, next) {
});
module.exports = router;
once i start my application i am getting the bellow error
(node:6436) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: Unexpected error while acquiring application default credentials: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
(node:6436) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): Error: Unexpected error while acquiring application default credentials: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
so i tried to figure out the issue and found that i need to Set up authentication with a service account. and i did that downloaded the key file that contain required keys and ran the command
set GOOGLE_APPLICATION_CREDENTIALS=[PATH]
but doing this also did nothing. is there a way to manually provide this key file from the code instead of setting an environment variable.
Upvotes: 1
Views: 973
Reputation: 1916
According to this link and github repo here you should be able to set the credentials in const sessionClient
:
const sessionClient = new dialogflow.SessionsClient({ keyFilename: "relative/path/to/key.json" })
Upvotes: 3