PromptDialog.Choice之后的动作

时间:2018-07-24 13:06:51

标签: c# .net botframework

这应该不太困难,但是我是C#的新手,似乎无法修复它。我有一个Prompt.Dialog.Choice来确认消息,如果用户希望将输入发送到数据库。

我被困在ChoiceReceivedAsync中,我想在此环境中采取行动,或者用户是否回答“是”或“否”,但是我该如何在if-else句子中称呼这些答案?

以下是相关代码:

public enum booleanChoice { Yes, No }

public async Task StartAsync(IDialogContext context)
    {
        //var message = await result as IMessageActivity;
        await context.PostAsync("Do you want you message to be sent?");

        PromptDialog.Choice(
            context: context,
            resume: ChoiceReceivedAsync,
            options: (IEnumerable<booleanChoice>)Enum.GetValues(typeof(booleanChoice)),
            prompt: " ",
            retry: "Please try again.",
            promptStyle: PromptStyle.Auto
        );
    }

public async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<booleanChoice> result)
    {
        booleanChoice response = await result;

        //Here's where I'm stuck:
        //if (PromptDialog.Choice == "Yes"){//send the inputs to the databse}
        //else (PromptDialog.Choice == "No"){//exit or enter the message again}


    }

1 个答案:

答案 0 :(得分:0)

您只需要将结果(response)与枚举值进行比较,如下所示:

public async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<booleanChoice> result)
{
    booleanChoice response = await result;

    if (response.Equals(booleanChoice.Yes))
    {
        //send the inputs to the databse}
    else 
    {
        //exit or enter the message again
    }
}