Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to call telegram api methods

Tags:

java

telegram

I'm working on Telegram api in my java application. I need to do authentication and authorization with my telegram account and get message list of my specific group. For this purpose, first I got api_id, api_hash and MTProto servers from telegram site. Second, I tried to authorize my account with auth.sendCode method in this way:

...
String url = "https://149.154.167.40:443/auth.sendCode";
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
httpPost.addHeader("charset", "UTF-8");

List<NameValuePair> nameValuePairs = new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair("phone_number", myPhoneNumber));
nameValuePairs.add(new BasicNameValuePair("sms_type", "5"));
nameValuePairs.add(new BasicNameValuePair("api_id", api_id));
nameValuePairs.add(new BasicNameValuePair("api_hash", api_hash));
nameValuePairs.add(new BasicNameValuePair("lang_code", "en"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));

HttpResponse response = httpClient.execute(httpPost);
...

But this returns me javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake exception. I tested url with http instead of https and this returned 404 Not Found html content. What is the correct way for calling telegram api method in java?

Update:

I tried using java socket for sending TCP post request, but this returns me 404 not found.

like image 528
hamed Avatar asked Oct 17 '16 09:10

hamed


People also ask

How can I access Telegram API?

Obtaining api_idLog in to your Telegram core: https://my.telegram.org. Go to "API development tools" and fill out the form. You will get basic addresses as well as the api_id and api_hash parameters required for user authorization. For the moment each number can only have one api_id connected to it.

What is the URL for Telegram API?

The first part of the URL indicates that you want to communicate with the Telegram API ( api.telegram.org ).

How does Telegram bot API work?

Bot API. This API allows you to connect bots to our system. Telegram Bots are special accounts that do not require an additional phone number to set up. These accounts serve as an interface for code running somewhere on your server.

What can I do with the telegram API?

The Telegram API and TDLib allow you to build your own customized Telegram clients. You are welcome to use both APIs free of charge. You can also add Telegram Widgets to your website. Designers are welcome to create Animated Stickers or Custom Themes for Telegram. This API allows you to connect bots to our system.

How can I make my own customised Telegram client?

1 Answer 1 ActiveOldestVotes 3 Telegramoffer two kinds of APIs for developers. The Bot API allows you to easily create programs that use Telegrammessages for an interface. The TelegramAPI allows you to build your own customised Telegramclients.

How to call all methods in telegram?

To call most of the methods, you first need to run the user authorization To call the Telegram method, use the api.call (method, params, options) method Method name from methods list.

What additional interface options can I add to telegram?

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.


Video Answer


1 Answers

Since it's mproto protocol, you must obey their specification - https://core.telegram.org/mtproto

I suggest you to use this project, since it has working examples - https://github.com/badoualy/kotlogram

like image 61
joojic Avatar answered Oct 21 '22 04:10

joojic