MCPcopy Index your code
hub / github.com/CalliEve/telexide

github.com/CalliEve/telexide @v0.1.17

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.17 ↗ · + Follow
553 symbols 793 edges 67 files 163 documented · 29%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

telexide

Crate Docs Build Status Rust Version

Telexide is an easy to use library for making a telegram bot, built on tokio and hyper.

View the examples on how to make and structure a bot.

Use the [ClientBuilder] to easily create a [Client] object to your preferences and register commands with the [create_framework] macro and/or register your own update handlers, before running [Client::start] to start your bot. All of this is designed to be highly customisable. For further information about the client, please see the client's module-level documentation.

API calls are easy to make using the [APIClient] and the api data models, or create and use your own api client by implementing the [API] trait. For further information about the api client, please see the api's module-level documentation.

A default command framework is provided using the [Framework] object, providing easy handling of incoming telegram bot commands sent by users of your bot. For further information about the framework, please see the framework's module-level documentation.

Example Bot

A basic ping-pong bot can be written like:

use std::env;
use telexide::{api::types::SendMessage, prelude::*};

#[command(description = "just a ping-pong command")]
async fn ping(context: Context, message: Message) -> CommandResult {
    context
        .api
        .send_message(SendMessage::new(message.chat.get_id().into(), "pong"))
        .await?;
    Ok(())
}

#[tokio::main]
async fn main() -> telexide::Result<()> {
    let token = env::var("BOT_TOKEN").expect("no token environment variable set");
    let bot_name = "ping-pong";

    ClientBuilder::new()
        .set_token(&token)
        .set_framework(create_framework!(bot_name, ping))
        .build()
        .start()
        .await
}

For more examples, please see the examples directory.

Crate Features

  • [x] Supports all of the telegram bot API, up to and including version 6.9
  • [x] easy to use and customisable client
  • [x] long-polling based update handling
  • [x] set your own timeout
  • [x] set your own limit for updates gotten at once
  • [x] easy to use, macro-based command framework
  • [x] easy to use and heavily customisable api client
  • [x] use your own hyper client
  • [x] use your own api struct so you control the get and post methods
  • [x] includes all telegram api endpoints
  • [x] webhook based update handling
  • [x] builder methods for creating all api call payloads

Planned

  • [ ] choosing what you want from the lib using feature flags
  • [ ] subscribe to non-message events using command (or similar) framework
  • [ ] run command on receiving an inline query or answer to one
  • [ ] run command on receiving a poll that matches your requirements
  • [ ] wait_for style Context method to wait for an update matching your criteria
  • [ ] methods on models for easier calling of API endpoints (like ChatMember::kick)

Installation

Add the following to your Cargo.toml file:

[dependencies]
telexide = "0.1.17"

Feature Flags

Telexide uses a set of feature flags to allow switching between rustls and native-tls for tls support. In the future flags may be added to enable/disable optional parts of the crate.

  • rustls: Makes the api client use hyper-rustls to create the tls connector. Enabled by default.
  • native-tls: Makes the api client use hyper-tls to create the tls connector. Overwrites the rustls feature if enabled.

Supported Rust Versions

The minimum supported version is 1.64. The current Telexide version is not guaranteed to build on Rust versions earlier than the minimum supported version.

Extension points exported contracts — how you extend this code

AsFormData (Interface)
(no doc) [1 implementers]
src/utils/form_data.rs
API (Interface)
(no doc) [1 implementers]
src/api/api.rs

Core symbols most depended-on inside this repo

post
called by 91
src/api/api_client.rs
get
called by 17
src/api/api_client.rs
get_id
called by 15
src/model/chat.rs
post_file
called by 14
src/api/api_client.rs
build
called by 11
src/client/builder.rs
set_token
called by 8
src/client/builder.rs
fire_handlers
called by 7
src/client/client.rs
fields_to_tokenstreams
called by 6
telexide_proc_macros/src/utils.rs

Shape

Class 267
Method 221
Function 34
Enum 29
Interface 2

Languages

Rust100%

Modules by API surface

src/api/api.rs115 symbols
src/model/message_contents.rs33 symbols
src/api/types/chat.rs28 symbols
src/model/chat.rs27 symbols
src/api/types/inline.rs22 symbols
src/api/types/send_messages.rs20 symbols
src/model/markup.rs16 symbols
src/client/webhook_handling.rs16 symbols
src/api/types/stickers.rs15 symbols
src/client/builder.rs13 symbols
src/api/types/other.rs13 symbols
src/api/types/forum.rs12 symbols

For agents

$ claude mcp add telexide \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page