Dialogflow easy way for authorization

Dialogflow easy way for authorization



Does there exist an easy way to connect my Dialogflow agent to my node.js code? When I use this code with the correct projectID taken from the Dialogflow agent's settings page, I have the following error:


node.js



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.


const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);



I visited the page, but for what I want I think is quite confused (they quotes other API and a lot of setting), how can I resolve this?



I would like to do it taking informations from a file and loading all without installing losts of APIs or some other...




2 Answers
2



It is not very well documented, but the easiest way to authenticate is using the JSON file provided on your google cloud platform console.


const sessionClient = new dialogflow.SessionsClient(
keyFilename: '/path/to/google.json'
);
const sessionPath = sessionClient.sessionPath(projectId, sessionId);





thanks, it should work, but i get this error: { Error: 7 PERMISSION_DENIED: IAM permission 'dialogflow.sessions.detectIntent' on 'projects/xxxx/agent' denied. I created for the test an access key and file correctly, with role of admin of dialogflow and owner of the project, but i still get "access denied", any ideas?
– Gray
May 26 at 20:24






You're missing some permissions on your google cloud platform settings. It's hard to debug without access.
– Marcos Casagrande
May 26 at 20:37





Do you have in IAM tab, your dialogflow integration added?
– Marcos Casagrande
May 26 at 20:48


IAM





Thanks for the answer, now i can't check out as soon as i can i will inform, thanks for your help and patience
– Gray
May 26 at 20:59





ok you were right, it was a little distraction, now i resolved. Thanks
– Gray
May 27 at 9:08



I am writing the code, which worked for me. Please follow all the steps provided in Reference link 2 and for coding purpose you can use the snippet provided.



I have also added the sample JSON of Google Cloud Oauth



References:




//Downloaded JSON format


"type": "service_account",
"project_id": "mybot",
"private_key_id": "123456asd",
"private_key": "YOURKEY",
"client_email": "yourID@mybot.iam.gserviceaccount.com",
"client_id": "098091234",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/yourID%40mybot.iam.gserviceaccount.com"



//------*********************---------------------------
//
const projectId = 'mybot';

//https://dialogflow.com/docs/agents#settings
// generate session id (currently hard coded)
const sessionId = '981dbc33-7c54-5419-2cce-edf90efd2170';
const query = 'hello';
const languageCode = 'en-US';

// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
let privateKey = 'YourKey';

// as per goolgle json
let clientEmail = "yourID@mybot.iam.gserviceaccount.com";
let config =
credentials:
private_key: privateKey,
client_email: clientEmail


const sessionClient = new dialogflow.SessionsClient(config);

// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);

// The text query request.
const request =
session: sessionPath,
queryInput:
text:
text: query,
languageCode: languageCode,
,
,
;

// Send request and log result
sessionClient
.detectIntent(request)
.then(responses =>
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.`);

)
.catch(err =>
console.error('ERROR:', err);
);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj