-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFCF-KeywordExtraction.js
38 lines (35 loc) · 1.24 KB
/
FCF-KeywordExtraction.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
33
34
35
36
37
38
var request = require("request");
module.exports = function(RED) {
function KeywordExtraction(config) {
RED.nodes.createNode(this, config);
var node = this;
var context = this.context();
node.token = config.token;
this.on('input', function(msg) {
var rules = node.rules;
var token = encodeURIComponent(node.token);
var output = [];
var matched = false;
request({
uri: "https://api.api.ai/v1/query?v=20150910",
method: "POST",
headers: {
"Authorization": "Bearer " + token,
"Content-Type": "application/json; charset=utf-8"
},
body: JSON.stringify({
"query": [
msg.payload.content
],
"lang": "zh",
"sessionId": "1234567890"
})
}, function(error, response, body) {
var parameters = JSON.parse(body);
msg.query = parameters.result.parameters;
node.send(msg);
});
});
}
RED.nodes.registerType('FCF-KeywordExtraction', KeywordExtraction);
};