All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.bot.builder.core.Middleware Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.bot.builder.core;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/// 
/// Represents middleware that can operate on incoming activities.
/// 
/// A  passes incoming activities from the user's 
/// channel to the middleware's 
/// method.
/// You can add middleware objects to your adapter’s middleware collection. The
/// adapter processes and directs incoming activities in through the bot middleware 
/// pipeline to your bot’s 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 
///  method.
/// 
/// public class SampleMiddleware : IMiddleware
/// {
///     public async Task OnTurn(ITurnContext context, MiddlewareSet.NextDelegate next)
///     {
///         context.SendActivity("before");
///         await next().ConfigureAwait(false);
///         context.SendActivity("after");
///     }
/// }
/// 
/// 
/// 
public interface Middleware
{
    /// 
    /// Processess an incoming activity.
    /// 
    /// The context object for this turn.
    /// The delegate to call to continue the bot middleware pipeline.
    /// A task that represents the work queued to execute.
    /// Middleware calls the  delegate to pass control to 
    /// the next middleware in the pipeline. If middleware doesn’t call the next delegate,
    /// the adapter does not call any of the subsequent middleware’s request handlers or the 
    /// bot’s receive handler, and the pipeline short circuits.
    /// The  provides information about the 
    /// incoming activity, and other data needed to process the activity.
    /// 
    /// 
    /// 
    // TODO: daveta review this (NextDelegate
    //CompletableFuture OnTurn(TurnContext context, NextDelegate next);
    CompletableFuture OnTurn(TurnContext context, NextDelegate next) throws ExecutionException, InterruptedException;
}







© 2015 - 2025 Weber Informatics LLC | Privacy Policy