pyrogram icon indicating copy to clipboard operation
pyrogram copied to clipboard

pyrogram: update MIN_CHANNEL_ID and MIN_CHAT_ID

Open rebeeh opened this issue 1 year ago • 10 comments

Contribution Request: Update MIN_CHANNEL_ID and MIN_CHAT_ID in Pyrogram

Title: Update MIN_CHANNEL_ID and MIN_CHAT_ID to Fix "Peer id invalid" Error

Description

This contribution request proposes an update to the MIN_CHANNEL_ID and MIN_CHAT_ID values in Pyrogram. The current values are causing a "Peer id invalid" error in some scenarios. This update changes the MIN_CHANNEL_ID to -1007852516352 and the MIN_CHAT_ID to -999999999999 to address this issue.

Changes

  • Old Value: MIN_CHANNEL_ID = -1002147483647
  • New Value: MIN_CHANNEL_ID = -1007852516352
  • Old Value: MIN_CHAT_ID = -2147483647
  • New Value: MIN_CHAT_ID = -999999999999

Reason for Change

The existing MIN_CHANNEL_ID and MIN_CHAT_ID values are no longer valid in certain cases, leading to the "Peer id invalid" error. By updating the values, we aim to resolve this error and ensure that Pyrogram can handle channel and chat IDs correctly.

Code Update

The change will be made in the relevant Pyrogram file where MIN_CHANNEL_ID and MIN_CHAT_ID are defined.

# Current values
MIN_CHANNEL_ID = -1002147483647
MIN_CHAT_ID = -2147483647

# Updated values
MIN_CHANNEL_ID = -1007852516352
MIN_CHAT_ID = -999999999999

Testing

To verify this change, tests will be conducted to ensure that channel and chat IDs are processed correctly without causing the "Peer id invalid" error. Specific test cases will include:

  • Creating a channel with an ID greater than -1007852516352 and verifying successful handling.
  • Creating a chat with an ID greater than -999999999999 and verifying successful handling.
  • Handling channel and chat IDs close to the boundary values to ensure no off-by-one errors or similar issues.
  • General regression testing to ensure no other functionality is impacted.

Impact

This update is expected to fix the "Peer id invalid" error without introducing any breaking changes. All existing functionalities should remain intact, with improved reliability in handling channel and chat IDs.

Acknowledgements

Special thanks to the users and developers who identified and reported the "Peer id invalid" error and contributed to the discussion around the solution.

Additional Notes

Please review and merge this contribution to improve the robustness of Pyrogram in handling Telegram channel and chat IDs. If there are any questions or further suggestions, I am available to discuss them.

Thank you for your time and consideration.

Submitted by: ebiza

rebeeh avatar Jun 09 '24 07:06 rebeeh

-1007852516352 should be the correct value.

SpEcHiDe avatar Jun 09 '24 09:06 SpEcHiDe

-1007852516352 should be the correct value.

Where did you get this info!! I referred, the value from pyrofork library.

Reference: https://telegram.me/pyrogramchat/593087 https://telegram.me/pyrogramchat/618119

rebeeh avatar Jun 10 '24 04:06 rebeeh

-1007852516352 should be the correct value.

As your information, I've updated MIN_CHANNEL_ID and MIN_CHAT_ID.

rebeeh avatar Jun 10 '24 05:06 rebeeh

I am still getting this error

Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMedia") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMedia") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMedia") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured

when trying to send message after git cloning and applying this patch and python3 setup.py install. I can app.get_chat(group_id) but not app.send_message(group_id, message)

Getting group before telegram upload
Chat title: redacted, Chat ID: -42398xxxx
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMedia") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMedia") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMedia") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
Error Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it (caused by "messages.SendMessage") occured
^CTraceback (most recent call last):

Code

 57 async def telegram_group_upload(short_path, long_video_link):
 58     print("Getting group before telegram upload")
 59     group_id = -4239xxxx
 60     try:
 61         chat = await app.get_chat(group_id)
 62         print(f"Chat title: {chat.title}, Chat ID: {chat.id}")
 63     except Exception as e:
 64         print(f"Failed to retrieve chat details: {e}")
 65         return
 66     for _ in range(3):
 67         try:
 68             await app.send_message(group_id, "New video uploaded")
 69             break
 70         except FloodWait as e:
 71             print(f"Flood wait error: Sleeping for {e.x} seconds.")
 72             await asyncio.sleep(e.x)
 73         except Exception as e:
 74             print(f"Error {e} occured")
 75     await asyncio.sleep(1)
 76     for _ in range(3):
 77         try:
 78             await app.send_video(group_id, video=short_path)
 79             break
 80         except FloodWait as e:
 81             print(f"Flood wait error: Sleeping for {e.x} seconds.")
 82             await asyncio.sleep(e.x)
 83         except Exception as e:
 84             print(f"Error {e} occured")
 85     await asyncio.sleep(1)
 ....
 ....
 ...

Created new supergroup and sent message there which somehow fixed it

neochine avatar Jun 13 '24 10:06 neochine

Bruhhhh, add your group_id correctly

rebeeh avatar Jun 13 '24 13:06 rebeeh

Tried on one channel, and worked for me! Thanks. Will update if other channels don't work.

Update: Tried multiple, and it's working for me in all.

ModsAreFlags avatar Jun 15 '24 05:06 ModsAreFlags

Very crucial change. 👍

LeCrew163 avatar Jun 16 '24 12:06 LeCrew163

Very crucial change. 👍

Why?? What you meant!!

rebeeh avatar Jun 19 '24 18:06 rebeeh

+1

i got same problem, my chat id is -100216****** but constant is -100214****** i fix constant and now it works this issue helped me sfm

naweka avatar Jul 23 '24 05:07 naweka

Where did you get this info!!

https://core.telegram.org/api/bots/ids @youesky

Danstiv avatar Nov 10 '24 10:11 Danstiv