在基于luis的机器人中调用表单

时间:2017-11-21 05:41:27

标签: c# luis

我正在尝试创建一个基于luis意图的机器人,我需要让客户提供他的详细信息和反馈。例如,如果客户不满意,我希望他的详细信息允许回调。我的luis意图识别对话框,但我无法启动表单。我的luis对话框代码是

namespace Microsoft.Bot.Sample.Luisbot
{
    [Serializable]
 public class FeedbackForm
{
    [Prompt(new string[] { "Name?" })]
    public string Name { get; set; }

    [Prompt("Contact Number")]
    public string Contact { get; set; }

    [Prompt("Query")]
    public string Query { get; set; }

        public static IForm<FeedbackForm> BuildForm()
    {
        return new FormBuilder<FeedbackForm>()
            .Build();
    }
}  


    [Serializable]
    class BasicLuisDialog : LuisDialog<object>
    {
         public BasicLuisDialog() : base(new LuisService(new LuisModelAttribute(ConfigurationManager.AppSettings["LuisAppId"], ConfigurationManager.AppSettings["LuisAPIKey"])))

        [LuisIntent("Greetings")]
        public async Task GreetingsIntent(IDialogContext context, LuisResult result)
        {
            await context.PostAsync("Hi. Please share your query");
            context.Wait(MessageReceived);
        }
        [LuisIntent("Critical")]
        public async Task CriticalIntent(IDialogContext context, LuisResult result)
        {
           await context.PostAsync("Thank you for your response.To help you better I will arrange a call back from our customer care team. Please provide following details");
           var feedbackForm = new FormDialog<FeedbackForm>(new FeedbackForm(), FeedbackForm.BuildForm, FormOptions.PromptInStart,result.Entities);
        context.Call(feedbackForm, FeedbackFormComplete);
        context.Wait(MessageReceived);
        }  
   }
}

我的messagecontroller代码是

namespace Microsoft.Bot.Sample.LuisBot
{
    using System;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Threading.Tasks;
    using System.Web.Http;
    using Microsoft.Bot.Builder.Dialogs;
    using Microsoft.Bot.Builder.FormFlow;   
    using Microsoft.Bot.Connector;

    [BotAuthentication]
    public class MessagesController : ApiController
    {

        private static IForm<FeedbackForm> BuildForm()

        internal static IDialog<FeedbackForm> MakeRoot()
    {
        return Chain.From(() => new BasicLuisDialog(BuildForm));
    }   

        [ResponseType(typeof(void))]

         public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                await Conversation.SendAsync(activity, () => new BasicLuisDialog());
            }
            else
            {
                await this.HandleSystemMessage(activity);
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }


        private async Task 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)
            {
                if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
                {
                    ConnectorClient client = new ConnectorClient(new Uri(message.ServiceUrl));

                    var reply = message.CreateReply();

                    reply.Text = "Welcome to RB Customer Care";

                    await client.Conversations.ReplyToActivityAsync(reply);
                }
            }
            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)
            {
            }
        }
    }
}

任何人都可以帮我理解这里的错误。我不是C#的专家

0 个答案:

没有答案