public async Task Guidance(IDialogContext context, LuisResult result)
        {
            FilterIntentScore(context, result);
            await Interactions.SendMessage(context, Interactions.MainMenu(), 0, 2000);

            context.Call(new MenuDialog(MenuDialog.State.INIT), ResumeAfterDialogueCall);
        }
Пример #2
0
        public async Task InitDialog(IDialogContext context, IAwaitable <IMessageActivity> activity)
        {
            var        reply = context.MakeMessage();
            Attachment att   = await getCardAttachment(CardType.FILTER);

            //Fills the form with the previous choosen filters
            if (state.Equals(State.FILTER_AGAIN))
            {
                await Interactions.SendMessage(context, "Modifique os seus requisitos para efetuarmos uma nova pesquisa no nosso catálogo.", 0, 2000);

                JObject json = JObject.Parse(att.Content.ToString());
                FilterLogic.SetFilterCardValue(json, StateHelper.GetFilters(context), context.Activity.ChannelId);
                att.Content = @json;
            }
            else
            {
                await Interactions.SendMessage(context, "Preencha o formulário abaixo com as suas preferências para que eu possa reunir os melhores produtos para si.", 0, 2000);
            }

            //send form
            reply.Attachments.Add(att);
            await context.PostAsync(reply);

            context.Wait(InputHandler);
        }
Пример #3
0
        public static async Task AddComparator(IDialogContext context, string message)
        {
            string[] parts   = message.Split(':');
            var      product = parts[1].Replace(" ", "");

            if (parts.Length >= 2)
            {
                List <string> items = StateHelper.GetComparatorItems(context);

                if (ComparatorLogic.MAX_PRODUCTS_ON_COMPARATOR <= items.Count)
                {
                    await context.PostAsync("Lamento mas só consigo avaliar até " +
                                            ComparatorLogic.MAX_PRODUCTS_ON_COMPARATOR.ToString() + " produtos.");
                }
                else
                {
                    Product productToAdd = ProductController.getProduct(product);

                    var reply = context.MakeMessage();
                    reply.Text = String.Format(Interactions.getAddComparator());
                    await context.PostAsync(reply);

                    StateHelper.AddItemComparator(context, product);
                }
            }
        }
Пример #4
0
        public async static Task ShowClosestStores(IDialogContext context)
        {
            //simulate user position
            Random r = new Random();

            Double[] coords = new Double[] {
                r.NextDouble() * 180 - 90,
                     r.NextDouble() * 180 - 90
            };

            List <Store> stores = StoreController.getClosesStores(coords);

            var reply = context.MakeMessage();

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            List <Attachment> attachments = new List <Attachment>();

            for (var i = 0; i < stores.Count() && i <= N_STORES_MAX; i++)
            {
                attachments.Add(StoreCard.GetStoreCard(stores[i]).ToAttachment());
            }

            reply.Attachments = attachments;

            await Interactions.SendMessage(context, Interactions.getClosesStore(), 0, 2000);

            await context.PostAsync(reply);
        }
Пример #5
0
        public static IMessageActivity CleanAllFilters(IDialogContext context)
        {
            StateHelper.CleanFilters(context);
            var reply = context.MakeMessage();

            reply.Text = Interactions.getCleanAllFilters();
            return(reply);
        }
        public async Task Greeting(IDialogContext context, LuisResult result)
        {
            var reply = context.MakeMessage();

            reply.Text = Interactions.Greeting(StateHelper.GetUser(context).Name);
            await context.PostAsync(reply);

            context.Done(new CODE(DIALOG_CODE.DONE));
        }
        public async Task RmvWishList(IDialogContext context, LuisResult result)
        {
            FilterIntentScore(context, result);

            WishListDialog.RemoveFromWishList(context, result.Query);
            var reply = Interactions.getRemWishList();
            await Helpers.BotTranslator.PostTranslated(context, reply, context.MakeMessage().Locale);

            context.Done(new CODE(DIALOG_CODE.DONE));
        }
