【问题标题】:DialogFlow actions-on-google: Call an Intent from a current IntentDialogFlow actions-on-google:从当前 Intent 调用 Intent
【发布时间】:2018-05-30 07:43:48
【问题描述】:

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

newGame.call(conv);

它抛出错误:“TypeError: Cannot read property 'ask' of undefined at 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);

【问题讨论】:

  • 嘿,你找到如何调用意图的解决方案了吗?

标签: node.js actions-on-google dialogflow-es google-home


【解决方案1】:

在您的代码中,您定义了两个var newGame,因此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"
    }));
}

【讨论】:

  • 定义“two var newGame”时输入错误。我已经更新了这个问题。对此感到抱歉。但我想知道如何根据条件触发不同的意图。
  • 正如我所提到的,您可以触发一个函数,而不是专门触发一个意图。为什么它需要是一个意图?
猜你喜欢
  • 1970-01-01
  • 2019-04-25
  • 2018-06-07
  • 1970-01-01
  • 2019-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多