Issue with "Entity Resolution - Movie Match II" Project


#1

I’m not to sure how to go about this; I don’t use the forums often, but here goes.
This is the project I’m working on: Entity Resolution - Movie Match II The project uses different formatting from what I was taught/learned (such as the use of “const” and the use of variables with strings using tildes(`) and shells($)) from the Introduction course, so I am kinda unfamiliar with everything. The projects are a bit trickier since I can’t make sure I didn’t miss something, but syntax/formatting seems to be fine.
When I try to test it, no matter what I do, I always get “There was a problem with the requested skill’s response” and get a “null” JSON output. Help/tips would be greatly appreciated. . .

Here is the JSON for the Interaction Model:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "movie match",
            "intents": [
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "FindMovieByGenreIntent",
                    "slots": [
                        {
                            "name": "genre",
                            "type": "MOVIE_GENRE"
                        },
                        {
                            "name": "type",
                            "type": "VIDEO_TYPE"
                        }
                    ],
                    "samples": [
                        "what's a good {genre} {type}",
                        "find me a {type} in the {genre} genre",
                        "give me a {genre} {type}",
                        "recommend me a {genre} movie",
                        "find me an {genre} movie",
                        "give me a {genre} movie",
                        "tell me an {genre} movie"
                    ]
                }
            ],
            "types": [
                {
                    "name": "MOVIE_GENRE",
                    "values": [
                        {
                            "name": {
                                "value": "drama",
                                "synonyms": [
                                    "stage",
                                    "dramatization",
                                    "theatrical",
                                    "theatre",
                                    "play"
                                ]
                            }
                        },
                        {
                            "name": {
                                "value": "horror",
                                "synonyms": [
                                    "fright",
                                    "frightening",
                                    "fear",
                                    "scary"
                                ]
                            }
                        },
                        {
                            "name": {
                                "value": "comedy",
                                "synonyms": [
                                    "comic",
                                    "funny",
                                    "humor",
                                    "joke"
                                ]
                            }
                        },
                        {
                            "name": {
                                "value": "action",
                                "synonyms": [
                                    "battle",
                                    "war",
                                    "combat"
                                ]
                            }
                        }
                    ]
                },
                {
                    "name": "VIDEO_TYPE",
                    "values": [
                        {
                            "name": {
                                "value": "other",
                                "synonyms": [
                                    "song",
                                    "music",
                                    "podcast",
                                    "book"
                                ]
                            }
                        },
                        {
                            "name": {
                                "value": "tv",
                                "synonyms": [
                                    "small screen",
                                    "show",
                                    "episode",
                                    "television"
                                ]
                            }
                        },
                        {
                            "name": {
                                "value": "movie",
                                "synonyms": [
                                    "film",
                                    "cinema",
                                    "big screen"
                                ]
                            }
                        }
                    ]
                }
            ]
        }
    }
}

And here is the lambda script:

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

const SKILL_NAME = 'Movie Match';
const HELP_MESSAGE = 'You can say give me an action movie. You can also ask for comedy, drama, and horror or, you can say exit... What can I help you with?';
const HELP_REPROMPT = 'You can say give me a comedy movie. You can also say - give me a horror movie. What would you like?';
const STOP_MESSAGE = '';

const movies = {
    "action":[
        {"title":"The Dark Knight","year":"2008","description":"superhero film directed, produced, and co-written by Christopher Nolan. Featuring the DC Comics character Batman, the film is the second part of Nolan's The Dark Knight Trilogy and a sequel to 2005's Batman Begins."},
        {"title":"Die Hard","year":"1988","description":"American action film directed by John McTiernan. It follows off-duty New York City Police Department officer John McClane (Bruce Willis) who is caught in a Los Angeles skyscraper during a Christmas Eve heist."},
        {"title":"The Terminator","year":"1984","description":"American science-fiction action film directed by James Cameron. It stars Arnold Schwarzenegger as the Terminator, a cyborg assassin sent back in time from 2029 to 1984."}
    ],
    "comedy":[
        {"title":"The Hangover","year":"2009","description":"American comedy film directed by Todd Phillips, co-produced with Daniel Goldberg, and written by Jon Lucas and Scott Moore. It is the first installment in The Hangover trilogy."},
        {"title":"The Mask","year":"1994","description":"American superhero comedy film directed by Charles Russell, produced by Bob Engelman, and written by Mike Werb, based on the comic series of the same name published by Dark Horse Comics."},
        {"title":"Dumb and Dumber","year":"1994","description":"an American comedy road film starring Jim Carrey and Jeff Daniels. The film tells the story of Lloyd Christmas and Harry Dunne, two unintelligent but well-meaning friends from Providence, Rhode Island."}
    ]    
};

// TASK-1: Add data for TV shows here
const tv = {
    "action":[
        {"title":"IDK","year":"2009","description":"Ain't got time for this"},
        {"title":"IDK","year":"2009","description":"Ain't got time for this"},
        ],
  	"western":[
        {"title":"The Rifleman","year":"1960","description":"Ain't got time for this"},
        {"title":"Bonanza","year":"1950","description":"Ain't got time for this"},
        ],
  	"cop":[
        {"title":"NCIS","year":"7891","description":"Ain't got time for this"},
        {"title":"Blue Blood","year":"2890","description":"Ain't got time for this"},
        ],
  	"cartoon":[
        {"title":"SpongeBob SquarePants","year":"1209","description":"Ain't got time for this"},
        {"title":"South Park","year":"2789","description":"Ain't got time for this"},
        ],
  	"drama":[
        {"title":"The Walking Dead","year":"1992","description":"Ain't got time for this"},
        {"title":"Friends","year":"2039","description":"Ain't got time for this"},
        ],
    "comedy":[
        {"title":"Seinfeld","year":"2023","description":"Ain't got time for this"},
        {"title":"The Big Bang Theory","year":"2009","description":"Ain't got time for this"},
        ]   
};

const handlers = {
    'LaunchRequest': function () {
        const speechOutput = `Hello, and welcome to Movie Match. ${HELP_MESSAGE}`;
        this.response.speak(speechOutput).listen(HELP_REPROMPT);
        this.emit(':responseReady');
    },
      'FindMovieByGenreIntent': function (){
        // console.log("the request JSON begins here")

        const genreRequested = this.event.request.intent.slots.genre.value;
        
// TASK-2: Find the synonym that the user used, and assign it to videoTypeRequested
        const videoTypeRequested = this.event.request.intent.slots.type.value;
        const genreSlotStatus = this.event.request.intent.slots.genre.resolutions.resolutionsPerAuthority[0].status.code;

// TASK-3: Find the status code of the slot videoType, and assign it to videoTypeSlotStatus
				const videoTypeSlotStatus = this.event.request.intent.slots.type.resolutions.resolutionsPerAuthority[0].status.code;
        
        if (genreSlotStatus == 'ER_SUCCESS_NO_MATCH'){
            console.log('NO SYNONYM MATCHED');
            this.response.speak(`Sorry, I can't find any ${genreRequested} movies`);
            this.emit(':responseReady');
        }
        else{
            console.log('SYNONYM MATCHED');
            const genreResolvedTo = this.event.request.intent.slots.genre.resolutions.resolutionsPerAuthority[0].values[0].value.name;
            
// TASK-4: Find the value the slot video_type was resolved to, and assign it to videoTypeResolvedTo
            
          	const videoTypeResolvedTo = this.event.request.intent.slots.type.resolutions.resolutionsPerAuthority[0].values[0].value.name;
            const video = randomPick(eval(videoTypeResolvedTo)[genreResolvedTo]);
            const videoTitle = video.title;
            const videoYear = video.year;
            const videoDescription = video.description;
        if(videoTypeResolvedTo === "other") {
          const speechOutput = `Sorry we don't have ${videoTypeRequested}, but we can add ${videoTypeResolvedTo} in our next version of the skill`;
            this.response.speak(speechOutput);
            this.emit(':responseReady');
} else {
						const speechOutput = `Here's your ${genreRequested} ${videoTypeRequested}: ${video.title} is a ${video.year} ${video.description}`;
            this.response.speak(speechOutput);
            this.emit(':responseReady');
}
            const speechOutput = `Here's your ${genreRequested} ${videoTypeRequested}: ${video.title} is a ${video.year} ${video.description}`;
            this.response.speak(speechOutput);
            this.emit(':responseReady');
        }

        
      },
    'AMAZON.HelpIntent': function () {
        const speechOutput = HELP_MESSAGE;
        const reprompt = HELP_REPROMPT;

        this.response.speak(speechOutput).listen(reprompt);
        this.emit(':responseReady');
    },
    'AMAZON.CancelIntent': function () {
        this.response.speak(STOP_MESSAGE);
        this.emit(':responseReady');
    },
    'AMAZON.StopIntent': function () {
        this.response.speak(STOP_MESSAGE);
        this.emit(':responseReady');
    },
};

function randomPick(arr) {
    let i = 0;
    i = Math.floor(Math.random() * arr.length);
    return(arr[i]);
    }

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

If you can help, that would be great.