Пример #8
0
        public static async Task RmvComparator(IDialogContext _context, string message)
        {
            string[] parts   = message.Split(':');
            var      product = parts[1].Replace(" ", "");

            if (parts.Length >= 2)
            {
                var reply = _context.MakeMessage();
                reply.Text = Interactions.getRemComparator();
                await _context.PostAsync(reply);

                StateHelper.RemItemComparator(_context, product);
            }
        }
Пример #9
0
        public async Task Register(IDialogContext context)
        {
            string msg = "Poderia preencher o formulário abaixo? Irá-me ajudar a conhecê-lo melhor e a lembrar-me de si numa próxima vez.";
            await Interactions.SendMessage(context, msg, 0, 1500);

            Attachment att = await getCardAttachment(CardType.REGISTER);

            var reply = context.MakeMessage();

            reply.Attachments.Add(att);
            await context.PostAsync(reply);

            context.Wait(InputHandler);
        }
Пример #10
0
        public async Task Login(IDialogContext context)
        {
            string msg = "Poderia-me dizer o seu email?\nAssim será mais fácil recordar-me de si.";
            await Interactions.SendMessage(context, msg, 0, 1500);

            Attachment att = await getCardAttachment(CardType.LOGIN);

            var reply = context.MakeMessage();

            reply.Attachments.Add(att);
            await context.PostAsync(reply);

            context.Wait(InputHandler);
        }
Пример #11
0
        public static async Task ShowStores(IDialogContext context, string productId)
        {
            var reply = context.MakeMessage();

            var storeCollection = DbSingleton.GetDatabase().GetCollection <Store>(AppSettings.StoreCollection);
            var filter          = Builders <Store> .Filter.Empty;

            List <Store> stores       = storeCollection.Find(filter).ToList();
            List <Store> storesWStock = new List <Store>();

            for (int i = 0; i < stores.Count(); i++)
            {
                for (int j = 0; j < stores[i].ProductsInStock.Count(); j++)
                {
                    if (stores[i].ProductsInStock[j].ProductId.ToString().Equals(productId))
                    {
                        if (stores[i].ProductsInStock[j].Stock > 0 && storesWStock.Count() <= N_STORES_MAX)
                        {
                            storesWStock.Add(stores[i]);
                            break;
                        }
                    }
                }
            }

            var text = "";

            if (storesWStock.Count() == 0)
            {
                reply.AttachmentLayout = AttachmentLayoutTypes.List;
                text = Interactions.getStockFail();
            }
            else
            {
                text = Interactions.getStockSuccess();
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                List <Attachment> cards = new List <Attachment>();

                for (var i = 0; i < storesWStock.Count() && i < 7; i++)
                {
                    cards.Add(StoreCard.GetStoreDetailsCard(storesWStock[i], productId).ToAttachment());
                }

                reply.Attachments = cards;
            }
            await Interactions.SendMessage(context, text, 0, 2000);

            await context.PostAsync(reply);
        }
Пример #12
0
        public async Task SaveAccount(IDialogContext context, List <InputData> data)
        {
            string fail_text = AccountLogic.SaveAccountInfo(data, context);

            if (fail_text != "")
            {
                await context.PostAsync(fail_text);
            }

            state = State.INIT;
            await Interactions.SendMessage(context, "Obrigado por me ter corrigido.", 0, 3000);

            await Interactions.SendMessage(context, "Existe alguma questão em que lhe possa ser útil? Com o menu principal é mais fácil mostrar-lhe as áreas em que o posso ajudar.", 0, 2000);

            context.Call(new MenuDialog(MenuDialog.State.INIT), ResumeAfterDialogCall);
        }
