forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathedit-markup.js
59 lines (41 loc) · 1.19 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
58
59
'use strict';
const TeleBot = require('../');
const bot = new TeleBot('-PASTEYOURTELEGRAMBOTAPITOKENHERE-');
var lastMessage;
bot.on('/start', msg => {
const markup = updateKeyboard('apples');
return bot.sendMessage(
msg.from.id, 'This is a editMarkup 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.answerCallback(msg.id);
if (!lastMessage) return bot.sendMessage(msg.from.id, 'Type /start');
const data = msg.data;
const [chatId, messageId] = lastMessage;
const markup = updateKeyboard(msg.data);
// Edit message markup
return bot.editMarkup({ chatId, messageId }, { markup });
});
bot.connect();
// 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' })
]
]);
}