forked from osdc/osdc-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
39 lines (36 loc) · 912 Bytes
/
api.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
'use strict';
const request = require('request');
const constants = require('./constants');
const TEST_FLAG = process.env.TEST;
const postBotReply = (message, username) => {
const text = username ? `@${username} ${message}` : message;
if (TEST_FLAG) {
console.log(text);
} else {
request({
url: constants.CHATROOM_URL,
headers: {
Authorization : `Bearer ${constants.TOKEN}`
},
method: 'POST',
json: true,
body: {
text
}
});
}
};
const getParsedMessage = (query, getBotReply, username, parsedMessage) => {
console.log(query);
request({
url: constants.SERVER_MESSAGE_PARSER_PREFIX_URL + query,
method: 'GET'
}, (error, response, body) => {
console.log(error, body, response);
getBotReply(username, body, parsedMessage);
});
};
module.exports = {
postBotReply,
getParsedMessage
};