Пример #13
0
        public async Task LoginStart(IDialogContext context, List <InputData> data)
        {
            var fail_text = AccountLogic.Login(data, context);

            if (fail_text != "")
            {
                await context.PostAsync(fail_text);
            }

            state = State.INIT;
            string msg = StateHelper.GetUser(context).Name + " agora já me lembro de você!";
            await Interactions.SendMessage(context, msg, 0, 2000);

            await Interactions.SendMessage(context, "Existe alguma questão em que lhe possa ser útil? Com o menu principal é mais fácil mostrar-lhe as áreas em que o posso ajudar.", 0, 2000);

            context.Call(new MenuDialog(MenuDialog.State.INIT), ResumeAfterDialogCall);
        }
Пример #14
0
        public async Task NotLoginDialog(IDialogContext context, IAwaitable <IMessageActivity> activity)
        {
            string msg = "Já nos apresentamos antes? Se sim, por favor identifique-se para que me possa lembrar de si e oferecer-lhe uma experiência " +
                         "mais personalizada e adequada a si.\nCaso ainda não nos tenhamos conhecido não há problema. Clique no botão abaixo para que se possa apresentar.";

            await Interactions.SendMessage(context, msg, 0, 1500);

            var        reply = context.MakeMessage();
            Attachment att   = await getCardAttachment(CardType.NOT_LOGIN);

            reply.Attachments.Add(att);
            await context.PostAsync(reply);

            await Interactions.SendMessage(context, "Não se sinta obrigado a se identificar ou a apresentar. Posso sempre tentar ajudá-lo na mesma.", 3000, 0);

            context.Wait(InputHandler);
        }
Пример #15
0
        public async Task EditAccount(IDialogContext context)
        {
            string msg = "Posso ter percebido mal alguma informação sobre si. Importar-se-ia de a corrigir no formulário abaixo?\nObrigado.";
            await Interactions.SendMessage(context, msg, 0, 1500);

            Attachment att = await getCardAttachment(CardType.EDIT_ACCOUNT);

            JObject content = att.Content as JObject;

            AccountLogic.SetAccountCardFields(content, context, true);

            var reply = context.MakeMessage();

            reply.Attachments.Add(att);
            await context.PostAsync(reply);

            context.Wait(InputHandler);
        }
Пример #16
0
        public async Task ViewAccountDialog(IDialogContext context, IAwaitable <IMessageActivity> activity)
        {
            string msg = "Esta é a informação que me deu sobre você. Se há algo que não está certo por favor avise-me, para isso, clique no " +
                         "botão para que eu possamos alterar a informação incorrecta.\nSe esta informação não pertencer a você por favor termine a conversa. Obrigado";
            await Interactions.SendMessage(context, msg, 0, 2000);

            var        reply = context.MakeMessage();
            Attachment att   = await getCardAttachment(CardType.VIEW_ACCOUNT);

            JObject json = att.Content as JObject;

            AccountLogic.SetAccountCardFields(json, context, false);

            reply.Attachments.Add(att);
            await context.PostAsync(reply);

            await Interactions.SendMessage(context, "Precisa de ajuda numa outra questão ?", 1000, 0);

            context.Wait(InputHandler);
        }
Пример #17
0
        public async Task Compare(IDialogContext context)
        {
            // fetch products
            var itemsToCompare = StateHelper.GetComparatorItems(context);

            foreach (string o in itemsToCompare)
            {
                products.Add(ProductController.getProduct(o.ToString()));
            }

            if (products.Count > 0)
            {
                var reply = context.MakeMessage();
                reply.Text = Interactions.getOngoingComp();
                await context.PostAsync(reply);

                ComparatorLogic.ShowProductComparison(context, products);

                /*
                 * //show options
                 * if(products.Count <= ComparatorLogic.MAX_PRODUCTS_ON_COMPARATOR)
                 * {
                 *  reply = context.MakeMessage();
                 *  reply.Attachments.Add(getCardButtonsAttachment(
                 *      new List<ButtonType> { ButtonType.ADD_PRODUCT }, DialogType.COMPARE));
                 *  await context.PostAsync(reply);
                 * }*/
            }
            else
            {
                await context.PostAsync("Não tem produtos para comparar.");

                //show options
                var reply = context.MakeMessage();
                reply.Attachments.Add(getCardButtonsAttachment(
                                          new List <ButtonType> {
                    ButtonType.ADD_PRODUCT
                }, DialogType.COMPARE));
                await context.PostAsync(reply);
            }
        }
