Table of Contents

Delegate TurnEventHandler

Namespace
Microsoft.Agents.Builder.App
Assembly
Microsoft.Agents.Builder.dll

Turn event handler to do something before or after a turn is run. Returning false from beforeTurn lets you prevent the turn from running and returning false from afterTurn lets you prevent the Agents state from being saved.

Returning false from beforeTurn does result in the Agents state being saved which lets you track the reason why the turn was not processed. It also means you can use beforeTurn as a way to call into the dialog system. For example, you could use the OAuthPrompt to sign the user in before allowing the AI system to run.

public delegate Task<bool> TurnEventHandler(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)

Parameters

turnContext ITurnContext

A strongly-typed context object for this turn.

turnState ITurnState

The turn state object that stores arbitrary data for this turn.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<bool>

True to continue execution of the current turn. Otherwise, False.

Constructors

TurnEventHandler(object, nint)

public TurnEventHandler(object @object, nint method)

Parameters

object object
method nint

Methods

BeginInvoke(ITurnContext, ITurnState, CancellationToken, AsyncCallback, object)

public virtual IAsyncResult BeginInvoke(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken, AsyncCallback callback, object @object)

Parameters

turnContext ITurnContext
turnState ITurnState
cancellationToken CancellationToken
callback AsyncCallback
object object

Returns

IAsyncResult

EndInvoke(IAsyncResult)

public virtual Task<bool> EndInvoke(IAsyncResult result)

Parameters

result IAsyncResult

Returns

Task<bool>

Invoke(ITurnContext, ITurnState, CancellationToken)

public virtual Task<bool> Invoke(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)

Parameters

turnContext ITurnContext
turnState ITurnState
cancellationToken CancellationToken

Returns

Task<bool>