大家好,我是机器人开发的新手,我想弄清楚如何在 formflow 之后将对话转发到 QnaDialog。我的表单流只是在用户被识别后询问他/她的姓名,之后它会简单地打个招呼(用户名),我想要的是之后的任何消息都将被转发到 QnaDialog,因为用户已经被识别。我曾尝试添加一个检查器来标记一个问候已经完成,但是由于你只被允许一个 Conversation.SendAsync 我现在迷失了关于如何正确纠正这个问题的想法。
形式流
public class ProfileForm
{
// these are the fields that will hold the data
// we will gather with the form
[Prompt("What is your name? {||}")]
public string Name;
// This method 'builds' the form
// This method will be called by code we will place
// in the MakeRootDialog method of the MessagesControlller.cs file
public static IForm<ProfileForm> BuildForm()
{
return new FormBuilder<ProfileForm>()
.Message("Welcome to the profile bot!")
.OnCompletion(async (context, profileForm) =>
{
// Set BotUserData
context.PrivateConversationData.SetValue<bool>("ProfileComplete", true);
context.PrivateConversationData.SetValue<string>("Name", profileForm.Name);
// Tell the user that the form is complete
await context.PostAsync("Your profile is complete.");
})
.Build();
}
}
消息控制器
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
//ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
//await Conversation.SendAsync(activity, () => new QnADialog());
#region Formflow
// Get any saved values
StateClient sc = activity.GetStateClient();
BotData userData = sc.BotState.GetPrivateConversationData(
activity.ChannelId, activity.Conversation.Id, activity.From.Id);
var boolProfileComplete = userData.GetProperty<bool>("ProfileComplete");
if (!boolProfileComplete)
{
// Call our FormFlow by calling MakeRootDialog
await Conversation.SendAsync(activity, MakeRootDialog);
}
else
{
//Check if Personalized Greeting is done
if (userData.GetProperty<bool>("Greet"))
{
//this doesnt work since their should be only one Conversation.SendAsync.
//ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
//await Conversation.SendAsync(activity, () => new QnADialog());
}
else
{
// Get the saved profile values
var Name = userData.GetProperty<string>("Name");
userData.SetProperty<bool>("Greet", true);
sc.BotState.SetPrivateConversationData(activity.ChannelId, activity.Conversation.Id,activity.From.Id, userData);
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
Activity replyMessage = activity.CreateReply(string.Format("Hi {0}!", Name));
await connector.Conversations.ReplyToActivityAsync(replyMessage);
}
}
#endregion
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}