Telegram client in PHP (and receiving messages using MadelineProto)
The solution was needed in PHP and the next hour was spent searching for it. It's amazing how little information is available about it (although no, not surprising ... who writes this in PHP at all ...) . In general, the road with StackOverflow led to MadelineProto . The library has quite a few links on the net.
What is Madeline ?This is a PHP telegram client that provides methods for working both on behalf of the user and on behalf of the bot. The purpose of the article is first of all to shorten the Madeline search path and draw attention to it. It is also interesting to learn from habravchan that there is a similar on other PL?
Well, of course, publish for example a piece of code that solved my problem:
//Подключение Madeline с гитхабаif (!file_exists(__DIR__ . '/madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', __DIR__ . '/madeline.php');
}
include__DIR__ . '/madeline.php';
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->start();
$me = $MadelineProto->get_self();
\danog\MadelineProto\Logger::log($me);
/* Получим историю сообщений */
$messages = $MadelineProto->messages->getHistory([
/* Название канала, без @ */'peer' => 'chatname',
'offset_id' => 0,
'offset_date' => 0,
'add_offset' => 0,
'limit' => 20,
'max_id' => 9999999,
/* ID сообщения, с которого начинаем поиск */'min_id' => $lastid,
]);
/* Сообщения, сортировка по дате (новые сверху) */
$messages = $messages['messages'];
foreach(array_reverse($messages) as $i => $message){
/* Шлем сообщение на свой канал */
$MadelineProto->messages->sendMessage([
'peer' => 'mychatname',
'message' => $message['message']
]);
}
UPD from mopkob : The project has an active community: the Russian-speaking @pwrtelegramgroupru and the international @pwrtelegramgroup .