/// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="conversationState">The managed conversation state.</param>
        /// <param name="loggerFactory">A <see cref="ILoggerFactory"/> that is hooked to the Azure App Service provider.</param>
        /// <seealso cref="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.1#windows-eventlog-provider"/>
        public MinditshopperBotBot(ConversationState conversationState, ILoggerFactory loggerFactory, RecommenderClient recommenderClient)
        {
            if (conversationState == null)
            {
                throw new System.ArgumentNullException(nameof(conversationState));
            }

            if (loggerFactory == null)
            {
                throw new System.ArgumentNullException(nameof(loggerFactory));
            }

            if (recommenderClient == null)
            {
                throw new System.ArgumentNullException(nameof(recommenderClient));
            }
            else
            {
                this.recommenderClient = recommenderClient;
            }

            _accessors = new MinditshopperBotAccessors(conversationState)
            {
                MindshopperUserState = conversationState.CreateProperty <MindshopperUserState>(MinditshopperBotAccessors.MinditshoperUserState),
            };

            _logger = loggerFactory.CreateLogger <MinditshopperBotBot>();
            _logger.LogTrace("Turn start.");
        }
        public async Task SelectedCategoryItem(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            ;
            var response = turnContext.Activity.Text;

            string text = "";
            var    item = RecommenderClient.ProcessItem(response);

            if (item != null)
            {
                state.SelectedItems.Add(item);
                text = $"You have choosen {response}. Type \"OK\" to continue.";
                state.LastProcessedItem = response;
                state.TurnCount         = State.CHOOSE_RECOMMENDED_ITEM;
            }
            else
            {
                text            = $"You have choosen an invalid item. Type \"OK\" to continue and select a correct item.";
                state.TurnCount = State.CHOOSE_CATEGORY_ITEM;
            }

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);

            await turnContext.SendActivityAsync(text);
        }
Exemplo n.º 3
0
        public async Task ChooseItemCategory(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var response = turnContext.Activity.Text;

            if (response != null && response.Contains("1"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("10");

                string text = $"Following items are top sellers in the category: 10\n";
                int    cnt  = 1;
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{cnt}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }

            //TODO add for other categories
        }
        public async Task SelectedRecommendedItem(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            string text     = "";
            var    response = turnContext.Activity.Text;

            if (response != null)
            {
                if (!response.ToLower().Contains("no"))
                {
                    var item = RecommenderClient.ProcessItem(response);
                    if (item != null)
                    {
                        state.SelectedItems.Add(item);
                        text = $"You have choosen {response}. Type \"OK\" to continue.";
                        state.LastProcessedItem = response;
                        state.TurnCount         = State.CHOOSE_RECOMMENDED_ITEM;
                    }
                    else
                    {
                        text            = $"You have choosen an invalid item. Type \"OK\" to continue and select a correct item.";
                        state.TurnCount = State.CHOOSE_CATEGORY_ITEM;
                    }
                }
                else
                {
                    state.TurnCount = State.CHOOSE_CATEGORY;
                    text            = $"You are being sent back to the category choosing.\n Please select the category of interest:" +
                                      $"\n\t\t1) Tobacco" +
                                      $"\n\t\t2) Liquor" +
                                      $"\n\t\t3) Food" +
                                      $"\n\t\t4) Perfumes & Cosmetics" +
                                      $"\n\t\tType\"none\" to close the cart.";
                }
            }

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);

            await turnContext.SendActivityAsync(text);
        }
        public async Task ChooseRecommendedItem(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var    response = turnContext.Activity.Text;
            string text     = "";

            if (response != null)
            {
                if (!response.ToLower().Contains("no"))
                {
                    response = response.ToLower().Equals("ok") ? state.LastProcessedItem : response;

                    IList <Item> list = RecommenderClient.ProcessRecommendedItem(response);

                    text = $"Following items are recommended to you based on the current items in your cart:\n";
                    foreach (Item i in list)
                    {
                        text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                    }
                    text += "\n Choose the item, otherwise, type \"none\".";

                    state.TurnCount = State.SELECTED_RECOMMENDED_ITEM;
                }
                else
                {
                    state.TurnCount = State.CHOOSE_CATEGORY;
                }
            }
            else
            {
                state.TurnCount = State.CHOOSE_RECOMMENDED_ITEM;
            }

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);

            await turnContext.SendActivityAsync(text);
        }
        public async Task ChooseCategory(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var response = turnContext.Activity.Text;

            if (response != null && response.Contains("1"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("10");

                string text = $"Following items are top sellers in the category: 10\n";
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
            else if (response != null && response.Contains("2"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("20");

                string text = $"Following items are top sellers in the category: 20\n";
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
            else if (response != null && response.Contains("3"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("30");

                string text = $"Following items are top sellers in the category: 30\n";
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
            else if (response != null && response.Contains("4"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("40");

                string text = $"Following items are top sellers in the category: 40\n";
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
            else if (response != null && response.ToLower().Contains("no"))
            {
                string text = $"Thank you for buying. Have a nice day! Type \"OK\" to confirm the completion of the cart.";
                state.TurnCount = State.END;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
        }