Is it possible to write a bot that repeats all messages of a specific group member? - telegram

So that whenever my group member Bob writes a message, the bot immediatly copies it (echoing him)?

Related

Getting member id of a specific member in telegram group

I have a telegram bot that can do several tasks in my telegram group.
I want to add a new task that can count the number of messages a specific user sends in a group.
Every time it will be updated, Let say a user name drhunter, if he sends a message then it will save in a text file as,
drhunter 1 for the next message will be updated to drhunter 2 and so on.
I can do it using telegram username but If a user hasn't set username then occurs a problem. It shows None
I get username using message.from_user.username
I use username & count the number of messages each time then save it in a file. Like this
count.txt
drhunter 5
drhunter2 45
Is there any way to do this? or more specifically is there any way to identify a telegram user without their username (inside a telegram group)?
Use the id instead, which is a unique identifier for the user independent of whether the user has a username.

how to structure unseen count and messages for group chat firebase realtime database?

unseen messages are unique for every member of the group.should I create and update last added message and unseen count for every member of the group. i am little confused how to structure the group in realtime database.my question is if I have to update unseen count for every member then I have to check who is active in the group at the moment and loop through every member to update unseen count and last messages.how to approach this group creation.
I typically track the key or timestamp of the last message each user has seen. From that you can then create a query that gets only messages from there on.
If you want a count of the unread message count for each user, you could store their "last seen key" in the database, and use that to determine the unseen message count for each of them by either running a query for each of them, or (better) by determining the oldest unseen, running a query for that, and then calculating the rest in code.
Of course you could also store the unseen message count for each user in the database, in which case I would use a Cloud Function that increments the counters on every message that is added, and decrements it whenever an (older) message is removed.

How to forward (filter) Telegram messages from a private group to myself based on sender?

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!
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.

Telethon IDs uniqueness

There are 3 types in telethon:
User: can a real user or a bot
Chat: telegram group
Channel: a telegram channel or a super group
All of three types have an ID attribute. Can i store them inside one column in database and make that column unique? Or there can be duplicate ids between these three types?
Yea you can do that. ID is a unique identifier in Telegram.
A simple way to check that is to take a look at sendMessage in Bot APIs. You can see that target chat is just recognized by its ID and it doesn't need any extra information about the type of that target chat.
users and normal chats(normal groups not supper group) have positive id.
and channels (include supper groups and broadcast channels) have negative id (for example: -1001050484879).
in some methods, telethon return channel id as positive number (for example 1050484879, remove -100 from first of id) you must add -100 at first of ids of channel then save them.

How to make auto respond bot to new member joined in groups without type command

How to make auto respond bot to new member joined in groups without type command?
Look at this picture:
Bot send new text when users joined in groups
When a user is added to a group, an update is sent to the bot. In it message field, there is another field, called new_chat_members, that contains an array of User objects that were added to the group. You should send the appropriate message when such an update is received. (You can use information provided in User objects to get information about those users, e.g. Their name, to include it into your message.)

Resources