-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmathbot.js
48 lines (38 loc) · 1.62 KB
/
mathbot.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
const ApiAiAssistant = require('actions-on-google').ApiAiAssistant;
function add(assistant) {
var left = parseInt(assistant.getArgument("left"));
var right = parseInt(assistant.getArgument("right"));
var answer = left + right;
assistant.setContext("result", 15, {"result": answer});
assistant.tell('The result of ' + left +' plus '+ right +' is '+ answer);
}
function minus(assistant) {
var left = parseInt(assistant.getArgument("left"));
var right = parseInt(assistant.getArgument("right"));
var answer = left - right;
assistant.setContext("result", 15, {"result": answer});
assistant.ask(`The result of ${left} minus ${right} is ${answer}`);
}
function multiply(assistant) {
var left = parseInt(assistant.getArgument("left"));
var right = parseInt(assistant.getArgument("right"));
var answer = left * right;
assistant.setContext("result", 15, {"result": answer});
assistant.ask(`The result of ${left} multiply ${right} is ${answer}`);
}
function divide(assistant) {
var left = parseInt(assistant.getArgument("left"));
var right = parseInt(assistant.getArgument("right"));
var answer = left / right;
assistant.setContext("result", 15, {"result": answer});
assistant.ask(`The result of ${left} divided by ${right} is ${answer}`);
}
exports.adder = function(request, response) {
var assistant = new ApiAiAssistant({request: request, response: response});
var actionMap = new Map();
actionMap.set("input.plus", add);
actionMap.set("input.minus", minus);
actionMap.set("input.multiply", multiply);
actionMap.set("input.divide", divide);
assistant.handleRequest(actionMap);
};