首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试检测dialogflow CX上的意图时,IAM权限被拒绝

尝试检测dialogflow CX上的意图时,IAM权限被拒绝
EN

Stack Overflow用户
提问于 2021-08-11 22:32:05
回答 3查看 313关注 0票数 1

我创建了服务帐户,并按照本指南提供给我的环境

https://cloud.google.com/dialogflow/cx/docs/quick/setup#windows

我尝试使用firebase serve运行我的代码,但得到了以下错误:

Error: 7 PERMISSION_DENIED: IAM permission 'dialogflow.sessions.detectIntent' on 'projects/botDialogflowCX/locations/us-central1/agents/chat' denied

我确信服务帐户是正确的。我已经尝试创建了dialogflow管理员帐户、客户端和项目所有者帐户。

以下是我的代码

代码语言:javascript
复制
const functions = require("firebase-functions");
const { SessionsClient } = require("@google-cloud/dialogflow-cx");
const crededentials = require("../../.env/botdialogflowcx-5e936a89c163.json");

exports.teste = functions.https.onRequest((request, response) => {
    functions.logger.info("Hello logs!", { structuredData: true });


    const client = new SessionsClient({
        apiEndpoint: "us-central1-dialogflow.googleapis.com",
    });

    const sessionId = Math.random().toString(36).substring(7);
    const sessionPath = client.projectLocationAgentSessionPath(
        "botDialogflowCX",
        "us-central1",
        "chat",
        sessionId);
    
    console.info(sessionPath);

    const requestDialogflow = {
        session: sessionPath,
        queryInput: {
            text: {
                text: "Oi",
            },
            languageCode: "pt-br",
        },
    };

    client.detectIntent(requestDialogflow).then((snapshot) => {
        const webhookResponse = {
            fulfillment_response: {
                messages: [{
                    text: {
                        text: ["testandoooo", snapshot],
                    },
                },
                ],
            },
        };
    
        response.send(webhookResponse);
    }).catch((error) => {
        console.log(error);
        response.status(500).send(error);
    });
});

我真的不知道发生了什么。

运行命令

gcloud projects get-iam-policy botdialogflowcx --flatten="bindings[].members" --format="table(bindings.role)" --filter="bindings.members:teste-889@botdialogflowcx.iam.gserviceaccount.com"

输出是roles/dialogflow.admin

我将电子邮件添加到对话框CX - agent - share中的服务帐户。

email in the dialogflow CX - agent - share

email in the account service

但是仍然有相同的错误,即IAM没有权限。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-08-12 21:38:58

出现IAM权限被拒绝错误通常是因为您正在使用的服务帐户没有被授予足够的权限,无法对连接到Dialogflow Agent的GCP项目执行所请求的操作,或者您在请求中使用了错误的凭据,或者您查询了错误的代理。

查看以下代码和遇到的错误,似乎使用了Project Name和Agent Name,而不是分别使用Project ID和Agent ID值。

代码语言:javascript
复制
const sessionPath = client.projectLocationAgentSessionPath(
        "botDialogflowCX", // update to Project ID
        "us-central1",
        "Chat", // update to Agent ID
        sessionId);

请注意,项目ID和代理ID与项目名称和代理名称不同,您可以参考how to collect IDs上的以下文档。

票数 1
EN

Stack Overflow用户

发布于 2021-08-12 17:09:44

这样啊,原来是这么回事。我只需要改变

代码语言:javascript
复制
client.projectLocationAgentSessionPath(
        "botDialogflowCX",
        "us-central1",
        "chat",
        sessionId);

代码语言:javascript
复制
    const sessionPath = client.projectLocationAgentSessionPath(
        "botdialogflowcx",
        "us-central1",
        "e55b9ef5-d1f2-4e5c-9e95-974501233d50",
        sessionId);

而且它起作用了。

票数 1
EN

Stack Overflow用户

发布于 2021-08-11 22:56:00

如果您在云函数中运行此代码,我认为您不需要提供凭据。如果你在本地运行,你可以这样设置你的凭证:

$env:GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

这样,您就不需要在代码中提供凭据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68749649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档