2017-11-25 89 views
0

我试图创建DialogFlow新Entity错误:资源名称“富”不匹配“项目/ * /剂”

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) }) 
); 
} 

当我执行该代码,但是,我收到以下错误:

Error: Resource name 'foo' does not match 'projects/*/agent'.

我已经使用gcloud auth application-default login我的机器上创建API访问凭据,以foo配置为当前选择的项目,但是这并没有帮助。

我在做什么错?

回答

1

您需要在创建实体请求中包含Dialogflow代理的完整路径,因为您的帐户可能有权访问多个代理。 Dialogflow v2 Node.js库(您似乎正在使用)有一个帮助器方法,可以使用代理的项目ID(可在your Dialogflow agent's settings中找到)为您构建代理路径。以下是code from Dialogflow's v2 Node.js samples的修改摘录,其中显示了如何构建并创建实体类型请求:

// 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); 
    }) 
); 
-2

您需要为您的项目代理提供精确的路径。相反,在你的ENTITY_DEFINITION_BOOLEAN分配使用parent : foo的,你应该使用:

parent: 'projects/foo/agent'

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

相关问题