forked from CatalystCode/bot-luis-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
luis.js
28 lines (24 loc) · 855 Bytes
/
luis.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
var request = require('request-promise');
var util = require('util');
// replace LUIS endpoint with your own
var luisEndpoint = 'https://api.projectoxford.ai/luis/v2.0/apps/6bbb97ee-7727-4651-aa22-f6ec704075d0?subscription-key=b46ebba7b9434807af2bb27de4719940&verbose=true';
var luisUrlTemplate = `${luisEndpoint}&q=%s`;
function query(text) {
return new Promise((resolve, reject) => {
var queryUrl = util.format(luisUrlTemplate, encodeURIComponent(text));
console.log(`invoking LUIS query: ${queryUrl}`);
return request(queryUrl)
.then((body) => {
var result = JSON.parse(body);
console.log(`got LUIS response: ${JSON.stringify(body, true, 2)}`);
return resolve(result);
})
.catch(err => {
console.error(`error: ${JSON.stringify(err, true, 2)}`);
return reject(err);
});
});
}
module.exports = {
query
};