-
Notifications
You must be signed in to change notification settings - Fork 3
/
wit.js
32 lines (26 loc) · 900 Bytes
/
wit.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
var https = require('https');
var Future = require('futures').future;
var config = require('./config');
var request_wit = function(user_text) {
var future = Future.create();
var options = {
host: 'api.wit.ai',
path: '/message?q=' + encodeURIComponent(user_text),
// the Authorization header allows you to access your Wit account
// make sure to replace it with your own
headers: {'Authorization': 'Bearer ' + config.authToken}
};
https.request(options, function(res) {
var response = '';
res.on('data', function (chunk) {
response += chunk;
});
res.on('end', function () {
future.fulfill(undefined, JSON.parse(response));
});
}).on('error', function(e) {
future.fulfill(e, undefined);
}).end();
return future;
};
module.exports.request_wit = request_wit;