Using Telegram API for Java Desktop App?

后端 未结 2 398
萌比男神i
萌比男神i 2020-12-13 09:45

I am not that new to Java Programming, but I have never worked with external libraries etc. Now I want to develop a desktop client for the \"Telegram\" open-source messaging

相关标签:
2条回答
  • 2020-12-13 10:08

    Essentially you will have to fill out the blanks in the code given on GitHub in the ex3ndr/telegram-api repository. If you've got the library Jar file you built and the tl-api-v12.jarfile on your Eclipse project's Java build path, then look at the RPC Calls section of the README and

    First you need to set up an AppInfo object with your API credentials, then you will also have to create some new classes that implement the AbsApiState and ApiCallback interfaces. Once these are available, you can create the TelegramApi object and make an RPC call to the Telegram service as follows; in this case using the suggested auth.checkPhone method:

    // TODO set up AbsApiState, AppInfo and ApiCallback objects
    TelegramApi api = new TelegramApi(state, appInfo, apiCallback);
    
    // Create request
    String phoneNumber = "1234567890";
    TLRequestAuthCheckPhone checkPhone = new TLRequestAuthCheckPhone(phoneNumber);
    
    // Call service synchronously
    TLCheckedPhone checkedPhone = api.doRpcCall(checkPhone);
    boolean invited = checkedPhone.getPhoneInvited();
    boolean registered = checkedPhone.getPhoneRegistered();
    // TODO process response further
    

    The TelegramApi object represents your connection to the remote service, which is a request response style of API. RPC calls are made via the doRpcCall method, which takes a request object from the org.telegram.api.requests package (the TLRequestAuthCheckPhone type in the example) filled in with the appropriate parameters. A response object (TLCheckedPhone above) is then returned with the result when it is available.

    In the case of an asynchronous call the method returns immediately, and the onResult callback method is executed when the result is available:

    // Call service aynchronously
    api.doRpcCall(checkPhone, new RpcCallbackEx<TLCheckedPhone>() {
        public void onConfirmed() { }
        public void onResult(TLCheckedPhone result) {
            boolean invited = checkedPhone.getPhoneInvited();
            boolean registered = checkedPhone.getPhoneRegistered();
            // TODO process response further
        }
        public void onError(int errorCode, String message) { }
    });
    
    0 讨论(0)
  • 2020-12-13 10:10

    Or just look at this API https://github.com/pengrad/java-telegram-bot-api

    It is really simple to use

    0 讨论(0)
提交回复
热议问题