0
votes

I am building a dialogflow Agent. I am using Node.js client library for dialogflow. When I call BatchUpdateIntents it works perfectly but also creates the intents if its already present in the agent, means api call does not prevent duplicate intents while it should have to be.

code sample

const createIntentRequest = {
    parent: agentPath,
    intentBatchInline: {
        intents: intents
    }
};

const [operation] = await intentsClient.batchUpdateIntents(createIntentRequest);

const [ response ] = await operation.promise();

Can someone guide me how to prevent intent duplication using Node.js client library?

1

1 Answers

1
votes

To be able to correctly find and update an intent, Dialogflow needs the intent's name property (not just the displayName), including the ID that was automatically assigned to the intent when it was first created.

Here's an example of the required format (the ID goes where the second asterisk is):

{ 
  displayName: 'myIntent',
  name: 'projects/*/agent/intents/*',
  trainingPhrases: []
}

I don't know what the intents in your intentBatch look like, but if the name property is missing, that could be the reason for the duplication.

The easiest way to get the ID is to send a ListIntentsRequest to the API - the resulting array will include all of the intents in your agent as objects, containing details such as the name and displayName as properties in each one.