TurnContextImpl Class

  • java.lang.Object
    • com.microsoft.bot.builder.TurnContextImpl

Implements

TurnContext java.lang.AutoCloseable

public class TurnContextImpl
implements TurnContext, java.lang.AutoCloseable

Provides context for a turn of a bot. Context provides information needed to process an incoming activity. The context object is created by a BotAdapter and persists for the length of the turn. Bot Middleware

Constructor Summary

Constructor Description
TurnContextImpl(BotAdapter withAdapter, Activity withActivity)

Creates a context object.

Method Summary

Modifier and Type Method and Description
void close()

AutoClosable#close.

java.util.concurrent.CompletableFuture<java.lang.Void> deleteActivity(ConversationReference conversationReference)

Deletes an existing activity.

java.util.concurrent.CompletableFuture<java.lang.Void> deleteActivity(String activityId)

Deletes an existing activity.

void finalize()

Auto call of #close.

Activity getActivity()

Gets the activity associated with this turn; or null when processing a proactive message.

BotAdapter getAdapter()

Gets the bot adapter that created this context object.

java.util.List<Activity> getBufferedReplyActivities()

Gets a list of activities to send when `context.Activity.DeliveryMode == 'expectReplies'.

java.lang.String getLocale()

Gets the locale on this context object.

boolean getResponded()

Indicates whether at least one response was sent for the current turn.

TurnContextStateCollection getTurnState()

Gets the services registered on this context object.

TurnContext onDeleteActivity(DeleteActivityHandler handler)

Adds a response handler for delete activity operations.

TurnContext onSendActivities(SendActivitiesHandler handler)

Adds a response handler for send activity operations.

TurnContext onUpdateActivity(UpdateActivityHandler handler)

Adds a response handler for update activity operations.

java.util.concurrent.CompletableFuture<ResourceResponse[]> sendActivities(List<Activity> activities)

Sends a set of activities to the sender of the incoming activity.

java.util.concurrent.CompletableFuture<ResourceResponse> sendActivity(Activity activityToSend)

Sends an activity to the sender of the incoming activity.

java.util.concurrent.CompletableFuture<ResourceResponse> sendActivity(String textReplyToSend)

Sends a message activity to the sender of the incoming activity.

java.util.concurrent.CompletableFuture<ResourceResponse> sendActivity(String textReplyToSend, String speak)

Sends a message activity to the sender of the incoming activity.

java.util.concurrent.CompletableFuture<ResourceResponse> sendActivity(String textReplyToSend, String speak, InputHints inputHint)

Sends a message activity to the sender of the incoming activity.

void setLocale(String withLocale)

Set the locale on this context object.

java.util.concurrent.CompletableFuture<ResourceResponse> updateActivity(Activity withActivity)

Replaces an existing activity.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

TurnContextImpl

public TurnContextImpl(BotAdapter withAdapter, Activity withActivity)

Creates a context object.

Parameters:

withAdapter - The adapter creating the context.
withActivity - The incoming activity for the turn; or null for a turn for a proactive message.

Method Details

close

public void close()

AutoClosable#close.

Throws:

java.lang.Exception - If the TurnContextStateCollection.

deleteActivity

public CompletableFuture deleteActivity(ConversationReference conversationReference)

Deletes an existing activity. The conversation reference's ConversationReference#getActivityId indicates the activity in the conversation to delete.

Parameters:

conversationReference - The conversation containing the activity to delete.

Returns:

A task that represents the work queued to execute.

deleteActivity

public CompletableFuture deleteActivity(String activityId)

Deletes an existing activity.

Parameters:

activityId - The ID of the activity to delete.

Returns:

A task that represents the work queued to execute.

finalize

public void finalize()

Auto call of #close.

Overrides:

TurnContextImpl.finalize()

getActivity

public Activity getActivity()

Gets the activity associated with this turn; or null when processing a proactive message.

getAdapter

public BotAdapter getAdapter()

Gets the bot adapter that created this context object.

Returns:

The BotAdaptor for this turn.

getBufferedReplyActivities

public List getBufferedReplyActivities()

Gets a list of activities to send when `context.Activity.DeliveryMode == 'expectReplies'.

