繁体   English   中英

上传 Intent 函数 Dialogflow V2

[英]Upload Intent function Dialogflow V2

我正在尝试开发一个 API 以将意图上传到Dialogflow V2。 我已经尝试了下面的代码片段,它不起作用但是如果尝试与Dialogflow通信它确实有效(检测意图)并且确实从Dialogflow获得查询回复。

允许

我是管理员 > 服务帐户 > DIALOGFLOW 管理员

错误

错误:7 PERMISSION_DENIED:“projects/dexter-47332/agent”上的 IAM 权限“dialogflow.entityTypes.create”被拒绝。

博客/参考资料

  1. Dialogflow 简单的授权方式
  2. https://github.com/dialogflow/dialogflow-nodejs-client-v2/blob/master/samples/resource.js#L26
  3. https://www.npmjs.com/package/dialogflow
  4. https://developers.google.com/apis-explorer/
  5. https://cloud.google.com/docs/authentication/production

 //------- keys.json (test 1) { "type": "service_account", "project_id": "mybot", "private_key_id": "123456asd", "private_key": "YOURKEY", "client_email": "yourID@mybot.iam.gserviceaccount.com", "client_id": "098091234", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/yourID%40mybot.iam.gserviceaccount.com" } //--------------------- ** (test 2) ** --------- let privateKey = 'key'; let clientEmail = "email"; let config = { credentials: { private_key: privateKey, client_email: clientEmail } } function createEntityTypes(projectId) { // [START dialogflow_create_entity] // Imports the Dialogflow library const dialogflow = require('dialogflow'); // ******** Instantiates clients (Test 1)******** const entityTypesClient = new dialogflow.EntityTypesClient({ 'keyFilename': './keys.json' }); const intentsClient = new dialogflow.IntentsClient({ 'keyFilename': './keys.json' }); // ******** Instantiates clients (Test 2)******** const entityTypesClient = new dialogflow.EntityTypesClient(config); const intentsClient = new dialogflow.IntentsClient(config); // The path to the agent the created entity type belongs to. const agentPath = intentsClient.projectAgentPath(projectId); const promises = []; // Create an entity type named "size", with possible values of small, medium // and large and some synonyms. const sizeRequest = { parent: agentPath, entityType: { displayName: 'test', kind: 'KIND_MAP', autoExpansionMode: 'AUTO_EXPANSION_MODE_UNSPECIFIED', entities: [{ value: 'small', synonyms: ['small', 'petit'] }, { value: 'medium', synonyms: ['medium'] }, { value: 'large', synonyms: ['large', 'big'] }, ], }, }; promises.push( 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); }) ); } createEntityTypes(projectId);

您可以使用 JWT(JSON Web 令牌)对服务帐户进行身份验证,如本例所示

 const serviceAccount = { };    // JSON key contents {"type": "service_account",...

 const serviceAccountAuth = new google.auth.JWT({
 email: serviceAccount.client_email,
 key: serviceAccount.private_key,
 scopes: 'https://www.googleapis.com/auth/calendar'
});

有关 Google API 的更多 OAuth2.0 范围,您可以在 此处查看完整列表。

我遇到了同样的错误。 我通过删除当前服务帐户并创建一个新帐户并为该角色选择“所有者”选项来更正它。

关联的服务帐户必须具有“Dialogflow API 管理员”角色才能创建意图和实体。

我认为您必须在 sizeRequest 中提供一个名称参数并使其等于一个空字符串。

看一下代码片段。

    let request = {
        parent: `projects/${PROJECID}/agent`,
        entityType: {
            name: '',
            autoExpansionMode: 'AUTO_EXPANSION_MODE_DEFAULT',
            displayName: 'size_type',
            enableFuzzyExtraction: false,
            entities: [
                {
                    value: 'Big',
                    synonyms: ['big', 'large', 'huge']
                },
                {
                    value: 'Medium',
                    synonyms: ['medium', 'not big']
                }
            ],
            kind: 'KIND_MAP'
        },
        languageCode: 'en'
};

请让我知道这可不可以帮你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM