繁体   English   中英

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

[英]DialogFlow actions-on-google: Call an Intent from a current Intent

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

newGame.call(conv);

它抛出错误:“TypeError:无法在 newGame 读取未定义的属性‘询问’”

如果我用下面的代码行替换注释。

它抛出错误:“错误:未设置响应。”

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);行中会出现问题app.intent('LoadGameIntent', loadGame); .

并且错误cannot read property ask of undefined意味着 conv 未保留在您的上下文中。 我会亲自尝试这样的事情:

app.intent('newGameIntent',conv => newGame(conv));

并修改您的新游戏:

function newGame(conv) {
conv.ask(new SimpleResponse({
      speech: "Welcome to new game",
      text: "Welcome to new game"
    }));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM