Commit d4f3507916effc29602a5d8665e6dc4c380672b0
1 parent
e8ec03a69f
Exists in
master
retry sending message if failed
Showing 1 changed file with 15 additions and 2 deletions Side-by-side Diff
index.js
... | ... | @@ -42,7 +42,11 @@ function getChatId(partner) { |
42 | 42 | |
43 | 43 | } |
44 | 44 | |
45 | -function sendMessage(destination, message) { | |
45 | +function sendMessage(destination, message, retry) { | |
46 | + if (retry === null || retry === undefined) { | |
47 | + retry = 10; | |
48 | + } | |
49 | + | |
46 | 50 | var chat_id = getChatId(destination); |
47 | 51 | |
48 | 52 | if (!chat_id) { |
... | ... | @@ -52,7 +56,16 @@ function sendMessage(destination, message) { |
52 | 56 | |
53 | 57 | logger.info('Sending reply to ' + destination + '(' + chat_id + '): ' + message); |
54 | 58 | |
55 | - bot.sendMessage(chat_id, message); | |
59 | + try { | |
60 | + bot.sendMessage(chat_id, message); | |
61 | + } | |
62 | + catch(e) { | |
63 | + logger.warn('Exception on sendMessage ' + e, {destination: destination, message: message, retry: retry, error: e}); | |
64 | + if (retry) { | |
65 | + setTimeout(sendMessage, 10000, destination, message, --retry); | |
66 | + } | |
67 | + } | |
68 | + | |
56 | 69 | } |
57 | 70 | |
58 | 71 | bot.getMe().then(function (me) { |