From e63769c379791738f689fb06f0f8034041e9b540 Mon Sep 17 00:00:00 2001 From: "Joseph J. Schmitt" Date: Sat, 29 Oct 2016 22:40:43 -0400 Subject: [PATCH] Add release date support (#14) Closes #11 Adds a couple of new utterances so you can limit your movie results by the release date. You can now add a movie by saying: > Add The Godfather released in 1972 > Add The Godfather from 1972 > Add The Godfather that came out in 1972 > Add The Godfather released in March 1972 If you've used previous versions of the Intent Schema and Sample Utterances, make sure to copy and paste the new ones in. --- interaction_model/intent_schema.json | 13 +++++++++++++ interaction_model/sample_utterances.txt | 21 +++++++++++++++++++++ package.json | 2 +- src/lib/handlers.js | 20 ++++++++++++++++++-- src/lib/index.js | 2 ++ 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/interaction_model/intent_schema.json b/interaction_model/intent_schema.json index 99460ae..7c9d673 100644 --- a/interaction_model/intent_schema.json +++ b/interaction_model/intent_schema.json @@ -9,6 +9,19 @@ } ] }, + { + "intent": "AddMovieDate", + "slots": [ + { + "name": "movieName", + "type": "AMAZON.LITERAL" + }, + { + "name": "releaseDate", + "type": "AMAZON.DATE" + } + ] + }, { "intent": "FindMovie", "slots": [ diff --git a/interaction_model/sample_utterances.txt b/interaction_model/sample_utterances.txt index eef428f..4f6789b 100644 --- a/interaction_model/sample_utterances.txt +++ b/interaction_model/sample_utterances.txt @@ -5,6 +5,27 @@ AddMovie add {The Avengers|movieName} AddMovie add {The Dark Knight|movieName} AddMovie add {Live or Let Die|movieName} +AddMovieDate add {The Godfather|movieName} came out in {releaseDate} +AddMovieDate add {Star Wars|movieName} came out in {releaseDate} +AddMovieDate add {Star Wars Episode Four A New Hope|movieName} came out in {releaseDate} +AddMovieDate add {The Avengers|movieName} came out in {releaseDate} +AddMovieDate add {The Dark Knight|movieName} came out in {releaseDate} +AddMovieDate add {Live or Let Die|movieName} came out in {releaseDate} + +AddMovieDate add {The Godfather|movieName} from {releaseDate} +AddMovieDate add {Star Wars|movieName} from {releaseDate} +AddMovieDate add {Star Wars Episode Four A New Hope|movieName} from {releaseDate} +AddMovieDate add {The Avengers|movieName} from {releaseDate} +AddMovieDate add {The Dark Knight|movieName} from {releaseDate} +AddMovieDate add {Live or Let Die|movieName} from {releaseDate} + +AddMovieDate add {The Godfather|movieName} released in {releaseDate} +AddMovieDate add {Star Wars|movieName} released in {releaseDate} +AddMovieDate add {Star Wars Episode Four A New Hope|movieName} released in {releaseDate} +AddMovieDate add {The Avengers|movieName} released in {releaseDate} +AddMovieDate add {The Dark Knight|movieName} released in {releaseDate} +AddMovieDate add {Live or Let Die|movieName} released in {releaseDate} + FindMovie is {The Godfather|movieName} on the list FindMovie is {Star Wars|movieName} on the list FindMovie is {Star Wars Episode Four A New Hope|movieName} on the list diff --git a/package.json b/package.json index b4cfeda..7e296f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "alexa-couchpotato", - "version": "1.0.4", + "version": "1.1.0", "description": "A skill to ask Alexa about your Couch Potato queue.", "main": "src/index.js", "scripts": { diff --git a/src/lib/handlers.js b/src/lib/handlers.js index 77f043b..87e76b2 100644 --- a/src/lib/handlers.js +++ b/src/lib/handlers.js @@ -14,6 +14,8 @@ import { CANCEL_RESPONSE } from './responses.js'; +const NUM_RESULTS = 5; + const config = require('dotenv').config(); const cp = new CouchPotato({ url: config.CP_URL, @@ -31,7 +33,7 @@ export default function handleLaunchIntent(req, resp) { export function handleFindMovieIntent(req, resp) { const movieName = req.slot('movieName'); - cp.movie.list({search: movieName, limit_offset: 5}).then(function (searchResp) { + cp.movie.list({search: movieName, limit_offset: NUM_RESULTS}).then(function (searchResp) { const movies = searchResp.movies; if (!movies || !movies.length) { @@ -56,7 +58,7 @@ export function handleFindMovieIntent(req, resp) { export function handleAddMovieIntent(req, resp) { const movieName = req.slot('movieName'); - cp.movie.search(movieName, 5).then(function (movies) { + cp.movie.search(movieName, NUM_RESULTS).then(function (movies) { movies = formatSearchResults(movies); sendSearchResponse(movies, movieName, resp); }); @@ -65,6 +67,20 @@ export function handleAddMovieIntent(req, resp) { return false; } +export function handleAddMovieDateIntent(req, resp) { + const movieName = req.slot('movieName'); + const releaseDate = new Date(req.slot('releaseDate')).getUTCFullYear(); + + // Grab more results since we'll end up filtering by date + cp.movie.search(movieName, NUM_RESULTS * 2).then(function (movies) { + movies = formatSearchResults(movies).filter((movie) => movie.year == releaseDate); + sendSearchResponse(movies, movieName, resp); + }); + + //Async response + return false; +} + export function handleYesIntent(req, resp) { const promptData = req.session('promptData'); diff --git a/src/lib/index.js b/src/lib/index.js index c952042..df83096 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -5,6 +5,7 @@ import Alexa from 'alexa-app'; import handleLaunchIntent, { handleFindMovieIntent, handleAddMovieIntent, + handleAddMovieDateIntent, handleYesIntent, handleNoIntent, handleCancelIntent, @@ -16,6 +17,7 @@ const app = new Alexa.app('couchPotato'); app.launch(handleLaunchIntent); app.intent('FindMovie', handleFindMovieIntent); app.intent('AddMovie', handleAddMovieIntent); +app.intent('AddMovieDate', handleAddMovieDateIntent); app.intent('AMAZON.YesIntent', handleYesIntent); app.intent('AMAZON.NoIntent', handleNoIntent); app.intent('AMAZON.CancelIntent', handleCancelIntent);