-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (54 loc) · 1.69 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
'use strict';
//Bring Readline module
const ReadLine = require('readline');
//ReadLine Functionality
const rl = ReadLine.createInterface ({
//standard I/O
input: process.stdin,
output: process.stdout,
terminal: false
});
const matcher = require('./matcher');
const weather = require('./weather');
const {currentWeather} = require('./parser');
//Output Shell
rl.setPrompt('> ');
rl.prompt();
//EventListener
rl.on('line', reply =>{
//data is a variable used for callback
matcher(reply,data => {
switch (data.intent) {
case 'Hello':
console.log(`${data.entities.greeting} to you too!`);
rl.prompt();
break;
case 'CurrentWeather':
{console.log(`Checking for Weather in ${data.entities.city}...`);
//Get Data using Weather API
weather(data.entities.city, 'current')
.then(response => {
let parseResult = currentWeather(response);
console.log(parseResult);
rl.prompt();
})
.catch(error => {
console.log("Oops. Can't Connect to the Weather Station");
rl.prompt();
})
//rl.prompt();
break;
}
case 'Exit':
{console.log("Understandable, Have a Great Day!");
process.exit();
break;
}
default:
{
console.log("Me no speak Espanol");
rl.prompt();
}
}
});
});