Fix Invalid Response, cleanup (#12)

This commit is contained in:
Jordan Hackworth 2016-10-29 15:57:45 -07:00 committed by Joseph J. Schmitt
parent 1422d49c31
commit e09ee66d1c
4 changed files with 13 additions and 14 deletions

View File

@ -15,7 +15,7 @@ Function](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/d
## Configuring The Skill ## Configuring The Skill
To configure the skill, open up the `.env` file and fill in the correct values for `CP_URL`, which To configure the skill, copy `default.env` to `.env` and fill in the correct values for `CP_URL`, which
should point to your Couch Potato server, and `CP_API_KEY` which should have your server's API key. should point to your Couch Potato server, and `CP_API_KEY` which should have your server's API key.
## Testing The Skill Locally ## Testing The Skill Locally
@ -40,7 +40,7 @@ in the Sample Utterances field, copy and paste the contents of
The skill is built to be easily hosted on Amazon's [AWS The skill is built to be easily hosted on Amazon's [AWS
Lambda service](https://aws.amazon.com/lambda/). Create your Lambda function (using the Lambda service](https://aws.amazon.com/lambda/). Create your Lambda function (using the
alexa-skills-kit-color-expert blueprint) and make sure you choose Node.js as the runtime. After alexa-skills-kit-color-expert blueprint) and make sure you choose Node.js as the runtime. After
you've created your Lambda function, look at the top right of the page to get your Lambda ARN you've created your Lambda function, look at the top right of the page to get your Lambda ARN
number and put that in the Alexa Skill Information Endpoint field. number and put that in the Alexa Skill Information Endpoint field.

View File

@ -9,4 +9,4 @@ AWS_TIMEOUT=10
AWS_DESCRIPTION= AWS_DESCRIPTION=
AWS_RUNTIME=nodejs AWS_RUNTIME=nodejs
CP_URL=http://url-to-couch-potato-server CP_URL=http://url-to-couch-potato-server
CP_API_KEY=apiKey CP_API_KEY=APIKEY

View File

@ -54,12 +54,12 @@ function handleFindMovieIntent(req, resp) {
function handleAddMovieIntent(req, resp) { function handleAddMovieIntent(req, resp) {
var movieName = req.slot('movieName'); var movieName = req.slot('movieName');
cp.movie.search(movieName,5).then(function (movies) { cp.movie.search(movieName,5).then(function (movies) {
movies = utils.formatSearchResults(movies); movies = utils.formatSearchResults(movies);
utils.sendSearchResponse(movies, movieName, resp); utils.sendSearchResponse(movies, movieName, resp);
}); });
//Async response //Async response
return false; return false;
} }

View File

@ -18,7 +18,7 @@ function buildPrompt(movies) {
} }
function sendSearchResponse(movies, movieName, resp) { function sendSearchResponse(movies, movieName, resp) {
if(!movies || !movies.length > 0) { if(!movies || !movies.length > 0) {
return resp.say('No movie found for ' + movieName).send(); return resp.say('No movie found for ' + movieName).send();
} }
@ -31,24 +31,24 @@ function sendSearchResponse(movies, movieName, resp) {
} }
function formatSearchResults(movies) { function formatSearchResults(movies) {
var newMovies = []; var newMovies = [];
if (movies != undefined) { if (movies != undefined) {
for (var i = 0; i < movies.length; i++) { for (var i = 0; i < movies.length; i++) {
newMovies.push({ newMovies.push({
original_title: movies[i].original_title, original_title: movies[i].original_title,
inLibrary: movies[i].in_library, in_library: movies[i].in_library,
year: movies[i].year, year: movies[i].year,
titles: movies[i].titles, titles: movies[i].titles,
imdb: movies[i].imdb imdb: movies[i].imdb
}); });
} }
} }
return newMovies; return newMovies;
} }
module.exports = { module.exports = {
@ -56,4 +56,3 @@ module.exports = {
sendSearchResponse: sendSearchResponse, sendSearchResponse: sendSearchResponse,
formatSearchResults: formatSearchResults formatSearchResults: formatSearchResults
}; };