BotAdapter class

Defines the core behavior of a bot adapter that can connect a bot to a service endpoint.

Remarks

The bot adapter encapsulates authentication processes and sends activities to and receives activities from the Bot Connector Service. When your bot receives an activity, the adapter creates a turn context object, passes it to your bot application logic, and sends responses back to the user's channel.

The adapter processes and directs incoming activities in through the bot middleware pipeline to your bot logic and then back out again. As each activity flows in and out of the bot, each piece of middleware can inspect or act upon the activity, both before and after the bot logic runs. Use the use method to add Middleware objects to your adapter's middleware collection.

For more information, see the articles on How bots work and Middleware.

Properties

BotIdentityKey
OAuthScopeKey
onTurnError

Gets or sets an error handler that can catch exceptions in the middleware or application.

Methods

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

Asynchronously resumes a conversation with a user, possibly after some time has gone by.

deleteActivity(TurnContext, Partial<ConversationReference>)

Asynchronously deletes an existing activity. This interface supports the framework and is not intended to be called directly for your code. Use TurnContext.deleteActivity to delete an activity from your bot code.

sendActivities(TurnContext, Partial<Activity>[])

Asynchronously sends a set of outgoing activities to a channel server. This method supports the framework and is not intended to be called directly for your code. Use the turn context's sendActivity or sendActivities method from your bot code.

updateActivity(TurnContext, Partial<Activity>)

Asynchronously replaces a previous activity with an updated version. This interface supports the framework and is not intended to be called directly for your code. Use TurnContext.updateActivity to update an activity from your bot code.

use((context: TurnContext, next: () => Promise<void>) => Promise | Middleware[])

Adds middleware to the adapter's pipeline.

Property Details

BotIdentityKey

BotIdentityKey: Symbol

Property Value

Symbol

OAuthScopeKey

OAuthScopeKey: Symbol

Property Value

Symbol

onTurnError

Gets or sets an error handler that can catch exceptions in the middleware or application.

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

Property Value

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

Remarks

The error handler is called with these parameters:

Name Type Description
context TurnContext The context object for the turn.
error Error The Node.js error thrown.

Method Details

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

Asynchronously resumes a conversation with a user, possibly after some time has gone by.

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

Parameters

reference
Partial<ConversationReference>

A reference to the conversation to continue.

logic
(revocableContext: TurnContext) => Promise<void>

The asynchronous method to call after the adapter middleware runs.

Returns

Promise<void>

Remarks

This is often referred to as a proactive notification, the bot can proactively send a message to a conversation or user without waiting for an incoming message. For example, a bot can use this method to send notifications or coupons to a user.

deleteActivity(TurnContext, Partial<ConversationReference>)

Asynchronously deletes an existing activity. This interface supports the framework and is not intended to be called directly for your code. Use TurnContext.deleteActivity to delete an activity from your bot code.

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

Parameters

context
TurnContext

The context object for the turn.

reference
Partial<ConversationReference>

Conversation reference information for the activity to delete.

Returns

Promise<void>

Remarks

Not all channels support this operation. For channels that don't, this call may throw an exception.

sendActivities(TurnContext, Partial<Activity>[])

Asynchronously sends a set of outgoing activities to a channel server. This method supports the framework and is not intended to be called directly for your code. Use the turn context's sendActivity or sendActivities method from your bot code.

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

Parameters

context
TurnContext

The context object for the turn.

activities
Partial<Activity>[]

The activities to send.

Returns

Promise<ResourceResponse[]>

An array of ResourceResponse

Remarks

The activities will be sent one after another in the order in which they're received. A response object will be returned for each sent activity. For message activities this will contain the ID of the delivered message.

updateActivity(TurnContext, Partial<Activity>)

Asynchronously replaces a previous activity with an updated version. This interface supports the framework and is not intended to be called directly for your code. Use TurnContext.updateActivity to update an activity from your bot code.

function updateActivity(context: TurnContext, activity: Partial<Activity>)

Parameters

context
TurnContext

The context object for the turn.

activity
Partial<Activity>

The updated version of the activity to replace.

Returns

Promise<void>

Remarks

Not all channels support this operation. For channels that don't, this call may throw an exception.

use((context: TurnContext, next: () => Promise<void>) => Promise | Middleware[])

Adds middleware to the adapter's pipeline.

function use(middleware: (context: TurnContext, next: () => Promise<void>) => Promise<void> | Middleware[])

Parameters

middleware
(context: TurnContext, next: () => Promise<void>) => Promise<void> | Middleware[]

The middleware or middleware handlers to add.

Returns

this

Remarks

Middleware is added to the adapter at initialization time. Each turn, the adapter calls its middleware in the order in which you added it.