在Microsoft Bot中使用ConnectorClient的“开始"对话框 [英] Begin dialog with ConnectorClient in Microsoft Bot

查看:57
本文介绍了在Microsoft Bot中使用ConnectorClient的“开始"对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部服务,正在以下代码段内向团队聊天发送消息:

I have an external service which is sending message within following code snippet to Teams chat:

MicrosoftAppCredentials.TrustServiceUrl("serviceUrl");
var appCredentials = new MicrosoftAppCredentials("app id", appPassword);
var connectorClient = new ConnectorClient("serviceUrl", appCredentials);
await connectorClient.Conversations.SendToConversationAsync("conversationId", activity);

如何以相同的方式开始对话框(现有的 ComponentDialog ,并且可以在 DialogContext 中的IBot OnTurnAsync方法中运行它)?

How can I begin dialog (existing ComponentDialog and I can run it inside IBot OnTurnAsync method within DialogContext) in same way?

我正在使用Microsoft Bot Framework 4.2.2.

I am using Microsoft Bot Framework 4.2.2.

推荐答案

您不会与连接器客户端开始对话.Bot Framework连接器客户端仅应了解Bot Framework REST API,并且不应与任何内部机器人逻辑(如对话框管理)有关.

You don't begin a dialog with a connector client. A Bot Framework connector client is only supposed to know about the Bot Framework REST API and isn't supposed to be concerned with any internal bot logic like dialog management.

对话框是基于基于机器人状态.使用特定密钥在已配置的存储中访问Bot状态.如果对话框使用的漫游器状态类型是用户状态,则密钥将从用户ID生成,如果是会话状态,则密钥将具有会话ID,如果是私有会话状态,则它将具有两者.当您了解到要继续对话时,机器人需要知道对话框的上下文时,这很有意义.当漫游器在与一个用户交谈时到达第4步时,则在与其他用户交谈时不应从第5步开始.这就是为什么使用上下文密钥访问状态很重要的原因.

Dialogs are based on dialog state which is based on bot state. Bot state is accessed in your configured storage using a specific key. If the type of bot state your dialogs use is user state then the key will be made from the user ID, if it's conversation state then the key will have the conversation ID, and if it's private conversation state then it will have both. This makes sense when you understand that in order to continue a dialog, the bot needs to know the context of the dialog. When the bot reaches step 4 while talking to one user, it shouldn't then start on step 5 when talking to a different user. That's why it's important for it to access the state by using a contextual key.

通常,在适配器创建的转弯上下文中可以找到访问正确的bot状态所需的信息.转弯上下文包含传入的活动,该活动具有在 from 属性中的用户ID和在其 conversation 属性中的对话ID.因此,这里的真正问题是,由于您要发送主动消息,因此在没有传入活动时如何访问正确的bot状态.

Normally the information needed to access the right bot state is found in the turn context created by the adapter. The turn context contains the incoming activity which has the user ID in its from property and the conversation ID in its conversation property. So the real question here is how to access the right bot state when there is no incoming activity, since you're sending a proactive message.

由于您可以通过连接器客户端发送消息,因此,主动触发器必须有权访问用户ID和/或会话ID.您可以使用此信息来创建伪造的传入活动.然后,您可以像使用 api/messages 端点那样通过适配器运行该活动,也可以使用该活动直接构建自己的转弯上下文.拥有转弯上下文后,您可以像普通对话框一样在对话框集中创建对话框上下文.

Since you're able to send a message with a connector client, your proactive trigger must have access to the user ID and/or the conversation ID. You can use this information to create a fake incoming activity. You can then run that activity through the adapter like you would for your api/messages endpoint, or you can use the activity to construct your own turn context directly. Once you have the turn context, you can make a dialog context out of a dialog set like normal.

这篇关于在Microsoft Bot中使用ConnectorClient的“开始"对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