如何在 node.js 中使用 response.speak() 调用意图?
How to call an intent using response.speak() in node.js?
this.response.speak('Okay, I will ask you some questions about ' +language +
'. Here is your first question.' + this.AskQuestion);
如果我输入 Python 作为语言,在 Alexa 模拟器上我得到的输出是
"Okay, I will ask you some questions about python. Here is your first question.undefined"
AskQuestion
看起来像这样:
'AskQuestion': function() {
var language = this.attributes['language'];
var currentQuestion=flashcardsDictionary
[this.attributes['currentFlashcardIndex']].question;
return 'In ' + language +', ' + currentQuestion;
}
为什么 AskQuestion return 是 undefined 值?
我假设 AskQuestion 是另一个处理程序。在项目末尾的 sdk example 中,它给出了如何在相同状态下调用另一个处理程序的示例。
const handlers = {
'LaunchRequest': function () {
this.emit('HelloWorldIntent');
},
'HelloWorldIntent': function () {
this.emit(':tell', 'Hello World!');
}
};
所以你不能 this.AskQuestion 因为它不存在,alexa sdk 将函数隐藏在对象内的另一组隐藏键中。
您可以做的是将意图转发给 AskQuestion 并在那里处理所有事情
this.response.speak('AskQuestion');
然后在 AskQuestion
'AskQuestion': function() {
var language = this.attributes['language'];
var currentQuestion=flashcardsDictionary
[this.attributes['currentFlashcardIndex']].question;
this.response.speak("Yes everything is alright");
this.emit(':responseReady');
}
this.response.speak('Okay, I will ask you some questions about ' +language +
'. Here is your first question.' + this.AskQuestion);
如果我输入 Python 作为语言,在 Alexa 模拟器上我得到的输出是
"Okay, I will ask you some questions about python. Here is your first question.undefined"
AskQuestion
看起来像这样:
'AskQuestion': function() {
var language = this.attributes['language'];
var currentQuestion=flashcardsDictionary
[this.attributes['currentFlashcardIndex']].question;
return 'In ' + language +', ' + currentQuestion;
}
为什么 AskQuestion return 是 undefined 值?
我假设 AskQuestion 是另一个处理程序。在项目末尾的 sdk example 中,它给出了如何在相同状态下调用另一个处理程序的示例。
const handlers = {
'LaunchRequest': function () {
this.emit('HelloWorldIntent');
},
'HelloWorldIntent': function () {
this.emit(':tell', 'Hello World!');
}
};
所以你不能 this.AskQuestion 因为它不存在,alexa sdk 将函数隐藏在对象内的另一组隐藏键中。 您可以做的是将意图转发给 AskQuestion 并在那里处理所有事情
this.response.speak('AskQuestion');
然后在 AskQuestion
'AskQuestion': function() {
var language = this.attributes['language'];
var currentQuestion=flashcardsDictionary
[this.attributes['currentFlashcardIndex']].question;
this.response.speak("Yes everything is alright");
this.emit(':responseReady');
}