Added support for extracting IDs and fetching content from Telegram “openmessage” links (#471)

Added support to fetch message content from Telegram “openmessage” links.
This commit is contained in:
Parvshah-01
2025-06-05 20:20:46 +05:30
committed by GitHub
parent 7d689dd7f1
commit d9a080d854
2 changed files with 20 additions and 9 deletions

View File

@@ -743,14 +743,21 @@ async def get_restricted_msg(event):
chat, msg = get_chat_and_msgid(match)
if not (chat and msg):
return await event.eor(
"Invalid link!\nEg: `https://t.me/TeamUltroid/3` or `https://t.me/c/1313492028/3`"
"Invalid link!\nExamples:\n"
"`https://t.me/TeamUltroid/3`\n"
"`https://t.me/c/1313492028/3`\n"
"`tg://openmessage?user_id=1234567890&message_id=1`"
)
try:
message = await event.client.get_messages(chat, ids=msg)
input_entity = await event.client.get_input_entity(chat)
message = await event.client.get_messages(input_entity, ids=msg)
except BaseException as er:
return await event.eor(f"**ERROR**\n`{er}`")
if not message:
return await event.eor("`Message not found or may not exist.`")
try:
await event.client.send_message(event.chat_id, message)
await xx.try_delete()
@@ -819,3 +826,4 @@ async def get_restricted_msg(event):
await event.eor("`Cannot process this type of media.`")
else:
await event.eor("`No media found in the message.`")

View File

@@ -1081,13 +1081,16 @@ def safe_load(file, *args, **kwargs):
def get_chat_and_msgid(link):
matches = re.findall("https:\\/\\/t\\.me\\/(c\\/|)(.*)\\/(.*)", link)
if not matches:
return None, None
_, chat, msg_id = matches[0]
if chat.isdigit():
chat = int("-100" + chat)
return chat, int(msg_id)
m = re.findall(r"t\.me\/(c\/)?(\d+)\/(\d+)", link)
if m:
_, chat, msg_id = m[0]
return int("-100" + chat) if _ else chat, int(msg_id)
m = re.findall(r"user_id=(\d+)&message_id=(\d+)", link)
if m:
return int(m[0][0]), int(m[0][1])
return None, None
# --------- END --------- #