grammers

repository·master·Indexed 21 days ago

https://github.com/lonami/grammers

A modular suite of Rust crates for interacting with the Telegram API, ranging from the high-level grammers-client for application development to low-level implementations like grammers-mtproto for the Mobile Transport Protocol. The ecosystem includes specialized crates for session management (grammers-session), TL type definitions (grammers-tl-types), cryptography (grammers-crypto), and TL parsing (grammers-tl-parser).

Tokens
41.8K
Snippets
151
Records
210
Agent score
74%

What's inside grammers

  1. Overview of grammers-mtproto

    master
    The grammers-mtproto crate provides a pure implementation of the Mobile Transport Protocol. It is designed for low-level cryptographic and structural operations, allowing you to create, encrypt, decrypt, and parse MTProto messages. Crucially, this library performs these operations without performing any I/O, making it suitable for integration into various networking stacks where the user manages the actual transport layer.
  2. Overview of the gramme.rs ecosystem

    master

    gramme.rs (tele)gramme.rs is a collection of Rust crates designed to interact with Telegram's API. The ecosystem is modular, allowing developers to use either a high-level client or lower-level protocol implementations depending on their needs.

    For most application developers, grammers-client is the primary entry point. For those building custom network layers or protocol implementations, the lower-level crates like grammers-mtproto and grammers-mtsender are available.

  3. Parse Type Language (TL) definitions with grammers-tl-parser

    master

    The grammers-tl-parser library provides a public interface for parsing Telegram [Type Language] (TL) definitions. It supports two primary modes of operation:

    1. Parsing entire files: You can parse complete TL files. The parser automatically ignores comments and splits the content into individual definitions based on the ; delimiter.
    2. Parsing single definitions: You can parse individual TL definitions directly.

    This library is essential for working with Telegram's schema definitions in a structured way.

  4. Use grammers-tl-types for MTProto type definitions

    master

    The grammers-tl-types library provides Rust struct and enum types that represent the official Telegram [Type Language] (TL) definitions.

    Each type generated by this library implements the following traits for handling Telegram's binary wire format:

    • Serializable: Allows converting an instance of a type into a byte array according to the MTProto [Binary Data Serialization] specification.
    • Deserializable: Allows reconstructing a type instance from a byte array.

    This is the core crate used when you need to work with the specific data structures defined by the Telegram schema.

  5. Use grammers-crypto for Telegram data encryption

    master
    The grammers-crypto library provides cryptographic methods specifically designed for encrypting and decrypting data used by Telegram. Its primary purpose is to offer a high-level interface for the AES-IGE (AES in Ciphertext Stealing mode with IGE) encryption mode, which is required for Telegram's communication protocol.
  6. Understand the core functional dependencies of grammers-client

    master

    The grammers-client crate relies on several specialized sub-crates and libraries to provide its core Telegram functionality:

    • grammers-crypto: Required if you need to support logging into accounts with 2-factor authentication (2FA) enabled.
    • grammers-mtsender: Handles the underlying network connection to Telegram.
    • grammers-session: Manages session data (authorization keys, user identifiers) and contains the logic for processing Telegram updates.
    • grammers-tl-types: Provides the implementation of the 'raw Telegram API' and powers the friendly client methods used for most operations.
  7. Understand the grammers crate hierarchy

    master

    The project is divided into several specialized crates. Understanding these dependencies helps in selecting the right level of abstraction:

    • grammers-client: The high-level API for building applications. It orchestrates other crates to handle requests, session persistence, networking, and 2FA.
    • grammers-mtsender: Manages the network connection to Telegram servers and provides an ergonomic RPC interface.
    • grammers-session: Provides storage mechanisms for client sessions, including datacenter configuration, logged-in users, and peer caches.
    • grammers-mtproto: Implements the core Mobile Transport Protocol (MTProto), handling message serialization and connection state.
    • grammers-tl-types: Contains the generated Rust types representing Telegram's Type Language (TL) definitions.
    • grammers-crypto: Provides cryptography-related methods used across the stack.
    • grammers-tl-parser & grammers-tl-gen: Internal tools used to parse TL files and generate the Rust code for grammers-tl-types.
  8. Understand how session updates are handled

    master
    Update handling in the Telegram protocol is distributed across the entire protocol. The grammers-session crate is used to manage logic related to updates, including types that are not updates themselves but affect them, and partial updates that are dependent on the specific request that produced them. Using grammers-session allows this logic to remain decoupled from the main sender implementation.
  9. Use formatting and media features in grammers-client

    master

    To utilize specific message formatting and media uploading features, the client uses the following dependencies:

    • Markdown: Supported via pulldown-cmark to allow sending formatted messages using markdown syntax.
    • HTML: Supported via html5ever to allow sending formatted messages using HTML syntax.
    • File Uploads:
      • Uses md5 for calculating checksums required by Telegram during file uploads.
      • Uses mime_guess to automatically detect the MIME type of uploaded files. If you do not explicitly set the MIME type, the client will attempt to guess it, as Telegram requires this field for media.
  10. Understand the role of grammers-mtproto

    master
    The grammers-mtproto crate provides the core implementation of the Telegram protocol without performing any I/O. In the context of the grammers-mtsender crate, grammers-mtproto is used to handle the protocol logic, while the sender crate manages the actual network communication and coordinates the sending of messages.