How to make basic remote procedure call (RPC) in Telegram?

I am trying to create a small program that can demonstrate some of the Telegram API features. I want to be able to register and authenticate users via SMS. In accordance with the user manual for authorization, I need to call auth.sendCodeRPC. However, the code base is inadequately documented and difficult to access.

How to send a auth.sendCoderemote procedure call in Telegram? . Provide a code snippet that shows everything from setup and initialization.

+4
source share
1 answer

Try it like this ...

TLSentCode sentCode;
    try {
        sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, 5, "your app id", "en"));
    } catch (RpcException e) {
        if (e.getErrorCode() == 303) {
            int destDC;
            if (e.getErrorTag().startsWith("NETWORK_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("NETWORK_MIGRATE_".length()));
            } else if (e.getErrorTag().startsWith("PHONE_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("PHONE_MIGRATE_".length()));
            } else if (e.getErrorTag().startsWith("USER_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("USER_MIGRATE_".length()));
            } else {
                throw e;
            }
            api.switchToDc(destDC);
            sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, 5, "youa app id", "en"));
        } else {
            throw e;
        }
    }
0

Source: https://habr.com/ru/post/1536408/


All Articles