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

Message::filter_reply_to_message() overrides the original message #751

Open
WaffleLapkin opened this issue Oct 17, 2022 · 2 comments
Open
Labels
A-update-managment Area: update managment (dptree & co) C-main crate: teloxide FIXME

Comments

@WaffleLapkin
Copy link
Member

Originally reported in #750.

Message::filter_reply_to_message() inserts a Message into the dependency map, this message overrides the original message. This makes it impossible to use Message::filter_reply_to_message() and retrieve both the original message and the message original message replies to.

A temporary workaround is to use dptree::filter_map with a new type, as follows:

use teloxide::dptree::filter_map;

struct Reply(Message);

// ...
.branch(filter_map(|m: Message| m.reply_to_message().cloned().map(Reply)).endpoint(reply_dispatcher))
// ...

pub async fn reply_dispatcher(bot: Bot, msg: Message, Reply(reply_to_message): Reply) -> ResponseResult<()> { /* ... */ }

Meta

  • teloxide version: 0.11.0
@WaffleLapkin WaffleLapkin added the K-bug Kind: bug label Oct 17, 2022
@Hirrolot
Copy link
Collaborator

That's the thing I thought about for a while as highly unlikely while designing dptree, but it eventually sprang out lol.

Indeed there's a bit of undocumented gray area here. Possible solutions on the site of dptree:

  • Prohibit appending a dependency if its type is a type of some other dependency in the context.
  • Emit a warning if so. (Don't like this solution, since it's not about semantics.)

Possible solutions on the site of teloxide:

  • Wrap dependencies in type wrappers (which ones?)

@TmLev
Copy link
Contributor

TmLev commented Nov 3, 2022

axum v0.6+ allows you to specify state needed by a handler as regular function arguments and do so in a compile-time fashion, erroring out when the state wasn't provided:

Maybe this can help with the dependency map of dptree.

@WaffleLapkin WaffleLapkin added C-main crate: teloxide FIXME and removed K-bug Kind: bug labels Dec 28, 2022
@WaffleLapkin WaffleLapkin added the A-update-managment Area: update managment (dptree & co) label Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-update-managment Area: update managment (dptree & co) C-main crate: teloxide FIXME
Projects
None yet
Development

No branches or pull requests

3 participants