我在我的机器人中使用了自适应智能卡和瀑布对话框。我想检索用户在表单中提供的数据,并在用户单击submit按钮后在另一个自适应卡中显示它。但是当我点击提交按钮时,空卡再次出现提示。
我已经阅读了这篇文章Stackoverflow和尝试使用回发通道数据的解决方案。它只在模拟器中起作用,我可以检索所有数据。但当我将其部署到Azure和MsTeams通道后,每次点击之后,它都会一次又一次地重新提示。
我的OnTurnAsync方法:
public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
await base.OnTurnAsync(turnContext, cancellationToken);
var activity = turnContext.Activity;
if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
{
activity.Text = JsonConvert.SerializeObject(activity.Value);
}
await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
}我的DialogExtensions.cs我取自Gags08的代码,它在模拟器上工作得很好,但不是在团队上:
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Newtonsoft.Json.Linq;
namespace Microsoft.BotBuilderSamples
{
public static class DialogExtensions
{
public static async Task Run(this Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor<DialogState> accessor, CancellationToken cancellationToken = default(CancellationToken))
{
var dialogSet = new DialogSet(accessor);
dialogSet.Add(dialog);
var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken);
// Ensure that message is a postBack (like a submission from Adaptive Cards)
if (dialogContext.Context.Activity.GetType().GetProperty("ChannelData") != null)
{
var channelData = JObject.Parse(dialogContext.Context.Activity.ChannelData.ToString());
if (channelData.ContainsKey("postBack"))
{
var postbackActivity = dialogContext.Context.Activity;
// Convert the user's Adaptive Card input into the input of a Text Prompt
// Must be sent as a string
postbackActivity.Text = postbackActivity.Value.ToString();
await dialogContext.Context.SendActivityAsync(postbackActivity);
}
}
var results = await dialogContext.ContinueDialogAsync(cancellationToken);
if (results.Status == DialogTurnStatus.Empty)
{
await dialogContext.BeginDialogAsync(dialog.Id, null, cancellationToken);
}
}
}还有我的名片:
{
"type": "AdaptiveCard",
"body": [
{
"type": "Image",
"style": "Person",
"url": "data:image/png;
"size": "Small",
"id": "image",
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "FTP Creation Card",
"id": "title",
"horizontalAlignment": "Center"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "FactSet",
"facts": [
{
"title": "Fill in all the fields",
"value": "with customer data"
},
{
"title": "Click Submit",
"value": "and wait notification to your email"
}
],
"id": "Exploration"
}
],
"width": "stretch"
}
]
},
{
"type": "Input.Text",
"placeholder": "First Name",
"id": "Name"
},
{
"type": "Input.Text",
"placeholder": "Last Name",
"id": "LastName"
},
{
"type": "Input.Text",
"placeholder": "Nickname",
"id": "Login"
},
{
"type": "Input.Text",
"placeholder": "Customer Email address",
"id": "Email"
},
{
"type": "Input.Text",
"placeholder": "Company Name",
"id": "Company"
},
{
"type": "Input.Text",
"placeholder": "Manager",
"id": "Manager"
},
{
"type": "Input.Text",
"placeholder": "Optional : employees",
"id": "InternalUsers"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Sumbit",
"style": "positive",
"id": "submit"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}我是机器人新手,也许我错了,但在我看来,问题出在消息属性"ChannelData“中。回发密钥仅在仿真器中可用,因此它不会通过团队截获它。我已经通过模拟器连接到我的Azure机器人,它工作得很好。告诉我如何通过团队正确使用卡片,这个问题有什么解决方案吗?
发布于 2019-08-24 03:52:57
最后,我修改了Teams通道的DialogExtensions.cs,并删除了OnTurnAsync方法中的所有代码。当我们从我们的卡片发送post数据时,就像前面的例子一样,我们试图捕获"postback“属性,它只存在于模拟器中。但是在团队中,channelData只包含对话的id和带有活动类型的“源”键。仅当我们尝试从自适应卡提交数据时,此密钥才存在。当我改变它时,我可以像在模拟器中一样在字符串类型中使用card中的值:
namespace Microsoft.BotBuilderSamples
{
public static class DialogExtensions
{
public static async Task Run(this Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor<DialogState> accessor, CancellationToken cancellationToken = default(CancellationToken))
{
var dialogSet = new DialogSet(accessor);
dialogSet.Add(dialog);
var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken);
if (dialogContext.Context.Activity.GetType().GetProperty("ChannelData") != null)
{
var channelData = JObject.Parse(dialogContext.Context.Activity.ChannelData.ToString());
//Check property in teams channel
if (channelData.ContainsKey("source"))
{
var postbackActivity = dialogContext.Context.Activity;
// Convert the user's Adaptive Card input into the input of a Text Prompt
// Must be sent as a string
postbackActivity.Text = postbackActivity.Value.ToString();
}
}
var results = await dialogContext.ContinueDialogAsync(cancellationToken);
if (results.Status == DialogTurnStatus.Empty)
{
await dialogContext.BeginDialogAsync(dialog.Id, null, cancellationToken);
}我明白在这种情况下,这不是明确的解决方案。但我只有通过这种方式才能让自适应卡在MS团队中工作。
https://stackoverflow.com/questions/57536168
复制相似问题