Share via


CloudAdapter class

Adapter for handling agent interactions with various channels through cloud-based services.

Extends

Remarks

CloudAdapter processes incoming HTTP requests from Microsoft Bot Framework channels, authenticates them, and generates outgoing responses. It manages the communication flow between agents and users across different channels, handling activities, attachments, and conversation continuations.

Constructors

CloudAdapter(AuthConfiguration, AuthProvider, UserTokenClient)

Creates an instance of CloudAdapter.

Properties

authConfig

The authentication configuration for the adapter.

connectorClient

Client for connecting to the Bot Framework Connector service

onTurnError

Gets the error handler for the adapter.

Inherited Properties

AgentIdentityKey

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

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.

userTokenClient

The user token client used for managing user tokens.

Methods

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

Continues a conversation.

createConversationAsync(string, string, string, string, ConversationParameters, (context: TurnContext) => Promise<void>)

Creates a conversation.

createTurnContext(Activity, AgentHandler)

Creates a TurnContext for the given activity and logic.

createTurnContextWithScope(Activity, AgentHandler, string)
deleteActivity(TurnContext, Partial<ConversationReference>)

Deletes an activity.

getAttachment(string, string)

Gets an attachment.

getAttachmentInfo(string)

Gets attachment information.

process(Request<Record<string, unknown>, Record<string, undefined | string | string[]>>, Response<any, Record<string, any>>, (context: TurnContext) => Promise<void>, HeaderPropagationDefinition)

Processes an incoming request and sends the response.

replyToActivity(Activity)

Replies to an activity.

sendActivities(TurnContext, Activity[])

Sends multiple activities to the conversation.

updateActivity(TurnContext, Activity)

Updates an activity.

uploadAttachment(string, AttachmentData)

Uploads an attachment.

Inherited Methods

use((Middleware | MiddlewareHandler)[])

Adds middleware to the adapter's middleware pipeline.

Constructor Details

CloudAdapter(AuthConfiguration, AuthProvider, UserTokenClient)

Creates an instance of CloudAdapter.

new CloudAdapter(authConfig?: AuthConfiguration, authProvider?: AuthProvider, userTokenClient?: UserTokenClient)

Parameters

authConfig
AuthConfiguration

The authentication configuration for securing communications

authProvider
AuthProvider

Optional custom authentication provider. If not specified, a default MsalTokenProvider will be used

userTokenClient
UserTokenClient

Property Details

authConfig

The authentication configuration for the adapter.

authConfig: AuthConfiguration

Property Value

connectorClient

Client for connecting to the Bot Framework Connector service

connectorClient: ConnectorClient

Property Value

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.

Inherited Property Details

AgentIdentityKey

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

AgentIdentityKey: symbol

Property Value

symbol

Inherited From BaseAdapter.AgentIdentityKey

authProvider

The authentication provider used for token management.

authProvider: AuthProvider

Property Value

Inherited From BaseAdapter.authProvider

ConnectorClientKey

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

ConnectorClientKey: symbol

Property Value

symbol

Inherited From BaseAdapter.ConnectorClientKey

OAuthScopeKey

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

OAuthScopeKey: symbol

Property Value

symbol

Inherited From BaseAdapter.OAuthScopeKey

userTokenClient

The user token client used for managing user tokens.

userTokenClient: null | UserTokenClient

Property Value

Inherited From BaseAdapter.userTokenClient

Method Details

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

Continues a conversation.

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

Parameters

reference
ConversationReference

The conversation reference to continue.

logic

(revocableContext: TurnContext) => Promise<void>

The logic to execute.

isResponse

Boolean

Returns

Promise<void>

A promise representing the completion of the continue operation.

createConversationAsync(string, string, string, string, ConversationParameters, (context: TurnContext) => Promise<void>)

Creates a conversation.

function createConversationAsync(agentAppId: string, channelId: string, serviceUrl: string, audience: string, conversationParameters: ConversationParameters, logic: (context: TurnContext) => Promise<void>): Promise<void>

Parameters

agentAppId

string

The agent application ID.

channelId

string

The channel ID.

serviceUrl

string

The service URL.

audience

string

The audience.

conversationParameters
ConversationParameters

The conversation parameters.

logic

(context: TurnContext) => Promise<void>

The logic to execute.

Returns

Promise<void>

A promise representing the completion of the create operation.

createTurnContext(Activity, AgentHandler)

Creates a TurnContext for the given activity and logic.

function createTurnContext(activity: Activity, logic: AgentHandler): TurnContext

Parameters

activity
Activity

The activity to process.

logic
AgentHandler

The logic to execute.

Returns

The created TurnContext.

createTurnContextWithScope(Activity, AgentHandler, string)

function createTurnContextWithScope(activity: Activity, logic: AgentHandler, scope: string): Promise<TurnContext>

Parameters

activity
Activity
logic
AgentHandler
scope

string

Returns

Promise<TurnContext>

deleteActivity(TurnContext, Partial<ConversationReference>)

Deletes an 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.

process(Request<Record<string, unknown>, Record<string, undefined | string | string[]>>, Response<any, Record<string, any>>, (context: TurnContext) => Promise<void>, HeaderPropagationDefinition)

Processes an incoming request and sends the response.

function process(request: Request<Record<string, unknown>, Record<string, undefined | string | string[]>>, res: Response<any, Record<string, any>>, logic: (context: TurnContext) => Promise<void>, headerPropagation?: HeaderPropagationDefinition): Promise<void>

Parameters

request

Request<Record<string, unknown>, Record<string, undefined | string | string[]>>

The incoming request.

res

Response<any, Record<string, any>>

The response to send.

logic

(context: TurnContext) => Promise<void>

The logic to execute.

headerPropagation

HeaderPropagationDefinition

Optional function to handle header propagation.

Returns

Promise<void>

replyToActivity(Activity)

Replies to an activity.

function replyToActivity(activity: Activity): Promise<ResourceResponse>

Parameters

activity
Activity

The activity to reply to.

Returns

Promise<ResourceResponse>

A promise representing the ResourceResponse for the sent activity.

sendActivities(TurnContext, Activity[])

Sends multiple 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 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.

Inherited Method Details

use((Middleware | MiddlewareHandler)[])

Adds middleware to the adapter's middleware pipeline.

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

Parameters

middlewares

(Middleware | MiddlewareHandler)[]

The middleware to add.

Returns

The adapter instance.

Inherited From BaseAdapter.use