Commit f9f372fb671282d8fce8429ec8efd0782a9d81fc
1 parent
338ccdd248
Exists in
master
keepalive message
Showing 2 changed files with 26 additions and 0 deletions Side-by-side Diff
config.sample.ini
index.js
... | ... | @@ -67,6 +67,18 @@ function reportToSMSIN(from, message) { |
67 | 67 | }); |
68 | 68 | } |
69 | 69 | |
70 | +function sendKeepAliveMessage() { | |
71 | + if (warming_up) { | |
72 | + return; | |
73 | + } | |
74 | + | |
75 | + if (!config || !config.globals || !config.globals.keepalive_id || !config.globals.keepalive_message) { | |
76 | + return; | |
77 | + } | |
78 | + | |
79 | + sendMessage(config.globals.keepalive_id, config.globals.keepalive_message); | |
80 | +} | |
81 | + | |
70 | 82 | xmpp.on('online', function(data) { |
71 | 83 | logger.info('XMPP online', {data: data}); |
72 | 84 | logger.info('Connected with JID: ' + data.jid.user); |
... | ... | @@ -78,6 +90,12 @@ xmpp.on('online', function(data) { |
78 | 90 | }); |
79 | 91 | |
80 | 92 | xmpp.on('chat', function(from, message) { |
93 | + if (config && config.globals && config.globals.keepalive_id == from) { | |
94 | + logger.verbose('Got keepalive message from ' + from); | |
95 | + sendMessage(from, keepalive_response); | |
96 | + return; | |
97 | + } | |
98 | + | |
81 | 99 | logger.info('Incoming message via XMPP ', {from: from, message: message}); |
82 | 100 | |
83 | 101 | if (warming_up) { |
... | ... | @@ -112,3 +130,7 @@ xmpp.connect({ |
112 | 130 | xmpp.getRoster(); |
113 | 131 | |
114 | 132 | createHttpListener(); |
133 | + | |
134 | +if (config && config.globals && config.globals.keepalive_interval) { | |
135 | + setInterval(sendKeepAliveMessage, config.globals.keepalive_interval); | |
136 | +} |