Middleware interface
Interface implemented by object based middleware.
Methods
on |
Called each time the bot receives a new request. |
Method Details
onTurn(TurnContext, () => Promise<void>)
Called each time the bot receives a new request.
function onTurn(context: TurnContext, next: () => Promise<void>): Promise<void>
Parameters
- context
- TurnContext
Context for current turn of conversation with the user.
- next
-
() => Promise<void>
Function to call to continue execution to the next step in the middleware chain.
Returns
Promise<void>
Remarks
Calling await next();
will cause execution to continue to either the next piece of
middleware in the chain or the bots main logic if you are the last piece of middleware.
Your middleware should perform its business logic before and/or after the call to next()
.
You can short-circuit further execution of the turn by omitting the call to next()
.
The following example shows a simple piece of logging middleware:
class MyLogger {
async onTurn(context, next) {
console.log(`Leading Edge`);
await next();
console.log(`Trailing Edge`);
}
}