1

I am trying to develop my first Alexa skill using Node.js, and every time I try to test it I get "There was a problem with the requested skill's response".

I am trying create a random restaurant generator. Pretty simple its an array of restaurants, a random index is selected, and Alexa says the restaurant. I don't know where I went wrong I have uploaded my .json and .js files if anyone can help i'd really appreciate it.

index.js:

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

const APP_ID = 'amzn1.ask.skill.9350e65b-fb41-48ce-9930-98b5156eb63c';

const handlers = {
  'LaunchRequest': function () {
    this.emit('randomRestaurantGeneratorIntent');
  },
  'randomRestaurantGeneratorIntent': function () {
    var randomResturant;
    var foodArray = ['IHOP', 'Dennys', 'burger king'];
    randomResturant = foodArray[Math.floor(Math.random() * foodArray.length)];
     
    
    this.response.speak(randomResturant);
    this.emit(':responseReady');
  },
  'AMAZON.HelpIntent': function () {
    const say = 'You can say what did I learn, or, you can say exit... How can I help you?';

    this.response.speak(say).listen(say);
    this.emit(':responseReady');
  },
  'AMAZON.CancelIntent': function () {
    this.response.speak('Bye!');
    this.emit(':responseReady');
  },
  'AMAZON.StopIntent': function () {
    this.response.speak('Bye!');
    this.emit(':responseReady');
  }
 
};

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

randomResturantGeneratorIntent.JSON:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "random restaurant generator",
            "intents": [
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                },
                {
                    "name": "randomRestaurantGeneratorIntent",
                    "slots": [],
                    "samples": [
                        "Launch Random Restaurant Generator "
                    ]
                }
            ],
            "types": []
        }
    }
}

Thank you

Mario
  • 71
  • 7
  • Hey Mario, took your code JSON and Index.js and it works, So my suggestion is to take a step back and make sure that in the folder that your zipping and uploading to AWS lambda that it contains the node_modules folder that houses your alexa-sdk libraries. I would also suggest setting the runtime in lambda to node 6.10 – Chuck LaPress Dec 27 '18 at 23:44
  • I am not uploading it AWS I am writing the code in the inline editor. please see https://imgur.com/a/KT7T0M3 screenshot for current project structure. Thank you – Mario Dec 28 '18 at 08:03
  • 1
    Mario, viewing your screenshot you clearly do not have a folder in that path named node_modules that would contain the alexa-sdk node library which is the first requirement of your index.js file const Alexa = require('alexa-sdk'); Your code will not function as you hope until it has this. – Chuck LaPress Dec 28 '18 at 11:50
  • ah that makes sense. Is that any way I can add those files manually? I'm working in an IDE. Or could you point me to a tutorial? Thank you – Mario Dec 29 '18 at 20:37

5 Answers5

0

Try this function in inline editor for your first skill. and try to test with open random restaurant generator,

/**
 * Called when the user launches the skill without specifying what they want.
 */
function onLaunch(launchRequest, session, callback) {
    console.log(`onLaunch requestId=${launchRequest.requestId}, sessionId=${session.sessionId}`);

    // Dispatch to your skill's launch.
    getWelcomeResponse(callback);
}


function buildResponse(sessionAttributes, speechletResponse) {
    return {
        version: '1.0',
        sessionAttributes,
        response: speechletResponse,
    };
}

function getWelcomeResponse(callback) {
    // If we wanted to initialize the session to have some attributes we could add those here.
    const sessionAttributes = {};
    const cardTitle = 'Welcome';
    const speechOutput = 'Welcome to Your First Alexa Skill';
    // If the user either does not reply to the welcome message or says something that is not
    // understood, they will be prompted again with this text.
    const repromptText = 'Please tell me What do you want to know?';
    const shouldEndSession = false;

    callback(sessionAttributes,
        buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}

function buildSpeechletResponse(title, output, repromptText, shouldEndSession) {
    return {
        outputSpeech: {
            type: 'PlainText',
            text: output,
        },
        //For testing purpose only
        // card: {
        //     type: 'Simple',
        //     title: `SessionSpeechlet - ${title}`,
        //     content: `SessionSpeechlet - ${output}`,
        // },
        reprompt: {
            outputSpeech: {
                type: 'PlainText',
                text: repromptText,
            },
        },
        shouldEndSession,
    };
}

exports.handler = (event, context, callback) => {
    try {
        console.log(`event.session.application.applicationId=${event.session.application.applicationId}`);


        if (event.request.type === 'LaunchRequest') {
            onLaunch(event.request,
                event.session,
                (sessionAttributes, speechletResponse) => {
                    callback(null, buildResponse(sessionAttributes, speechletResponse));
                });
        }

    }
    catch (err) {
        callback(err);
    }
};
0

I’ve been using lambda for two years and it’s terrible to debug and deploy for me until I started to use aws cloud9.

I suggest that you use aws cloud9 which is a cloud IDE for writing, running and debugging code. You could run the lambda function as local environment.

Check their website to get more information. It’s time consuming, but totally worth it, especially if you want to develop an Alexa skill.

troy
  • 2,145
  • 2
  • 23
  • 31
  • It looks like he is using the inline cloud 9. In that scenario the aws-sdk and other modules are already included. The is no need for the extra node modules dir. I notice the use of console.log in one spot. I've used that and the created log to study my reply content as well as where I am in the code. Sprinkle some more and look at the logger -- just some debugging thoughts. Good luck. – uDude Feb 19 '19 at 23:14
0

Most of the times you get that error for 2 things:

  1. You don't have the trigger "Alexa Skill Kit" in your lambda function. If you don't have it, you can add one in the designer tab of the configuration of the lambda function.

  2. You don't have the neccesary modules in your lambda function. You can add them locally with "npm install ask-sdk-core" and then upload the folder.

bhalgalix
  • 29
  • 1
  • 9
0

Try this way to render responses.

var speechOutput =  'Your response here';
var reprompt = "How can I help?";
this.response.speak(speechOutput);
this.response.listen(reprompt);
this.emit(":responseReady");
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
0

Use this way:

var speechOutput =  'Your response here';
var reprompt = "How can I help?";
this.response.speak(speechOutput);
this.response.listen(reprompt);
this.emit(":responseReady");
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83