Replies: 2 comments 2 replies
|
Hmm your setup should work generally, in that PTB already updates conversation's state when/if returned from a fallback, no need to force it :) However the issue seems that your |
|
Returning a state from a fallback changes the state for the next update; it does not send the current update back through handler selection. Re-queueing the same update is therefore the wrong level of abstraction here. There are two issues in the example:
For this use case, separate “validate/store this field” from “advance the conversation”. Then the edit fallback can call the same field logic directly while leaving the user's current conversation state unchanged: async def save_company(text: str, context: ContextTypes.DEFAULT_TYPE) -> None:
# validate text and update the existing database row
...
async def company(
update: Update, context: ContextTypes.DEFAULT_TYPE
) -> int:
message = update.effective_message
if message is None or message.text is None:
return COMPANY
await save_company(message.text, context)
context.bot_data["message_map"][(message.chat_id, message.message_id)] = COMPANY
return PERIOD
EDIT_HANDLERS = {
COMPANY: save_company,
PERIOD: save_period,
COST: save_cost,
}
async def handle_edited_message(
update: Update, context: ContextTypes.DEFAULT_TYPE
) -> None:
message = update.edited_message
if message is None or message.text is None:
return None
state = context.bot_data["message_map"].get(
(message.chat_id, message.message_id)
)
save = EDIT_HANDLERS.get(state)
if save is not None:
await save(message.text, context)
# None means: keep the current ConversationHandler state.
return NoneUse Also avoid feeding the same If you intentionally want the user to return to that old state and provide a new message, simply |
Uh oh!
There was an error while loading. Please reload this page.
I have a bot that collects some user input and save it to the database. Each state deals with non-edited messages only and perform user input validation. I want to allow the user to edit a previously sent information so she/he can make corrections to the input. To do that, I keep a map relating message_id to the state that handle it. The callback that deal with edited messages, located in the fallbacks sections, retrieves this mapping, put the update back in the queue and set the appropriate conversation state but I don't know how to force the conversation handler to be executed again and to process the edited message in its appropriate state.
Any guidance on this?
Thanks all.
All reactions