conogram 0.1.0

An async wrapper for Telegram Bot API
Documentation

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 API entities (e.g. message.reply method)
  • Ability to set default request params (e.g. parse_mode or allow_sending_without_reply)
  • Can be used in multithreaded context
  • Full control over update handling

TODO

  • More handy entity methods
  • Webhooks support

  • Logging
  • More examples

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);

Setting default parse_mode

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

    // Setting parse_mode for sendMessage request
    api.set_default_request_param(SendMessageRequest::get_name(), "parse_mode", "html")?;

    // For all applicable requests
    api.set_parse_mode("html")?;

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
    let message = API::request(request).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?;
    }

FAQ

Q: Is it production-ready? A: It may be, or may be not. The library is not thoroughly tested, some stuff may be broken. Q: Are there any bots made with it? A: I developed this library to be used by @hintorbot, so at least this one. If you want to list your bot here, contact me in tg: @encrypted_for