javascriptnode.jsdialogflow-es

How to specify agent ID when calling Dialogflow API?


I am using the following NodeJS code to make an API call to Dialogflow to send message "Hello there", I am able to specify project ID, session ID but I am not sure where I can specify agent ID.

  let projectId = 'DEMO PROJECT';
  let message ='Hello there';
  // 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: message,
        // The language used by the client (en-US)
        languageCode: 'en-US',
      },
    },
  };

  // Send request and log result
  const responses = await sessionClient.detectIntent(request);

The problem is I am pragmatically creating agents under project DEMO, therefore, I need to specify which agent this conversation is going to send to. At the moment I am only able to specify project ID and session ID, however, my question is how can I specify agent ID?


Solution

  • According to google official document

    Note: You can only create one agent for a GCP project. If you need multiple agents, you will need to create multiple projects.

    That is why you are not able to specify the agent ID as there is only 1 agent under each project.