Name | tg-secret JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | Secret chats support for Telegram (MTProto) client libraries |
upload_time | 2025-07-10 12:41:28 |
maintainer | None |
docs_url | None |
author | RuslanUC |
requires_python | <4.0,>=3.11 |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# tg-secret
This library provides secret chat support for python Telegram (MTProto) client libraries.
Currently, tg-secret supports [Pyrogram](https://github.com/pyrogram/pyrogram) and [Telethon](https://github.com/LonamiWebs/Telethon) (not tested),
but any library can be supported by creating client adapter implementing tg_secret.SecretClientAdapter class.
It is work-in-progress and not recommended to use in production yet.
Currently, following critical features are not implemented:
- Media downloading
- Some security checks (check if dh_config.p is safe prime, inconsistent seq_no in terms of parity)
### Example with pyrogram
```python
from asyncio import sleep
from io import BytesIO
from pyrogram import Client, filters
from pyrogram.types import User, Message
from tg_secret import TelegramSecretClient, ChatRequestResult, SecretChat, SecretMessage
from tg_secret.client_adapters.pyrogram_adapter import PyrogramClientAdapter
client = Client(
"secret_client",
api_id=..., # Your api id
api_hash=..., # Your api hash
)
secret = TelegramSecretClient(PyrogramClientAdapter(client))
@client.on_message(filters.private & filters.command("start_secret_chat"))
async def on_user_requested_secret_chat(_: Client, message: Message):
print(f"Requesting new secret chat with {message.from_user.first_name} ({message.from_user.id})")
await secret.request_encryption(message.from_user.id)
@secret.on_request
async def secret_chat_request(chat: SecretChat) -> ChatRequestResult:
user: User = await client.get_users(chat.peer_id)
print(f"Accepting new secret chat from {user.first_name} ({user.id})")
return ChatRequestResult.ACCEPT
@secret.on_chat_ready
async def secret_chat_ready(chat: SecretChat) -> None:
print(f"Secret chat with {chat.peer_id} is ready!")
await chat.send_message("Hello!")
@secret.on_new_message
async def new_secret_message(message: SecretMessage) -> None:
print(f"New message from {message.chat.peer_id}: {message.text}")
if message.text == "/delete_chat":
await message.reply("Discarding chat...")
await message.chat.delete(delete_history=False)
return
elif message.text == "/file":
await secret.send_document(
message.chat.id, BytesIO(b"test 123"), caption="Here's your file", file_name="test.txt"
)
return
elif message.text == "/delete_message":
message_to_delete = await message.reply("This message will be deleted in 5 seconds")
await sleep(5)
await message_to_delete.delete()
return
elif message.text == "/delete_history":
await message.chat.delete_history()
await message.chat.send_message("History was deleted")
return
await message.reply(f"**{message.text}**")
@secret.on_messages_deleted
async def secret_messages_deleted(chat: SecretChat, random_ids: list[int]):
print(f"Messages were deleted: {random_ids} in chat with {chat.peer_id}")
@secret.on_chat_deleted
async def secret_chat_deleted(chat: SecretChat, history_deleted: bool):
print(f"Secret chat with {chat.peer_id} was deleted, with history: {history_deleted}")
if __name__ == "__main__":
client.run(secret.pyrogram_start())
```
Raw data
{
"_id": null,
"home_page": null,
"name": "tg-secret",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": null,
"author": "RuslanUC",
"author_email": "dev_ruslan_uc@protonmail.com",
"download_url": "https://files.pythonhosted.org/packages/4e/7e/e0237fd94dd2d8370e21206f2f81105be4dafbb9589baae3f650b677e56e/tg_secret-0.1.1.tar.gz",
"platform": null,
"description": "# tg-secret\n\nThis library provides secret chat support for python Telegram (MTProto) client libraries.\nCurrently, tg-secret supports [Pyrogram](https://github.com/pyrogram/pyrogram) and [Telethon](https://github.com/LonamiWebs/Telethon) (not tested), \nbut any library can be supported by creating client adapter implementing tg_secret.SecretClientAdapter class.\n\nIt is work-in-progress and not recommended to use in production yet.\nCurrently, following critical features are not implemented:\n - Media downloading\n - Some security checks (check if dh_config.p is safe prime, inconsistent seq_no in terms of parity)\n\n\n### Example with pyrogram\n```python\nfrom asyncio import sleep\nfrom io import BytesIO\n\nfrom pyrogram import Client, filters\nfrom pyrogram.types import User, Message\n\nfrom tg_secret import TelegramSecretClient, ChatRequestResult, SecretChat, SecretMessage\nfrom tg_secret.client_adapters.pyrogram_adapter import PyrogramClientAdapter\n\nclient = Client(\n \"secret_client\",\n api_id=..., # Your api id\n api_hash=..., # Your api hash\n)\nsecret = TelegramSecretClient(PyrogramClientAdapter(client))\n\n\n@client.on_message(filters.private & filters.command(\"start_secret_chat\"))\nasync def on_user_requested_secret_chat(_: Client, message: Message):\n print(f\"Requesting new secret chat with {message.from_user.first_name} ({message.from_user.id})\")\n await secret.request_encryption(message.from_user.id)\n\n\n@secret.on_request\nasync def secret_chat_request(chat: SecretChat) -> ChatRequestResult:\n user: User = await client.get_users(chat.peer_id)\n print(f\"Accepting new secret chat from {user.first_name} ({user.id})\")\n return ChatRequestResult.ACCEPT\n\n\n@secret.on_chat_ready\nasync def secret_chat_ready(chat: SecretChat) -> None:\n print(f\"Secret chat with {chat.peer_id} is ready!\")\n await chat.send_message(\"Hello!\")\n\n\n@secret.on_new_message\nasync def new_secret_message(message: SecretMessage) -> None:\n print(f\"New message from {message.chat.peer_id}: {message.text}\")\n if message.text == \"/delete_chat\":\n await message.reply(\"Discarding chat...\")\n await message.chat.delete(delete_history=False)\n return\n elif message.text == \"/file\":\n await secret.send_document(\n message.chat.id, BytesIO(b\"test 123\"), caption=\"Here's your file\", file_name=\"test.txt\"\n )\n return\n elif message.text == \"/delete_message\":\n message_to_delete = await message.reply(\"This message will be deleted in 5 seconds\")\n await sleep(5)\n await message_to_delete.delete()\n return\n elif message.text == \"/delete_history\":\n await message.chat.delete_history()\n await message.chat.send_message(\"History was deleted\")\n return\n\n await message.reply(f\"**{message.text}**\")\n\n\n@secret.on_messages_deleted\nasync def secret_messages_deleted(chat: SecretChat, random_ids: list[int]):\n print(f\"Messages were deleted: {random_ids} in chat with {chat.peer_id}\")\n\n\n@secret.on_chat_deleted\nasync def secret_chat_deleted(chat: SecretChat, history_deleted: bool):\n print(f\"Secret chat with {chat.peer_id} was deleted, with history: {history_deleted}\")\n\n\nif __name__ == \"__main__\":\n client.run(secret.pyrogram_start())\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "Secret chats support for Telegram (MTProto) client libraries",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/RuslanUC/tg_secret",
"Repository": "https://github.com/RuslanUC/tg_secret"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c207753f2547958248fb8d9c273fcdf6223d0ca813c262e8cc504615712437c0",
"md5": "64ec0fc4eab1fdbbab51931ba062d733",
"sha256": "50005c99b3eca90f77253144a51136fcf1d70804177d15810b1e30b66f81e5f5"
},
"downloads": -1,
"filename": "tg_secret-0.1.1-cp311-cp311-manylinux_2_40_x86_64.whl",
"has_sig": false,
"md5_digest": "64ec0fc4eab1fdbbab51931ba062d733",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": "<4.0,>=3.11",
"size": 43685,
"upload_time": "2025-07-10T12:41:27",
"upload_time_iso_8601": "2025-07-10T12:41:27.487378Z",
"url": "https://files.pythonhosted.org/packages/c2/07/753f2547958248fb8d9c273fcdf6223d0ca813c262e8cc504615712437c0/tg_secret-0.1.1-cp311-cp311-manylinux_2_40_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4e7ee0237fd94dd2d8370e21206f2f81105be4dafbb9589baae3f650b677e56e",
"md5": "fee0d0a04b767adfe7ecb1aacd084b3d",
"sha256": "a36da66ab69a441ceeeecdffd7b49e2504cd6d1e4af78b9549c2afe6fee81b6a"
},
"downloads": -1,
"filename": "tg_secret-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "fee0d0a04b767adfe7ecb1aacd084b3d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 31403,
"upload_time": "2025-07-10T12:41:28",
"upload_time_iso_8601": "2025-07-10T12:41:28.608818Z",
"url": "https://files.pythonhosted.org/packages/4e/7e/e0237fd94dd2d8370e21206f2f81105be4dafbb9589baae3f650b677e56e/tg_secret-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-10 12:41:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "RuslanUC",
"github_project": "tg_secret",
"github_not_found": true,
"lcname": "tg-secret"
}