Bot Framework v4中的下一个对话框瀑布步骤之前的数据验证

时间:2019-07-12 11:44:30

标签: c# botframework

我正在从JSON文件获取用户值。当我读取文件并且给定的输入与下面的JSON(用户)匹配时,它将转到下一步,否则我将遇到错误并返回上一步。如果我输入了正确的用户名,它将转到正确的步骤,否则,将不会。

private async Task<DialogTurnResult> AfterUserNameAsync(WaterfallStepContext stepContext,
    CancellationToken cancellationToken)
{
    this.username = stepContext.Context.Activity.Text;
    GetUserJson(stepContext, cancellationToken);
    var msg = string.Empty;
    User = lstUsers.FirstOrDefault(x => x.userid.ToLower() == UserID.ToLower());

    /// if user lists not matched with json file getting error
    if (User == null)
    {
        await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions
        {
            Prompt = MessageFactory.Text("user not found. Please enter correct user name")
        }, cancellationToken);

        await AfterUserNameAsync(stepContext, cancellationToken);
    }
    /// else it will ask next question pls enter order no.
    else
    {
        msg = "Please enter order number";
    }

    return await stepContext.PromptAsync(nameof(TextPrompt), 
        new PromptOptions
        {
            Prompt = MessageFactory.Text(msg)
        }, cancellationToken);
}

0 个答案:

没有答案