我创建了服务帐户,并按照本指南提供给我的环境
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 管理员帐户、客户和项目所有者帐户。
这是我的代码
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:[email protected]"
输出为roles/dialogflow.admin
。
我将电子邮件添加到 dialogflow CX - 代理 - 共享中的服务帐户。
dialogflow CX 中的电子邮件 - 代理 - 共享
但仍然有同样的错误,即 IAM 没有权限。
IAM Permission denied 错误通常是因为您使用的服务帐户没有被授予足够的权限来对连接到 Dialogflow Agent 的 GCP 项目执行请求的操作,您在请求中使用了不正确的凭据,或者您查询了不正确的代理。
查看以下代码和遇到的错误,似乎分别使用了 Project Name 和 Agent Name 而不是 Project ID 和 Agent ID 值。
const sessionPath = client.projectLocationAgentSessionPath(
"botDialogflowCX", // update to Project ID
"us-central1",
"Chat", // update to Agent ID
sessionId);
请注意,项目 ID 和代理 ID 与项目名称和代理名称不同,您可以参考以下文档来了解如何收集 ID。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句