Пример #18
0
        public async Task RegisterSave(IDialogContext context, List <InputData> data)
        {
            await Interactions.SendMessage(context, "Estou a analizar os seus dados ...", 0, 0);

            string fail_text = AccountLogic.Register(data, context);

            if (fail_text != "")
            {
                await context.PostAsync(fail_text);
            }
            else
            {
                await Interactions.SendMessage(context, Interactions.Register(StateHelper.GetUser(context)), 0, 2000);
            }

            state = State.INIT;

            await Interactions.SendMessage(context, "Existe alguma questão em que lhe possa ser útil? Com o menu principal é mais fácil mostrar-lhe as áreas em que o posso ajudar.", 0, 3000);

            context.Call(new MenuDialog(MenuDialog.State.INIT), ResumeAfterDialogCall);
        }
        public async Task ShowWishesAsync(IDialogContext context, IAwaitable <IMessageActivity> activity)
        {
            List <string> wishes = StateHelper.GetWishlistItems(context);

            //Retrive wishes information
            var to_retrieve = wishes;

            //options
            List <ButtonType> buttons = new List <ButtonType>();

            //fetch only a limited number of wishes
            if (wishes.Count() > Constants.N_ITEMS_CARROUSSEL)
            {
                to_retrieve = wishes.Skip(this.skip)
                              .Take(Constants.N_ITEMS_CARROUSSEL)
                              .ToList();
            }

            var products = new List <Product>();

            foreach (string i in to_retrieve)
            {
                products.Add(ProductController.getProduct(i));
            }

            //Prepare answer

            var reply = context.MakeMessage();
            var text  = "";

            var button_text = "";

            // No products on wishlsit
            if (products.Count == 0)
            {
                text = Interactions.getWishList(Interactions.State.FAIL, 0);
                await context.PostAsync(text);
            }
            // Has Products
            else
            {
                text = Interactions.getWishList(Interactions.State.SUCCESS, skip / Constants.N_ITEMS_CARROUSSEL + 1);
                await Interactions.SendMessage(context, text, 0, 2500);

                //display products
                reply = context.MakeMessage();
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                List <Attachment> cards = new List <Attachment>();

                //limit
                for (var i = 0; i < products.Count && i < Constants.N_ITEMS_CARROUSSEL; i++)
                {
                    cards.Add(ProductCard.GetProductCard(products[i], ProductCard.CardType.WISHLIST).ToAttachment());
                }

                reply.Attachments = cards;
                await context.PostAsync(reply);

                //Check if pagination is needed and display wishes
                if (wishes.Count() > this.skip + Constants.N_ITEMS_CARROUSSEL)
                {
                    buttons.Add(ButtonType.PAGINATION);
                    skip        += skip + Constants.N_ITEMS_CARROUSSEL;
                    button_text += "Não consegui exibir todos os seus produtos favoritos. Se desejar ver mais clique no botão abaixo.";
                }
            }

            //add option add more products
            buttons.Add(ButtonType.ADD_PRODUCT);
            button_text += "\nSe desejar adicionar mais produtos aos seus favoritos faça uma pesquisa no nosso catálogo. Para isso, clique no botão abaixo.";

            await Interactions.SendMessage(context, button_text, 2000, 2000);

            //show options
            reply = context.MakeMessage();
            reply.Attachments.Add(getCardButtonsAttachment(buttons, DialogType.WISHLIST));
            await context.PostAsync(reply);

            context.Wait(this.InputHandler);
        }
