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

[Suggestion] Add mention_XXX to Chat class #3216

Closed
Poolitzer opened this issue Aug 29, 2022 · 27 comments · Fixed by #3308
Closed

[Suggestion] Add mention_XXX to Chat class #3216

Poolitzer opened this issue Aug 29, 2022 · 27 comments · Fixed by #3308

Comments

@Poolitzer
Copy link
Member

Poolitzer commented Aug 29, 2022

XXX means .html and .markdown(_v2). It is supposed to mention the Chat in the picked markup. Use title or first_name + space + Lastname as the text if the input parameter name is not set (otherwise use that), and the inline mention of the chat.id.

The logic will be close to the User one, have a look at it here: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/telegram/_user.py#L222

Also check out our contrib document to get started with this project, and don't forget to unit test your changes!

@DhwanishShah
Copy link

DhwanishShah commented Sep 9, 2022

Hi, i want contribute in this project. Please assign this project to me.

@zeehio
Copy link
Contributor

zeehio commented Sep 9, 2022

Hi, i want contribute in this project. Please assign this project to me @Poolitzer @lorien @iley @zeehio @wjt.

Hi, my contribution to this project has been just one word, fixing a typo. Please do not tag random contributors, it is distracting to us, it is inconsiderate towards our time and we are powerless to help you.

You can check the contributor insights page to find major contributors to a project

https://github.com/python-telegram-bot/python-telegram-bot/graphs/contributors

Have a nice day

Edit: Reading again this reply I was too harsh without need. I stand by what I said but I think I could have expressed it with a much better choice of words. I apologize for that and I hope this doesn't discourage you to contribute to this or other open source projects.

@Bibo-Joshi
Copy link
Member

@DhwanishShah glad that you like to contribute. I'm assigning this issue to you.
And please indeed don't tag people without good reason ;)

@DhwanishShah
Copy link

Hi I am new to this community. Can you please explain in brief about this suggestion @Poolitzer ?

@Poolitzer
Copy link
Member Author

Hey, sure. Please read the description and if you have a specific technical question while implementing the mentioned changes to the Chat class, ask them, and I will explain :D

@Srijan-bot
Copy link

Hi, i want contribute in this project. Please assign this project to me.

@Bibo-Joshi
Copy link
Member

Sicne @DhwanishShah hasn't PRed so far, I'll re-assign to @Srijan-bot . @DhwanishShah if you are in fact preparing a PR, please leave a short comment here.

@Bibo-Joshi Bibo-Joshi assigned Srijan-bot and unassigned DhwanishShah Oct 3, 2022
@Paari1263
Copy link

Can I contribute to this project @Bibo-Joshi. Can you assign me please.

@DhwanishShah
Copy link

Sicne @DhwanishShah hasn't PRed so far, I'll re-assign to @Srijan-bot . @DhwanishShah if you are in fact preparing a PR, please leave a short comment here.

Yes I am preparing PR

@Bibo-Joshi
Copy link
Member

All right. Can you give an estimate on when you'll be PRin @DhwanishShah? It has been two weeks since your last comment 😉

@Srijan-bot @Paari1263 please for now have a look at the other hacktoberfest issues instead.

@Bibo-Joshi Bibo-Joshi assigned DhwanishShah and unassigned Srijan-bot Oct 3, 2022
@Bibo-Joshi
Copy link
Member

@DhwanishShah since I've not seen a reply from you since 10 days, I'll unassign you again. @Srijan-bot @Paari1263 (or anyone else) if you're still interested, please leave a short comment.

@miles170
Copy link
Contributor

tg://user?id={user_id} is for mentioning a user.
I cannot find how to mention chat on the Telegram doc.

@MRZHD1
Copy link

MRZHD1 commented Oct 16, 2022

Hello! I'd like to contribute if that's okay. I'm new to this repo and new to contributing, but I have worked with python quite a bit.

@MRZHD1
Copy link

MRZHD1 commented Oct 16, 2022

Hey, sure. Please read the description and if you have a specific technical question while implementing the mentioned changes to the Chat class, ask them, and I will explain :D
@Poolitzer

I don't get the 'mention the Chat in the picked markup'. As mentioned by miles, I can't seem to find anywhere in the API to mention chats, only mentioning users. Could you elaborate on this?

@Poolitzer
Copy link
Member Author

Poolitzer commented Oct 16, 2022

