我使用 QnA Maker 创建了一个机器人,根据答案我应该返回相同的答案或调用另一个服务,在我的例子中是从 JSON 组装一个表单流。
但是当调用这个服务时,我开始了一个新的对话,所以它不会返回到模拟器。
我正在另一个对话中创建一个对话。一定少了点什么。
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;
}
}
消息控制器.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;
}
模拟器响应:
我无法发送,重复