Code Monkey home page Code Monkey logo

telegram-client's Introduction

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

td and rtdlib/telegram-client

Version mapping

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

The version 1.3, 1.4, 1.5, 1.6, 1.7 is outdated. the reason you can read

Therefore, if tdlib has not had a new release version, the telegram-client 1.x version will no longer be maintained. Please use 0.x and if you used 1.x you can change your dependency to 0.x.

telegram-client and rtdlib

A fixed version is recommended, you can read Comparison requirements about the fixed version. Because of cargo's dependency mechanism, if you don't specify a specific version, it will be automatically upgraded, but there is usually a dependency between t and a, and the new version cannot be applied. The current dependencies are as follows:

telegram-client rtdlib
=0.7.2 =0.7.2
=1.3.7 =1.3.7
=1.4.6 =1.4.6
=1.5.5 =1.5.5
=1.6.6 =1.6.6
=1.7.0 =1.7.0
=1.7.1 =1.7.1

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

telegram-client's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.