botframework - 如何区分 MS Bot Framework V3 中 Adaptive Card Submit Action 和 User type Text 发送的 Activity?
问题描述
我正在将 Bing Spell Check 集成到我的机器人中,以在将拼写错误发送到QnA Maker之前自动更正拼写错误。
我还实现了一个带有不同按钮的自适应卡片响应,如果 Bot 不理解用户的话语,用户可以尝试一些建议。
现在的挑战是用户可以点击建议列表中的自适应卡片按钮。在这种情况下,我不希望 Bing Spell Check 被击中,因为理想情况下句子是正确的。
我正在使用托管在网页上的 MS Web Chat 控件和 Bot。问题是我无法根据活动中的任何属性区分操作提交和用户键入的文本。我尝试在AdaptiveSubmitAction中添加DataJson ,但是当我这样做时,单击的按钮的文本不会显示在机器人中。使用 Data 属性,如果用户单击按钮,它将在机器人中显示文本。
请指导我,让我知道是否有人需要对此问题进行更多说明。
编辑:添加示例可重现代码。bot 作为响应返回的自适应卡片模板,其中包含一些 Action.Submit 按钮。
public static AdaptiveCard GetQuestionSuggestionsCard(List<string> Questions)
{
AdaptiveCard card = new AdaptiveCard()
{
Body = new List<AdaptiveElement>()
{
new AdaptiveContainer()
{
Items = new List<AdaptiveElement>()
{
new AdaptiveColumnSet()
{
Columns = new List<AdaptiveColumn>()
{
new AdaptiveColumn()
{
Width = "stretch",
Items = new List<AdaptiveElement>()
{
new AdaptiveTextBlock()
{
Text = string.Format("I am not sure what you are asking. \n\n I have {0} {1} that might help you find an answer.", Questions.Count, Questions.Count > 1 ? "suggestions" : "suggestion" ),
Wrap = true
}
}
}
}
}
}
}
},
// Buttons
Actions = new List<AdaptiveAction>()
};
foreach (string question in Questions)
{
card.Actions.Add(new AdaptiveSubmitAction() { Title = question, Data = question });
}
//Add None choice if have suggestive questions
if (Questions.Count > 0 && card.Actions.Count > 0)
{
card.Actions.Add(new AdaptiveSubmitAction() { Title = AppSettings.NoneSuggestionChoiceText, Data = AppSettings.NoneSuggestionChoiceText });
}
return card;
}
自适应卡返回给机器人 -
private Activity DisplaySuggestions(IDialogContext context, IMessageActivity message, QnAMakerResults result)
{
if (lstDisplaySuggestionQuestions.Count > 0)
{
//create the reply
Activity reply = ((Activity)context.Activity).CreateReply();
reply.Attachments = new List<Attachment>();
// Create the attachment.
Attachment attachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
//take the max displayed suggestions configured from Config Key
Content = AdaptiveCardHelper.GetQuestionSuggestionsCard(lstDisplaySuggestionQuestions.Take(AppSettings.QnAMaxNumberOfDisplayedSuggestions).ToList())
};
reply.Attachments.Add(attachment);
return reply;
}
}
当用户单击操作按钮时,它会向机器人发布一个文本,该文本也显示为对话中的话语。现在我想唯一确定话语是从文本输入框还是从自适应卡片按钮单击发布的。
我希望,我会说得通的。要重现创建机器人,请添加卡片,然后键入一些文本并检查消息控制器中的 Post 方法并查看 Activity 对象。然后对 Action Button Click 执行相同操作并关注 Text 属性。
解决方案
v3 自适应卡片示例机器人有一个示例,用于在收到卡片的响应后在您的机器人中整理提交操作。基本上,“提交”响应将有一个value
字段,而普通消息则没有。
if (session.message && session.message.value) {
// A Card's Submit Action obj was received
processSubmitAction(session, session.message.value);
return;
}
if (message.Value != null)
{
// Got an Action Submit
dynamic value = message.Value;
string submitType = value.Type.ToString();
...
因此,如果这对您的机器人来说是错误的,您可以将其发送给拼写检查器。
推荐阅读
- python - Tesseract ocr 输出在检测到的文本之间带有单个字符
- arduino - 当点亮 8x8 矩阵中的特定 LED 时,整列不会关闭 Arduino Uno
- r - 3D散点图与R中的Plotly无线
- reactjs - React-Testing 库未在快照中呈现 Material-UI 对话框
- maven - 使用 azure devops 从 git 存储库的特定位置的项目文件夹构建 jar 文件
- azure - Microsoft 图形无法从 .Net 核心应用程序获取所需数据
- android - 在启动时启动 Android 服务
- c - 如何在c中显示值及其数据类型?
- .net-core - 从 appsettings.json 迁移到 ARM
- date - Google 表格:如果时间在 23:00 至 05:00(或 11:00 PM 至 05:00 AM)范围内,则返回“False”