forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit-markup.js
57 lines (40 loc) · 1.26 KB
/
edit-markup.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const TeleBot = require('../');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
var lastMessage;
bot.on('/start', msg => {
const markup = updateKeyboard('apples');
return bot.sendMessage(
msg.from.id, 'This is a editMessageReplyMarkup example. So, apples or oranges?', {markup}
).then(re => {
// Start updating message
lastMessage = [msg.from.id, re.result.message_id];
});
});
// On button callback
bot.on('callbackQuery', msg => {
// Send confirm
bot.answerCallbackQuery(msg.id);
if (!lastMessage) return bot.sendMessage(msg.from.id, 'Type /start');
const data = msg.data;
const [chatId, messageId] = lastMessage;
const replyMarkup = updateKeyboard(data);
// Edit message markup
return bot.editMessageReplyMarkup({chatId, messageId}, {replyMarkup});
});
bot.start();
// Returns keyboard markup
function updateKeyboard(fruit) {
let apples = 'apples';
let oranges = 'oranges';
if (fruit == 'apples') {
apples = `==> ${ apples } <==`;
} else {
oranges = `==> ${ oranges } <==`;
}
return bot.inlineKeyboard([
[
bot.inlineButton(apples, {callback: 'apples'}),
bot.inlineButton(oranges, {callback: 'oranges'})
]
]);
}