forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit-caption.js
38 lines (27 loc) · 1019 Bytes
/
edit-caption.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
const TeleBot = require('../');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
var lastMessage;
var photoUrl = 'https://telegram.org/img/tl_card_destruct.gif';
bot.on('/start', msg => {
// Send image with caption
return bot.sendPhoto(
msg.from.id, photoUrl, {caption: 'This is a default caption.'}
).then(re => {
// Get message id and chat
lastMessage = [msg.from.id, re.result.message_id];
bot.sendMessage(msg.from.id, 'Now set a new caption using /edit <caption>');
});
});
bot.on('/edit', msg => {
if (!lastMessage) {
return bot.sendMessage(msg.from.id, 'Type /start and then /edit <caption>');
}
let [chatId, messageId] = lastMessage;
let caption = msg.text.replace('/edit ', '');
if (caption == '/edit') caption = 'No caption.';
// Change caption
return bot.editMessageCaption({chatId, messageId}, caption).then(() => {
bot.sendMessage(msg.from.id, `Caption changed to: ${ caption }`);
});
});
bot.start();