Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

Unable to join private channel using telegram's new invite hash format.

Open dsx12 opened this issue 2 years ago • 17 comments

It is no longer possible to join a private channel via their invite links/hashes. I will provide a proof of concept of the failure and the corresponding error log below.

import asyncio
from telethon.sync import TelegramClient
from telethon.tl.functions.messages import ImportChatInviteRequest

async def main():
    tg_hash = '<enter_invite_hash_here>'
    async with TelegramClient('anon', <enter_API_id_here>, '<enter_API_hash_here>') as client:
        chat_invite = await client(ImportChatInviteRequest(tg_hash))
asyncio.run(main())
File "test.py", line 27, in main
    chat_invite = await client(ImportChatInviteRequest(tg_hash))
  File "/home/test/.local/lib/python3.7/site-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "/home/test/.local/lib/python3.7/site-packages/telethon/client/users.py", line 79, in _call
    result = await future
telethon.errors.rpcerrorlist.InviteHashExpiredError: The chat the user tried to join has expired and is not valid anymore (caused by ImportChatInviteRequest)

Raises InviteHashExpiredError even when:

  • After stripping/remove '+' character from the telegram invite hash string (example: hlQ3QhNi6q05ZDIx).
  • Providing full telegram invite hash string (example: +hlQ3QhNi6q05ZDIx
  • Providing full telegram invite hash string with link/t.me domain (example: https://t.me/+hlQ3QhNi6q05ZDIx)

dsx12 avatar Jan 27 '22 05:01 dsx12

Have you installed the development version to test this? Please use the issue templates. They exist for a reason.

Lonami avatar Jan 27 '22 08:01 Lonami

I've tested it with my own API hash and API ID.

dsx12 avatar Jan 27 '22 18:01 dsx12

API ID and hash to not affect how the API behaves (to my knowledge). The layer used (which is the latest in the development version) does though.

Lonami avatar Jan 27 '22 18:01 Lonami

I have same problem , did you solved it ?

I've tested it with my own API hash and API ID.

amirpdl avatar Feb 01 '22 15:02 amirpdl

Same issue

EgorVoron avatar Feb 12 '22 17:02 EgorVoron

Hi. I have faced the same issue. Here is a solution:

  1. Use hash without "+" character, like in your first example.
  2. Call the API like above: await client(ImportChatInviteRequest(hash=tg_hash))

aleseyko avatar Feb 12 '22 21:02 aleseyko

Hi. I have faced the same issue. Here is a solution:

  1. Use hash without "+" character, like in your first example.
  2. Call the API like above: await client(ImportChatInviteRequest(hash=tg_hash))

Thanks , and how can we get entity of the group?

amirpdl avatar Feb 13 '22 08:02 amirpdl

assign the result to this await channel = await client(ImportChatInviteRequest(hash=tg_hash))

Mariownyou avatar Mar 22 '22 12:03 Mariownyou

I use await client(ImportChatInviteRequest(hash='hlQ3QhNi6q05ZDIx')) but it can't work

ljhOfGithub avatar Apr 16 '22 13:04 ljhOfGithub

Any ideias how to make this work? Not able to join a private channel with the invite links that have a + sign, strip it or not

arthurbarros avatar Apr 28 '22 22:04 arthurbarros

i got the same Problem. Any Ideas to fix it?

DLX23 avatar May 07 '22 16:05 DLX23

I also am getting this problem

0xdefidevin avatar May 10 '22 13:05 0xdefidevin

I think the main reason caused links which are required admin approval to join.

I have tested regular links - it is working Admin approval links are not working

lorrod avatar May 13 '22 12:05 lorrod

Same problem. Does anybody solved it?

parotikov avatar Jun 20 '22 19:06 parotikov

yes, i solved it. i changed https://t.me/+ab12xxxxxxx to https://t.me/joinchat/ab12xxxxxx

DLX23 avatar Jun 21 '22 06:06 DLX23

yes, i solved it. i changed https://t.me/+ab12xxxxxxx to https://t.me/joinchat/ab12xxxxxx

But problem in hash ab12xxxxxx, without +, /joinchat/ or anything else in url. ImportChatInviteRequest(hash='hlQ3QhNi6q05ZDIx')) doesn't accept hash, it return an error.

Anyway, somebody says, that I can use newthon. It solve the problem.

parotikov avatar Jun 21 '22 06:06 parotikov

i use client.get_entity(chan_url) did you use excatly the same format? https://t.me? if /joinchat/ isn present, add it... i try it in browser first. build the correct url.

DLX23 avatar Jun 21 '22 07:06 DLX23

Closing since v1.25 available in PyPi should accept the new invite link hash.

Lonami avatar Sep 20 '22 16:09 Lonami

I have same problem. Did somebody solve it?

Akim05 avatar Jul 23 '23 18:07 Akim05

Same problem, telebot 1.3x

leqord avatar Nov 13 '23 14:11 leqord