Skip to content

Repository files navigation

PyroSecret 🔐

Primitive unstable and incomplete Python library to work with Telegram's Secret Chats based on Pyrogram.

This library was just a test of mine, i don't even remember if it works 💀.

Note This library is not maintained anymore, it was made for personal use and is not production ready.

This project is basically derived from painor/telethon-secret-chat and Telegram's docs.

The e2e schema is taken from tdlib.

I don't know if this library is even useful, but i'm sharing it anyway.

Warning This library is not stable, it may not work at all, i can't guarantee its security, some pre-generated raw methods are already provided because the generator is pretty broken.

Installation

git clone https://github.com/doggyhaah/pyrosecret
cd pyrosecret
pip install .

Usage

frompyrogramimportClientfrompyrogram_secret_chatimportSecretChatManagerfrompyrogram_secret_chat.typesimportSecretEventimportloggingfromioimportBytesIOfrompyrogram_secret_chat.raw.e2eimportDecryptedMessageMediaPhotofrompyrogram_secret_chatimportsave_photoclient=Client("prod2", test_mode=False, api_id=123456, api_hash='yourapihash')
ids= []
asyncdefreplier(event: SecretEvent):
print(event)
print("event received")
ifevent.decrypted_event.raw.message:
ifevent.base_update.message.chat_idnotinids:
ids.append(event.base_update.message.chat_id)
awaitevent.reply("Hello there!")
else:
awaitevent.reply(event.decrypted_event.raw.message) # parse_mode is markdown by defaultelse:
ifevent.decrypted_event.raw.mediaandisinstance(event.decrypted_event.raw.media, DecryptedMessageMediaPhoto):
bio=BytesIO()
media=event.decrypted_event.raw.mediasave_photo(event.decrypted_event, bio)
sc=manager.get_secret_chat(event.base_update.message.chat_id)
awaitmanager.send_secret_photo(sc, bio, bio, media.thumb_w, media.thumb_h, media.w, media.h, media.size, media.caption)
asyncdefnew_chat(chat, created_by_me):
ifcreated_by_me:
print("User {} has accepted our secret chat request".format(chat))
else:
t="nuova chat top secret {}".format(chat)
print(t)
awaitclient.send_message("me", t)
awaitclient.send_message("me", "admin id: {}".format(chat.admin_id))
log=logging.getLogger('secretchats')
log.setLevel(logging.DEBUG)
manager=SecretChatManager(client, auto_accept=True,
new_chat_created=new_chat) # automatically accept new secret chatsmanager.add_secret_event_handler(func=replier) # we can specify the type of the eventclient.run()

Note Due to the fact that secret chats are end-to-end encrypted, if the user tries to accept a secret chat which was already accepted from another session (for example if the user is online from an official client).

License

This project is licensed under the MIT License - see the LICENSE file for details

Everyone is welcome to contribute to this project maybe even continuing it.

About

Secret chats with pyrogram

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Contributors

Languages