Giter Site home page Giter Site logo

telegram-api's Introduction

Java Telegram Api Library

This library allows you to make rpc calls to Telegram.

Depends on tl-core and mtproto libraries.

Now it used in our production-ready product Telegram S.

Telegram build server

Including in your project

Dependencies

This project depends on java MTProto implementation and tl-core library

Binary

Download latest distribution at releases page and include jars from it to your project.

Building from source code

Project definded and gradle and expected to use IntelliJ IDEA 13 (now it is Beta) as IDE.

  1. Checkout this repository to telegram-api folder
  2. Checkout mtproto java implementation to mtproto folder
  3. Checkout tl core library to tl-core folder
  4. Execute gradle build at telegram-api folder

Usage of library

Implement storage

You might to implement storage class for working with api. This storage used for saving state of telegram api across execution instances.

Extend class org.telegram.api.engine.storage.AbsApiState and implement suitable methods.

Generating keys

In your storage might be information about keys in current datacenter. Keys might be generated manualy by using org.telegram.mtproto.pq.Authorizer class.

RPC calls

Now you have proper key for accessing telegram api.

TelegramApi api = new TelegramApi(new MyApiStorage(), new AppInfo(... put application information here...), new ApiCallback()
{
  @Override
  public void onApiDies(TelegramApi api) {
    // When auth key or user authorization dies
  }
  @Override
  public void onUpdatesInvalidated(TelegramApi api) {
    // When api engine expects that update sequence might be broken  
  }
});

// Syncronized call
// All request objects are in org.telegram.api.requests package
TLConfig config = api.doRpcCall(new TLRequestHelpGetConfig());

// Standart async call
api.doRpcCall(new TLRequestHelpGetConfig(), new RpcCallback<TLConfig>()
{
  public void onResult(TLConfig result)
  {
    
  }

  public void onError(int errorCode, String message)
  {
    // errorCode == 0 if request timeouted  
  }
});

// Priority async call
// Such rpc call executed with high pripory and sends to server as fast as possible this may improve message delivery speed
api.doRpcCall(new TLRequestHelpGetConfig(), new RpcCallbackEx<TLConfig>()
{
  public void onConfirmed()
  {
    // when message was received by server
  }

  public void onResult(TLConfig result)
  {
    
  }
  
  public void onError(int errorCode, String message)
  {
    // errorCode == 0 if request timeouted  
  }
});

// File operations
// Method that downloads file part. Automaticaly managed connections for file operations, automaticaly create keys for dc if there is no one.
api.doGetFile(...)
// Uploads file part
api.doSaveFilePart(...)

More information

####Telegram project

http://telegram.org/

Telegram api documentation

English: http://core.telegram.org/api

Russian: http://dev.stel.com/api

MTProto documentation

English: http://core.telegram.org/mtproto

Russian: http://dev.stel.com/mtproto

Type Language documentation

English: http://core.telegram.org/mtproto/TL

Russian: http://dev.stel.com/mtproto/TL

Android Client that uses this library

Telegram S

Licence

Project uses MIT Licence

telegram-api's People

Contributors

ex3ndr avatar

Watchers

 avatar  avatar

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.