Skip to content

Add inline button to update status messages #354

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

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

HappyTetrahedron
Copy link

@HappyTetrahedron HappyTetrahedron commented Jan 24, 2025

Good evening!

I've made a few small changes to accommodate my own preferences when it comes to Telegram Bot UX. I'm using these changes for myself, but I'd like to offer them to be integrated upstream, if you like them.

In this change, I'm adding a configuration option that, when enabled, causes an "update" button to appear under the status message. Pressing this button triggers a manual update of the status, just as if the /status command had been used.

Personally, I like inline buttons as a way to interact with bots, and I was missing this feature.

The default is for this button to not show up (like before), but users who want it can now enable it in their config.

To accomplish this change, I refactored the way message data is passed around in the notifications.py module (and also, to a lesser extent, in the main.py module). I've added a new class that represents a Telegram message to send, with all its parameters. This class is useful when a message is constructed before it is known how exactly that message gets sent (whether it's sent as a reply, or as an update to an existing message...) - the message-specific metadata can get passed around in a bundle, and the method that handles the actual sending doesn't need to know all of the specifics of how this message is supposed to be set up.

Messages can still easily be sent directly. Rather than refactoring every single occurrence of message sending, I am using my new class only where it's most useful. In the future, it can be used in more places if it's beneficial.

Let me know what you think.

This also adds several helper functions to send such messages more
easily.
Using the abstraction makes sense if the "content" of a message is
defined before we know how/where it is to be sent.
@aka13-404
Copy link
Collaborator

This is probably the best PR we have so far received over the years, thank you for your time and effort.
We had a short discussion, and basically everything that you did makes sense and the rework is welcome as well.
The button will be probably a default config option, since it is more elegant than having the status msg in the chat.

Also, this is the last straw to finally update the contribution docs. Would you kindly in the meantime redirect your PR towards dev? I swear I will update the pages to reflect that the PRs go to dev.

@HappyTetrahedron HappyTetrahedron changed the base branch from master to development January 26, 2025 00:54
@HappyTetrahedron
Copy link
Author

Thank you for your kind words! I've updated the PR target.

@nlef nlef added the Next release Extra attention is needed label Jan 26, 2025
…ication

In my refactor, it seems like I accidentally forgot to pass the photo on
to the method updating the message. Whoops.
@nlef nlef merged commit c82f8c4 into nlef:development Jan 30, 2025
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Next release Extra attention is needed
Projects
Status: testing
Development

Successfully merging this pull request may close these issues.

3 participants