-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwit.js
More file actions
28 lines (25 loc) · 1 KB
/
wit.js
File metadata and controls
28 lines (25 loc) · 1 KB
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
var https = require('https');
var Future = require('futures').future;
var request_wit = function(user_text) {
var future = Future.create();
var options = {
host: 'api.wit.ai',
path: '/message?q=' + encodeURIComponent(user_text),
//This is the Authorization header added to access your Wit account
//This access token is protected for security reason,
//in the demo this access token was equals to FSN2DG6YY64JD2T6WG5D6NVIXWU2F2QK
//Make sure you replace it with your own or it won't work
headers: {'Authorization': 'Bearer ' + process.env.ACCESS_TOKEN}
};
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;