Share via


BaseAdapter class

Abstract base class for all adapters in the Agents framework.

Remarks

This class provides core functionality for handling conversations, managing middleware, authentication, and error handling. Adapters are responsible for translating between the Agents framework and specific communication channels (like Teams, Web Chat, etc.).

Key features:

  • Middleware pipeline for processing incoming and outgoing activities
  • Error handling and recovery mechanisms
  • Authentication provider integration
  • Abstract methods for channel-specific operations
  • Context management with revocable proxies for security

Properties

AgentIdentityKey

Symbol key used to store agent identity information in the TurnContext.

authConfig

The authentication configuration for the adapter.

authProvider

The authentication provider used for token management.

ConnectorClientKey

Symbol key used to store connector client instances in the TurnContext.

OAuthScopeKey

Symbol key used to store OAuth scope information in the TurnContext.

onTurnError

Gets the error handler for the adapter.

userTokenClient

The user token client used for managing user tokens.

Methods

continueConversation(Partial<ConversationReference>, (revocableContext: TurnContext) => Promise<void>)

Continues a conversation.

deleteActivity(TurnContext, Partial<ConversationReference>)

Deletes an existing activity.

getAttachment(string, string)

Gets an attachment.

getAttachmentInfo(string)

Gets attachment information.

sendActivities(TurnContext, Activity[])

Sends a set of activities to the conversation.

updateActivity(TurnContext, Activity)

Updates an existing activity.

uploadAttachment(string, AttachmentData)

Uploads an attachment.

use((Middleware | MiddlewareHandler)[])

Adds middleware to the adapter's middleware pipeline.

Property Details

AgentIdentityKey

Symbol key used to store agent identity information in the TurnContext.

AgentIdentityKey: symbol

Property Value

symbol

authConfig

The authentication configuration for the adapter.

authConfig: AuthConfiguration

Property Value

authProvider

The authentication provider used for token management.

authProvider: AuthProvider

Property Value

ConnectorClientKey

Symbol key used to store connector client instances in the TurnContext.

ConnectorClientKey: symbol

Property Value

symbol

OAuthScopeKey

Symbol key used to store OAuth scope information in the TurnContext.

OAuthScopeKey: symbol

Property Value

symbol

onTurnError

Gets the error handler for the adapter.

(context: TurnContext, error: Error) => Promise<void> onTurnError

Property Value

(context: TurnContext, error: Error) => Promise<void>

The current error handler function.

userTokenClient

The user token client used for managing user tokens.

userTokenClient: null | UserTokenClient

Property Value

Method Details

continueConversation(Partial<ConversationReference>, (revocableContext: TurnContext) => Promise<void>)

Continues a conversation.

function continueConversation(reference: Partial<ConversationReference>, logic: (revocableContext: TurnContext) => Promise<void>): Promise<void>

Parameters

reference

Partial<ConversationReference>

The conversation reference to continue.

logic

(revocableContext: TurnContext) => Promise<void>

The logic to execute.

Returns

Promise<void>

A promise representing the completion of the continue operation.

deleteActivity(TurnContext, Partial<ConversationReference>)

Deletes an existing activity.

function deleteActivity(context: TurnContext, reference: Partial<ConversationReference>): Promise<void>

Parameters

context
TurnContext

The TurnContext for the current turn.

reference

Partial<ConversationReference>

The conversation reference of the activity to delete.

Returns

Promise<void>

A promise representing the completion of the delete operation.

getAttachment(string, string)

Gets an attachment.

function getAttachment(attachmentId: string, viewId: string): Promise<ReadableStream>

Parameters

attachmentId

string

The attachment ID.

viewId

string

The view ID.

Returns

Promise<ReadableStream>

A promise representing the NodeJS.ReadableStream for the requested attachment.

getAttachmentInfo(string)

Gets attachment information.

function getAttachmentInfo(attachmentId: string): Promise<AttachmentInfo>

Parameters

attachmentId

string

The attachment ID.

Returns

Promise<AttachmentInfo>

A promise representing the AttachmentInfo for the requested attachment.

sendActivities(TurnContext, Activity[])

Sends a set of activities to the conversation.

function sendActivities(context: TurnContext, activities: Activity[]): Promise<ResourceResponse[]>

Parameters

context
TurnContext

The TurnContext for the current turn.

activities

Activity[]

The activities to send.

Returns

Promise<ResourceResponse[]>

A promise representing the array of ResourceResponses for the sent activities.

updateActivity(TurnContext, Activity)

Updates an existing activity.

function updateActivity(context: TurnContext, activity: Activity): Promise<void | ResourceResponse>

Parameters

context
TurnContext

The TurnContext for the current turn.

activity
Activity

The activity to update.

Returns

Promise<void | ResourceResponse>

A promise representing the ResourceResponse for the updated activity.

uploadAttachment(string, AttachmentData)

Uploads an attachment.

function uploadAttachment(conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse>

Parameters

conversationId

string

The conversation ID.

attachmentData
AttachmentData

The attachment data.

Returns

Promise<ResourceResponse>

A promise representing the ResourceResponse for the uploaded attachment.

use((Middleware | MiddlewareHandler)[])

Adds middleware to the adapter's middleware pipeline.

function use(middlewares: (Middleware | MiddlewareHandler)[]): BaseAdapter

Parameters

middlewares

(Middleware | MiddlewareHandler)[]

The middleware to add.

Returns

The adapter instance.