Worked with VK API. There it was specifically described that it is necessary to form an HTTP request and receive a JSON response in response. It is written transparently.

But how to work with the Telegram API, which is not for bots, but for direct interaction with the server? How to send and receive requests?

  • Where is the exile or examples then? - teran
  • It is necessary to start not with the API, but with the protocol apparently. - teran
  • What is the problem? In my opinion core.telegram.org/bots/api - hedgehogues
  • @hedgehogues, it's not about bot APIs - mymedia

1 answer 1

The Telgram Core API works using MtProto , a proprietary protocol. Although it provides both encryption and most of the services that TLS provides, it is still very different from it. (Let me remind you that HTTPS is plain HTTP over TLS, and which in turn is built on top of TCP).

MtProto can work using quite diverse transport (TCP, HTTP, etc.). The protocol consists of two main parts: for cloud chat rooms that are accessible on any authorized device, and for secret chat rooms that are completely encrypted from device to device (end- to-end).

The basic telegram protocol allows you to exchange arbitrary finite length messages with the server. The messages here imply certain pieces of data: setting parameters, querying the list of chats, notifications, etc. In a word, everything that is so-called. high-level API. The complete scheme can be found on the Telegram website https://core.telegram.org/schema .

Fortunately, to interact with MtProto, you don’t have to implement it yourself. You can use the finished application telegram-cli . Its code is closed (at least the part related to the protocol). If there is a desire to study the protocol in more detail, in my opinion, the current code can be found in the Telegram Desktop repository.

See my other answer for an example of a script for telegram-cli .

NB: please do not confuse the above with the Telegram Bot API. This is the usual Rest API and works on top of the usual HTTPS (like on VKontakte, as well as the API of many other popular services).

  • I mean, to send / receive at least some information, you need to communicate with the servers only on MTProto? - Vidoom
  • MtProto is required only if you are trying to write a Telegram client. If your target is a bot, you have a Rest API over HTTPS. It is not clear what information you want to get from telegrams. - mymedia
  • No, it was planned just a client. Thanks for the info - Vidoom
  • In this case, the tdlib - mymedia library may be useful to you.
  • Java does not suit me, unfortunately - Vidoom