This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathindex.js
executable file
·66 lines (56 loc) · 2.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
const tmdb = require('tmdbv3').init('35440259b50e646a6485055c83367ccd');
// Close dialog with the customer, reporting fulfillmentState of Failed or Fulfilled ("Thanks, your pizza will arrive in 20 minutes")
function close(sessionAttributes, fulfillmentState, message) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
},
};
}
// --------------- Events -----------------------
function dispatch(intentRequest, callback) {
console.log('request received for userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.intentName}');
const sessionAttributes = intentRequest.sessionAttributes;
const slots = intentRequest.currentIntent.slots;
var moviename = slots.name;
var whatInfo = slots.summary;
console.log(`request received for Slots=${moviename}, ${whatInfo}`);
tmdb.search.movie( `${moviename}`, function(err,res) {
if (err)
console.log(err);
else
tmdb.movie.info(res.results[0].id, function(err,res){
var resPlot = res.overview;
var resDate = res.release_date;
console.log(res);
if (whatInfo === 'Year' || whatInfo === 'Release Date' || whatInfo === 'release date'|| whatInfo === 'date'|| whatInfo === 'date'|| whatInfo === 'Release Year' || whatInfo === 'release year' || whatInfo === 'year'){
callback(close(sessionAttributes, 'Fulfilled',
{'contentType': 'PlainText', 'content': ` ${moviename} released in: ${resDate}`}));
}
else if (whatInfo === 'Plot' || whatInfo === 'Story' || whatInfo === 'plot' || whatInfo === 'story'){
callback(close(sessionAttributes, 'Fulfilled',
{'contentType': 'PlainText', 'content': `Plot of ${moviename} is: ${resPlot}`}));
}
else
callback(close(sessionAttributes, 'Fulfilled',
{'contentType': 'PlainText', 'content': `MovieName: ${moviename}, Year: ${resDate}, APlot: ${resPlot}`}));
});
});
}
// --------------- Main handler -----------------------
// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.
exports.handler = (event, context, callback) => {
try {
dispatch(event,
(response) => {
callback(null, response);
});
} catch (err) {
callback(err);
}
};