botbuilder-python icon indicating copy to clipboard operation
botbuilder-python copied to clipboard

Fix Middleware Chain to Allow Awaiting Final Logic Result

Open gandiddi opened this issue 11 months ago • 0 comments

Fixes #2197

Description

Previously, the middleware chain executed each handler sequentially, but none could await the final logic result. This prevented middlewares from processing the response of the last middleware (which runs the actual logic).

This PR updates the TurnContext class in the botbuilder-core library to modify the middleware chain handling. The changes ensure that middleware can await the result of the "next" middleware, including the final logic. This allows for more flexible and powerful middleware handling.

Specific Changes

1. TurnContext Class:

  • Modified the _emit method to ensure that each middleware can await the result of the next middleware in the chain, including the final logic.
  • Updated the _emit method to return the result of the logic coroutine correctly.

2. Test Cases:

  • Updated the test_update_activity_should_apply_conversation_reference test case to handle the ResourceResponse correctly and ensure the update_activity method returns the correct ResourceResponse.

gandiddi avatar Mar 12 '25 14:03 gandiddi