저는 봇 프레임 워크를 사용하여 놀고 있었고 가족/애완 동물의 구성원을 자세하게 설명하는 재미있는 채팅 봇을 만들었습니다.FormFlow : 반복적 인 질문을 사용하여 여러 항목 추가
사용자가 만족할 때까지 동일한 일련의 질문을 되풀이하는 방법이 있습니까? 아래 예제 코드 :
[Prompt("What is your family name?")]
public string familyName{ get; set; }
[Prompt("What is your postcode?")]
public string postcode { get; set; }
[Prompt("Would you like to add a family member? {||}")]
public bool AddPerson { get; set; }
[Prompt("What is their name?")]
public string PersonName { get; set; }
[Prompt("How old are they?")]
public string PersonAge{ get; set; }
[Prompt("How are they related to you?")]
public string PersonRelation{ get; set; }
[Prompt("Would you like to add another family member? {||}")]
public bool addAnotherPerson { get; set; }
public IForm<Family> BuildForm()
{
return new FormBuilder<GetQuoteDialog>()
.Field(nameof(familyName))
.Field(nameof(postcode))
//Choose to add a person to the family
.Field(nameof(AddPerson))
//Details of that person.
.Field(new FieldReflector<Family>(nameof(PersonName))
.SetActive((state) => state.AddPerson== true))
.Field(new FieldReflector<Family>(nameof({PersonAge))
.SetActive((state) => state.AddPerson== true))
.Field(new FieldReflector<Family>(nameof({PersonRelation))
.SetActive((state) => state.AddPerson== true))
//Prompts the user to add another if they wish
//Recurs to the PersonName field and lets them go through the
//process of adding another member
.Field(new FieldReflector<Family>(nameof({AddAnotherMember))
.SetActive((state) => state.AddPerson== true))
.Confirm("Is this your family? {*}")
.Build();
}
}
누구든지이 작업을 수행하는 방법에 대한 아이디어가 있습니까?
public async Task confirmAdd(IDialogContext context, IAwaitable<bool> result)
{
if (await result)
{
// builds and calls the form from here
var myform = new FormDialog<BuildFamily>(new BuildFamily(), BuildForm, FormOptions.PromptInStart, null);
context.Call<BuildFamily>(myform, End);
}
}
private async Task End(IDialogContext context, IAwaitable<BuildFamily> result)
{
BuildFamily data = null;
try
{
data = await result;
await context.PostAsync("Nice family you got there :)");
}
catch (OperationCanceledException)
{
await context.PostAsync("You canceled the form!");
return;
}
}
전체 코드를 게시하여 어떻게 호출하는지 확인할 수 있습니까? – JasonSowers
formflow를 호출하는 코드와 대화 상자의 작동 방식을 명확히하는 몇 가지 추가 코드가 추가되었습니다. 이상적으로 나는 이것이 "옵션"이라는 것을 알고 있지만, "mini"formflow를 호출 할 필요없이 매번 같은 폼 플로우로 유지하는 방법을 찾고 싶습니다. – Witted
동일하게 할 수 없다면 흐름, 이런 종류의 재귀를 수행하는 가장 좋은 방법은 무엇이라고 제안 하시겠습니까? – Witted