Commit aff0e584c0ce5cb882b205d64bdf127d16984134
1 parent
d94bc60ef5
Exists in
master
perbaikan sendMessage
Showing 1 changed file with 13 additions and 4 deletions Side-by-side Diff
index.js
... | ... | @@ -28,12 +28,22 @@ function deleteChatId(from) { |
28 | 28 | } |
29 | 29 | |
30 | 30 | function updateChatId(from, chat_id) { |
31 | - chat_ids[from] = chat_id; | |
31 | + chat_ids[from.toLowerCase()] = chat_id; | |
32 | 32 | logger.verbose('Chat id ' + chat_id + ' ' + from); |
33 | 33 | } |
34 | 34 | |
35 | +function getChatId(partner) { | |
36 | + try { | |
37 | + return chat_ids[partner.toLowerCase()]; | |
38 | + } | |
39 | + catch(e) { | |
40 | + return; | |
41 | + } | |
42 | + | |
43 | +} | |
44 | + | |
35 | 45 | function sendMessage(destination, message) { |
36 | - var chat_id = chat_ids[destination]; | |
46 | + var chat_id = getChatId(destination); | |
37 | 47 | |
38 | 48 | if (!chat_id) { |
39 | 49 | logger.warn('Can not find approriate chat id for ' + destination + '. Abort sending message.'); |
... | ... | @@ -53,6 +63,7 @@ bot.on('text', function (msg) { |
53 | 63 | logger.info('Incoming message (' + msg.chat.id + '): ' + msg.text, {message: msg}); |
54 | 64 | |
55 | 65 | var from = msg.from.username.toUpperCase() + config.msisdn_suffix; |
66 | + updateChatId(from, msg.chat.id); | |
56 | 67 | |
57 | 68 | var now = Math.floor(new Date().getTime()/1000); |
58 | 69 | |
... | ... | @@ -64,8 +75,6 @@ bot.on('text', function (msg) { |
64 | 75 | return; |
65 | 76 | } |
66 | 77 | |
67 | - updateChatId(from, msg.chat.id); | |
68 | - | |
69 | 78 | var greeting_prefix = "Pesan anda telah diterima:"; |
70 | 79 | if (config.greeting_prefix) { |
71 | 80 | greeting_prefix = config.greeting_prefix; |