2

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?

4

2 回答 2

2

您需要在创建实体请求中包含 Dialogflow 代理的完整路径,因为您的帐户可能有权访问多个代理。Dialogflow v2 Node.js 库(您似乎正在使用)有一个帮助方法,可以使用代理的项目 ID(可以在Dialogflow 代理的设置中找到)为您构建代理路径。以下是来自 Dialogflow 的 v2 Node.js 示例的修改后的代码摘录,展示了如何构造和发出创建实体类型请求:

// 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);
  })
);
于 2017-12-06T01:28:46.023 回答
-2

您需要提供到项目代理的精确路径。而不是parent : foo在你的分配中使用ENTITY_DEFINITION_BOOLEAN,你应该使用:

parent: 'projects/foo/agent'

这与 DialogFlow 预期的路径结构相匹配。

于 2017-11-25T16:35:51.397 回答