我正在尝试创建一个Webhook,该Webhook可以使用Node.js的Google Actions-on-Google库获取Intent和当前状态,更改状态并发送回覆。
index.js 如下:
'use strict';
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
app.intent('welcome', conv => {
let replyState = setReplyState( conv, 'prompt' );
let intent = getIntentName( conv );
sendReply( conv, intent, replyState );
});
function getReplyState( conv ){
return conv.data['replyState'];
}
function setReplyState( conv, state ){
conv.data['replyState'] = state;
return state;
}
function getIntentName( conv ){
return conv.intent;
}
const welcomeReplies = [
"Welcome!"
];
const allReplies = {
welcome: welcomeReplies,
};
function sendReply( conv, intent, replyState ){
let repliesNamed = replyState;
let replies = allReplies[repliesNamed];
conv.add( reply );
}
exports.fulfillment = functions.https.onRequest(action);
package.json 如下:
{
"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": {
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.0.3",
"actions-on-google": "~2.5.0"
},
"private": true
}
发生错误:
格式错误的响应 由于无效的平台响应,无法将Dialogflow响应解析为AppResponse:在agentId:ab93fe46-9eb1-4a6c-aea7-1699d67d7369和intentId:1ec758db-d03a-40b7-85fe-189d9245e6e2的平台响应中找不到RichResponse或SystemIntent。 / p>
我推荐了https://github.com/afirstenberg/examples/tree/master/conversation-to-code-2-aog
答案 0 :(得分:1)
您没有显示函数执行日志,但是看起来action
并未在任何地方定义,因此调用functions.https.onRequest(action);
返回错误。
在您工作的来源中,action
被定义为
const action = dialogflow();
并且所有Intent Handler均已注册
action.intent(...)
虽然您有类似的定义
const app = dialogflow({debug: true});
因此您可以将定义函数的行更改为
exports.fulfillment = functions.https.onRequest(app);
解决您的直接问题。