Crates.io | telegram-client |
lib.rs | telegram-client |
version | 1.8.1 |
source | src |
created_at | 2019-06-11 06:47:05.322485 |
updated_at | 2022-01-29 04:49:03.165488 |
description | Telegram client |
homepage | https://github.com/fewensa/telegram-client |
repository | https://github.com/fewensa/telegram-client |
max_upload_size | |
id | 140357 |
size | 654,434 |
Telegram client for rust.
This crate use td to call telegram client api. support async api.
[dependencies]
telegram-client = "1.8.*"
Please read: version
Note that you need tdjson dylib file in your path for building and running your application. See also rtdlib-sys for more details.
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");
}
#[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 examples
Most of the events are from td, two events of particular concern.
This event is receive everything from td, returned data type is a json string.
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"))
});