29 releases (stable)

100.100.100 Aug 27, 2019
1.7.0 Feb 15, 2021
1.6.2 Sep 20, 2020
1.6.1 May 27, 2020
0.1.0 Jun 11, 2019

#55 in Web programming

Download history 2/week @ 2020-12-21 1/week @ 2020-12-28 2/week @ 2021-01-04 2/week @ 2021-01-11 26/week @ 2021-01-18 13/week @ 2021-01-25 6/week @ 2021-02-01 38/week @ 2021-02-08 162/week @ 2021-02-15 36/week @ 2021-02-22 16/week @ 2021-03-01 11/week @ 2021-03-08 7/week @ 2021-03-15 90/week @ 2021-03-22 98/week @ 2021-03-29 205/week @ 2021-04-05

109 downloads per month

MIT license

355KB
6K SLoC

telegram-client

Build Status

Telegram client for rust.

This crate use td to call telegram client api. support async api.

Usage

[dependencies]
telegram-client = "1.7.*"

version

Since the telegram-client version follows td.

Version mapping

telegram-client td
0.* master
1.3.* 1.3.*
1.4.* 1.4.*
1.5.* 1.5.*
1.6.* 1.6.*
1.7.* 1.7.*

Note

Note that you need tdjson dylib file in your path for building and running your application. See also rtdlib-sys for more details.

Examples

block

fn main() {
  let api = Api::default();
  let mut client = Client::new(api.clone());
  let listener = client.listener();

  listener.on_receive(|(api, json)| {
    debug!("receive {}", json);
    Ok(())
  });

  client.daemon("telegram-rs");
}

async

#[tokio::main]
async fn main() {
  let api = Api::rasync();

  let mut client = Client::new(api.api().clone());
  let listener = client.listener();

  // listener.on_update_authorization_state...

  client.start();

  let chat = api.get_chat(GetChat::builder().chat_id(1)).await;
  println!("{:#?}", chat);
}

more

more examples

Event

Most of the events are from td, two events of particular concern.

on_receive

This event is receive everything from td, returned data type is a json string.

on_exception

When td returned json can not deserialize, or your event handler returned error. will be call is event.

a sample of event handler returned error

listener.on_proxy(|(api, pxy)| {
  debug!("Proxy info => {:?}", pxy);
  Err(TGError::new("some error"))
});

Dependencies

~8.5MB
~180K SLoC