-
Notifications
You must be signed in to change notification settings - Fork 2
/
ai.js
30 lines (25 loc) · 843 Bytes
/
ai.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
var authToken = null
var request = require('request');
function makeWolframRequest(question, callback) {
question = question.toLowerCase().replace(/ /g, "+").trim();
if (authToken == null) {
console.log("Aborting wolfram request because authToken has not been set");
return
}
// Configure the request
var options = {
url: 'https://api.wolframalpha.com/v1/result?i=' + question + "&appid=" + authToken,
method: "GET",
}
// Start the request
console.log("Call wolfram with " + options.url)
request(options, function(error, response, body) {
body = body.replace("Wolfram|Alpha", "I")
callback(body)
})
}
function setAuthToken(token) {
authToken = token
}
module.exports.answer = makeWolframRequest
module.exports.init = setAuthToken