您好,有人可以解释一下如何使用瀑布stepcontext.Option吗?
我一直在示例中看到它,但我不太明白如何使用它。
以下是来自的示例 and .
我计划重构我的整个代码,并且如果可能的话希望使用此选项。感谢!
private static async Task<DialogTurnResult> TableStepAsync(
WaterfallStepContext step,
CancellationToken cancellationToken = default(CancellationToken))
{
string greeting = step.Options is GuestInfo guest
&& !string.IsNullOrWhiteSpace(guest?.Name)
? $"Welcome {guest.Name}" : "Welcome";
string prompt = $"{greeting}, How many diners will be at your table?";
string[] choices = new string[] { "1", "2", "3", "4", "5", "6" };
return await step.PromptAsync(
TablePrompt,
new PromptOptions
{
Prompt = MessageFactory.Text(prompt),
Choices = ChoiceFactory.ToChoices(choices),
},
cancellationToken);
}
and
private async Task<DialogTurnResult> SelectionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
// Continue using the same selection list, if any, from the previous iteration of this dialog.
List<string> list = stepContext.Options as List<string> ?? new List<string>();
stepContext.Values[CompaniesSelected] = list;
// Create a prompt message.
string message;
if (list.Count is 0)
{
message = $"Please choose a company to review, or `{DoneOption}` to finish.";
}
else
{
message = $"You have selected **{list[0]}**. You can review an additional company, " +
$"or choose `{DoneOption}` to finish.";
}
// Create the list of options to choose from.
List<string> options = _companyOptions.ToList();
options.Add(DoneOption);
if (list.Count > 0)
{
options.Remove(list[0]);
}
// Prompt the user for a choice.
return await stepContext.PromptAsync(
SelectionPrompt,
new PromptOptions
{
Prompt = MessageFactory.Text(message),
RetryPrompt = MessageFactory.Text("Please choose an option from the list."),
Choices = ChoiceFactory.ToChoices(options),
},
cancellationToken);
}
如果可能的话,我还想学习如何在本示例中像这样传递和获取值
private static async Task<DialogTurnResult> RoomStepAsync(
WaterfallStepContext step,
CancellationToken cancellationToken = default(CancellationToken))
{
// Save the name and prompt for the room number.
string name = step.Result as string;
((GuestInfo)step.Values[GuestKey]).Name = name;
return await step.PromptAsync(
TextPrompt,
new PromptOptions
{
Prompt = MessageFactory.Text($"Hi {name}. What room will you be staying in?"),
},
cancellationToken);
}
private static async Task<DialogTurnResult> FinalStepAsync(
WaterfallStepContext step,
CancellationToken cancellationToken = default(CancellationToken))
{
// Save the room number and "sign off".
string room = step.Result as string;
((GuestInfo)step.Values[GuestKey]).Room = room;
await step.Context.SendActivityAsync(
"Great, enjoy your stay!",
cancellationToken: cancellationToken);
// End the dialog, returning the guest info.
return await step.EndDialogAsync(
(GuestInfo)step.Values[GuestKey],
cancellationToken);
}
}
现在这就是我保存值的方式。
var userstate = await (stepContext.Context.TurnState["BasicAccessors"] as BasicAccessors).BasicUserStateAccessor.GetAsync(stepContext.Context);
userstate.Name = value;