New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do basic RPC #12

Open
brain56 opened this Issue Apr 14, 2014 · 23 comments

Comments

Projects
None yet
8 participants
@brain56

brain56 commented Apr 14, 2014

Hi! First and foremost, I'm new here. So if this is the wrong place to be writing this, please guide me accordingly. Please be kind!

How do I make a basic remote procedure call in Telegram? I've been searching for a tutorial for quite a while now but they all seem to be insufficient for beginners, even the readme on the Github page.

Please provide a guide from set up to finish on how to initialize a TelegramApi instance, how to use the doRpcCall method and how to properly extend from TLMethod. Please provide code on how to make an auth.sendCode call from start to finish. Thank you very much! I'm sure this will be helping a lot of beginners.

P.S.

I also posted a question in StackOverflow: http://stackoverflow.com/questions/23055525/how-to-do-a-basic-remote-procedure-call-rpc-in-telegram

@brain56

This comment has been minimized.

Show comment
Hide comment
@brain56

brain56 Apr 14, 2014

I tried the sample works of @SireInsectus (https://github.com/SireInsectus/telegram-api-samples) but they end with UNKNOWN_ERROR for me.

brain56 commented Apr 14, 2014

I tried the sample works of @SireInsectus (https://github.com/SireInsectus/telegram-api-samples) but they end with UNKNOWN_ERROR for me.

@SireInsectus

This comment has been minimized.

Show comment
Hide comment
@SireInsectus

SireInsectus Apr 14, 2014

I haven't had time to get follow up on the samples - the main problem being
that registration wasn't even working from the server's end... I'm going on
vacation for a week and can look into it when I get back.

If you want to give me a friendly poke, I can take another look at it then.

-//---------//
///\UNCHIE-///\ONSTER.com
Jacob-D-Parr--|--559-640-7277
General-Manager-/-Owner
www.MunchieMonster.com http://www.munchiemonster.com/

On Mon, Apr 14, 2014 at 4:45 AM, Brian Lee notifications@github.com wrote:

I tried the sample works of @SireInsectushttps://github.com/SireInsectus(
https://github.com/SireInsectus/telegram-api-samples) but they end with
UNKNOWN_ERROR for me.


Reply to this email directly or view it on GitHubhttps://github.com/ex3ndr/telegram-api/issues/12#issuecomment-40357239
.

I haven't had time to get follow up on the samples - the main problem being
that registration wasn't even working from the server's end... I'm going on
vacation for a week and can look into it when I get back.

If you want to give me a friendly poke, I can take another look at it then.

-//---------//
///\UNCHIE-///\ONSTER.com
Jacob-D-Parr--|--559-640-7277
General-Manager-/-Owner
www.MunchieMonster.com http://www.munchiemonster.com/

On Mon, Apr 14, 2014 at 4:45 AM, Brian Lee notifications@github.com wrote:

I tried the sample works of @SireInsectushttps://github.com/SireInsectus(
https://github.com/SireInsectus/telegram-api-samples) but they end with
UNKNOWN_ERROR for me.


Reply to this email directly or view it on GitHubhttps://github.com/ex3ndr/telegram-api/issues/12#issuecomment-40357239
.

@brain56

This comment has been minimized.

Show comment
Hide comment
@brain56

brain56 Apr 15, 2014

@SireInsectus , thanks! I would love to see a follow up on your work. Please, do so. And if possible, update us here, via this thread for others to see. Thanks!

brain56 commented Apr 15, 2014

@SireInsectus , thanks! I would love to see a follow up on your work. Please, do so. And if possible, update us here, via this thread for others to see. Thanks!

@saturngod

This comment has been minimized.

Show comment
Hide comment
@saturngod

saturngod Apr 15, 2014

@brain56 , you can use like this

private static void login() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        System.out.print("Loading fresh DC list...");
        TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
        apiState.updateSettings(config);
        System.out.println("completed.");
        System.out.print("Phone number for bot:");
        String phone = reader.readLine();
        System.out.print("Sending sms to phone " + phone + "...");
        TLSentCode sentCode;
        try {
            sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0,
                    5, "1c5c96d5edd401b1ed40db3fb5633e2d", "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, "1c5c96d5edd401b1ed40db3fb5633e2d", "en"));
            } else {
                throw e;
            }
        }
        System.out.println("sent.");
        System.out.print("Activation code:");
        String code = reader.readLine();
        TLAuthorization auth = api.doRpcCallNonAuth(new TLRequestAuthSignIn(
                phone, sentCode.getPhoneCodeHash(), code));
        apiState.setAuthenticated(apiState.getPrimaryDc(), true);
        System.out.println("Activation complete.");
        System.out.print("Loading initial state...");
        TLState state = api.doRpcCall(new TLRequestUpdatesGetState());
        System.out.println("loaded.");
    }

