php – Get all messages from Telegram public chat


How to parse a user-specified number of messages from a Telegram public chat?

At the entrance, the user enters the url of the chat and the number of messages to be parsed. I have never worked with either Telegram bots or its API before. What is the best way to implement this? Perhaps there are ready-made libraries for this task?


If you need to parse from any random public chat, then you cannot do this via the Telegram-Bot-API. Because the bot reads only from the chat, where it was added by itself.

For bots, there is only one way to receive messages – the getUpdates method receives all messages for a certain period, but you need to understand that data for all chats comes in response and you will have to determine the right one yourself.

To understand how to write bots for Telegram, you can read this article – well, or any other telegram бот на php at the request of them there are a lot of them =)

In order to parse from any chat, you need to write your own client for Telegram, then you can use the messages.getHistory () method

Found the implementation of the Telegram client in PHP – MadelineProto , you can try using it.

Additionally, you can read: – the answers have a short description of the steps to create a client for Telegram – dock on TelegramAPI

Scroll to Top