表单流程机器人自定义问题

时间:2018-03-12 04:51:37

标签: c# botframework formflow qnamaker

我想构建一个可以使用QnA api和google drive的搜索API的机器人。我会询问用户是否要查询知识库,或者他想要在驱动器中搜索文件。为此,我选择了Bot Framework的Form Flow bot模板。在这种情况下,如果用户选择查询qna api,那么我想将问题发布到QNA api。我怎么能在我的机器人中实现这个?我在哪里可以找到用户在流程中的选择。

这是 MessageController.cs

        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                await Conversation.SendAsync(activity, MakeRootDialog);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }

        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;
        }
        internal static IDialog<UserIntent> MakeRootDialog()
        {
            return Chain.From(() => FormDialog.FromForm(UserIntent.BuildForm));
        }

表单构建器

public static IForm<UserIntent> BuildForm()
 {
   return new FormBuilder<UserIntent>()
     .Message("Welcome to the bot!")
     .OnCompletion(async (context, profileForm) =>
      {
         await context.PostAsync("Thank you");
      }).Build();
 }

2 个答案:

答案 0 :(得分:1)

FormFlow 更适用于指导对话流程。在我看来,它似乎不符合您的要求。您可以使用 PromptDialog 来获取用户对他们喜欢的搜索类型的回答,然后将下一条消息转发到相应的对话框。类似的东西:

None

答案 1 :(得分:0)

首先,你需要在LUIS门户上创建你的LUIS应用程序,用你的话语添加你的意图,例如: - intent是“KnowlegeBase”,你可以创建尽可能多的话语来返回这个意图。< / p>

在应用程序内部,创建一个LUISDialog类并从BuildForm中调用它: -

    await context.Forward(new MyLuisDialog(), ResumeDialog, activity, CancellationToken.None);

LuisDialog课程: -

  public class MyLuisDialog : LuisDialog<object>
{
    private static ILuisService GetLuisService()
    {
        var modelId = //Luis modelID;
        var subscriptionKey = //Luis subscription key
        var staging = //whether point to staging or production LUIS
        var luisModel = new LuisModelAttribute(modelId, subscriptionKey) { Staging = staging };
        return new LuisService(luisModel);
    }

    public MyLuisDialog() : base(GetLuisService())
    {

    }

 [LuisIntent("KnowledgeBase")]
    public async Task KnowledgeAPICall(IDialogContext context, LuisResult result)
    {
        //your code
    }

要利用用户传递的消息,您可以从参数中的上下文中使用它。