code from https://github.com/yarneo/telegram-trivia-bot/blob/master/src/org/telegram/bot/Application.java

@brain56 , you can use like this

private static void login() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        System.out.print("Loading fresh DC list...");
        TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
        apiState.updateSettings(config);
        System.out.println("completed.");
        System.out.print("Phone number for bot:");
        String phone = reader.readLine();
        System.out.print("Sending sms to phone " + phone + "...");
        TLSentCode sentCode;
        try {
            sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0,
                    5, "1c5c96d5edd401b1ed40db3fb5633e2d", "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, "1c5c96d5edd401b1ed40db3fb5633e2d", "en"));
            } else {
                throw e;
            }
        }
        System.out.println("sent.");
        System.out.print("Activation code:");
        String code = reader.readLine();
        TLAuthorization auth = api.doRpcCallNonAuth(new TLRequestAuthSignIn(
                phone, sentCode.getPhoneCodeHash(), code));
        apiState.setAuthenticated(apiState.getPrimaryDc(), true);
        System.out.println("Activation complete.");
        System.out.print("Loading initial state...");
        TLState state = api.doRpcCall(new TLRequestUpdatesGetState());
        System.out.println("loaded.");
    }

code from https://github.com/yarneo/telegram-trivia-bot/blob/master/src/org/telegram/bot/Application.java

@brain56

This comment has been minimized.

Show comment
Hide comment
@brain56

brain56 Apr 15, 2014

@saturngod, I'm sorry, but I'm having a java.lang.NullPointerException error in the api.switchToDc(destDC); call inside the catch clause of the function.

I initialized api and apiState like so:

ConnectionInfo[] connections = new ConnectionInfo[]{
    new ConnectionInfo(1, 0, "173.240.5.253", 443)
};
SampleApiState apiState = new SampleApiState(connections);
TelegramApi api = new TelegramApi(apiState, new SampleAppInfo(), new SampleApiCallback());

SampleAppInfo and SampleApiCallback are defined here: https://github.com/SireInsectus/telegram-api-samples/tree/master/src/main/java/org/telegram/api/samples/support

Can you please tell me what I could be doing wrong? Thanks!

brain56 commented Apr 15, 2014

@saturngod, I'm sorry, but I'm having a java.lang.NullPointerException error in the api.switchToDc(destDC); call inside the catch clause of the function.

I initialized api and apiState like so:

ConnectionInfo[] connections = new ConnectionInfo[]{
    new ConnectionInfo(1, 0, "173.240.5.253", 443)
};
SampleApiState apiState = new SampleApiState(connections);
TelegramApi api = new TelegramApi(apiState, new SampleAppInfo(), new SampleApiCallback());

SampleAppInfo and SampleApiCallback are defined here: https://github.com/SireInsectus/telegram-api-samples/tree/master/src/main/java/org/telegram/api/samples/support

Can you please tell me what I could be doing wrong? Thanks!

@saturngod

This comment has been minimized.

Show comment
Hide comment
@saturngod

saturngod Apr 15, 2014

@brain56 , try to add TLConfig for apiState after init the state like following

TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
apiState.updateSettings(config);

@brain56 , try to add TLConfig for apiState after init the state like following

TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
apiState.updateSettings(config);
@brain56

This comment has been minimized.

Show comment
Hide comment
@brain56

brain56 Apr 15, 2014

@saturngod

I did what you told me, so that now my intialization code looks like:

ConnectionInfo[] connections = new ConnectionInfo[]{
     new ConnectionInfo(1, 0, "173.240.5.1", 443)
};
SampleApiState apiState = new SampleApiState(connections);
TelegramApi api = new TelegramApi(apiState, new SampleAppInfo(), new SampleApiCallback());

TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
apiState.updateSettings(config);

The problem now is that I timeout at:

TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());

Any thoughts on what's happening? Is my connection to 173.240.5.1:443 in order?

brain56 commented Apr 15, 2014

@saturngod

I did what you told me, so that now my intialization code looks like:

ConnectionInfo[] connections = new ConnectionInfo[]{
     new ConnectionInfo(1, 0, "173.240.5.1", 443)
};
SampleApiState apiState = new SampleApiState(connections);
TelegramApi api = new TelegramApi(apiState, new SampleAppInfo(), new SampleApiCallback());

TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
apiState.updateSettings(config);

The problem now is that I timeout at:

TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());

Any thoughts on what's happening? Is my connection to 173.240.5.1:443 in order?

@saturngod

This comment has been minimized.

Show comment
Hide comment
@saturngod

saturngod Apr 15, 2014

I tested now and time out problem , too.

I tested now and time out problem , too.

@brain56

This comment has been minimized.

Show comment
Hide comment
@brain56

brain56 Apr 15, 2014

Do you think it's a problem with our code or with the servers?

brain56 commented Apr 15, 2014

Do you think it's a problem with our code or with the servers?

@saturngod

This comment has been minimized.

Show comment
Hide comment
@saturngod

saturngod Apr 15, 2014

no idea . Look like we miss something in the code. only @ex3ndr can answer this question.

no idea . Look like we miss something in the code. only @ex3ndr can answer this question.

@saturngod

This comment has been minimized.

Show comment
Hide comment
@saturngod

saturngod Apr 23, 2014

@brain56 , because of the layer12 api. I tested with layer 11 api and it's working fine.

You can download at http://cl.ly/V9it/download/telegram-v11.zip and try again. API key from my.telegram.org is not working. Please use other api key and hash code.

@brain56 , because of the layer12 api. I tested with layer 11 api and it's working fine.

You can download at http://cl.ly/V9it/download/telegram-v11.zip and try again. API key from my.telegram.org is not working. Please use other api key and hash code.

@brain56

This comment has been minimized.

Show comment
Hide comment
@brain56

brain56 Apr 23, 2014

@saturngod Thanks for the help! But how do I get another API key and hash code if I'm not going to use the one provided in my.telegram.org? There was an issue about that and the answer to the question was to get the API key and hash code from my.telegram.org.

brain56 commented Apr 23, 2014

@saturngod Thanks for the help! But how do I get another API key and hash code if I'm not going to use the one provided in my.telegram.org? There was an issue about that and the answer to the question was to get the API key and hash code from my.telegram.org.

@saturngod

This comment has been minimized.

Show comment
Hide comment
@saturngod

saturngod Apr 23, 2014

@brain56 , now I am using APPI ID and hash code from https://github.com/SireInsectus/telegram-api-samples/blob/master/src/main/java/org/telegram/api/samples/support/SampleAppInfo.java. from It always response not authorise when I use app id and hash from http://my.telegram.org ,

@brain56 , now I am using APPI ID and hash code from https://github.com/SireInsectus/telegram-api-samples/blob/master/src/main/java/org/telegram/api/samples/support/SampleAppInfo.java. from It always response not authorise when I use app id and hash from http://my.telegram.org ,

@brain56

This comment has been minimized.

Show comment
Hide comment
@brain56

brain56 Apr 23, 2014

@saturngod, thanks! I'll give it a shot. I also tweeted to Telegram weeks ago for some support, but they haven't replied yet.

brain56 commented Apr 23, 2014

@saturngod, thanks! I'll give it a shot. I also tweeted to Telegram weeks ago for some support, but they haven't replied yet.

@brain56

This comment has been minimized.

Show comment
Hide comment
@brain56

brain56 May 12, 2014

@saturngod , did you use the the same IP as the Telegram Samples project (109.239.131.195)?

brain56 commented May 12, 2014

@saturngod , did you use the the same IP as the Telegram Samples project (109.239.131.195)?

@saturngod

