在代码的注释区域,如果函数调用已完成。
newGame.call(conv);
它引发错误:“ TypeError:无法读取newGame上未定义的属性'ask'”
如果我用下面的代码替换注释。
它引发错误:“错误:未设置响应。”
app.intent('newGameIntent',newGame);
这里是代码。
const functions = require('firebase-functions');
process.env.DEBUG = 'actions-on-google:*';
const {dialogflow,SimpleResponse} = require('actions-on-google');
const app = dialogflow();
var welcome =(conv)=>{
if(newUser)
{
// how to trigger 'newGameIntent' here
}
else
{
// how to trigger 'LoadGameIntent' here
}
}
var newGame =(conv)=>{
conv.ask(new SimpleResponse({
speech: "Welcome to new game",
text: "Welcome to new game"
}));
}
var loadGame =(conv)=>{
conv.ask(new SimpleResponse({
speech: "Resuming the game for you",
text: "Resuming the game for you"
}));
}
app.intent('Default Welcome Intent',welcome);
app.intent('newGameIntent',newGame);
app.intent('LoadGameIntent',loadGame);
exports.MySample = functions.https.onRequest(app);
在您的代码中定义了两个var newGame
,因此在app.intent('LoadGameIntent', loadGame);
行中将出现问题。
并且错误cannot read property ask of undefined
表示conv不在您的上下文中。我会个人尝试这样的事情:
app.intent('newGameIntent',conv => newGame(conv));
并修改您的newGame:
function newGame(conv) {
conv.ask(new SimpleResponse({
speech: "Welcome to new game",
text: "Welcome to new game"
}));
}