microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Teams.Bot.Core/ITurnMiddleWare.cs
34lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Bot.Core.Schema; |
| 5 | |
| 6 | namespace Microsoft.Teams.Bot.Core; |
| 7 | |
| 8 | /// <summary> |
| 9 | /// Represents a delegate that invokes the next middleware component in the pipeline asynchronously. |
| 10 | /// </summary> |
| 11 | /// <remarks>This delegate is typically used in middleware scenarios to advance the request processing pipeline. |
| 12 | /// The cancellation token should be observed to support cooperative cancellation.</remarks> |
| 13 | /// <param name="cancellationToken">A cancellation token that can be used to cancel the asynchronous operation.</param> |
| 14 | /// <returns>A task that represents the completion of the middleware invocation.</returns> |
| 15 | public delegate Task NextTurn(CancellationToken cancellationToken); |
| 16 | |
| 17 | /// <summary> |
| 18 | /// Defines a middleware component that can process or modify activities during a bot turn. |
| 19 | /// </summary> |
| 20 | /// <remarks>Implement this interface to add custom logic before or after the bot processes an activity. |
| 21 | /// Middleware can perform tasks such as logging, authentication, or altering activities. Multiple middleware components |
| 22 | /// can be chained together; each should call the nextTurn delegate to continue the pipeline.</remarks> |
| 23 | public interface ITurnMiddleWare |
| 24 | { |
| 25 | /// <summary> |
| 26 | /// Triggers the middleware to process an activity during a bot turn. |
| 27 | /// </summary> |
| 28 | /// <param name="botApplication"></param> |
| 29 | /// <param name="activity"></param> |
| 30 | /// <param name="nextTurn"></param> |
| 31 | /// <param name="cancellationToken"></param> |
| 32 | /// <returns></returns> |
| 33 | Task OnTurnAsync(BotApplication botApplication, CoreActivity activity, NextTurn nextTurn, CancellationToken cancellationToken = default); |
| 34 | } |
| 35 | |