Spaces:
Paused
Paused
CBV01 commited on
Commit ·
321f116
1
Parent(s): b3d2c70
Fix Cannot cast InputPeerUser to InputChannel when joining by ID
Browse files- backend/main.py +6 -0
backend/main.py
CHANGED
|
@@ -262,6 +262,9 @@ async def resolve_tg_entity(client, target):
|
|
| 262 |
|
| 263 |
try:
|
| 264 |
entity = await client.get_entity(resolved_id)
|
|
|
|
|
|
|
|
|
|
| 265 |
return entity
|
| 266 |
except Exception as e:
|
| 267 |
# If it's a positive number, try adding -100 prefix (common for Channels/Supergroups)
|
|
@@ -315,6 +318,9 @@ async def smart_join(client, target, user_id: str, phone_number: str):
|
|
| 315 |
if not res:
|
| 316 |
raise Exception(f"Could not resolve entity for {target}")
|
| 317 |
|
|
|
|
|
|
|
|
|
|
| 318 |
if isinstance(res, tuple) and res[0] == "invite":
|
| 319 |
result = await client(ImportChatInviteRequest(res[1]))
|
| 320 |
target_id = str(target) # For invite links, we use the link as ID or the hash
|
|
|
|
| 262 |
|
| 263 |
try:
|
| 264 |
entity = await client.get_entity(resolved_id)
|
| 265 |
+
# If we got a User object but asked for a positive int, it's likely a channel missing the -100 prefix.
|
| 266 |
+
if getattr(entity, '__class__', None) and entity.__class__.__name__ == 'User' and isinstance(resolved_id, int) and resolved_id > 0:
|
| 267 |
+
raise ValueError("Resolved to User, but likely meant a Channel/Group. Forcing -100 prefix check.")
|
| 268 |
return entity
|
| 269 |
except Exception as e:
|
| 270 |
# If it's a positive number, try adding -100 prefix (common for Channels/Supergroups)
|
|
|
|
| 318 |
if not res:
|
| 319 |
raise Exception(f"Could not resolve entity for {target}")
|
| 320 |
|
| 321 |
+
if getattr(res, '__class__', None) and res.__class__.__name__ == 'User':
|
| 322 |
+
raise Exception(f"Target '{target}' resolved to a User entity. You cannot join a User.")
|
| 323 |
+
|
| 324 |
if isinstance(res, tuple) and res[0] == "invite":
|
| 325 |
result = await client(ImportChatInviteRequest(res[1]))
|
| 326 |
target_id = str(target) # For invite links, we use the link as ID or the hash
|