Hi, sorry for my late response. You both are right, there is no documented way of dealing with Chats without usernames, i forgot this when writing the issue.

There is however the link to specific messages in chats with no username, https://t.me/c/chat_id/message_id. This only works if you are part of the chat ofc, and it is only really implemented for super groups/channels. But it can be used to link to a chat without a username.

I need the opinion of the maintainers of this repository before "I" can tell you if/how to implement this. There are three ways to try to abuse this link I can think of, either with adding nothing, with adding -1 or with adding a very large number (this is problematic because some groups might reach this number of messages and then the "chat link" turns into a "message link"). I have collected the behaviour on all official telegram apps:

Normal group links only work in the Android App and the Web apps.

App Adding Nothing Adding -1 Adding 10000000
Telegram Android ✔️ ✔️
Telegram X for Android
(opens the browser)

(opens the browser)
✔️
(error message that message doesn't exist, stays in the last position in the chat)
Telegram iOS ✔️ ✔️
Telegram Web K ✔️ ✔️
(jumps to the beginning, not to the end)
✔️
Telegram Web X ✔️
(Right now chats don't load their content, so I couldn't verify if they open at the bottom or not)
✔️ ✔️
Telegram Desktop
(opens the browser)
✔️
Unigram ✔️
(stays in the last position in the chat)

Until we reached a consent if and if yes, how to implement this, you could implement mentioning by chat username. This works with https://t.me/username, in the respective markup. @miles170 commented earlier, so if they want to implement this, I would give them a day to say so.

@MRZHD1
Copy link

MRZHD1 commented Oct 16, 2022

Alright, no problem! I'll check in on this tomorrow.

@Poolitzer
Copy link
Member Author

@Poolitzer https://bugs.telegram.org/c/21352 got created. Ideally we get a proper documented way to mention chats without usernames at some point.

@Bibo-Joshi
Copy link
Member

Tbh I had thought that the main use case here would be private chats, where mentioning the chat boils down to mentioning the user. IMO it would be perfectly fine to just return None (or raise an exception) if the chat is not private until we have a documented way of mentioning chats.

In any case, Chat.mention_* should coincide with User.mention_* for private chats IMO.

@Poolitzer
Copy link
Member Author

I would prefer the method returns the t.me link for public chats instead of None.

@harshil21
Copy link
Member

Agree with poolitzer for public chats. For private chats we can just use tg://user?id= syntax

@Bibo-Joshi
Copy link
Member

I would prefer the method returns the t.me link for public chats instead of None.

For public chats, sure. For private group-chats, I'm leaning towards returning None rather than relying on not-really-supported links 🤔

For private chats we can just use tg://user?id= syntax

That's exactly what User.mention_* does, yes :)

@MRZHD1
Copy link

MRZHD1 commented Oct 17, 2022

Hello, is it possible I work on this issue? 🙂

@Poolitzer
Copy link
Member Author

Poolitzer commented Oct 24, 2022

We have reached a decision. Please implement the return function the following way:
If the chat type is PRIVATE, make the function return the usual inline text link.

If not and the chat has a username, make the text link to https://t.me/username.

If the chat does not have a username, raise a TypeError with the text set to something like "Can not create a link to a private group chat".

If you want to implement this @MRZHD1 I will assign you, everyone else had enough time to speak up :D

@miles170
Copy link
Contributor

I can work on this if no one wants to take over.

@Poolitzer
Copy link
Member Author

Looks like it's yours.

@Poolitzer Poolitzer assigned MRZHD1 and miles170 and unassigned DhwanishShah and MRZHD1 Oct 25, 2022
@miles170
Copy link
Contributor

miles170 commented Oct 25, 2022

I have one question left to implement this. Should I change mention_html in python-telegram-bot/telegram/helpers.py

def mention_html(user_id: Union[int, str], name: str) -> str

to

def mention_html(user_id: Union[int, str], name: str, tg_link_prefix: str = "tg://user?id=") -> str

Since mention_XXX in chat might use it like mention_html(id, name, tg_link_prefix="https://t.me/")

Or should we implement it inside the chat class?

@Poolitzer
Copy link
Member Author

Currently the .link attributes of chat and user do not allow to change the prefix, I wouldn't add it in this PR.

If you think it's a good thing to have that, you can make a new issue, and we can add it everywhere at once.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants