From fc6ac9236e3af42e2d459c62ac67f95135b5c2cd Mon Sep 17 00:00:00 2001
From: xyhtac <73641145+xyhtac@users.noreply.github.com>
Date: Wed, 12 Jul 2023 21:22:13 +0300
Subject: [PATCH 1/4] Update edit-caption.js
store var LastMessage separertely to prevent race condition between users
---
examples/edit-caption.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/examples/edit-caption.js b/examples/edit-caption.js
index 3951569..b15d7e4 100644
--- a/examples/edit-caption.js
+++ b/examples/edit-caption.js
@@ -1,7 +1,7 @@
const TeleBot = require('../');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
-var lastMessage;
+var lastMessage = {};
var photoUrl = 'https://telegram.org/img/tl_card_destruct.gif';
bot.on('/start', msg => {
@@ -11,7 +11,7 @@ bot.on('/start', msg => {
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];
+ lastMessage[msg.from.id] = [msg.from.id, re.result.message_id];
bot.sendMessage(msg.from.id, 'Now set a new caption using /edit
');
});
From df71a0177a22dede529399cba74af26ad3b66564 Mon Sep 17 00:00:00 2001
From: xyhtac <73641145+xyhtac@users.noreply.github.com>
Date: Wed, 12 Jul 2023 21:27:39 +0300
Subject: [PATCH 2/4] Update edit-markup.js
store var LastMessage separertely to prevent race condition between users
---
examples/edit-markup.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/examples/edit-markup.js b/examples/edit-markup.js
index 716c51f..c5d84b4 100644
--- a/examples/edit-markup.js
+++ b/examples/edit-markup.js
@@ -1,7 +1,7 @@
const TeleBot = require('../');
const bot = new TeleBot('TELEGRAM_BOT_TOKEN');
-var lastMessage;
+var lastMessage = {};
bot.on('/start', msg => {
@@ -11,7 +11,7 @@ bot.on('/start', msg => {
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];
+ lastMessage[msg.from.id] = [msg.from.id, re.result.message_id];
});
});
From 82c2a8808eace0de1d325020089cefd00e791967 Mon Sep 17 00:00:00 2001
From: xyhtac <73641145+xyhtac@users.noreply.github.com>
Date: Wed, 12 Jul 2023 21:31:46 +0300
Subject: [PATCH 3/4] Update edit-markup.js
store var LastMessage separertely to prevent race condition between users
---
examples/edit-markup.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/examples/edit-markup.js b/examples/edit-markup.js
index c5d84b4..a937955 100644
--- a/examples/edit-markup.js
+++ b/examples/edit-markup.js
@@ -22,10 +22,10 @@ bot.on('callbackQuery', msg => {
// Send confirm
bot.answerCallbackQuery(msg.id);
- if (!lastMessage) return bot.sendMessage(msg.from.id, 'Type /start');
+ if (!lastMessage[msg.from.id]) return bot.sendMessage(msg.from.id, 'Type /start');
const data = msg.data;
- const [chatId, messageId] = lastMessage;
+ const [chatId, messageId] = lastMessage[msg.from.id];
const replyMarkup = updateKeyboard(data);
// Edit message markup
From 2a912ed19870a6a7e4aca83fe9ad4cad91ce2d99 Mon Sep 17 00:00:00 2001
From: xyhtac <73641145+xyhtac@users.noreply.github.com>
Date: Wed, 12 Jul 2023 21:33:12 +0300
Subject: [PATCH 4/4] Update edit-caption.js
store var LastMessage separertely to prevent race condition between users
---
examples/edit-caption.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/examples/edit-caption.js b/examples/edit-caption.js
index b15d7e4..6dd85c8 100644
--- a/examples/edit-caption.js
+++ b/examples/edit-caption.js
@@ -19,11 +19,11 @@ bot.on('/start', msg => {
bot.on('/edit', msg => {
- if (!lastMessage) {
+ if (!lastMessage[msg.from.id]) {
return bot.sendMessage(msg.from.id, 'Type /start and then /edit ');
}
- let [chatId, messageId] = lastMessage;
+ let [chatId, messageId] = lastMessage[msg.from.id];
let caption = msg.text.replace('/edit ', '');
if (caption == '/edit') caption = 'No caption.';