Dialogflow webhook中未调用Google Cloud函数

问题描述 投票:0回答:1

我正在创建Google Assistant操作,其中我使用了Firebase云功能并将代码部署到Firebase云功能。

我复制了Webhook URL并将其粘贴到Dialogflow控制台中,并为Webhook调用启用了默认的欢迎意图。

当我运行代码时,出现如下错误

enter image description here

这里是云功能代码

const { dialogflow, Suggestions } = require("actions-on-google");

const functions = require("firebase-functions");

const app = dialogflow({ debug: true });

app.intent("Default Welcome Intent", conv => {
  if (conv.user.last.seen) {
    conv.ask(`Welcome back to Standup Sheet`);
  } else {
    const ssml = `<speak>Welcome to Standup Sheet. I will assist you to know about your teams daily task as well the over all time taken for each project.</speak>`;
    conv.ask(ssml);
  }
  conv.ask(
    new Suggestions(["Todays entries", "Yesterday entries", "Team", "Projects"])
  );
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

Package.json文件

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "actions-on-google": "^2.12.0",
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^3.0.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.1.6"
  },
  "private": true
}

来自Firebase云功能的日志

dialogflowFirebaseFulfillment
{
    "@type":"type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo":{
      "principalEmail":"[email protected]"
    },
    "requestMetadata":{
        "callerIp":"2409:4072:9e:14e2:ddf4:6a38:779f:f147",
        "callerSuppliedUserAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36,gzip(gfe)",
        "requestAttributes":{
            "time":"2020-03-31T17:07:39.032Z",
            "auth":{}
        },
        "destinationAttributes":{}
    },
    "serviceName":"cloudfunctions.googleapis.com",
    "methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction",
    "authorizationInfo":[
        {
            "resource":"projects/standup-sheet/locations/us-central1/functions/dialogflowFirebaseFulfillment",
            "permission":"cloudfunctions.functions.update",
            "granted":true,
            "resourceAttributes":{}
        }
    ],
    "resourceName":"projects/standup-sheet/locations/us-central1/functions/dialogflowFirebaseFulfillment",
    "request":{
        "updateMask":"description,entryPoint,timeout,availableMemoryMb,labels,environmentVariables,runtime,httpsTrigger,maxInstances,ingressSettings,vpcConnector,serviceAccountEmail,sourceUploadUrl",
        "@type":"type.googleapis.com/google.cloud.functions.v1.UpdateFunctionRequest",
        "function":{
            "ingressSettings":"ALLOW_ALL",
            "httpsTrigger":{},
            "serviceAccountEmail":"[email protected]",
            "entryPoint":"dialogflowFirebaseFulfillment",
            "labels":{
                "deployment-tool":"console-cloud"
            },
            "sourceUploadUrl":"https://storage.googleapis.com/gcf-upload-us-central1-6a75406d-6f0b-41ee-aeb5-e264da4377bc/22bd91a1-48f6-4daa-981a-e76122332e1c.zip?GoogleAccessId=service-1064672465268@gcf-admin-robot.iam.gserviceaccount.com&Expires=1585676258&Signature=QqhcwyJXqap%2BWXvJ6Xu2hqINSaw5uNAdRadrfIFAyXEd%2F5DTkKeEmUBjlOWrcHOrbdR6lXzgLeiIERBGHud4sZ5FQSWHOJ6HBJ3OHTI0PhEuUPBhEyuGSn%2FqI3kav9QHf5tETNw2L1DXvUw0oU%2BcD6V0MSwC35D4pGCUPoqvxW38W0q7Yz0bXm26Wnlk3HwTm%2FjP2OwbQEH5Ae5mntn%2BdQHH4n2RFjXyg2JIIDVBe1f1rOzSh0vDL4Eg6Fc9n7HMfOSfJ04RoqnAj1gUUZo38uQSVfIfjVjSqEjbR%2BGvF8E2lw5CUX%2FS8BKeqq4hvSpTUmvdmGJe0qGt8ohBq524Lw%3D%3D",
            "timeout":"60s",
            "availableMemoryMb":256,
            "name":"projects/standup-sheet/locations/us-central1/functions/dialogflowFirebaseFulfillment",
            "runtime":"nodejs8"
        }
    },
    "resourceLocation":{
        "currentLocations":["us-central1"]
    }
}
firebase google-cloud-functions dialogflow actions-on-google dialogflow-fulfillment
1个回答
0
投票

现在,代码可以按照以下步骤进行操作以使其正常工作。如果有人遇到这种问题,请检查以下步骤。

根本原因#1

在Dialogflow控制台中,我已删除导致上述错误的默认欢迎意图中的所有默认响应。因此,我添加了默认响应并测试了效果良好的操作。但是未显示来自云功能的响应。

根本原因#2

试图在Dialogflow中使用内联编辑器,并检查是否正在调用该函数。尝试启用内联编辑器,但未启用声明需要配置Google Cloud,请刷新页面。查看了GCP控制台,并比较了我创建的每个操作所具有的其他操作都具有存储,但是此操作没有,因此我在启用了存储内联编辑器后在Firebase中创建了存储(在Dialogflow中引发查询以确认是否是由于存储不会打开内联编辑器)。

解决方案1

一旦打开内联编辑器,将上面的代码和package.json文件粘贴并部署代码并对其进行了测试,并按预期工作了

解决方案2

试图从我的计算机上部署相同的代码并启用了Webhook而不是嵌入式编辑器,并测试了该操作是否按预期工作

解决方案3

将导出dialogflowFirebaseFulfillment名称更改为fulfillment,并部署了代码并对其进行了测试,因此对这两个函数进行了比较,发现fulfillment函数没有以下权限:下图

enter image description here

如果您在上图中注意到有一个名为allUsers的角色,而在fulfillment函数中则没有allUsers角色

enter image description here

以及查看功能仪表板(dialogflowFirebasefulfillment)也会注意到差异

enter image description here

实现(仪表板)

enter image description here

要为其启用权限,请在信息面板上单击,然后单击添加成员并添加allUsers,如下所示

enter image description here

完成后,通过单击Cloud Functions]和Cloud Functions Invoker,为allUser添加角色,然后单击Save。

enter image description here

现在您可以看到更新的仪表板,如下所示

enter image description here

现在,如果您测试操作,它将调用云功能。

© www.soinside.com 2019 - 2024. All rights reserved.