A
A
Alexander Tsymbal2022-03-24 21:36:37
API
Alexander Tsymbal, 2022-03-24 21:36:37

How to correctly send requests to Telegram API (not Bot API)?

Good afternoon.
I'm trying to send requests to the Telegram API in PHP using cURL. Important, not the Bot API, but https://core.telegram.org/api#telegram-api , in which we authorize the user.

I know that there are ready-made libraries like MadelineProto, but it has recently been updated poorly and is very cumbersome. I would like to write something simple. I only need a couple of methods for application needs.

I have a configured app, got api_id, api_hash and everything else.
623cb89c6297d300207161.jpeg

I start with the basic auth.sendCode method as follows:
As the request address, I use the received server IP (both the test one and the production one), and after the slash the name of the method. Well, I think this is the most logical way. I'm probably wrong here.

$ch = curl_init('https://149.154.XXX.XXX/auth.sendCode');
curl_setopt_array($ch, array(
  CURLOPT_POST => 1,
  CURLOPT_POSTFIELDS => array(
    'phone_number' => "+7960XXXXXXX",
    'api_id' => XXXXXX,
    'api_hash' => 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
  ),
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_VERBOSE => true
));
$chresult = curl_exec($ch);
$chinfo = curl_getinfo($ch);
curl_close($ch);


As a result, this construction does not return anything to me. Even the response code is 0.

Surely, somehow everything is a little more complicated there.
Perhaps someone faced with a similar, maybe there is an experience?

I will be grateful for the answer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2022-03-25
@AlexanderTsymbal

There is not just an http protocol, so it cannot be easily repeated. If it is php that is interesting, then the library is advised https://github.com/danog/MadelineProto
For python, the telethon library or, alternatively, pyrogram. For js - mtproto-core. Most bot writers use python and telethon.

A
Alexander Tsymbal, 2022-03-24
@AlexanderTsymbal

Googled it here:
https://stackoverflow.com/a/49581502/6705359 .
In short, you need to use TDLib.
Maybe someone can be more specific?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question