Middleware Interface

public interface Middleware

Represents middleware that can operate on incoming activities. A BotAdapter passes incoming activities from the user's channel to the middleware's onTurn(TurnContext turnContext, NextDelegate next) method.

You can add middleware objects to your adapter\u2019s middleware collection. The adapter processes and directs incoming activities in through the bot middleware pipeline to your bot\u2019s logic and then back out again. As each activity flows in and out of the bot, each piece of middleware can inspect or act upon the activity, both before and after the bot logic runs.

For each activity, the adapter calls middleware in the order in which you added it.

This defines middleware that sends "before" and "after" messages before and after the adapter calls the bot's onTurn(TurnContext turnContext) method. public class SampleMiddleware : Middleware { public async Task OnTurn(TurnContext context, MiddlewareSet.NextDelegate next) { context.SendActivity("before"); await next().ConfigureAwait(false); context.SendActivity("after"); } } Bot

Method Summary

Modifier and Type Method and Description
abstract java.util.concurrent.CompletableFuture<java.lang.Void> onTurn(TurnContext turnContext, NextDelegate next)

Processes an incoming activity.

Method Details

onTurn

public abstract CompletableFuture onTurn(TurnContext turnContext, NextDelegate next)

Processes an incoming activity.

Parameters:

turnContext - The context object for this turn.
next - The delegate to call to continue the bot middleware pipeline.

Returns:

A task that represents the work queued to execute. Middleware calls the next delegate to pass control to the next middleware in the pipeline. If middleware doesn\u2019t call the next delegate, the adapter does not call any of the subsequent middleware\u2019s request handlers or the bot\u2019s receive handler, and the pipeline short circuits.

The context provides information about the incoming activity, and other data needed to process the activity. TurnContext Activity

Applies to