1

I am trying to create a bot wherein based on luis intent i need to ask customer to feed in his details and feedback. For example, if customer is unhappy i want his details to allow a callback. My luis intent identifies the dialog but i am not able to fire up a form. My luis dialog code is

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);
        }  
   }
}

And my messagecontroller code is

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)
            {
            }
        }
    }
}

Can anyone help me understand what is wrong here. I am not a pro at C#

  • Possible duplicate of [How to forward from RootDialog to LuisDialog in Bot Framework](https://stackoverflow.com/questions/45464455/how-to-forward-from-rootdialog-to-luisdialog-in-bot-framework) – Ezequiel Jadib Nov 21 '17 at 13:47
  • Not exactly the same duplicate but the problem is quite similar. You are calling the form and also waiting in the current form. You can't do that, you need to choose and in your case you just need to remove the `context.Wait` call – Ezequiel Jadib Nov 21 '17 at 13:48

0 Answers0