From 16c560faa2c5fd92b2cf01dc56384f9e3011a9d4 Mon Sep 17 00:00:00 2001 From: ssiwinter <112714996+ssiwinter@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:30:05 +0200 Subject: [PATCH 1/3] Update telegram_serving.py Uses chat id instead of usernames and can be used by more than one user. --- nodes/telegram_serving.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nodes/telegram_serving.py b/nodes/telegram_serving.py index 2b1e585..643cc4f 100644 --- a/nodes/telegram_serving.py +++ b/nodes/telegram_serving.py @@ -21,8 +21,9 @@ class TelegramServing: def telegram_handler(self): @self.bot.message_handler(commands=[self.command_name]) def handle_command(message): - if self.allowed_user and message.from_user.username != self.allowed_user: - print(f"Allowed user: {self.allowed_user}, but got message from user: {message.from_user.username}! Skipping message.") + userid=str(message.chat.id) + if not userid in self.allowed_user: + print(f"Allowed chatids are: {self.allowed_user}, but got message from user: {message.from_user.username}, chatid: {userid} ! Skipping message.") return # Silently ignore messages from unauthorized users print(f"Received command from {message.chat.id}: {message.text}") parsed_data = parse_command_string(message.text, self.command_name) From 48a450dcafc9cb0eaa3fcebbb5059371bec2b3ad Mon Sep 17 00:00:00 2001 From: ssiwinter <112714996+ssiwinter@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:32:11 +0200 Subject: [PATCH 2/3] Update telegram_serving.py allowed multiline to be used by more users --- nodes/telegram_serving.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes/telegram_serving.py b/nodes/telegram_serving.py index 643cc4f..fbbfc42 100644 --- a/nodes/telegram_serving.py +++ b/nodes/telegram_serving.py @@ -80,7 +80,7 @@ class TelegramServing: }, "optional": { "allowed_user": ("STRING", { - "multiline": False, + "multiline": True, "default": "" }) } From acd6ba34ea0d58d2e4fe2a04b48453c91e55ec76 Mon Sep 17 00:00:00 2001 From: Matan Date: Mon, 9 Sep 2024 19:53:00 +0300 Subject: [PATCH 3/3] use chat_ids instead of user --- nodes/telegram_serving.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nodes/telegram_serving.py b/nodes/telegram_serving.py index fbbfc42..bf0bd28 100644 --- a/nodes/telegram_serving.py +++ b/nodes/telegram_serving.py @@ -16,15 +16,15 @@ class TelegramServing: self.telegram_running = False self.bot = None self.command_name = None - self.allowed_user = None + self.allowed_chat_ids = None def telegram_handler(self): @self.bot.message_handler(commands=[self.command_name]) def handle_command(message): - userid=str(message.chat.id) - if not userid in self.allowed_user: - print(f"Allowed chatids are: {self.allowed_user}, but got message from user: {message.from_user.username}, chatid: {userid} ! Skipping message.") - return # Silently ignore messages from unauthorized users + chat_id=str(message.chat.id) + if self.allowed_chat_ids and not chat_id in self.allowed_chat_ids: + print(f"Allowed chatids are: {self.allowed_chat_ids}, but got message from user: {message.from_user.username}, chatid: {chat_id} ! Skipping message.") + return # Silently ignore messages print(f"Received command from {message.chat.id}: {message.text}") parsed_data = parse_command_string(message.text, self.command_name) @@ -79,7 +79,7 @@ class TelegramServing: }), }, "optional": { - "allowed_user": ("STRING", { + "allowed_chat_ids": ("STRING", { "multiline": True, "default": "" }) @@ -94,8 +94,8 @@ class TelegramServing: def IS_CHANGED(cls, **kwargs): return float("NaN") - def serve(self, telegram_token, command_name, allowed_user=""): - self.allowed_user = allowed_user + def serve(self, telegram_token, command_name, allowed_chat_ids=""): + self.allowed_chat_ids = allowed_chat_ids if not self.telegram_running: self.bot = telebot.TeleBot(telegram_token) self.command_name = command_name