Cannot write intercepting middleware
See original GitHub issueDue to PR #118, it appears we can no longer write middleware that “intercepts” a message from the user (ie: doesn’t call await next()
)
The easiest example is:
public class Interceptor : IMiddleware, IReceiveActivity
{
public Task ReceiveActivity(IBotContext context, MiddlewareSet.NextDelegate next) => Task.CompletedTask;
}
because the above Middleware implementation doesn’t call await next()
, the hosting Bot’s OnReceive
should never be hit; however it will be.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
c# - .NET 6 Why does fail to intercept the response body in ...
I'm curious why the response body cannot be intercepted by the middleware after the request is canceled? This is my middleware:
Read more >Writing Intercept middleware to capture and record all ...
I'm writing a VCR style record/playback system for the API calls that an application makes. We've already gotten this working with cy.route ...
Read more >Intercepting RESTful Responses with Middleware
An article discussing the application of HTTP middleware to control server responses that would otherwise be influenced by third-party APIs.
Read more >How to add intercept API Routes with Middleware in NEXT js?
Hey folks, so this video is all about setting up middleware to your ... Manual Authorization Setup: 02:00 Middleware Setup: 03:40 Writing ......
Read more >Middleware - Routing
Middleware allows you to run code before a request is completed. Then, based on the incoming request, you can modify the response by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is fixed by PR #146.
Tests around intercepting middleware have also been added into the test suite. Test showing OnReceive slated to run. Test showing OnReceive running when the Middlware pipeline is empty. Test #1 showing an Intercepting Middleware. Test #2 showing an Intercepting Middlware.
@nrobert I haven’t looked at the QnA Maker middleware implementation but i’m assuming it’s currently designed to run on the leading edge of routing which is problematic in general. QnA Maker can be a bit aggressive about answering queries so more often than not you’d want to run it as a fallback if nothing else answers. With our latest middleware design you can do that but it looks like C# is currently missing a key addition that I made to the JS SDK to enable this.
You can code QnA Maker to run on the trailing edge of routing which means it will run after everything else has run but you need a way of knowing if the bot has already replied or not. You could look at the responses queue but that’s not super reliable as it can get flushed (and it’s going away soon) so on the JS side I added a read-only
context.responded
property you can check to see if any responses have been sent during the turn (it would be a great PR to add that to the C# side.) Using this flag QnA Maker could conditionally decide to run only when nothing else has sent a message.