Skip to content

Instantly share code, notes, and snippets.

@nuhmanpk
Last active June 30, 2024 10:20
Show Gist options
  • Save nuhmanpk/5b2b29fcecd479754c599c36c0961363 to your computer and use it in GitHub Desktop.
Save nuhmanpk/5b2b29fcecd479754c599c36c0961363 to your computer and use it in GitHub Desktop.
Generate Pyrogram Session string using Bot token or Phone Number
from pyrogram import Client
# get these values from api.telegram.org
api_id = "API_ID"
api_hash = "API_HASH"
async def main():
async with Client(":memory:", api_id=int(api_id), api_hash=api_hash) as app:
# Generate the session string
session_string = await app.export_session_string()
print("Your session string is:", session_string)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
@nuhmanpk
Copy link
Author

Create a venv and install pyrogram and tgcrypto, then replace the api_id and api_hash with your credentials .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment