Commit 8e673129c2c23551aa1974e230de6c8cff2e79ce

Authored by Adhidarma Hadiwinoto
1 parent 1075631ae9
Exists in master

terminate on error

Showing 1 changed file with 10 additions and 9 deletions Side-by-side Diff

... ... @@ -30,14 +30,14 @@ var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'));
30 30 function createHttpListener() {
31 31  
32 32 var httpServer = http.createServer(function(request,response){
33   -
  33 +
34 34 var qs = url.parse(request.url, true).query;
35 35 logger.info('Incoming message from SMSIN server', {qs: qs});
36 36 response.end('OK');
37   -
  37 +
38 38 sendMessage(qs.PhoneNumber, qs.text);
39 39 });
40   -
  40 +
41 41 httpServer.listen(config.globals.listen_port, function(){
42 42 logger.info("HTTP server listening on " + config.globals.listen_port);
43 43 })
... ... @@ -58,7 +58,7 @@ function reportToSMSIN(from, message) {
58 58 SMSCID: config.globals.smscid
59 59 }
60 60 }
61   -
  61 +
62 62 request(opts, function(err, response, body) {
63 63 if (err) {
64 64 logger.warn('Error reporting to SMSIN: ' + err);
... ... @@ -70,7 +70,7 @@ function reportToSMSIN(from, message) {
70 70 xmpp.on('online', function(data) {
71 71 logger.info('XMPP online', {data: data});
72 72 logger.info('Connected with JID: ' + data.jid.user);
73   -
  73 +
74 74 setTimeout(function() {
75 75 warming_up = false;
76 76 logger.info('BOT selesai warming up, pesan-pesan selanjutnya akan diproses');
... ... @@ -79,22 +79,23 @@ xmpp.on('online', function(data) {
79 79  
80 80 xmpp.on('chat', function(from, message) {
81 81 logger.info('Incoming message via XMPP ', {from: from, message: message});
82   -
  82 +
83 83 if (warming_up) {
84 84 logger.info('BOT masih dalam tahap warming up, abaikan pesan');
85 85 var response_message = 'Pesan diabaikan. Silahkan diulang kembali: ' + message;
86 86 sendMessage(from, response_message);
87 87 return;
88 88 }
89   -
  89 +
90 90 var response_message = 'Pesan anda telah diterima dan akan segera diproses: ' + message;
91 91 sendMessage(from, response_message);
92   -
  92 +
93 93 reportToSMSIN(from, message);
94 94 });
95 95  
96 96 xmpp.on('error', function(err) {
97   - logger.warn('XMPP error', {err: err});
  97 + logger.warn('XMPP error, terminating in 3 secs', {err: err});
  98 + setTimeout(process.exit, 3000, 1);
98 99 });
99 100  
100 101 xmpp.on('subscribe', function(from) {