Пример #20
0
        public async Task FilterAsync(IDialogContext context, IAwaitable <IMessageActivity> activity)
        {
            List <Filter> filters = StateHelper.GetFilters(context);

            // search products based on the last fetch id (inclusive)
            // search will fetch +1 product to know if pagination is needed
            List <Product> products = ProductController.getProductsFilter(
                FilterLogic.GetJoinedFilter(filters),
                Constants.N_ITEMS_CARROUSSEL + 1,
                last_fetch_id);

            if (products.Count > 1)
            {
                last_fetch_id = products[products.Count - 2].Id;
            }

            var reply = context.MakeMessage();
            var text  = "";

            if (products.Count > 0)
            {
                text = Interactions.getFilter(Interactions.State.SUCCESS, page) + "  \n";
            }
            else
            {
                text = Interactions.getFilter(Interactions.State.FAIL, page) + "  \n";
            }

            //display current filters
            for (int i = 0; i < filters.Count; i++)
            {
                text += filters[i].FilterName + filters[i].Operator + filters[i].Value;
                if (i != filters.Count - 1)
                {
                    text += ", ";
                }
            }

            await Interactions.SendMessage(context, text, 2000, 3000);

            bool done = false;
            List <ButtonType> buttons = new List <ButtonType>();

            string button_text = "";

            //show products
            if (products.Count > 0)
            {
                //display products
                reply = context.MakeMessage();
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                List <Attachment> cards = new List <Attachment>();

                //limit
                for (var i = 0; i < products.Count && i < Constants.N_ITEMS_CARROUSSEL; i++)
                {
                    cards.Add(ProductCard.GetProductCard(products[i], ProductCard.CardType.SEARCH).ToAttachment());
                }

                reply.Attachments = cards;
                await context.PostAsync(reply);

                //Check if pagination is needed
                if (products.Count > Constants.N_ITEMS_CARROUSSEL)
                {
                    button_text = "Não consegui trazer todos os produtos do catálogo com esses requisitos. Se quiser ver mais produtos clique no botão abaixo.";
                    buttons.Add(ButtonType.PAGINATION);
                }
            }

            button_text += "\nPara alterar os parâmetros da pesquisa carregue no respetivo botão.";
            await Interactions.SendMessage(context, button_text, 2000, 2000);

            buttons.Add(ButtonType.FILTER_AGAIN);

            //show options
            reply = context.MakeMessage();
            reply.Attachments.Add(getCardButtonsAttachment(buttons, DialogType.FILTER));
            await context.PostAsync(reply);

            context.Wait(this.InputHandler);
        }
Пример #21
0
        private async Task ShowRecommendations(IDialogContext context, IAwaitable <object> result)
        {
            await Interactions.SendMessage(context, "Tenho tantos produtos que sei que poderiam ser do seu interesse. Espere só um momento, vou analisar o nosso catálogo.", 0, 4000);

            List <Product> products = new List <Product>();
            List <Filter>  popular  = RecommendationsLogic.GetPopularFilters(StateHelper.GetFiltersCount(context));

            while (true)
            {
                FilterDefinition <Product> joinedFilters = FilterLogic.GetJoinedFilter(popular);

                //fetch +1 product to see if pagination is needed
                products = ProductController.getProductsFilter(
                    joinedFilters,
                    Constants.N_ITEMS_CARROUSSEL + 1,
                    this.lastFetchId);

                //filters didn't retrieved any products at the first try
                if (products.Count == 0 && lastFetchId == null)
                {
                    popular.RemoveAt(popular.Count - 1);
                }
                else
                {
                    break;
                }
            }

            List <string> currentWishlist = StateHelper.GetWishlistItems(context);

            foreach (string str in currentWishlist)
            {
                ObjectId       obj = new ObjectId(str);
                List <Product> l   = Logic.RecommendationsLogic.GetSimilarProducts(obj);
                products.InsertRange(0, l);
            }

            if (products.Count > Constants.N_ITEMS_CARROUSSEL)
            {
                lastFetchId = products[products.Count - 2].Id;
            }

            var reply = context.MakeMessage();

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            List <Attachment> cards = new List <Attachment>();

            for (int i = 0; i < products.Count && i < Constants.N_ITEMS_CARROUSSEL; i++)
            {
                cards.Add(ProductCard.GetProductCard(products[i], ProductCard.CardType.RECOMMENDATION).ToAttachment());
            }

            await Interactions.SendMessage(context, "Estas são as minhas recomendações:", 0, 2000);

            reply.Attachments = cards;
            await context.PostAsync(reply);

            //Check if pagination is needed
            if (products.Count <= Constants.N_ITEMS_CARROUSSEL)
            {
                context.Done(new CODE(DIALOG_CODE.DONE));
            }
            else
            {
                await Interactions.SendMessage(context, "Ainda tenho mais recomendações para si. Se for do seu interesse não hesite, carregue no botão abaixo.", 2000, 2000);

                reply = context.MakeMessage();

                reply.Attachments.Add(
                    getCardButtonsAttachment(new List <ButtonType> {
                    ButtonType.PAGINATION
                }, DialogType.RECOMMENDATION));
                await context.PostAsync(reply);


                context.Wait(this.InputHandler);
            }
        }
