feat: enhance sender ID handling in Telegram channel

- Update sender ID construction to prioritize user ID while maintaining username for allowlist compatibility.
- Improve allowlist checking in BaseChannel to support sender IDs with multiple parts separated by '|'.
This commit is contained in:
codeLzq 2026-02-02 14:36:24 +08:00 committed by Re-bin
parent 2a26eb0c77
commit 1663acd1a1
2 changed files with 12 additions and 3 deletions

View File

@ -72,7 +72,14 @@ class BaseChannel(ABC):
if not allow_list:
return True
return str(sender_id) in allow_list
sender_str = str(sender_id)
if sender_str in allow_list:
return True
if "|" in sender_str:
for part in sender_str.split("|"):
if part and part in allow_list:
return True
return False
async def _handle_message(
self,

View File

@ -199,8 +199,10 @@ class TelegramChannel(BaseChannel):
user = update.effective_user
chat_id = message.chat_id
# Get sender identifier (prefer username, fallback to user_id)
sender_id = str(user.username or user.id)
# Use stable numeric ID, but keep username for allowlist compatibility
sender_id = str(user.id)
if user.username:
sender_id = f"{sender_id}|{user.username}"
# Store chat_id for replies
self._chat_ids[sender_id] = chat_id