response-server.js
1.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
29
30
31
32
33
34
35
36
37
38
39
40
"use strict";
const http = require('http');
const url = require("url");
const config = require("./config");
const logger = require("./logger");
const bot = require("./xmpp");
const archive = require("./message-archive");
function createHttpServer() {
const httpServer = http.createServer(function(request,response){
const qs = url.parse(request.url, true).query;
logger.verbose('Incoming message from EVO', {qs: qs});
response.end('OK');
const partner = qs.to || qs.user_id;
const msg = qs.msg || qs.info;
if (!partner || !msg) {
logger.warn('Invalid partner or message from EVO', {qs: qs});
return;
}
bot.sendMessage(partner, msg);
if (qs.topup_status == 'R' && qs.ref_id) {
logger.verbose('Got R status, deleting trx from archive');
archive.remove(partner, qs.ref_id);
}
});
httpServer.listen(config.response_server_listen_port, function(){
logger.info("HTTP Response Server listening on port " + config.response_server_listen_port);
})
}
createHttpServer();