I’m trying to use the Telegram API to make an online advertising app with PHP, but the problem I have is that I can’t even understand making request to telegram website. This is a short code I wrote based on Telegram’s API and protocol:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Length" content="348">
<meta http-equiv="Connection" content="keep-alive">
<meta http-equiv="Host" content="149.154.167.40:80">
</head>
<body>
<?php
$url = '149.154.167.40';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
$result = curl_exec($curl);
echo $result;
?>
</body>
</html>
Does anyone have any idea how to make it work?
2
Answers
The Telegram API is a pain to use, you have to apply all sort of encryption sorcery to work with their MTProto protocol and there’s very little reference or example for PHP available. I would suggest you use their new Bot API. It is a service the created that abstracts all the MTProto interactions behind a simple HTTP layer. You first need to generate a bot using their Bot Father and then you use the ID to interact with the API.
Receiving new messages (polling):
Sending messages:
You can also use a webhook instead of polling for updates. You can find more information in the API documentation I linked.
You can use this library:
PHP implementation of the telegram MTProto protocol (better tg-cli)
https://github.com/danog/MadelineProto
Simple sample code: