DialogFlow actions-on-google:从当前Intent调用Intent

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

在代码的注释区域,如果函数调用已完成。

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);
node.js actions-on-google dialogflow google-home
1个回答
0
投票

在您的代码中定义了两个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"
    }));
}
© www.soinside.com 2019 - 2024. All rights reserved.