Skip to main content

Telethon secret chat plugin

Project description

Secret chat plugin for telethon, available on PyPi.

This is still a work in progress so expect more commits to it. Originally based on the End-to-End Encryption, Secret Chats document, but it wasn’t clear enough so I followed their advice and checked one of the implementations that had it (MadelineProto). Therefore, this plugin is based on Daniil’s implementation at its core.

Features

  • ☒ Accepting secret chats

  • ☒ Creating secret chats

  • ☒ Closing secret chats

  • ☒ Sending text messages

  • ☒ Recieving text messages

  • ☒ Uploading/downloading media

  • ☒ Dealing with rekeying [1]

  • ☒ Saving secret chats keys to database [2]

  • ☐ Saving messages to database [3]

  • ☒ Automatic decryption/accepting/finishing

  • ☐ Compatibility with tdlib [4]

Installation

Easiest way is to install it through pip

pip install telethon-secret-chat~=0.2

Example

from telethon import TelegramClient
from telethon_secret_chat import SecretChatManager

client = TelegramClient(...)

async def replier(event):
    # all events are encrypted by default
    if event.decrypted_event.message and event.decrypted_event.message == "hello":
        await event.reply("**hi**") # parse_mode is markdown by default


async def new_chat(chat, created_by_me):
    if created_by_me:
        print("User {} has accepted our secret chat request".format(chat))
    else:
        print("We have accepted the secret chat request of {}".format(chat))


manager = SecretChatManager(client, auto_accept=True,
                            new_chat_created=new_chat)  # automatically accept new secret chats
manager.add_secret_event_handler(func=replier)  # we can specify the type of the event

with client:
    client.run_until_disconnected()

To start a secret chat you can call:

manager.start_secret_chat(target)

To use sqlite as a storage session you need to pass an sqlite connection to SecretChatManager:

manager = SecretChatManager(client, session=db_conn, auto_accept=True)
# you can also pass client.session from telethon as such
manager = SecretChatManager(client, session=client.session, auto_accept=True)

To manually accept incoming you can do as follow:

from telethon_secret_chat import SecretChatManager, SECRET_TYPES

manager = SecretChatManager(client, auto_accept=False)
manager.add_secret_event_handler(
    event_type=SECRET_TYPES.accept,
    func=accept_secret_chat_handler
)

In your handler, you can do the following:

await manager.accept_secret_chat(event.chat)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

telethon_secret_chat-0.2.4-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file telethon_secret_chat-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: telethon_secret_chat-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.0

File hashes

Hashes for telethon_secret_chat-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 918568c5f652b8ec24bc1a01c28c929f6b1544a7126664e64a95815fb7f0892c
MD5 c94a7a3b996e75351ce38b5dc0f101f2
BLAKE2b-256 98acf5fdf078ab21212160d03d0a98142c4ce8dc27af0b527241a10facd64831

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page