17 releases

0.2.19 Nov 17, 2024
0.2.15 Sep 21, 2024
0.2.11 Jul 1, 2024
0.2.5 Sep 22, 2023
0.1.1 Jun 9, 2023

#138 in Asynchronous

Download history 100/week @ 2024-08-12 126/week @ 2024-09-02 4/week @ 2024-09-09 131/week @ 2024-09-16 30/week @ 2024-09-23 8/week @ 2024-09-30 5/week @ 2024-10-07 313/week @ 2024-10-14 11/week @ 2024-10-21 117/week @ 2024-10-28 51/week @ 2024-11-04 50/week @ 2024-11-11 66/week @ 2024-11-18 6/week @ 2024-11-25

179 downloads per month

MIT license

1MB
20K SLoC

Conogram: async Telegram Bot API client written in Rust


Aims

  • Full support of latest Bot API version no webhooks yet
  • 1 to 1 API methods and entitities mapping
  • Ease of use

Features

  • Fully async
  • Utility extension methods for (not all yet) API entities (e.g. message.reply method)
  • Can be used in multithreaded context
  • Full control over update handling

TODO

  • More handy entity extension methods
  • Webhooks support

  • More examples

Logging

How to enable logging in your executable

Quick usage overview

Using Local Bot API Server

    let server_config = ApiServerConfig::local("http://localhost", 80, true);

    let api_config = APIConfig::new("BOT_TOKEN", server_config)?

    let api = API::new(api_config);

Calling API methods

    let mut api = API::new(/**/);

    // Required request parameters are in the request constructor, optionals are set via builder-like methods
    // ChatId can be username of a channel
    let request = api.send_message("@channelusername","Text").reply_to_message_id(42);

    // All requests implement IntoFuture
    let message = request.await?;

    // You can handle some common API errors automatically:

    // 1. By wrapping manually 
    let message = API::request(request).await?;

    // 2. Or by using a trait
    use conogram::api::WrapRequest;
    let message = request.wrap().await?;

Mutating and calling requests by references

    let mut request = api.send_message(chat_id, "Text");
    for i in 0..5 {
        request = request.chat_id(i);

        // &Request implements IntoFuture too
        let message = (&request).await?;
    }

Very-Mini-FAQ

Q: Is it production-ready?
A: The library is not thoroughly tested, some stuff may be broken, unconventional or unusable for you. The reason is I'm developing it for my personal use. But if you're using it too, suggestions on improvement are welcome

Dependencies

~7–18MB
~241K SLoC