ActivityContext 类
传递给具有中间件支持的活动处理程序的上下文对象。
构造函数
ActivityContext(activity: T, app_id: str, storage: Storage[str, Any], api: ApiClient, user_token: str | None, conversation_ref: ConversationReference, is_signed_in: bool, connection_name: str, activity_sender: ActivitySender, app_token: str | StringLike | Callable[[], str | StringLike | None | Awaitable[str | StringLike | None]] | None, cloud: CloudEnvironment = CloudEnvironment(login_endpoint='https://login.microsoftonline.com', login_tenant='botframework.com', bot_scope='https://api.botframework.com/.default', token_service_url='https://token.botframework.com', openid_metadata_url='https://login.botframework.com/v1/.well-known/openidconfiguration', token_issuer='https://api.botframework.com', graph_scope='https://graph.microsoft.com/.default'))
参数
| 名称 | 说明 |
|---|---|
|
activity
必需
|
|
|
app_id
必需
|
|
|
storage
必需
|
|
|
api
必需
|
|
|
user_token
必需
|
|
|
conversation_ref
必需
|
|
|
is_signed_in
必需
|
|
|
connection_name
必需
|
|
|
activity_sender
必需
|
|
|
app_token
必需
|
|
|
cloud
|
默认值: CloudEnvironment(login_endpoint='https://login.microsoftonline.com', login_tenant='botframework.com', bot_scope='https://api.botframework.com/.default', token_service_url='https://token.botframework.com', openid_metadata_url='https://login.botframework.com/v1/.well-known/openidconfiguration', token_issuer='https://api.botframework.com', graph_scope='https://graph.microsoft.com/.default')
|
方法
| next |
调用链中的下一个中间件。 |
| quote |
向对话发送一条消息,其中包含文本前面有引号的消息引用。 Teams 将带引号的消息呈现为响应文本上方的预览气泡。 Warning 即将推出 此 API 即将推出,将来可能会更改。 诊断:ExperimentalTeamsQuotedReplies |
| reply |
使用入站消息的可视引号在当前对话中发送消息。 在通道中,使用带引号的答复发送到当前线程。 在其他范围内,使用带引号的答复发送。 若要发送而不引用,请使用 send。 |
| send |
在当前对话中发送消息,而无需引用。 在通道中,发送到当前线程。 在不支持线程处理(群组聊天、会议)的范围中,以正常消息的形式发送。 若要使用入站消息的可视引号发送,请使用 reply。 |
| set_next |
在中间件链中设置下一个处理程序。 |
| sign_in |
为用户启动登录流。 |
| sign_out |
通过清除其令牌注销用户。 此方法将从存储中删除用户的令牌。 |
next
调用链中的下一个中间件。
async next() -> None
quote
向对话发送一条消息,其中包含文本前面有引号的消息引用。 Teams 将带引号的消息呈现为响应文本上方的预览气泡。
Warning
即将推出
此 API 即将推出,将来可能会更改。
诊断:ExperimentalTeamsQuotedReplies
async quote(message_id: str, input: str | MessageActivityInput | MessageReactionActivityInput | TypingActivityInput) -> SentActivity
参数
| 名称 | 说明 |
|---|---|
|
message_id
必需
|
要引用的消息的 ID |
|
input
必需
|
响应文本或活动 — message_id的引号占位符将在其文本前面 |
返回
| 类型 | 说明 |
|---|---|
|
发送的活动 |
reply
使用入站消息的可视引号在当前对话中发送消息。
在通道中,使用带引号的答复发送到当前线程。 在其他范围内,使用带引号的答复发送。 若要发送而不引用,请使用 send。
async reply(input: str | MessageActivityInput | MessageReactionActivityInput | TypingActivityInput) -> SentActivity
参数
| 名称 | 说明 |
|---|---|
|
input
必需
|
|
send
在当前对话中发送消息,而无需引用。
在通道中,发送到当前线程。 在不支持线程处理(群组聊天、会议)的范围中,以正常消息的形式发送。 若要使用入站消息的可视引号发送,请使用 reply。
async send(message: str | MessageActivityInput | MessageReactionActivityInput | TypingActivityInput | AdaptiveCard, conversation_ref: ConversationReference | None = None) -> SentActivity
参数
| 名称 | 说明 |
|---|---|
|
message
必需
|
要发送的消息可以是字符串、ActivityParams 或 AdaptiveCard |
|
conversation_ref
|
用于发送到其他会话或线程的可选会话引用 默认值: None
|
set_next
在中间件链中设置下一个处理程序。
set_next(handler: Callable[[], Awaitable[None]]) -> None
参数
| 名称 | 说明 |
|---|---|
|
handler
必需
|
|
sign_in
为用户启动登录流。
async sign_in(options: SignInOptions | None = None) -> str | None
参数
| 名称 | 说明 |
|---|---|
|
options
|
用于自定义流的可选登录选项 默认值: None
|
返回
| 类型 | 说明 |
|---|---|
|
令牌(如果已可用),否则发送 OAuth 卡后无 |
sign_out
通过清除其令牌注销用户。
此方法将从存储中删除用户的令牌。
async sign_out() -> None
属性
app_graph
获取使用应用令牌配置的Microsoft Graph客户端。
此客户端可用于不需要用户上下文的仅限应用操作。
例外
| 类型 | 说明 |
|---|---|
|
如果没有可用的应用令牌。 |
|
|
如果无法创建图形客户端。 |
|
|
如果未安装图形依赖项。 |
user_graph
获取使用用户令牌配置的Microsoft Graph客户端。
例外
| 类型 | 说明 |
|---|---|
|
如果用户未登录或没有有效的令牌。 |
|
|
如果无法创建图形客户端。 |
|
|
如果未安装图形依赖项。 |