-
-
Save aviraltandon21/1da518c34fd21f9ff0234cfedde38f7d to your computer and use it in GitHub Desktop.
Source Code for Alan Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
intent('What does this app do ?' , 'What can I do here ?', | |
reply('This is a movie database application. You can get the details of your favorite movies here.')); | |
// intent('Start a command', (p) => { | |
// p.play('Hello , I understood') | |
// }) | |
const API_KEY = '41a7bcbe590435723a2aa997f6ece6f4'; | |
let savedMovies = []; | |
intent('Show me latest (movies|movie)',(p) => { | |
let MOVIE_API_URL = `https://api.themoviedb.org/3/movie/popular?api_key=${API_KEY}&language=en-US&page=1`; | |
api.request(MOVIE_API_URL,(error,response,body) => { | |
const {results} = JSON.parse(body); | |
if(!results.length) { | |
p.play('Sorry , I could not find any movies'); | |
return; | |
} | |
savedMovies = results; | |
p.play({command: 'NewMovies',results}); | |
p.play('Here are some of the latest movies'); | |
p.play('Would you like me to read the movie name along with their release dates ?'); | |
p.then(confirmation); | |
}); | |
}) | |
intent('Show me (details|detail) of movie $(term* (.*))',(p) => { | |
let MOVIE_API_URL = `https://api.themoviedb.org/3/search/movie?api_key=${API_KEY}&language=en-US&page=1&include_adult=false`; | |
if(p.term.value) { | |
MOVIE_API_URL = `${MOVIE_API_URL}&query=${p.term.value.toLowerCase().split(" ").join('-')}` | |
} | |
api.request(MOVIE_API_URL,(error,response,body) => { | |
const {results} = JSON.parse(body); | |
if(!results.length) { | |
p.play('Sorry , I could not find any movie with this name'); | |
return; | |
} | |
savedMovies = results; | |
p.play({command: 'NewMovies',results}); | |
p.play(`Here are details of movie ${p.term.value}`); | |
p.play('Would you like me to read the movie name along with their release dates ?'); | |
p.then(confirmation); | |
}); | |
}) | |
intent('Show me top rated (movies|movie)',(p) => { | |
let MOVIE_API_URL = `https://api.themoviedb.org/3/movie/top_rated?api_key=${API_KEY}&language=en-US&page=1`; | |
api.request(MOVIE_API_URL,(error,response,body) => { | |
const {results} = JSON.parse(body); | |
if(!results.length) { | |
p.play('Sorry , I could not find any movies'); | |
return; | |
} | |
savedMovies = results; | |
p.play({command: 'NewMovies',results}); | |
p.play('Here are some of the top rated movies.'); | |
p.play('Would you like me to read the movie name along with their release dates ?'); | |
p.then(confirmation); | |
}); | |
}); | |
const confirmation = context(() => { | |
intent('yes', async (p) => { | |
for(let i = 0; i < savedMovies.length; i++){ | |
p.play({ command: 'highlight', movie: savedMovies[i]}); | |
p.play(`${savedMovies[i].original_title}`); | |
p.play(`Release date is ${savedMovies[i].release_date}`); | |
} | |
}) | |
intent('no', (p) => { | |
p.play('Sure, sounds good to me.') | |
}) | |
}) | |
intent('(go|) back', (p) => { | |
p.play('Sure, going back'); | |
p.play({ command: 'NewMovies', results: []}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment