我想在我的Dialog流程中实现“建议”芯片(将在Google助手中使用)。但是我收到此错误
“ ReferenceError:未定义conv”
我不了解。我已经查阅了官方文档,但是我想念的是什么?我还在他的活动
中添加了actions_intent_OPTION
以下是我的代码
const functions = require('firebase-functions');
const {actionssdk} = require('actions-on-google');
const app = actionssdk({debug: true});
var admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
var firestore = admin.firestore();
exports.webhook = functions.https.onRequest((request, response) => {
switch (request.body.result.action) {
case 'countitem':
firestore.collection('orders').get()
.then((querySnapshot) => {
var orders = [];
querySnapshot.forEach((doc) => { orders.push(doc.data()) });
// now orders have something like this [ {...}, {...}, {...} ]
response.send({
speech: `you have ${orders.length} orders11, would you like to see them? (yes/no)`
});
})
.catch((err) => {
console.log('Error getting documents', err);
response.send({
speech: "something went wrong when reading from database"
})
})
conv.ask(new Suggestions('Suggestion Chips'));
conv.ask(new Suggestions(['suggestion 1', 'suggestion 2']));
break;
default:
response.send({
speech: "no action matched in webhook"
})
}
});
答案 0 :(得分:3)
问题是conv
未定义。通常,如果您使用的是actions-on-google library,则conv
会传递给您的履行功能,其中包含可用于设置回复等的方法。
您似乎要自己处理一切并手动生成JSON响应。如果是这样,则应将guide for using JSON作为Webhook的一部分,并将repository of JSON examples作为Webhook的一部分。