-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (58 loc) · 1.7 KB
/
app.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
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
const matcher = require('./matcher');
const weather = require('./weather');
const parser = require('./parser');
rl.setPrompt('> ');
rl.prompt();
rl.on('line', (input) => {
matcher(input, data => {
switch(data.intent) {
case 'Hello':
console.log(`${data.entities.greeting} mate!!!`)
rl.prompt();
break;
case 'Bye':
console.log("Have a nice day!");
process.exit(0);
break;
case 'CurrentWeather':
console.log('Oh, let me check...');
weather.currentWeather(data.entities.city)
.then(weatherData => {
console.log(parser.parseCurrentWeather(weatherData));
rl.prompt();
})
.catch(err => {
console.log(err);
console.log('Sorry, I could not get a response from Open Weather :(');
rl.prompt();
});
break;
case 'WeatherForecast':
console.log('Oh, let me check that for you...');
weather.weatherForecast(data.entities.city)
.then(weatherData => {
console.log(parser.parseWeatherForecast(weatherData, data.entities.time));
rl.prompt();
})
.catch(err => {
console.log('Sorry, I could not get a response from Open Weather :(');
rl.prompt();
});
break;
case 'Thanks':
console.log('You are welcome! :)')
rl.prompt();
break;
default: {
console.log("I do not know what you mean :(");
rl.prompt();
}
}
});
})