Commit 41f4181c1a183c8870cefacb51f393611cbe1640
1 parent
56a7a389a5
Exists in
master
Pemanasan saat awal
Showing 1 changed file with 15 additions and 1 deletions Side-by-side Diff
transport-telegram.js
... | ... | @@ -3,12 +3,14 @@ |
3 | 3 | const TelegramBot = require('node-telegram-bot-api'); |
4 | 4 | const LRU = require('lru-cache'); |
5 | 5 | |
6 | -const config = require('komodo-sdk/config') | |
6 | +const config = require('komodo-sdk/config'); | |
7 | 7 | const logger = require('komodo-sdk/logger'); |
8 | 8 | |
9 | 9 | let bot; |
10 | 10 | let _callback; |
11 | 11 | |
12 | +let isReady = false; | |
13 | + | |
12 | 14 | const chats = LRU({ |
13 | 15 | max: config.max_chats || 200, |
14 | 16 | maxAge: 1000 * 3600 |
... | ... | @@ -17,6 +19,11 @@ const chats = LRU({ |
17 | 19 | function onMessage(msg) { |
18 | 20 | //console.log(msg); |
19 | 21 | |
22 | + if (!isReady) { | |
23 | + logger.info('Pesan diabaikan karena center belum siap (masih melakukan pemanasan)'); | |
24 | + return; | |
25 | + } | |
26 | + | |
20 | 27 | const now = Math.floor(new Date().getTime()/1000); |
21 | 28 | const age = now - msg.date; |
22 | 29 | |
... | ... | @@ -52,6 +59,13 @@ function init(cb) { |
52 | 59 | bot = new TelegramBot(config.transport.token, {polling: true}); |
53 | 60 | |
54 | 61 | bot.on('message', onMessage); |
62 | + | |
63 | + setTimeout( | |
64 | + function() { | |
65 | + isReady = true; | |
66 | + }, | |
67 | + 60 * 1000 | |
68 | + ); | |
55 | 69 | } |
56 | 70 | |
57 | 71 | function send(partner, msg) { |