2017-05-13 5 views
1

ボットフレームワークを使用してボットを作成しようとしていますが、FormFlowを使用して部門名を入力し、名前、私が検証し、FormFlowボットフレームワークで最初に間違った試行をした後、オプションのリストを検証して与える方法を教えてください。

DepartmentName列から選択する選択肢のリスト恩返ししたい:

[Prompt("What is your department name? {||}")] 
public string DepartmentName { get; set; } 

Deaprtment名フィールドを次のようになります。

.Field(nameof(DepartmentName), 

      validate: async (state, response) => 
      { 
       var value = (string)response; 
       var result = new ValidateResult() { IsValid = false, Feedback = "Department name is not valid"}; 
       if (Enum.GetNames(typeof(Department)).Any(x => x.ToLower() == value)) 
       { 
        result.IsValid = true; 
        result.Feedback = null; 
        result.Value = value; 
       } 
       return result; 
      }) 
public enum Department 
{ 
    hr = 1, 
    sales, 
    marketing, 
    development, 
    qm 
} 

を最初の試みがうまくいかない場合はどのように私は列挙型での部署の一覧をユーザーに促すことができる:部門の列挙型は、以下の通りですか?

答えて

1

1)Thnaksあなただけのフィードバックの最後にオプションを追加することができます

.Field(nameof(DepartmentName), 
    validate: (state, response) => 
    { 
     var value = (string)response; 
     string[] departments = Enum.GetNames(typeof(Department)).ToArray(); 

     IEnumerable<Choice> choices = departments.Select(d => new Choice() 
       { 
        Description = new DescribeAttribute(d, null, null, null, null), 
        Terms = new TermsAttribute() { Alternatives = new[] { d } }, 
        Value = d 
       }).ToArray(); 

     var result = new ValidateResult() 
     { 
      IsValid = false, 
      Choices = choices, 
      Feedback = "Department name is not valid." 
     }; 

     if (departments.Any(x => x.ToLower() == value)) 
     { 
      result.IsValid = true; 
      result.Feedback = null; 
      result.Value = value; 
     } 
     return Task.FromResult<ValidateResult>(result); 
    }); 

.Field(nameof(DepartmentName), 
validate: (state, response) => 
{ 
    var value = (string)response; 
    string[] departments = Enum.GetNames(typeof(Department)).ToArray(); 
    var feedback = $"Department name is not valid. Options:\n\n {String.Join("\n\n", departments)}"; 

    var result = new ValidateResult() { IsValid = false,            
             Feedback = feedback }; 

    if (departments.Any(x => x.ToLower() == value)) 
    { 
     result.IsValid = true; 
     result.Feedback = null; 
     result.Value = value; 
    } 
    return Task.FromResult<ValidateResult>(result); 
}); 

2)あなたは(通常は)曖昧さ回避のための選択クラスを使用することができます

関連する問題