forked from jaanus/voicebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.php
44 lines (31 loc) · 1.08 KB
/
math.php
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
<?php
function operate($param1, $param2, $operation) {
if ($operation == "plus") {
return $param1 . " plus " . $param2 . " is " . ($param1 + $param2) . ".";
}
if ($operation == "minus") {
return $param1 . " minus " . $param2 . " is " . ($param1 - $param2) . ".";
}
if ($operation == "times") {
return $param1 . " times " . $param2 . " is " . ($param1 * $param2) . ".";
}
if ($operation == "divided by") {
return $param1 . " divided by " . $param2 . " is " . ($param1 / $param2) . ".";
}
return "Unknown operation.";
}
$json = file_get_contents('php://input');
$input = json_decode($json, true);
$parameters = $input["result"]["parameters"];
$number1 = (int)$parameters["number-integer1"];
$number2 = (int)$parameters["number-integer2"];
$operation = $parameters["operation"];
$outString = operate($number1, $number2, $operation);
header("Content-type: application/json");
$out = array(
"speech" => $outString,
"displayText" => $outString,
"source" => "JaanusTestBot"
);
echo(json_encode($out));
?>