【问题标题】:Once the message forwarded from LUIS to QnA depending on the intent, not returning to LUIS in c# from the second instance. What to do?一旦消息根据意图从 LUIS 转发到 QnA,则不会从第二个实例返回到 c# 中的 LUIS。该怎么办?
【发布时间】: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


    【解决方案1】:

    当对话框完成它应该做的事情时,您需要调用context.Done(new MyDialogResult())。 bot 框架为每个对话保留一堆对话框,每当您执行 context.Forward 时,它都会将一个新对话框推送到堆栈,并且发送给机器人的每条消息将始终进入堆栈顶部的对话框并跳过下面的其他对话框,因此当您执行context.Done 时,它会从堆栈中弹出当前对话框,并且对话会返回到上一个对话框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-22
      • 2018-10-19
      • 1970-01-01
      • 2018-05-20
      相关资源
      最近更新 更多