diff --git a/index.js b/index.js index afa716d..ff11a53 100644 --- a/index.js +++ b/index.js @@ -28,12 +28,22 @@ function deleteChatId(from) { } function updateChatId(from, chat_id) { - chat_ids[from] = chat_id; + chat_ids[from.toLowerCase()] = chat_id; logger.verbose('Chat id ' + chat_id + ' ' + from); } +function getChatId(partner) { + try { + return chat_ids[partner.toLowerCase()]; + } + catch(e) { + return; + } + +} + function sendMessage(destination, message) { - var chat_id = chat_ids[destination]; + var chat_id = getChatId(destination); if (!chat_id) { logger.warn('Can not find approriate chat id for ' + destination + '. Abort sending message.'); @@ -53,6 +63,7 @@ bot.on('text', function (msg) { logger.info('Incoming message (' + msg.chat.id + '): ' + msg.text, {message: msg}); var from = msg.from.username.toUpperCase() + config.msisdn_suffix; + updateChatId(from, msg.chat.id); var now = Math.floor(new Date().getTime()/1000); @@ -64,8 +75,6 @@ bot.on('text', function (msg) { return; } - updateChatId(from, msg.chat.id); - var greeting_prefix = "Pesan anda telah diterima:"; if (config.greeting_prefix) { greeting_prefix = config.greeting_prefix;