Skip to content

[FEATURE] A function to automatically decide if update.message.reply_text or update.callback_query.edit_message_text will be used. #2826

Closed
@evakdev

Description

@evakdev

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:

def send_message(update, text, reply_markup=None, parse_mode=None):
    """
    Sends a message to the user.
    This will use callback_query.edit_message_text as priority. if it doesn't work, will use message.reply_text instead.
    To be used when we're not sure which one will be needed.
    """
    try:
        return update.callback_query.edit_message_text(
            text, reply_markup=reply_markup, parse_mode=parse_mode
        )
    except:
        return update.message.reply_text(
            text, reply_markup=reply_markup, parse_mode=parse_mode
        )

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions