亚马逊alexa技能套件(ASK)

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

在amazon alexa EG中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');
    }
}
amazon alexa-skills-kit
2个回答
2
投票

Alexa Skills Kit documentation有详细解释。

来自Response vs ResponseBuilder部分:

目前,有两种方法可以在Node.js SDK中生成响应对象。第一种方法是使用格式遵循格式this.emit(:${action}, 'responseContent')

如果您想手动创建自己的回复,可以使用this.response来提供帮助。 this.response包含一系列函数,可用于设置响应的不同属性。这使您可以利用Alexa Skills Kit的内置音频和视频播放器支持。设置好回复后,您可以致电this.emit(':responseReady')将回复发送给Alexa。 this.response中的函数也是可链接的,因此您可以连续使用任意数量的函数。

完成设置响应后,只需调用this.emit(':responseReady')即可关闭响应。下面是两个使用多个响应对象构建响应的示例:

例1:

this.response.speak(speechOutput) .listen(repromptSpeech); this.emit(':responseReady');

例2

this.response.speak(speechOutput) .cardRenderer(cardTitle, cardContent, cardImage) .renderTemplate(template) .hint(hintText, hintType); this.emit(':responseReady');

由于responseBuilder更灵活地构建丰富的响应对象,因此我们更喜欢使用此方法来构建响应。


1
投票

欢迎来到StackOverflow。答案可以在问题本身中找到。

当你有一个ask时,它实质上意味着会话仍然保持,而Alexa期待用户的某些东西。而另一方面,如果你要告诉,这意味着没有可用的会话。以下示例将有所帮助。

告诉

User: Alexa, how are you doing.

Alexa: I'm doing good thank you. 

--Conversation ended

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.

希望这对你有所帮助。

快乐的编码!!!

© www.soinside.com 2019 - 2024. All rights reserved.