I'm trying to create a new Entity
on DialogFlow:
const dialogflow = require('dialogflow');
/**
* trains the NLP to recognize language constructs
*/
export function intTraining() {
const ENTITY_DEFINITION_BOOLEAN = {
parent: 'foo',
entityType: {
displayName: 'myBoolean',
kind: 'KIND_MAP',
autoExpansionMode: 'AUTO_EXPANSION_MODE_UNSPECIFIED',
entities: [
{value: 'true', synonyms: [ 'yes', 'yeah', 'sure', 'okay' ]},
{value: 'false', synonyms: [ 'no', 'no thanks', 'never' ]}
],
},
};
// allocate
const entityTypesClient = new dialogflow.EntityTypesClient();
// declare promises
const promises = [];
// allocate entities
prepareEntity(entityTypesClient, promises, ENTITY_DEFINITION_BOOLEAN);
// execute state initialization
Promise.all(promises);
}
/** Buffers an Entity onto the Promise Queue. */
function prepareEntity(entityTypesClient, promises, definition) {
// boolean entity
promises.push(entityTypesClient
.createEntityType(definition)
.then(responses => { })
.catch(err => { console.error('', err) })
);
}
When I execute this code, however, I receive the following error:
Error: Resource name 'foo' does not match 'projects/*/agent'.
I've already used gcloud auth application-default login
to create API access credentials on my machine, with foo
configured as the currently selected project, but this hasn't helped.
What am I doing wrong?
You need to include the full path to your Dialogflow agent in the create entity request because you account may have access to more than one agent. The Dialogflow v2 Node.js library (which you seem to be using) has a helper method to construct the agent path for you using your agent's project ID (which can be found in your Dialogflow agent's settings). Here is an modified excerpt of code from Dialogflow's v2 Node.js samples that shows how to construct and make a create entity type request:
// Imports the Dialogflow library
const dialogflow = require('dialogflow');
// Instantiates clients
const entityTypesClient = new dialogflow.EntityTypesClient();
const intentsClient = new dialogflow.IntentsClient();
// The path to the agent the created entity type belongs to.
const agentPath = intentsClient.projectAgentPath(projectId);
// Create an entity type named "size", with possible values of small, medium
// and large and some synonyms.
const sizeRequest = {
parent: agentPath,
entityType: {
displayName: 'size',
entities: [
{value: 'small', synonyms: ['small', 'petit']},
{value: 'medium', synonyms: ['medium']},
{value: 'large', synonyms: ['large', 'big']},
],
},
};
entityTypesClient.createEntityType(sizeRequest)
.then(responses => {
console.log('Created size entity type:');
logEntityType(responses[0]);
})
.catch(err => {
console.error('Failed to create size entity type:', err);
})
);