forked from mager/slack-genius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (32 loc) · 1.01 KB
/
index.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
39
40
var express = require('express');
var app = express();
var url = require('url');
var request = require('request');
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.set('port', (process.env.PORT || 9001));
app.get('/', function(req, res){
res.send('It works!');
});
app.post('/post', function(req, res){
var parsed_url = url.format({
pathname: 'https://documentation.powerreviews.com/rest/api/content/search',
query: {
cql: "text~'" + req.body.text + "'"
}
});
request(parsed_url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
var first_url = 'https://documentation.powerreviews.com' + data.results[0]._links.webui;
body = {
response_type: "in_channel",
text: first_url
};
res.send(body);
}
});
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port')); });