-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[FEATURE] A function to automatically decide if update.message.reply_text or update.callback_query.edit_message_text will be used. #2826
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
Comments
Hi. I would vote to say this is the responsibility of the end user. Easy enough to do in code: callback(update, context):
text = "This is the text to get to the user"
if update.effective_message:
update.effective_message.reply_text(text)
else:
update.callback_query.edit_message_text(text) Or even more if statements if you have more potentially callbacks. Thats easy to know because you register them with specific handlers, normally. |
Sure, its easy enough to do. Just thought it can be a common issue, as I've had it several times :) |
It might be, though I personally define one callback per handler type. Anyway, I don't think the library should just switch methods for the user. This is not the responsibility of it. |
Alright, should I close the issue then? |
You can leave it up if you are still convinced its a good idea and see what the other maintainers think. |
Hi. The Note that there is also |
Ohh, I wasn't aware that covers them all! That makes things much easier. Thanks :) If you think that's a helpful addition, I could make that change. Otherwise I'll just close the ticket :) |
We list the updates which set it here, where is your string from? |
Yes, that's where I got it from. It says it will be none for this and that. It doesn't say that it will return whichever of message, edited_message, callback_query, channel_post, edited_channel_post that is present. |
@evakdev Ohh you mean instead of saying when it is None, you would say when it is the message? |
yes, exactly! it could say both too, actually |
If you like to, you're very welcome to open a PR against the |
FYI: I added a commit to #2822 that addresses the documentation. For |
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
In some situations, it may not be possible to know if you should use update.message.reply_text or update.callback_query.edit_message_text. This could happen if user can start a conversation from different stages of a conversation (where sometimes they are using an inline keyboard and sometimes sending text.) IF it happens, you'll face an exception.
Describe the solution you'd like
I think it would be useful to have a function in update, that decides automatically if it should use update.message.reply_text or update.callback_query.edit_message_text. This could even be a simple try except block such as this:
Describe alternatives you've considered
No response
Additional context
This may also an issue for accessing
from_user
, but I haven't checked the docs to see if there is a solution for that or not.The text was updated successfully, but these errors were encountered: