forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit-text.js
More file actions
30 lines (22 loc) · 704 Bytes
/
edit-text.js
File metadata and controls
30 lines (22 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const TeleBot = require('../');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
bot.on('/time', msg => {
return bot.sendMessage(msg.from.id, 'Getting time...').then(re => {
// Start updating message
updateTime(msg.from.id, re.message_id);
});
});
function updateTime(chatId, messageId) {
// Update every second
setInterval(() => {
bot.editMessageText(
{chatId, messageId}, `<b>Current time:</b> ${ time() }`,
{parseMode: 'html'}
).catch(error => console.log('Error:', error));
}, 1000);
}
bot.start();
// Get current time
function time() {
return new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
}