【发布时间】:2019-03-13 19:49:33
【问题描述】:
我正在将 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 属性。
【问题讨论】:
-
您使用的是哪个 sdk? C# 还是 nodejs?您还可以发布自适应卡的通用架构吗?
标签: botframework