I'm trying to create an entity on Dialogflow using Node.js. Is it possible? If yes, how should I execute it? Thank you.
Yes it is possible. For reference see EntityTypesClient() for other methods you can use regarding entities.
Prior to executing the code, make sure you have done the following as mentioned in Dialogflow nodejs quickstart.
The code example below creates an entity test_sizing with a value that have corresponding synonyms. You can also print values of response
if you need information from it.
'use strict';
const dialogflow = require('@google-cloud/dialogflow');
const entityClient = new dialogflow.EntityTypesClient();
const agentPath = entityClient.projectAgentPath('your-project-id-here');
const entityType = {
displayName: 'test_sizing',
kind: 'KIND_MAP',
entities: [
{value: 'small', synonyms: ['small', 'petit']},
{value: 'medium', synonyms: ['medium']},
{value: 'large', synonyms: ['large', 'big']},
],
};
const request = { parent: agentPath, entityType: entityType };
const response = entityClient.createEntityType(request);
Dialogflow output:
test_sizing entity: