2

I'm in a private Telegram group that has a continual stream of many messages from a large number of people. I need to somehow pull out just those from a handful of specific people, and forward them to myself somehow - e.g. a new group I'm the only member of, or private chat, or some other way (email?). I just need to read them, not reply.

I'm a full stack developer (PHP back end but willing to consider others if works better) and know how to interface with APIs etc so can write some code to do this.

Can anyone advise on what API functions I'd use, or other approach here - and is it the Telegram or Bots API? Or is there a pre-existing solution out there?

Asking here as I've done my own research and not finding any solutions!

Alex Kerr
  • 956
  • 15
  • 44

1 Answers1

1

You can create a bot and put it in the private group. Set the bot as administrator so it can read all messages from all users. For each message the users send in the group, the bot will recive an update containing a message object. The message object contains all the information about the message just sent in the group, including the user's data. To filter a message from a specific user you can compare the user_id in $update['message']['from']['id'] with an array containing all the user_ids of the users you want to forward their messages to you, with the in_array php function passing the user_id and the array. Then, if it match, use the forwardMessage method with these parameters:

{
  "chat_id": "YOUR_USER_ID",
  "from_chat_id": "PRIVATE_GROUP_CHAT_ID",
  "message_id": "THE_FILTERED_MESSAGE_ID"
}

If you use your user_id in the chat_id field, the bot will forward the message from the private group to your chat with it. The from_chat_id field is the chat_id of the private group (you can get it from $update['message']['chat']['id']). The message_id is the unique identifier for a message in that private group. It's contained in $update['message']['message_id'].

Instead of comparing the user_id to filter users, you can compare the first_name, last_name or username of the users but only the user_id is unique for each user and can not be changed.


You are using the Bot API.

GioIacca9
  • 406
  • 4
  • 8
  • @Giolacca9 That's great, thanks - my only problem with that is I don't have control of the private group I'm in, I'm not allowed to add a bot user into it, and I don't have control over who is an administrator. My own personal Telegram account is a regular user in the group (I can read and post), that's all I'm allowed to do. So any solution would have to use my own personal account details to read the messages out from other users. This should be possible, right? As that's what the Telegram client app is doing. Then I guess I can filter the messages as you suggest. Thanks again. – Alex Kerr Aug 24 '20 at 16:27
  • It is possible to do that but it's very difficult. You should use te [Telegram API](https://core.telegram.org/api#telegram-api) – GioIacca9 Aug 24 '20 at 16:55