BotAdapter Class
- java.
lang. Object - com.
microsoft. bot. builder. BotAdapter
- com.
public abstract class BotAdapter
Represents a bot adapter that can connect a bot to a service endpoint. This class is abstract.
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 context object, passes it to your bot's application logic, and sends responses back to the user's channel.
Use use(Middleware middleware) to add Middleware objects to your adapter\u2019s middleware collection. The adapter processes and directs incoming activities in through the bot middleware pipeline to your bot\u2019s 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.
Field Summary
| Modifier and Type | Field and Description |
|---|---|
| static final java.lang.String |
BOT_IDENTITY_KEY
Key to store bot claims identity. |
| static final java.lang.String |
OAUTH_CLIENT_KEY
Key to store bot oauth client. |
| static final java.lang.String |
OAUTH_SCOPE_KEY
Key to store bot oauth scope. |
Constructor Summary
| Constructor | Description | |
|---|---|---|
| BotAdapter() | ||
Method Summary
| Modifier and Type | Method and Description |
|---|---|
| java.util.concurrent.CompletableFuture<java.lang.Void> |
continueConversation(ClaimsIdentity claimsIdentity, Activity continuationActivity, BotCallbackHandler callback)
Sends a proactive message to a conversation. |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
continueConversation(ClaimsIdentity claimsIdentity, Activity continuationActivity, String audience, BotCallbackHandler callback)
Sends a proactive message to a conversation. |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
continueConversation(ClaimsIdentity claimsIdentity, ConversationReference reference, BotCallbackHandler callback)
Sends a proactive message to a conversation. |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
continueConversation(ClaimsIdentity claimsIdentity, ConversationReference reference, String audience, BotCallbackHandler callback)
Sends a proactive message to a conversation. |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
continueConversation(String botId, Activity continuationActivity, BotCallbackHandler callback)
Sends a proactive message to a conversation. |
| java.util.concurrent.CompletableFuture<java.lang.Void> |
continueConversation(String botAppId, ConversationReference reference, BotCallbackHandler callback)
Sends a proactive message to a conversation. |
| abstract java.util.concurrent.CompletableFuture<java.lang.Void> |
deleteActivity(TurnContext context, ConversationReference reference)
When overridden in a derived class, deletes an existing activity in the conversation. |
|
protected
Middleware |
getMiddlewareSet()
Gets the collection of middleware in the adapter's pipeline. |
|
On |
getOnTurnError()
Gets the error handler that can catch exceptions in the middleware or application. |
| protected java.util.concurrent.CompletableFuture<java.lang.Void> |
runPipeline(TurnContext context, BotCallbackHandler callback)
Starts activity processing for the current bot turn. |
|
abstract
java.util.concurrent.CompletableFuture<Resource |
sendActivities(TurnContext context, List<Activity> activities)
When overridden in a derived class, sends activities to the conversation. |
| void |
setOnTurnError(OnTurnErrorHandler withTurnError)
Sets the error handler that can catch exceptions in the middleware or application. |
|
abstract
java.util.concurrent.CompletableFuture<Resource |
updateActivity(TurnContext context, Activity activity)
When overridden in a derived class, replaces an existing activity in the conversation. |
|
Bot |
use(Middleware middleware)
Adds middleware to the adapter's pipeline. |
Methods inherited from java.lang.Object
Field Details
BOT_IDENTITY_KEY
public static final String BOT_IDENTITY_KEY
Key to store bot claims identity.
OAUTH_CLIENT_KEY
public static final String OAUTH_CLIENT_KEY
Key to store bot oauth client.
OAUTH_SCOPE_KEY
public static final String OAUTH_SCOPE_KEY
Key to store bot oauth scope.
Constructor Details
BotAdapter
public BotAdapter()
Method Details
continueConversation
public CompletableFuture
Sends a proactive message to a conversation.
Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with a bot before the bot can send activities to the user.
Parameters:
Returns:
continueConversation
public CompletableFuture
Sends a proactive message to a conversation.
Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with a bot before the bot can send activities to the user.
Parameters:
Returns:
continueConversation
public CompletableFuture
Sends a proactive message to a conversation.
Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with a bot before the bot can send activities to the user.
Parameters:
Returns:
continueConversation
public CompletableFuture
Sends a proactive message to a conversation.
Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with a bot before the bot can send activities to the user.
Parameters:
Returns:
continueConversation
public CompletableFuture
Sends a proactive message to a conversation.
Call this method to proactively send a message to a conversation. Most channels require a user to initiate a conversation with a bot before the bot can send activities to the user.
Parameters:
Returns:
continueConversation
public CompletableFuture
Sends a proactive message to a conversation.
Parameters:
Returns:
<xref uid="com.microsoft.bot.builder.BotAdapter.runPipeline(com.microsoft.bot.builder.TurnContext,com.microsoft.bot.builder.BotCallbackHandler)" data-throw-if-not-resolved="false" data-raw-source="#runPipeline(TurnContext, BotCallbackHandler)"></xref>
deleteActivity
public abstract CompletableFuture
When overridden in a derived class, deletes an existing activity in the conversation.
Parameters:
Returns:
getMiddlewareSet
protected MiddlewareSet getMiddlewareSet()
Gets the collection of middleware in the adapter's pipeline.
Returns:
getOnTurnError
public OnTurnErrorHandler getOnTurnError()
Gets the error handler that can catch exceptions in the middleware or application.
Returns:
runPipeline
protected CompletableFuture
Starts activity processing for the current bot turn. The adapter calls middleware in the order in which you added it. The adapter passes in the context object for the turn and a next delegate, and the middleware calls the delegate to pass control to the next middleware in the pipeline. Once control reaches the end of the pipeline, the adapter calls the callback method. If a middleware component does not call the next delegate, the adapter does not call any of the subsequent middleware\u2019s onTurn(TurnContext turnContext, NextDelegate next) methods or the callback method, and the pipeline short circuits.
When the turn is initiated by a user activity (reactive messaging), the callback method will be a reference to the bot's onTurn(TurnContext turnContext) method. When the turn is initiated by a call to continueConversation(String botAppId, ConversationReference reference, BotCallbackHandler callback) (proactive messaging), the callback method is the callback method that was provided in the call.
Parameters:
Returns:
sendActivities
public abstract CompletableFuture
When overridden in a derived class, sends activities to the conversation.
Parameters:
Returns:
setOnTurnError
public void setOnTurnError(OnTurnErrorHandler withTurnError)
Sets the error handler that can catch exceptions in the middleware or application.
Parameters:
updateActivity
public abstract CompletableFuture
When overridden in a derived class, replaces an existing activity in the conversation.
Parameters:
Returns:
Before calling this, set the ID of the replacement activity to the ID of the activity to replace. onUpdateActivity(UpdateActivityHandler handler)
use
public BotAdapter use(Middleware middleware)
Adds middleware to the adapter's pipeline.
Parameters:
Returns: