【发布时间】:2018-09-17 11:04:28
【问题描述】:
我试图连接 LUIS 和 QnA,但在第一个实例上它会从消息控制器转到 luis,如果需要相应地转到 QnA,但是一旦在 QnA 中,下一条消息不会发送到 LUIS,仅由 QnA 执行.有人可以帮忙吗?
messageControler.cs
public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
//await Conversation.SendAsync(activity, () => new BasicLuisDialog());
// check if activity is of type message
if (activity.GetActivityType() == ActivityTypes.Message)
{
//await Conversation.SendAsync(activity, () => new BasicQnAMakerDialog());
await Conversation.SendAsync(activity, () => new BasicLuisDialog());
}
else
{
//await Conversation.SendAsync(activity, () => new BasicQnAMakerDialog());
HandleSystemMessage(activity);
}
return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
}
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
}
}
BasicLuisDialog.cs 这是基本 luisdialog 的代码,从这里开始,如果意图匹配,那么它应该提供所需的回复,否则如果没有,它将搜索重定向到基本 qna。这仅对第一个实例执行。从第二个实例开始,如果它在 qna 中,它不会从 luis 开始。
public class BasicLuisDialog : LuisDialog<object>
{
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
{
var mForward = await message as Activity;
var username = context.Activity.From.Name;
string reply = $"Hello {username}! Your query we are taking forward, as we are not aware about what exactly you want to know.";
//await context.PostAsync(reply);
await context.Forward(new IDialog(), this.ResumeAfterQnA, mForward, CancellationToken.None);
}
private async Task ResumeAfterQnA(IDialogContext context, IAwaitable<object> result)
{
context.Wait(MessageReceived);
}
[LuisIntent("leave.apply")]
public async Task ApplyLeave(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
{
var username = context.Activity.From.Name;
string reply = $"Hello {username}! we are processing it";
await context.PostAsync(reply);
}
[LuisIntent("it")]
public async Task IT(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
{
var username = context.Activity.From.Name;
string reply = $"Hello {username}! we would look into your IT problems shortly";
await context.PostAsync(reply);
}
}
BasicQnAMakerDialog 基本 QnA 代码如下所示。请帮我找出问题所在。
public class IDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
/* Wait until the first message is received from the conversation and call MessageReceviedAsync
* to process that message. */
context.Wait(this.MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
/* When MessageReceivedAsync is called, it's passed an IAwaitable<IMessageActivity>. To get the message,
* await the result. */
var message = await result;
var activity = await result as Activity;
var qnaAuthKey = ConfigurationManager.AppSettings["QnAAuthKey"];
var qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];
var endpointHostName = ConfigurationManager.AppSettings["QnAEndpointHostName"];
// QnA Subscription Key and KnowledgeBase Id null verification
if (!string.IsNullOrEmpty(qnaAuthKey) && !string.IsNullOrEmpty(qnaKBId))
{
// Forward to the appropriate Dialog based on whether the endpoint hostname is present
if (string.IsNullOrEmpty(endpointHostName)) {
await context.Forward(new BasicQnAMakerPreviewDialog(), AfterAnswerAsync, message, CancellationToken.None);
}
else
{
await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);
}
}
else
{
await context.PostAsync("Please set QnAKnowledgebaseId, QnAAuthKey and QnAEndpointHostName (if applicable) in App Settings. Learn how to get them at https://aka.ms/qnaabssetup.");
}
//var activity = await result as Activity;
//await context.Forward(new BasicLuisDialog(), ResumeAfterLuisDialog, activity, CancellationToken.None);
}
【问题讨论】:
标签: c# .net botframework azure-language-understanding azure-bot-service