Commit b97e43da1273ef746f07a0a24588743b66f2fa83
1 parent
499b09cf36
Exists in
master
dumpChatIds
Showing 1 changed file with 20 additions and 19 deletions Side-by-side Diff
index.js
... | ... | @@ -28,27 +28,17 @@ function deleteChatId(from) { |
28 | 28 | } |
29 | 29 | |
30 | 30 | function sendMessage(destination, message) { |
31 | - logger.info('Sending reply to ' + destination + ': ' + message); | |
32 | - var chat_id = chat_ids[destination]; | |
33 | - bot.sendMessage(chat_id, message); | |
34 | -} | |
31 | + var chat_id = chat_ids[destination]; | |
32 | + | |
33 | + if (!chat_id) { | |
34 | + logger.warn('Can not find approriate chat id for ' + destination + '. Abort sending message.'); | |
35 | + return; | |
36 | + } | |
35 | 37 | |
36 | -/* | |
37 | -function createHttpResponseServer(){ | |
38 | - var httpServer = http.createServer(function(request,response){ | |
39 | - var qs = url.parse(request.url, true).query; | |
40 | - logger.info('Incoming request from SMSIN server:', {qs: qs}) | |
41 | - //logger.info(qs); | |
42 | - response.end('OK'); | |
43 | - | |
44 | - sendMessage(qs.PhoneNumber, qs.text); | |
45 | - }); | |
46 | - httpServer.listen(config.listen_port, function(){ | |
47 | - logger.info("listening on " + config.listen_port); | |
48 | - }) | |
38 | + logger.info('Sending reply to ' + destination + '(' + chat_id + '): ' + message); | |
39 | + | |
40 | + bot.sendMessage(chat_id, message); | |
49 | 41 | } |
50 | -createHttpResponseServer(); | |
51 | -*/ | |
52 | 42 | |
53 | 43 | bot.getMe().then(function (me) { |
54 | 44 | logger.info('Hi my name is %s!', me.username); |
... | ... | @@ -83,3 +73,14 @@ bot.on('text', function (msg) { |
83 | 73 | from, msg.text, msg.date * 1000, sendMessage |
84 | 74 | ); |
85 | 75 | }); |
76 | + | |
77 | +function dumpChatIds() { | |
78 | + var i = 0; | |
79 | + for (var key in chat_ids) { | |
80 | + logger.verbose('DUMPED CHAT IDS #' + ++i + ' ' + key + ': ' + chat_ids[key]) | |
81 | + } | |
82 | +} | |
83 | + | |
84 | +if (config.dump_chat_ids_interval) { | |
85 | + setInterval(dumpChatIds, config.dump_chat_ids_interval * 1000); | |
86 | +} |