【发布时间】:2019-02-22 20:40:51
【问题描述】:
我正在尝试在 MS Bot Framework 4 中的 2 个对话框之间传递数据。但是,它不起作用。我使用了 stepContext.Values。但它不能将数据转发到另一个Dialog。我是 Microsoft bot Framework 中的一种新人。如果有人可以帮助我,将不胜感激。
第一个对话框:
public class Step1Dialog : WaterfallDialog
{
public Step1Dialog(string dialogId, string dataA, IEnumerable<WaterfallStep> steps = null) : base(dialogId, steps)
{
AddStep(async (stepContext, cancellationToken) =>
{
var choices = new List<Choice>();
for (int i = 1; i<3; i++)
{
choices.Add(new Choice { Value = "" + i.ToString()});
}
PromptOptions _choicePromptOptions = new PromptOptions { Choices = choices, Prompt = stepContext.Context.Activity.CreateReply("What type of help you want? \n 1. Help 1\n 2. Help 2" ) };
return await stepContext.PromptAsync("choicePrompt", _choicePromptOptions);
});
AddStep(async (stepContext, cancellationToken) =>
{
stepContext.Values["mamun1"].Equals("Mamun");
var response = (stepContext.Result as FoundChoice)?.Value;
if (response == "1")
{
return await stepContext.BeginDialogAsync(Help1.Id);
}
if (response == "2")
{
return await stepContext.BeginDialogAsync(Help2.Id);
}
return await stepContext.NextAsync();
});
AddStep(async (stepContext, cancellationToken) => { return await stepContext.ReplaceDialogAsync(Id); });
}
public static string Id => "step1Dialog";
public static string data;
public static Step1Dialog Instance { get;} = new Step1Dialog(Id,data);
}
第二个对话框:
public class Help1 : WaterfallDialog
{
public Help1(string dialogId, string dataA, IEnumerable<WaterfallStep> steps = null) : base(dialogId, steps)
{
AddStep(async (stepContext, cancellationToken) =>
{
string msgFromPreviousDilog = (string) stepContext.Values["mamun1"];
await stepContext.Context.SendActivityAsync($"Hi" + msgFromPreviousDilog );
return await stepContext.EndDialogAsync();
});
AddStep(async (stepContext, cancellationToken) => { return await stepContext.ReplaceDialogAsync(Id); });
}
public static string Id => "help1";
public static string data;
public static Help1 Instance { get;} = new Help1(Id,data);
}
【问题讨论】:
-
嗨,您能分享一下您从哪里获取代码吗?你在看教程还是什么?
-
我应该提到
Equals执行比较,而不是分配 -
嗨,这是我从 Microsoft 默认示例中获得的标准对话框编码。
-
什么默认示例?您是说这是 VSIX 模板的一部分吗?哪一个?
-
是的,它的 VSIX 模板。但我根据自己的需要进行了编辑。
标签: c# dialog chat botframework bots