PrinceOfBorgo
PrinceOfBorgo

Reputation: 590

Execute function and continue control flow with Teloxide

I want to execute some code every time a message is received by my telegram bot and always pass the control to the next branch

let handler = Update::filter_message()
    .branch(
        dptree::endpoint(fn_called_for_every_message)
    )
    .branch(
        dptree::endpoint(branch_1)
    )
    .branch(
        dptree::endpoint(branch_2)
    )
    // ... branches
    
Dispatcher::builder(bot, handler)
    .build()
    .dispatch()
    .await;

Reading the documentation it seems that the control flow continues only if an error is returned by previous branches so I tried replacing the first .branch call with a .chain and making fn_called_for_every_message return always an error to force the behaviour (not working, of course). I even tried remapping the result of the first .endpoint to ControlFlow::Continue as follows:

let handler = Update::filter_message()
    .branch(
        dptree::endpoint(fn_called_for_every_message).map(|| {
            ControlFlow::<Result<(), HandlerResult>>::Continue
        }),
    )
    // ... branches

Any ideas?

Upvotes: 0

Views: 159

Answers (0)

Related Questions