在amazon中,this.emit(:ask)和this.response(:speak)有什么区别:
let handler = {
'PlayVideoIntent' : function() {
// VideoApp.Play directives can be added to the response
if (this.event.context.System.device.supportedInterfaces.VideoApp) {
this.response.playVideo('http://path/to/my/video.mp4');
} else {
this.response.speak("The video cannot be played on your device. " +
"To watch this video, try launching the skill from your echo show device.");
}
this.emit(':responseReady');
}
}发布于 2017-12-18 14:45:26
Alexa技能工具包文档有一个详细的解释。
来自响应与ResponseBuilder部分:
目前,在Node.js SDK中生成响应对象有两种方法。第一种方法是按照
this.emit(:${action}, 'responseContent')格式使用语法。 如果要手动创建自己的响应,可以使用this.response帮助。this.response包含一系列函数,可以用来设置响应的不同属性。这允许您利用Alexa技能工具包的内置音频和视频播放器支持。一旦您设置了您的响应,您只需调用this.emit(':responseReady')将您的响应发送给Alexa。this.response中的函数也是可链接的,因此您可以在一行中使用任意数量的函数。 当您完成您的响应,只需调用this.emit(':responseReady')发送您的响应。下面是两个用几个响应对象构建响应的示例: Example1:this.response.speak(speechOutput) .listen(repromptSpeech); this.emit(':responseReady');示例2this.response.speak(speechOutput) .cardRenderer(cardTitle, cardContent, cardImage) .renderTemplate(template) .hint(hintText, hintType); this.emit(':responseReady');由于responseBuilder在构建丰富的响应对象方面更加灵活,所以我们更喜欢使用这种方法来构建响应。
发布于 2017-12-12 12:39:10
欢迎来到StackOverflow。问题本身就有答案。
当您有一个ask时,本质上意味着会话仍然被维护,而Alexa正在期待用户的一些东西。另一方面,如果您要使用tell,这意味着没有可用的会话。下面的例子将会很有帮助。
告诉
User: Alexa, how are you doing.
Alexa: I'm doing good thank you.
--Conversation endedask
User: Alexa set an alarm
Alexa: sure, at what time? <-- This is where we use ask, as the conversation is incomplete
User: at 5:30 AM
Alexa: Alarm set <-- This is where we use tell, as the task is done and there is no use of user's input anymore.希望这能帮到你。
编码愉快!
https://stackoverflow.com/questions/47770088
复制相似问题