使用 NodeJS 客户端的 Webhook 响应
Response from Webhook using NodeJS Client
我构建了一个自定义 webhook 作为 Dialogflow 意图的实现端点。当我用原始 JSON 回复时它工作正常,即:{'fullfillmentText':'hi'}
,
但似乎无法使用 "actions-on-google" 库。
他们网站上的代码暗示这应该有效:
app.intent('myintent', (conv) => {
conv.close('See you later!');
});
但事实并非如此。 Google 主页只是说我的应用程序没有响应。可能是因为它代表我的功能(使用 Fn 项目)必须 return JSON 并且如果我 return JSON 作为它不期望它失败的响应.也许有人可以解释一下?
编辑 1:
我正在使用自定义 webhook,使用 Fn Project 开源函数作为服务。演示如何使用该项目是我在这里的目的,所以我不想使用内联编辑器或 Google Cloud Functions 或 firebase 或任何其他默认选项。
这是代码的其余部分
const fdk = require('@fnproject/fdk');
const request = require('request');
const dialogflow = require('actions-on-google');
const app = dialogflow({
debug: true,
});
fdk.handle(function (input) {
app.intent('myintent', (conv) => {
conv.ask('I could not understand. Can you say that again?');
});
return {'fulfillmentText': 'response from webhook'}
});
虽然您正在创建 app
对象,它执行 Intent 处理程序处理等,并通过 app.intent()
向其注册处理程序,但您没有对 "export" 因此 app
的方法在触发 webhook 时被调用。调用时,它获取请求的主体并将格式化 JSON 作为响应。
例如,如果您使用的是 Firebase 函数,您可以连接 app
以通过函数处理,例如
exports.fulfillment = functions.https.onRequest(app);
但你不是。您正在使用不同的框架。
该库附带了一些 frameworks that are supported out of the box, but the Fn Project isn't one of them. In theory, you can create your own Framework object which will do this for you (the "Frameworks" section of this article 对其进行了简要讨论,但没有详细说明如何进行讨论)。
正如您推测的那样,您可能最简单的方法是 read the JSON request and generate the JSON response yourself without using the actions-on-google library. Or you can look into a library such as multivocal 看看是否更容易利用其多框架支持。
我构建了一个自定义 webhook 作为 Dialogflow 意图的实现端点。当我用原始 JSON 回复时它工作正常,即:{'fullfillmentText':'hi'}
,
但似乎无法使用 "actions-on-google" 库。
他们网站上的代码暗示这应该有效:
app.intent('myintent', (conv) => {
conv.close('See you later!');
});
但事实并非如此。 Google 主页只是说我的应用程序没有响应。可能是因为它代表我的功能(使用 Fn 项目)必须 return JSON 并且如果我 return JSON 作为它不期望它失败的响应.也许有人可以解释一下?
编辑 1: 我正在使用自定义 webhook,使用 Fn Project 开源函数作为服务。演示如何使用该项目是我在这里的目的,所以我不想使用内联编辑器或 Google Cloud Functions 或 firebase 或任何其他默认选项。
这是代码的其余部分
const fdk = require('@fnproject/fdk');
const request = require('request');
const dialogflow = require('actions-on-google');
const app = dialogflow({
debug: true,
});
fdk.handle(function (input) {
app.intent('myintent', (conv) => {
conv.ask('I could not understand. Can you say that again?');
});
return {'fulfillmentText': 'response from webhook'}
});
虽然您正在创建 app
对象,它执行 Intent 处理程序处理等,并通过 app.intent()
向其注册处理程序,但您没有对 "export" 因此 app
的方法在触发 webhook 时被调用。调用时,它获取请求的主体并将格式化 JSON 作为响应。
例如,如果您使用的是 Firebase 函数,您可以连接 app
以通过函数处理,例如
exports.fulfillment = functions.https.onRequest(app);
但你不是。您正在使用不同的框架。
该库附带了一些 frameworks that are supported out of the box, but the Fn Project isn't one of them. In theory, you can create your own Framework object which will do this for you (the "Frameworks" section of this article 对其进行了简要讨论,但没有详细说明如何进行讨论)。
正如您推测的那样,您可能最简单的方法是 read the JSON request and generate the JSON response yourself without using the actions-on-google library. Or you can look into a library such as multivocal 看看是否更容易利用其多框架支持。