Returns:

A list of activities.

getLocale

public String getLocale()

Gets the locale on this context object.

Returns:

The string of locale on this context object.

getResponded

public boolean getResponded()

Indicates whether at least one response was sent for the current turn.

Returns:

true if at least one response was sent for the current turn.

getTurnState

public TurnContextStateCollection getTurnState()

Gets the services registered on this context object.

Returns:

the TurnContextStateCollection for this turn.

onDeleteActivity

public TurnContext onDeleteActivity(DeleteActivityHandler handler)

Adds a response handler for delete activity operations.

Parameters:

handler - The handler to add to the context object.

Returns:

The updated context object.

onSendActivities

public TurnContext onSendActivities(SendActivitiesHandler handler)

Adds a response handler for send activity operations.

Parameters:

handler - The handler to add to the context object.

Returns:

The updated context object.

onUpdateActivity

public TurnContext onUpdateActivity(UpdateActivityHandler handler)

Adds a response handler for update activity operations.

Parameters:

handler - The handler to add to the context object.

Returns:

The updated context object.

sendActivities

public CompletableFuture sendActivities(List activities)

Sends a set of activities to the sender of the incoming activity.

Parameters:

activities - The activities to send.

Returns:

A task that represents the work queued to execute. If the activities are successfully sent, the task result contains an array of ResourceResponse objects containing the IDs that the receiving channel assigned to the activities.

sendActivity

public CompletableFuture sendActivity(Activity activityToSend)

Sends an activity to the sender of the incoming activity.

Parameters:

activityToSend - The activity to send.

Returns:

A task that represents the work queued to execute.

sendActivity

public CompletableFuture sendActivity(String textReplyToSend)

Sends a message activity to the sender of the incoming activity.

If the activity is successfully sent, the task result contains a ResourceResponse object containing the ID that the receiving channel assigned to the activity.

See the channel's documentation for limits imposed upon the contents of textReplyToSend.

Parameters:

textReplyToSend - The text of the message to send.

Returns:

A task that represents the work queued to execute.

sendActivity

public CompletableFuture sendActivity(String textReplyToSend, String speak)

Sends a message activity to the sender of the incoming activity.

If the activity is successfully sent, the task result contains a ResourceResponse object containing the ID that the receiving channel assigned to the activity.

See the channel's documentation for limits imposed upon the contents of textReplyToSend.

Parameters:

textReplyToSend - The text of the message to send.
speak - To control various characteristics of your bot's speech such as voice rate, volume, pronunciation, and pitch, specify Speech Synthesis Markup Language (SSML) format.

Returns:

A task that represents the work queued to execute.

sendActivity

public CompletableFuture sendActivity(String textReplyToSend, String speak, InputHints inputHint)

Sends a message activity to the sender of the incoming activity.

If the activity is successfully sent, the task result contains a ResourceResponse object containing the ID that the receiving channel assigned to the activity.

See the channel's documentation for limits imposed upon the contents of textReplyToSend.

Parameters:

textReplyToSend - The text of the message to send.
speak - To control various characteristics of your bot's speech such as voice rate, volume, pronunciation, and pitch, specify Speech Synthesis Markup Language (SSML) format.
inputHint - (Optional) Input hint.

Returns:

A task that represents the work queued to execute.

setLocale

public void setLocale(String withLocale)

Set the locale on this context object.

Parameters:

withLocale - The string of locale on this context object.

updateActivity

public CompletableFuture updateActivity(Activity withActivity)

Replaces an existing activity.

Parameters:

withActivity - New replacement activity.

Returns:

A task that represents the work queued to execute.

Applies to