Fix for invalid response in AddMovie Intent
Rebuild new array of returned movies with minimum required movie data to fix invalid response on Echo devices (due to response size limitation).
This commit is contained in:
parent
8bf943fb25
commit
2580f55829
@ -11,7 +11,6 @@ var HELP_RESPONSE = ['You can ask Couch Potato about the movies in your queue or
|
|||||||
var config = require('dotenv').config();
|
var config = require('dotenv').config();
|
||||||
var cp = new CouchPotato({
|
var cp = new CouchPotato({
|
||||||
url: config.CP_URL,
|
url: config.CP_URL,
|
||||||
apikey: config.CP_API_KEY
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleLaunchIntent(req, resp) {
|
function handleLaunchIntent(req, resp) {
|
||||||
@ -52,10 +51,16 @@ 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).then(function (movies) {
|
cp.movie.search(movieName,5).then(function (movies) {
|
||||||
utils.sendSearchResponse(movies, resp);
|
|
||||||
});
|
movies = utils.formatSearchResults(movies);
|
||||||
|
utils.sendSearchResponse(movies, movieName, resp);
|
||||||
|
})
|
||||||
|
|
||||||
|
//Async response
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//Async response
|
//Async response
|
||||||
return false;
|
return false;
|
||||||
|
36
lib/utils.js
36
lib/utils.js
@ -1,6 +1,6 @@
|
|||||||
function buildPrompt(movies) {
|
function buildPrompt(movies) {
|
||||||
var promptData = {
|
var promptData = {
|
||||||
searchResults: movies.slice(0, 5),
|
searchResults: movies,
|
||||||
yesAction : 'addMovie',
|
yesAction : 'addMovie',
|
||||||
yesResponse: 'Added ' + movies[0].original_title + ' (' + movies[0].year + ')' + ' to your list of movies to download.'
|
yesResponse: 'Added ' + movies[0].original_title + ' (' + movies[0].year + ')' + ' to your list of movies to download.'
|
||||||
};
|
};
|
||||||
@ -24,12 +24,42 @@ function sendSearchResponse(movies, resp) {
|
|||||||
|
|
||||||
resp
|
resp
|
||||||
.say(['Add', movies[0].original_title, '(' + movies[0].year + ')', 'to your list?'].join(' '))
|
.say(['Add', movies[0].original_title, '(' + movies[0].year + ')', 'to your list?'].join(' '))
|
||||||
.session('promptData', buildPrompt(movies.slice(0, 5)))
|
.session('promptData', buildPrompt(movies))
|
||||||
.shouldEndSession(false)
|
.shouldEndSession(false)
|
||||||
.send();
|
.send();
|
||||||
|
|
||||||
|
function formatSearchResults(movies)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
|
||||||
|
if (movies != undefined)
|
||||||
|
{
|
||||||
|
|
||||||
|
var newMovies = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < movies.length; i++)
|
||||||
|
{ newMovies.push({
|
||||||
|
original_title: movies[i].original_title,
|
||||||
|
inLibrary: movies[i].in_library,
|
||||||
|
year: movies[i].year,
|
||||||
|
titles: movies[i].titles,
|
||||||
|
imdb: movies[i].imdb });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return newMovies;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
buildPrompt: buildPrompt,
|
buildPrompt: buildPrompt,
|
||||||
sendSearchResponse: sendSearchResponse
|
sendSearchResponse: sendSearchResponse,
|
||||||
|
formatSearchResults: formatSearchResults
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user