Anu
Anu

Reputation: 11

amazon alexa skill kit (ASK)

what is the difference between this.emit(:ask) and this.response(:speak) in Amazon Alexa EG:

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');
    }
}

Upvotes: 1

Views: 980

Answers (2)

Chacko
Chacko

Reputation: 1556

Alexa Skills Kit documentation have a detailed explanation.

From Response vs ResponseBuilder section:

Currently, there are two ways to generate the response objects in Node.js SDK. The first way is using the syntax follows the format this.emit(:${action}, 'responseContent').

If you want to manually create your own responses, you can use this.response to help. this.response contains a series of functions, that you can use to set the different properties of the response. This allows you to take advantage of the Alexa Skills Kit's built-in audio and video player support. Once you've set up your response, you can just call this.emit(':responseReady') to send your response to Alexa. The functions within this.response are also chainable, so you can use as many as you want in a row.

When you have finished set up your response, simply call this.emit(':responseReady') to send your response off. Below are two examples that build response with several response objects:

Example1:

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

Example 2

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

Since responseBuilder is more flexible to build rich response objects, we prefer using this method to build the response.

Upvotes: 2

user3872094
user3872094

Reputation: 3351

Welcome to StackOverflow. The answer is available in the question itself.

When you have an ask it essentially means that the session is still maintained and Alexa is expecting something from the user. And on the other hand if you are going with a tell, it means that there is no session available. below example will be helpful.

tell

User: Alexa, how are you doing.

Alexa: I'm doing good thank you. 

--Conversation ended

ask

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.

Hope this helps you.

Happy Coding!!!

Upvotes: 1

Related Questions