Hi, I've problem with dialogflow .
'IAM permission \'dialogflow.sessions.detectIntent\' on \'projects/alanaconding/agent\' denied.' }
But i export credentials with JSON file.
my code :
let express = require('express')
let app = express()
let bodyParser = require('body-parser')
const dialogflow = require('dialogflow');
//DialogFlow vairable
const common = require('@google-cloud/common');
const fs = require('fs');
const structjson = require('./structjson.js');
const pump = require('pump');
const through2 = require('through2');
const projectId = 'alanaconding'; //https://dialogflow.com/docs/agents#settings
const sessionId = ' ';
var query = '';
const languageCode = 'fr-FR';
//---------------------
//Moteur de template
//---------------------
app.set('view engine', 'ejs')
//---------------------
//MIDDLEWARE
//---------------------
//Gestion des fichiers statique
app.use('/assets',express.static('public'))
//Gestion du parsing des messages
app.use(bodyParser.urlencoded({ extended:false}))
app.use(bodyParser.json())
//Gestion des session
/*app.use(session({
secret: 'azerty',
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}))
// Gestion des messages flash
// Middleware maison
app.use(require ('./middleware/flash'))*/
function dialogFlowRequest(){
// You can find your project ID in your Dialogflow agent settings
const projectId = 'alanaconding'; //https://dialogflow.com/docs/agents#settings
const sessionId = ' ';
const query = 'bonjour';
const languageCode = 'fr-FR';
// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient();
// 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);
});
}
//Routes
app.get('/',(request,response) => {
response.render('pages/index')
})
app.post('/', (request,response) => {
if(request.body.message === undefined || request.body.message === ''){
//request.flash('error',"vous n'avez pas post茅 de message")
response.redirect('/')
} else {
console.log('envoi requ锚te ');
dialogFlowRequest();
}
})
app.listen(8060);
If you are still having issues, please be sure to include as much information as
possible:
dialogflow version: 2Following these steps will guarantee the quickest resolution possible. Thanks!
make sure you have given admin access to google-service.json which you have set in you system variable GOOGLE APPLICATION CREDENTIAL
make sure you have given admin access to google-service.json which you have set in you system variable GOOGLE APPLICATION CREDENTIAL
I have given "Project owner" role and I still get an authentication error.
Could you please double-check what JSON file GOOGLE_APPLICATION_CREDENTIALS points set:
console.log(process.env.GOOGLE_APPLICATION_CREDENTIALS);
And then look at the client_email field in the file to make sure you granted the IAM permissions to exactly the right account.
Can this be documented in the Readme?
@nnegrey @matthewayne Do y'all have any particular context for this?
I haven't personally run into this when using Dialogflow. The steps I've taken have simple been enabling the Dialogflow API. Reading the steps to reproduce above, it's not clear to me how to reproduce this.
I'm curious is this is something Dialogflow users run into or if it's common to all Google Cloud APIs.
From most issues I've seen, it's usually from what dysnomia said about setting the GOOGLE_APPLICATION_CREDENTIALS:
export GOOGLE_APPLICATION_CREDENTIALS=keyfile.json
But, if it is not that, then I'd need some more info.
To further follow up, the README has a Before you begin section
Which takes you here
Step 4 in that doc is to setup auth
If there is a reproduction of this which is not solved by setting GOOGLE_APPLICATION_CREDENTIALS=[path to service account key.json], please feel free to enter a reproduction case and we can re-open!
Pending more information, closing as we have GOOGLE_APPLICATION_CREDENTIALS documented in various locations, including near the top of most of our product Quickstart pages. For Dialogflow EE, the Quickstart begins with Set up your GCP project and authentication, including the top of this repo's README.
In my case this was because my Service Account was a "DialogFlow API Client" instead of a "DialogFlow API Admin". Apparently the Export function requires admin.
Hi,
I have followed all of these steps but still getting PERMISSION DENIED. My service account is set to DialogFlow Admin.
Need help ASAP on this issue.
Most helpful comment
In my case this was because my Service Account was a "DialogFlow API Client" instead of a "DialogFlow API Admin". Apparently the Export function requires admin.