BotFrameworkAdapter 类
- java.lang.Object
- com.microsoft.bot.builder.BotAdapter
- com.microsoft.bot.builder.BotFrameworkAdapter
实现
public class BotFrameworkAdapter
extends BotAdapter
implements AdapterIntegration, UserTokenProvider, ConnectorClientBuilder
可将机器人连接到服务终结点的机器人适配器。 机器人适配器封装了身份验证过程,并将活动发送到机器人连接器服务并从机器人连接器服务接收活动。 当机器人收到活动时,适配器会创建上下文对象,将其传递给机器人的应用程序逻辑,并将响应发送回用户的通道。
使用 use(Middleware middleware) 将对象添加到 Middleware adapter\u2019s 中间件集合。 适配器通过机器人中间件管道处理传入的活动并将其定向到 bot\u2019s 逻辑,然后再次退出。 当每个活动流入和流出机器人时,每个中间件都可以在机器人逻辑运行前后对其进行检查或执行操作。
字段摘要
修饰符和类型 | 字段和描述 |
---|---|
static final java.lang.String |
CONNECTOR_CLIENT_KEY
用于存储连接器 |
static final java.lang.String |
INVOKE_RESPONSE_KEY
用于存储调用 |
static final java.lang.String |
TEAMSCONNECTOR_CLIENT_KEY
用于存储 Teams |
构造函数摘要
方法摘要
方法继承自 BotAdapter
方法继承自 java.lang.Object
字段详细信息
CONNECTOR_CLIENT_KEY
public static final String CONNECTOR_CLIENT_KEY
用于存储 ConnectorClient 的密钥。
INVOKE_RESPONSE_KEY
public static final String INVOKE_RESPONSE_KEY
用于存储 InvokeResponse 的键。
TEAMSCONNECTOR_CLIENT_KEY
public static final String TEAMSCONNECTOR_CLIENT_KEY
用于存储 TeamsConnectorClient 的密钥。 仅用于测试。
构造函数详细信息
BotFrameworkAdapter
public BotFrameworkAdapter(AppCredentials withCredentials, AuthenticationConfiguration withAuthConfig, ChannelProvider withChannelProvider, RetryStrategy withRetryStrategy, Middleware withMiddleware)
使用凭据提供程序初始化 类的新实例 BotFrameworkAdapter 。
Parameters:
BotFrameworkAdapter
public BotFrameworkAdapter(CredentialProvider withCredentialProvider)
使用凭据提供程序初始化 类的新实例 BotFrameworkAdapter 。
Parameters:
BotFrameworkAdapter
public BotFrameworkAdapter(CredentialProvider withCredentialProvider, AuthenticationConfiguration withAuthConfig, ChannelProvider withChannelProvider, RetryStrategy withRetryStrategy, Middleware withMiddleware)
使用凭据提供程序初始化 类的新实例 BotFrameworkAdapter 。
Parameters:
BotFrameworkAdapter
public BotFrameworkAdapter(CredentialProvider withCredentialProvider, ChannelProvider withChannelProvider, RetryStrategy withRetryStrategy, Middleware withMiddleware)
使用凭据提供程序初始化 类的新实例 BotFrameworkAdapter 。
Parameters:
方法详细信息
addConnectorClientToCache
protected void addConnectorClientToCache(String serviceUrl, String appId, String scope, ConnectorClient client)
将 ConnectorClient 插入缓存中。 仅适用于单元测试。
Parameters:
buildAppCredentials
protected CompletableFuture
为指定的 appId 和范围创建 AppCredentials 对象。
Parameters:
Returns:
continueConversation
public CompletableFuture
向对话发送主动消息。
调用此方法可主动向会话发送消息。 大多数通道要求用户先启动与机器人的对话,然后机器人才能向用户发送活动。
Overrides:
BotFrameworkAdapter.continueConversation(ClaimsIdentity claimsIdentity, ConversationReference reference, BotCallbackHandler callback)Parameters:
Returns:
continueConversation
public CompletableFuture
向对话发送主动消息。
调用此方法可主动向会话发送消息。 大多数通道要求用户先启动与机器人的对话,然后机器人才能向用户发送活动。
Overrides:
BotFrameworkAdapter.continueConversation(ClaimsIdentity claimsIdentity, ConversationReference reference, String audience, BotCallbackHandler callback)Parameters:
Returns:
continueConversation
public CompletableFuture
将主动消息从机器人发送到聊天。
调用此方法可主动向会话发送消息。 大多数通道要求用户先启动与机器人的对话,然后机器人才能向用户发送活动。
此重载不同于 Node 实现,要求传入 BotId。 .Net 代码允许将多个机器人托管在 Node 不支持的单个适配器中。
processActivity(String authHeader, Activity activity, BotCallbackHandler callback) runPipeline(TurnContext context, BotCallbackHandler callback)
Overrides:
BotFrameworkAdapter.continueConversation(String botAppId, ConversationReference reference, BotCallbackHandler callback)Parameters:
Returns:
createConnectorClient
public CompletableFuture
异步创建连接器客户端。
Parameters:
Returns:
createConversation
public CompletableFuture
在指定通道上创建会话。 若要开始对话,机器人必须知道其帐户信息和该通道上的用户帐户信息。 大多数频道仅支持 (非组) 对话发起直接消息。
适配器尝试在通道上创建新会话,然后通过其中间件管道将活动发送到 conversationUpdate
callback
方法。
如果与指定用户建立对话,则活动的 Activity#getConversation ID 将包含新会话的 ID。
Parameters:
Returns:
createConversation
public CompletableFuture
在指定通道上创建对话。 若要开始对话,机器人必须知道其帐户信息和该通道上的用户帐户信息。 大多数频道仅支持 (非组) 对话发起直接消息。
适配器尝试在通道上创建新会话,然后通过其中间件管道将活动发送到 conversationUpdate
callback
方法。
如果与指定用户建立对话,则活动的 Activity#getConversation ID 将包含新会话的 ID。
Parameters:
Returns:
createOAuthAPIClient
protected CompletableFuture
为机器人创建 OAuth 客户端。
注意:这主要受到保护,以便单元测试可以重写以提供模拟 OAuthClient。
Parameters:
Returns:
deleteActivity
public CompletableFuture
删除对话中的现有活动。
Overrides:
BotFrameworkAdapter.deleteActivity(TurnContext context, ConversationReference reference)Parameters:
Returns:
deleteConversationMember
public CompletableFuture
从当前对话中删除成员。
Parameters:
Returns:
exchangeToken
public CompletableFuture
执行令牌交换操作,例如用于单一登录。
Parameters:
Returns:
exchangeToken
public CompletableFuture
执行令牌交换操作,例如用于单一登录。
Parameters:
Returns:
getAadTokens
public CompletableFuture<>
使用自定义的 AppCredentials 检索配置连接上特定资源的 Azure Active Directory 令牌。
Parameters:
Returns:
getAadTokens
public CompletableFuture<>
检索已配置连接上特定资源的 Azure Active Directory 令牌。
Parameters:
Returns:
getActivityMembers
public CompletableFuture<>
列出给定活动的成员。
Parameters:
Returns:
getActivityMembers
public CompletableFuture<>
列出给定活动的成员。
Parameters:
Returns:
getConnectorClientCache
protected Map
获取 ConnectorClient 缓存。 用于单元测试。
Returns:
getConversationMembers
public CompletableFuture<>
列出当前对话的成员。
Parameters:
Returns:
getConversations
public CompletableFuture
列出此机器人为给定通道服务器参与的对话。 通道服务器以页面形式返回结果,每个页面将包含一个可用于从服务器提取下一页结果的“continuationToken”。 可以在标准活动处理期间调用此重载,此时将使用机器人的服务 URL 和当前活动处理管道一部分的凭据。
Parameters:
Returns:
getConversations
public CompletableFuture
列出此机器人为给定通道服务器参与的对话。 通道服务器以页面形式返回结果,每个页面将包含一个可用于从服务器提取下一页结果的“continuationToken”。 可以在标准活动处理期间调用此重载,此时将使用机器人的服务 URL 和当前活动处理管道一部分的凭据。
Parameters:
Returns:
getConversations
public CompletableFuture
列出此机器人为给定通道服务器参与的对话。 通道服务器以页面形式返回结果,每个页面将包含一个可用于从服务器提取下一页结果的“continuationToken”。
Parameters:
context.activity.serviceUrl
。
Returns:
可以从会话上下文外部调用此重载,因为只需要机器人的 ServiceUrl 和凭据。
getConversations
public CompletableFuture
列出此机器人为给定通道服务器参与的对话。 通道服务器以页面形式返回结果,每个页面将包含一个可用于从服务器提取下一页结果的“continuationToken”。 可以从会话上下文外部调用此重载,因为只需要机器人的 ServiceUrl 和凭据。
Parameters:
context.activity.serviceUrl
。
Returns:
getCredentialsCache
protected Map
获取 AppCredentials 缓存。 用于单元测试。
Returns:
getOAuthSignInLink
public CompletableFuture
使用自定义的 AppCredentials 获取要发送给用户以登录的连接名称的原始登录链接。
Parameters:
Returns:
If the task completes successfully, the result contains the raw
signin link.
getOAuthSignInLink
public CompletableFuture
使用机器人的 AppCredentials 获取要发送给用户用于登录的连接名称的原始登录链接。
Parameters:
Returns:
If the task completes successfully, the result contains the raw
signin link.
getOAuthSignInLink
public CompletableFuture
获取要发送给用户进行登录的原始登录链接,以获取连接名称。
Parameters:
Returns:
getOAuthSignInLink
public CompletableFuture
获取要发送给用户进行登录的原始登录链接,以获取连接名称。
Parameters:
Returns:
getOrCreateConnectorClient
protected CompletableFuture
从缓存或新建返回 ConnectorClient。
注意:这主要是为了允许单元测试重写此内容以提供模拟 ConnectorClient
Parameters:
Returns:
getSignInResource
public CompletableFuture
获取要发送给用户进行登录的原始登录链接,以获取连接名称。
Parameters:
Returns:
If the task completes successfully, the result contains the raw
signin link.
getSignInResource
public CompletableFuture
获取要发送给用户进行登录的原始登录链接,以获取连接名称。
Parameters:
Returns:
If the task completes successfully, the result contains the raw
signin link.
getSignInResource
public CompletableFuture
获取要发送给用户进行登录的原始登录链接,以获取连接名称。
Parameters:
Returns:
If the task completes successfully, the result contains the raw
signin link.
getTokenStatus
public CompletableFuture<>
使用自定义的 AppCredentials 检索给定用户的每个已配置连接的令牌状态。
Parameters:
Returns:
getTokenStatus
public CompletableFuture<>
检索给定用户的每个已配置连接的令牌状态。
Parameters:
Returns:
getUserToken
public CompletableFuture
尝试使用自定义 AppCredentials 检索登录流中的用户的令牌。
Parameters:
Returns:
getUserToken
public CompletableFuture
尝试检索登录流中的用户的令牌。
Parameters:
Returns:
keyForAppCredentials
protected static String keyForAppCredentials(String appId, String scope)
生成用于访问应用凭据缓存的密钥。
Parameters:
Returns:
keyForConnectorClient
protected static String keyForConnectorClient(String serviceUrl, String appId, String scope)
生成用于访问连接器客户端缓存的密钥。
Parameters:
Returns:
processActivity
public CompletableFuture
创建轮次上下文并运行传入活动的中间件管道。
Parameters:
Returns:
processActivity
public CompletableFuture
创建轮次上下文并运行传入活动的中间件管道。
Parameters:
Returns:
sendActivities
public CompletableFuture
将活动发送到对话。
Overrides:
BotFrameworkAdapter.sendActivities(TurnContext context, List<Activity> activities)Parameters:
Returns:
<xref uid="com.microsoft.bot.builder.TurnContext.onSendActivities(com.microsoft.bot.builder.SendActivitiesHandler)" data-throw-if-not-resolved="false" data-raw-source="TurnContext#onSendActivities(SendActivitiesHandler)"></xref>
signOutUser
public CompletableFuture
使用自定义 AppCredentials 使用令牌服务器将用户注销。
Parameters:
Returns:
signOutUser
public CompletableFuture
使用令牌服务器注销用户。
Parameters:
Returns:
updateActivity
public CompletableFuture
替换对话中的现有活动。
Overrides:
BotFrameworkAdapter.updateActivity(TurnContext context, Activity activity)Parameters:
Returns:
在调用此项之前,请将替换活动的 ID 设置为要替换的活动的 ID。 onUpdateActivity(UpdateActivityHandler handler)
use
public BotFrameworkAdapter use(Middleware middleware)
将中间件添加到适配器的管道。 中间件在初始化时添加到适配器。 对于每个轮次,适配器按添加它的顺序调用中间件。
Overrides:
BotFrameworkAdapter.use(Middleware middleware)Parameters:
Returns: