我使用QnA Maker创建了一个机器人,根据答案我应该返回相同的答案或调用另一个服务,在我的例子中是从JSON组装表单流。
但是在调用此服务时,我启动了一个新的Conversation,因此它不会返回到模拟器。
我正在另一个对话中创建对话。必须有一些东西丢失。
RootDialog.cs:
[Serializable]
public class RootDialog : QnAMakerDialog
{
public RootDialog() : base(
new QnAMakerService(
new QnAMakerAttribute(
ConfigurationManager.AppSettings["QnaSubscriptionKey"],
ConfigurationManager.AppSettings["QnaKnowledgebaseId"],
"Não encontrei sua resposta",
0.5
)
)
)
{
}
protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
{
var primeiraResposta = result.Answers.First().Answer;
if (primeiraResposta.IndexOf("form") == -1)
{
await context.PostAsync(primeiraResposta);
return;
}
await Conversation.SendAsync(message, () => Chain.From(() => FormDialog.FromForm(() => Formulario.JsonForm.BuildJsonForm(), FormOptions.PromptFieldsWithValues)));
return;
}
}
MessagesController.cs
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
if (activity.Type == ActivityTypes.ConversationUpdate)
{
if (activity.MembersAdded.Any(o => o.Id == activity.Recipient.Id))
{
var reply = activity.CreateReply();
reply.Text = "Hello...";
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
else if (activity.Type == ActivityTypes.Message)
{
// HEREE!!!
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
模拟器的响应:
我无法发送,重复