-
Notifications
You must be signed in to change notification settings - Fork 0
/
meaning.js
55 lines (45 loc) · 1.67 KB
/
meaning.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
const random = require('random-item');
const unknownResponses = [
"Sorry, I cannot talk about that. I can only tell you a new word or help you practice your already learned words.",
"I did not understand that. Let me know if you want to learn a new word or you want to practice a learned word.",
"Sorry, I can only talk about words. Tell me if you want to learn a new word, or you want to test the words you learned already."
];
let meaning = function (admin, words) {
this.db = admin.database();
this.words = words;
};
meaning.prototype.handleRequest = function (app) {
let word = app.getArgument("word");
if (!word) {
let rawInput = app.getRawInput();
if (rawInput.indexOf(' ') == -1) {
word = rawInput;
}
}
let response;
if (word) {
if (this.words[word]) {
response = app.buildRichResponse()
.addSimpleResponse("Here's the meaning of " + word)
.addBasicCard(
app.buildBasicCard()
.setTitle(word)
.setSubtitle(this.words[word].pos)
.setBodyText(this.words[word].meaning)
)
.addSimpleResponse("What's next?");
} else {
response = app.buildRichResponse()
.addSimpleResponse("Sorry! The word " + word + " is not present in our database");
}
} else {
response = app.buildRichResponse()
.addSimpleResponse(random(unknownResponses));
}
response.addSuggestions([
"Learn a new word",
"Test learned words"
]);
app.ask(response);
};
exports.meaning = meaning;