Search code examples
node.jspermissionsdialogflow-esgoogle-iam

Dialogflow Node SDK permission fail (dialogflow.sessions.detectIntent)


I got a problem with Node DialogFlow API integration.

I can not have the necessary permissions to make calls to the API, although I have followed all possible documentation.

Here is my Agent Service Account from Dialogflow admin :

DialogFlow Service Account Then the Service Account roles :

Service Account Authorizations

The "Client de l'API Dialogflow" role detail, where we can see "dialogflow.sessions.detectIntent" :

DialogFlow API Authorizations

And finally, the Node error after downloading the JSON file corresponding to the Service Account :

Node error

Am I missing something ?

I tried to generate other JSON files, create other Service Accounts, nothing worked...

The Node script is simple, just pasted from the official tutorial :

const projectId = 'newagent-9e77e '; //https://dialogflow.com/docs/agents#settings
const sessionId = 'quickstart-session-id';
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);
  });

Thanks !


Solution

  • The problem was on space on the "projectId" constant. Shame on me.