alexa implement CanFulfillIntentRequest in node.js

614 Views Asked by At

Alexa has released CanFulfillIntentRequest feature or Name-free Interaction for custom skills recently. I am trying to implement it in my existing skill which uses alexa-sdk. Please find my code below:

'use strict';
const Alexa = require('alexa-sdk');

var handlers = {
    'LaunchRequest': function() {
        var speechOutput = "You can ask me to read out quotes from Steve Jobs";
        var repromptText = "Sorry I didnt understand";
        this.emit(':tell', speechOutput, repromptText);
    },
    'RandomQuote': function() {
        let data = getQuoteFunction();
        const author = data[0];
        const quote = data[1];

        let cardTitle = "Quotation from author";
        let cardContent = "Actual quote";
        let speechOutput = "Actual quote";

        // Speak out the output along with card information
        this.emit(':tellWithCard', speechOutput, cardTitle, cardContent);   
    }    
}

exports.handler = function (event, context, callback) {
    const alexa = Alexa.handler(event, context, callback);
    alexa.registerHandlers(handlers);
    alexa.execute();
};

Do we need to add handler for CanFulfillIntentRequest, the way I did for other handlers ? for example:

var handlers = {
    'LaunchRequest': function() {
    },
    'RandomQuote': function() {
    },
    'CanFulfillIntentRequest': function() {
        //code to handle
    }
}

Is this feature only available in ASK SDK v2 for Node.js ? Can we implement it in skill developed using alexa-sdk. Could anyone please let me know ?

Thanks

0

There are 0 best solutions below