microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

[Question] Help me understand where the response "Please enter a number of Pizzas" is coming from when testing with Emulator? #4014

Closed sahootanmay closed 6 years ago

sahootanmay commented 6 years ago

Bot Info

Issue Description

i am not getting from where the response "Please enter a number of Pizzas" is coming in Microsoft bot framework emulator, even i have not added this questions in my Luis app(Restaurantbot/Chatbot) too? As i have to develop a chat bot using Microsoft bot framework , it is required me to know if the setting has been made in the Luis app or some where else? Can you please help me find out, from where the message is displaying?

Code Example

Reproduction Steps

  1. Start communication with chat bot emulator, Greetings part completed.
  2. During communicating with bot emulator, I typed "i want to order", it shows me pizza options, like Large, medium and small ---> //my comments- This part i have managed in my code.
  3. I choose large, it asks me "please enter a no of pizzas" ---> //my comments- i am not getting where this response coming from, i have neither manged it in the .net code nor in the Luis App.

Expected Behavior

luis app i am not getting where this response("please enter a no of pizzas") coming from, i have neither manged it in the .net code nor in the Luis App.

how the bot framework emulator response to those part which are not managed in code as well as Luis App.

Actual Results

The bot framework emulator responses "please enter a number of pizzas".

nwhitmont commented 6 years ago

@sahootanmay Can you share the bot code that is causing the issue?

sahootanmay commented 6 years ago

Hi there, i have created a class UserOrder.cs, where i have mentioned pizza options:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Bot.Builder.FormFlow;

namespace RestraurantBot.Models
{
    public enum PizzaSizeOptions
    {
        Regular,
        Medium,
        Large
    }

    public enum AmmenitiesOptions
    {
        Banquet,
        Pool,
        Garden,
        KidsZone
    }
    [Serializable]
    public class UserOrder
    {
        public PizzaSizeOptions? PizzaSize;
        public int? Pizzas;
        public DateTime? DeliveryDate;
        public List<AmmenitiesOptions> Ammenities; 
        public static IForm<UserOrder> BuildForm()
        {
            return new FormBuilder<UserOrder>().Message("Welcome to the Restaurant bot").Build();            
        }
    }    
}

//Also created a class LuisDialog.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using RestraurantBot.Models;
using Microsoft.Bot.Builder.FormFlow;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis; 
using Microsoft.Bot.Builder.Luis.Models;
using System.Threading.Tasks;
using DemoResturantBot.Dialogs;

namespace RestraurantBot.Dialogs    
{
    [LuisModel("3b8c3a2c-04f2-4671-b3c6-72164e4c9fda", "40b8ec8399034a489a9656fc5566ba17")]
    [Serializable]
    public class LuisDialog : LuisDialog<UserOrder>
    {
        private readonly BuildFormDelegate<UserOrder> OrderPizza;

        public LuisDialog(BuildFormDelegate<UserOrder> PizzaOrder)
        {
            this.OrderPizza = PizzaOrder;
        }
        [LuisIntent("")]

        public async Task None(IDialogContext context, LuisResult result)
        {
            await context.PostAsync("I'm sorry. I didn't understand you.");
            context.Wait(MessageReceived);
        }

        [LuisIntent("Greetings")]

        public async Task Greeting(IDialogContext context, LuisResult result)
        {

            context.Call(new RootDialog(), Callback);
        }
        private async Task Callback(IDialogContext context,IAwaitable<object> result)
        {
            context.Wait(MessageReceived);
        }
        [LuisIntent("Order")]

        public async Task PizzaOrder(IDialogContext context,LuisResult result)
        {
            var enrollmentForm = new FormDialog<UserOrder>(new UserOrder(), this.OrderPizza, FormOptions.PromptInStart);
            context.Call<UserOrder>(enrollmentForm, Callback);
        }
        [LuisIntent("AvailableAmenities")]

        public async Task QueryAmenities(IDialogContext context,LuisResult result)
        {

            foreach(var entity in result.Entities.Where(Entity =>Entity.Type== "Amenities"))
            {

                var value = entity.Entity.ToLower();
                if(value=="banquet" || value=="pool" ||value=="garden" ||  value=="kidszone")
                {
                    await context.PostAsync("Yes we have that!");
                    context.Wait(MessageReceived);
                    return;
                }
                else
                {

                    await context.PostAsync("I'm sorry we don't have that.");
                    context.Wait(MessageReceived);
                    return;
                }
            }
            await context.PostAsync("I'm sorry we don't have that.");
            context.Wait(MessageReceived);
            return;
        }
    }
}
// MessageController 

using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using RestraurantBot.Models;
using RestraurantBot.Dialogs;

namespace RestraurantBot.Models
{
    [BotAuthentication]
    public class MessagesController : ApiController
    {
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        /// 
        //Bike_AdDetailsModel model = new Bike_AdDetailsModel();
        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {

                await Conversation.SendAsync(activity, MakeLuisDialog);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }

        internal static IDialog<UserOrder> MakeLuisDialog()
        {
            return Chain.From(() => new LuisDialog(UserOrder.BuildForm));
        }

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

luis app

JasonSowers commented 6 years ago

@sahootanmay It comes from here it is part of form flow.

In your UserOrder class you have this: public int? Pizzas; if you changed Pizzas to bananas it would prompt you with how many bananas would you like. To customize this you can add a prompt attribute to your Pizzas variable like this

[Prompt("Some Text Here? {||}")]
public int? Pizzas;
sahootanmay commented 6 years ago

Thanks. It was helpful