Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add bot mentioned filter #3799

Closed
Poolitzer opened this issue Jul 13, 2023 · 27 comments · Fixed by #3941
Closed

[FEATURE] Add bot mentioned filter #3799

Poolitzer opened this issue Jul 13, 2023 · 27 comments · Fixed by #3941

Comments

@Poolitzer
Copy link
Member

Poolitzer commented Jul 13, 2023

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

There is currently no filter defined by us which simply checks if message contains a bot mention, so @botusername message.

Describe the solution you'd like

Make a new filter which checks if a message contains the mention of a bot. So first check if the message has the telegram.constants.MessageEntityType.MENTION, and then check if the username is the one of the bot

Describe alternatives you've considered

One can do this filter by themselves, but providing one would be nice

Additional context

Maybe having the only_start parameter here would be nice, same as with the command filter.

Assignees:

Current assignee: @ElmurodovJavohir - #3857. If they don't commit/reply by Oct 7th, the next in line to tackle this issue is:

- @Prathmesh-rajurkar
- @AbhigyanBaruah

Issue is being tackled by dev team due to the continued inactivity from the contributors.

@shivamsn97
Copy link
Contributor

I would love to work on this. Please assign me if you would like me to do this.

@harshil21
Copy link
Member

@shivamsn97 Assigned you 👍

@Bibo-Joshi
Copy link
Member

Before work goes into a PR for this, I would like to clarify at least the naming of the filter. Also I have two more thoughts:

  • I think it would be good to make the filter generic in the way that only the bot but any specified user/chat can be mentioned
  • it might even be beneficial to filter for any specified MessageEntity object, optionally with ignoring the offset and length. e.g. You could filter for messages that contain a specific underlined word

@harshil21
Copy link
Member

it might even be beneficial to filter for any specified MessageEntity object

We already have filters.Entity for this?

@shivamsn97
Copy link
Contributor

Got them. Let me know what you think about the naming of the filter.

@Bibo-Joshi
Copy link
Member

@harshil21 This filters only for the type, not a specific instance. I.e. you can filter for messages that contain any bold word, but not for a specific one

@Bibo-Joshi
Copy link
Member

Okay, my rambling was nonsense, as MessageEntity objects don't contain the text that is formatted. One could pass a MessageEntity object along with the expected text, but I see that this clumsy to use and the use case is surely minimal.
I would like to see a generic "mention" filter though instead of a specifc "bot mention" filter. I guess it should accept as input a

  • a username
  • a user id (as string or int)
  • a User object

and then use a combination of MessageEntity.user and Message.parse_entities to check if any of the MENTION or TEXT_MENTION entities mentions that user.
Accepting a sequence as input also sounds reasonable, allowing several users to be mentioned.

I guess filters.Mention would make sense as name.

@Poolitzer @harshil21 what do you think?

@aelkheir
Copy link
Contributor

Hi @shivamsn97, are you still interested in this? I'd love to take it if you found yourself busy, no pressure tho

@Bibo-Joshi
Copy link
Member

@aelkheir if shivam doesn't reply fover the weekend, I guess you can go ahead and pr :)

@shivamsn97
Copy link
Contributor

@Bibo-Joshi the name wasn't finalized yet right? That's what I was waiting for. There was no update from harshil and poolitzer.
Anyways, @aelkheir you can take it if you want, no issues.

@Bibo-Joshi
Copy link
Member

Ah, right, my bad. let me ping them offline

@aelkheir
Copy link
Contributor

@Bibo-Joshi the name wasn't finalized yet right? That's what I was waiting for. There was no update from harshil and poolitzer. Anyways, @aelkheir you can take it if you want, no issues.

Oh sorry for the confusion. I was just a little excited for my first contribution :). @shivamsn97 you can wait for their input and I'll take the next issue 😄.

@harshil21
Copy link
Member

I guess filters.Mention would make sense as name.

@Poolitzer @harshil21 what do you think?

Yes that name and the implementation seems fine with me

@Bibo-Joshi
Copy link
Member

Poolitzer is currently unavailable, but with harshils approval I'd say we're good to go @shivamsn97 :)

@shivamsn97
Copy link
Contributor

Thanks. I'll let you know about any update or questions.

@aelkheir
Copy link
Contributor

aelkheir commented Aug 5, 2023

I see no sign of another good first issue. So consider me standby for this one 👍

@harshil21
Copy link
Member

@aelkheir #3825 is also a good first issue, if you'd like to do that

@aelkheir
Copy link
Contributor

aelkheir commented Aug 5, 2023

Yes, totally. Replied on the issue.

@Bibo-Joshi
Copy link
Member

Due to inactivity, I guess this issue is up for the taking again. If anyone is working on a PR, please leave a short comment.

@ElmurodovJavohir
Copy link
Contributor

I want to work on this feature. Could you check my work https://github.com/ElmurodovJavohir/python-telegram-bot/tree/mention-feature

@Bibo-Joshi
Copy link
Member

Bibo-Joshi commented Aug 24, 2023

@ElmurodovJavohir Please open a pull request so that we can do a proper review:)

PS: sorry, I missed #3857

@ElmurodovJavohir
Copy link
Contributor

Accepting a sequence as input also sounds reasonable, allowing several users to be mentioned.

Could you a bit explain about user id and user object, if it possible with example

@Bibo-Joshi
Copy link
Member

Sorry, I don't understand what exactly you want explained. Please join us at https://t.me/pythontelegrambotchannel/125 for a easier communication.

ElmurodovJavohir added a commit to ElmurodovJavohir/python-telegram-bot that referenced this issue Aug 29, 2023
@Prathmesh-rajurkar
Copy link

I would love to work on this. Please assign me if you would like me to do this.

@harshil21
Copy link
Member

I would love to work on this. Please assign me if you would like me to do this.

There is already an open PR for it (#3857). If @ElmurodovJavohir doesn't commit/reply in a week, we'll close that PR and assign it to you.

@AbhigyanBaruah
Copy link

Is this issue still open? I'd like to try working on this issue.

@harshil21
Copy link
Member

Is this issue still open? I'd like to try working on this issue.

This issue is hot, there is a queue of contributors waiting to finish this, I will edit OP to show status

@Bibo-Joshi Bibo-Joshi mentioned this issue Oct 22, 2023
5 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
8 participants