Пример #22
0
        public async Task InitAsync(IDialogContext context, IAwaitable <IMessageActivity> activity)
        {
            List <ButtonType> buttons = new List <ButtonType>();

            // fetch products
            var itemsToCompare = StateHelper.GetComparatorItems(context);

            foreach (string o in itemsToCompare)
            {
                products.Add(ProductController.getProduct(o));
            }

            var reply = context.MakeMessage();

            string intro_msg  = "Bem-vindo ao comparador. Aqui posso dar-lhe sugestões sobre quais os melhores produtos que deseja comparar.";
            string button_msg = "";

            if (products.Count > 0)
            {
                intro_msg = "\nVou buscar os produtos em que demonstrou interesse em avaliar. Espere só um momento por favor.";
                await Interactions.SendMessage(context, intro_msg, 0, 0);

                //display products
                reply = context.MakeMessage();
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                List <Attachment> cards = new List <Attachment>();

                //limit
                for (var i = 0; i < products.Count && i < Constants.N_ITEMS_CARROUSSEL; i++)
                {
                    cards.Add(ProductCard.GetProductCard(products[i], ProductCard.CardType.COMPARATOR).ToAttachment());
                }

                reply.Attachments = cards;

                await Interactions.SendMessage(context, "Aqui estão os produtos:", 4000, 2000);

                await context.PostAsync(reply);

                if (products.Count <= ComparatorLogic.MAX_PRODUCTS_ON_COMPARATOR)
                {
                    buttons.Add(ButtonType.ADD_PRODUCT);
                }

                buttons.Add(ButtonType.COMPARE);

                button_msg = "Se quiser posso fazer uma avaliação dos produtos, clique no botão abaixo para que eu iniciar a comparação.";
            }
            else
            {
                intro_msg = "\nDe momentos ainda não adicionou nenhum produto para ser avaliado.";
                await Interactions.SendMessage(context, intro_msg, 0, 3000);

                buttons.Add(ButtonType.ADD_PRODUCT);
            }

            button_msg += "\nSe tiver interesse em adicionar produtos para serem avaliados, faça uma pesquisa no nosso catálogo. Para isto, clique no botão abaixo para preencher um formulário de pesquisa.";
            await Interactions.SendMessage(context, button_msg, 3000, 2000);

            //show options
            reply = context.MakeMessage();
            reply.Attachments.Add(getCardButtonsAttachment(buttons, DialogType.COMPARE));
            await context.PostAsync(reply);

            context.Wait(InputHandler);
        }
Пример #23
0
        public async Task Logout(IDialogContext context)
        {
            await Interactions.SendMessage(context, "A nossa conversa foi terminada.\n Mas não se preocupe, podemos sempre continuá-la numa outra ocasião.", 0, 0);

            context.Done <CODE>(new CODE(DIALOG_CODE.RESET));
        }