This comment has been minimized.

Show comment
Hide comment
@saturngod

saturngod May 12, 2014

@brain56 no . 109.239.131.195 for register the developer account and it's not require anymore.

@brain56 no . 109.239.131.195 for register the developer account and it's not require anymore.

@tonymitcher

This comment has been minimized.

Show comment
Hide comment
@tonymitcher

tonymitcher May 22, 2014

Hi!@saturngod, @ex3ndr I test the telegram-api-samples with telegram-api-1.1.127-shadow.jar , but I get a problem, the problem is that I timeout at:
TLState state = api.doRpcCall(new TLRequestUpdatesGetState());

Hi!@saturngod, @ex3ndr I test the telegram-api-samples with telegram-api-1.1.127-shadow.jar , but I get a problem, the problem is that I timeout at:
TLState state = api.doRpcCall(new TLRequestUpdatesGetState());

@ilanta

This comment has been minimized.

Show comment
Hide comment
@ilanta

ilanta Jun 30, 2014

i have this problem:
i get this Error: " org.telegram.api.engine.RpcException: PHONE_NUMBER_UNOCCUPIED"
when i try : "TLAuthorization auth = api.doRpcCallNonAuth(new TLRequestAuthSignIn(
phone, sentCode.getPhoneCodeHash(), code));"

ilanta commented Jun 30, 2014

i have this problem:
i get this Error: " org.telegram.api.engine.RpcException: PHONE_NUMBER_UNOCCUPIED"
when i try : "TLAuthorization auth = api.doRpcCallNonAuth(new TLRequestAuthSignIn(
phone, sentCode.getPhoneCodeHash(), code));"

@ashokcoolguys

This comment has been minimized.

Show comment
Hide comment
@ashokcoolguys

ashokcoolguys Dec 1, 2014

@ilanta PHONE_NUMBER_UNOCCUPIED means that the number is not registered.
Though we have the app installed and signed up in our mobiles ,it will ask us for signup from application also..
Try this once .... and later ur code itself work from the second time
TLAuthorization auth = api.doRpcCallNonAuth(new TLRequestAuthSignUp(
phone, sentCode.getPhoneCodeHash(), code,"FirstName","Lastname"));

@ilanta PHONE_NUMBER_UNOCCUPIED means that the number is not registered.
Though we have the app installed and signed up in our mobiles ,it will ask us for signup from application also..
Try this once .... and later ur code itself work from the second time
TLAuthorization auth = api.doRpcCallNonAuth(new TLRequestAuthSignUp(
phone, sentCode.getPhoneCodeHash(), code,"FirstName","Lastname"));

@ashokcoolguys

This comment has been minimized.

Show comment
Hide comment
@ashokcoolguys

ashokcoolguys Dec 1, 2014

@saturngod / @brain56 , Have you tried sending messages ..I have registered my application.
But I ve tried to retrieve the user/chat id for sending messages .but I couldn't. Can you share me some ideas over this .. Plz share some samples also

@saturngod / @brain56 , Have you tried sending messages ..I have registered my application.
But I ve tried to retrieve the user/chat id for sending messages .but I couldn't. Can you share me some ideas over this .. Plz share some samples also

@ilanta

This comment has been minimized.

Show comment
Hide comment
@ilanta

ilanta Dec 1, 2014

thanks ashokcoolguys !

ilanta commented Dec 1, 2014

thanks ashokcoolguys !

@Raakh

This comment has been minimized.

Show comment
Hide comment
@Raakh

Raakh Sep 19, 2015

Hi can anybody send me compiled working code? I shall be thankful to you from the bottom of my heart. My email is ghayel@gmail.com

Raakh commented Sep 19, 2015

Hi can anybody send me compiled working code? I shall be thankful to you from the bottom of my heart. My email is ghayel@gmail.com

@starbug1

This comment has been minimized.

Show comment
Hide comment
@starbug1

starbug1 Sep 24, 2015

Hi. I will very thank to who that share a working code with me. i try to write it myself. but i need a good man's help. this is my email address programbug0@gmail.com

Hi. I will very thank to who that share a working code with me. i try to write it myself. but i need a good man's help. this is my email address programbug0@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment