diff --git a/transport-telegram.js b/transport-telegram.js index d910ac3..fa1efa0 100644 --- a/transport-telegram.js +++ b/transport-telegram.js @@ -3,12 +3,14 @@ const TelegramBot = require('node-telegram-bot-api'); const LRU = require('lru-cache'); -const config = require('komodo-sdk/config') +const config = require('komodo-sdk/config'); const logger = require('komodo-sdk/logger'); let bot; let _callback; +let isReady = false; + const chats = LRU({ max: config.max_chats || 200, maxAge: 1000 * 3600 @@ -17,6 +19,11 @@ const chats = LRU({ function onMessage(msg) { //console.log(msg); + if (!isReady) { + logger.info('Pesan diabaikan karena center belum siap (masih melakukan pemanasan)'); + return; + } + const now = Math.floor(new Date().getTime()/1000); const age = now - msg.date; @@ -52,6 +59,13 @@ function init(cb) { bot = new TelegramBot(config.transport.token, {polling: true}); bot.on('message', onMessage); + + setTimeout( + function() { + isReady = true; + }, + 60 * 1000 + ); } function send(partner, msg) {