Documentation - v1.2.0-alpha.3
    Preparing search index...

    Represents the context for a single turn in a conversation between a user and an agent.

    TurnContext is a central concept in the Agents framework - it contains:

    • The incoming activity that started the turn
    • Access to the adapter that can be used to send responses
    • A state collection for storing information during the turn
    • Methods for sending, updating, and deleting activities
    • Middleware hooks for intercepting activity operations

    The TurnContext object is created by the adapter when an activity is received and is passed to the agent's logic to process the turn. It maintains information about the conversation and provides methods to send responses.

    This class follows the builder pattern for registering middleware handlers.

    Index

    Constructors

    Properties

    bufferedReplyActivities: Activity[] = []

    A list of reply activities that are buffered until the end of the turn.

    This is primarily used with the 'expectReplies' delivery mode where all activities during a turn are collected and returned as a single response.

    Accessors

    Methods

    • Parameters

      • attachmentId: string

        The ID of the attachment

      • viewId: string

        The view to get

      Returns Promise<ReadableStream>

      A promise that resolves to a readable stream of the attachment content

      This function will not be supported in future versions. Use TurnContext.turnState.get(CloudAdapter.ConnectorClientKey). Gets the content of an attachment.

    • Parameters

      • attachmentId: string

        The ID of the attachment

      Returns Promise<AttachmentInfo>

      A promise that resolves to the attachment information

      This function will not be supported in future versions. Use TurnContext.turnState.get(CloudAdapter.ConnectorClientKey). Gets information about an attachment.

    • Registers a handler for intercepting and processing activities being sent.

      Parameters

      Returns this

      The current TurnContext instance for chaining

      This method follows a middleware pattern, allowing multiple handlers to be chained together. Handlers can modify activities or inject new ones.

    • Sends multiple activities to the sender of the incoming activity.

      Parameters

      • activities: Activity[]

        The array of activities to send

      Returns Promise<ResourceResponse[]>

      A promise that resolves to an array of resource responses

      This method applies conversation references to each activity and emits them through the middleware chain before sending them to the adapter.

    • Sends an activity to the sender of the incoming activity.

      Parameters

      • activityOrText: string | Activity

        The activity to send or a string for a simple message

      • Optionalspeak: string

        Optional text to be spoken by the agent

      • OptionalinputHint: string

        Optional input hint to indicate if the agent is expecting input

      Returns Promise<ResourceResponse | undefined>

      A promise that resolves to the resource response or undefined

      This is the primary method used to respond to the user. It automatically addresses the response to the correct conversation and recipient using information from the incoming activity.

    • Sends a trace activity for debugging purposes.

      Parameters

      • name: string

        The name/category of the trace

      • Optionalvalue: any

        The value/data to include in the trace

      • OptionalvalueType: string

        Optional type name for the value

      • Optionallabel: string

        Optional descriptive label for the trace

      Returns Promise<ResourceResponse | undefined>

      A promise that resolves to the resource response or undefined

      Trace activities are typically used for debugging and are only visible in channels that support them, like the Bot Framework Emulator.

    • Updates an existing activity in the conversation.

      Parameters

      • activity: Activity

        The activity to update with its ID specified

      Returns Promise<void>

      A promise that resolves when the activity has been updated

      This can be used to edit previously sent activities, for example to update the content of an adaptive card or change a message.

    • Parameters

      • conversationId: string

        The ID of the conversation

      • attachmentData: AttachmentData

        The attachment data to upload

      Returns Promise<ResourceResponse>

      A promise that resolves to the resource response

      This function will not be supported in future versions. Use TurnContext.turnState.get(CloudAdapter.ConnectorClientKey). Uploads an attachment to the conversation.