Esempio n. 1
0
        public async Task UserErrorLimitExceeded()
        {
            await _context.PostAsync(MessagesResource.ErrorLimitExceeded);

            var sender = new SendCorrectGreetingCard(_context);
            await sender.Send();
        }
        public async Task GetTask(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            try
            {
                var userResponse = await result;

                var categorySelected = JsonConvert.DeserializeObject <OptionSelectionPayload>(userResponse.Text, new JsonSerializerSettings {
                    Error = delegate(object sender, ErrorEventArgs args) { args.ErrorContext.Handled = true; }
                });

                if (categorySelected != null)
                {
                    switch (categorySelected.Action)
                    {
                    case "add":
                    {
                        var products = new List <ProductDto>()
                        {
                            new ProductDto()
                            {
                                CategoryId  = 3034,
                                Description = "prodotto 1",
                                Id          = 1,
                                SKU         = "1"
                            },
                            new ProductDto()
                            {
                                CategoryId  = 3034,
                                Description = "prodotto 2",
                                Id          = 2,
                                SKU         = "2"
                            },
                            new ProductDto()
                            {
                                CategoryId  = 3034,
                                Description = "prodotto 3",
                                Id          = 3,
                                SKU         = "3"
                            },
                            new ProductDto()
                            {
                                CategoryId  = 3034,
                                Description = "prodotto 4",
                                Id          = 4,
                                SKU         = "4"
                            }
                        };

                        context.UserData.SetValue("CategoryPromoProducts", products);

                        if (products.Count == 0)
                        {
                            await context.PostAsync(MessagesResource.NoPromoProductForCategorySelected);

                            await context.PostAsync(MessagesResource.SelectAnotherCategory);

                            var clusters = new List <ClusterDto>()
                            {
                                new ClusterDto()
                                {
                                    Description = "prodotto 1",
                                    Id          = 1
                                },
                                new ClusterDto()
                                {
                                    Description = "prodotto 2",
                                    Id          = 2
                                },
                                new ClusterDto()
                                {
                                    Description = "prodotto 3",
                                    Id          = 3
                                },
                                new ClusterDto()
                                {
                                    Description = "prodotto 4",
                                    Id          = 4
                                }
                            };

                            var sender = new SendCorrectCategoriesListCard(context);
                            await sender.Send(clusters);

                            context.Wait(GetTask);
                        }
                        else
                        {
                            context.Call(_dialogFactory.Create <GetCategoryPromoProductByCardTask>(), Callback);
                        }
                        break;
                    }

                    case "cancel":
                    {
                        var sender = new SendCorrectGreetingCard(context);
                        await sender.Send();

                        context.Call(_dialogFactory.Create <GreetingDialog>(), Callback);
                    }
                    break;
                    }
                }
                else
                {
                    var handler = new HandleUserIncorrectInput(context);

                    if (handler.CheckCounterErrors())
                    {
                        await handler.UserErrorLimitExceeded();

                        context.Call(_dialogFactory.Create <GreetingDialog>(), Callback);
                    }
                    else
                    {
                        await context.PostAsync(MessagesResource.CourtesyCategoryError);

                        var clusters = new List <ClusterDto>()
                        {
                            new ClusterDto()
                            {
                                Description = "prodotto 1",
                                Id          = 1
                            },
                            new ClusterDto()
                            {
                                Description = "prodotto 2",
                                Id          = 2
                            },
                            new ClusterDto()
                            {
                                Description = "prodotto 3",
                                Id          = 3
                            },
                            new ClusterDto()
                            {
                                Description = "prodotto 4",
                                Id          = 4
                            }
                        };

                        var sender = new SendCorrectCategoriesListCard(context);
                        await sender.Send(clusters);

                        context.Wait(GetTask);
                    }
                }
            }
            catch (Exception ex)
            {
                await context.PostAsync(MessagesResource.CourtesyError);

                context.Call(_dialogFactory.Create <GreetingDialog>(), Callback);
            }
        }
Esempio n. 3
0
        public async Task StartAsync(IDialogContext context)
        {
            try
            {
                var openingHours = new OpeningHoursDto()
                {
                    RegularOpening = new List <Tuple <string, string> >()
                    {
                        Tuple.Create("lun", "10:00 - 11:00"),
                        Tuple.Create("mar", "10:00 - 11:00")
                    },
                    SpecialOpenings = new List <Tuple <string, string> >()
                    {
                        Tuple.Create("sab", "10:00 - 11:00"),
                        Tuple.Create("dom", "10:00 - 11:00")
                    }
                };

                var channel = context.Activity.ChannelId;

                if (openingHours != null)
                {
                    var sb = new StringBuilder();

                    var newLine = defaultNewLine;

                    if (channel == "facebook")
                    {
                        newLine = facebookNewLine;
                    }

                    sb.Append(MessagesResource.ShowOpeningHours + newLine);

                    foreach (var regularOpening in openingHours.RegularOpening)
                    {
                        sb.Append($"{regularOpening.Item1}  {regularOpening.Item2}" + newLine);
                    }

                    if (openingHours.SpecialOpenings != null && openingHours.SpecialOpenings.Any())
                    {
                        sb.Append(MessagesResource.ShowExtraOpeningHours + newLine);

                        foreach (var regularOpening in openingHours.SpecialOpenings)
                        {
                            sb.Append($"{regularOpening.Item1}  {regularOpening.Item2}" + newLine);
                        }
                    }

                    var message = sb.ToString();

                    await context.PostAsync(message);
                }
                else
                {
                    await context.PostAsync(MessagesResource.NoOpeningHours);
                }

                var sender = new SendCorrectGreetingCard(context);
                await sender.Send();

                context.Wait(MessageReceivedAsync);
            }
            catch (Exception ex)
            {
                await context.PostAsync(MessagesResource.CourtesyError);

                context.Wait(MessageReceivedAsync);
            }
        }
Esempio n. 4
0
        public async Task GetTask(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            try
            {
                var message = await result;

                var itemSelected = JsonConvert.DeserializeObject <ProductSelectionPayload>(message.Text, new JsonSerializerSettings {
                    Error = delegate(object sender, ErrorEventArgs args) { args.ErrorContext.Handled = true; }
                });

                if (itemSelected != null)
                {
                    switch (itemSelected.Action)
                    {
                    case "add":
                    {
                        var product = itemSelected.Product;

                        context.UserData.SetValue("SelectedCategoryPromoProduct", product);

                        context.Call(_dialogFactory.Create <AskWhatListMustUsedTask>(), Callback);
                        break;
                    }

                    case "cancel":
                    {
                        var sender = new SendCorrectGreetingCard(context);
                        await sender.Send();

                        context.Call(_dialogFactory.Create <GreetingDialog>(), Callback);
                        break;
                    }

                    default:
                        break;
                    }
                }
                else
                {
                    var handler = new HandleUserIncorrectInput(context);

                    if (handler.CheckCounterErrors())
                    {
                        await handler.UserErrorLimitExceeded();

                        context.Call(_dialogFactory.Create <GreetingDialog>(), Callback);
                    }
                    else
                    {
                        await context.PostAsync(MessagesResource.NotUnderstoodRequest);

                        await context.PostAsync(MessagesResource.SelectProduct);

                        var productsList = context.UserData.GetValueOrDefault <List <ProductDto> >("CategoryPromoProducts");

                        var sendProductsListCard = new SendCorrectProductsListCard(context);
                        await sendProductsListCard.Send(productsList);

                        context.Wait(GetTask);
                    }
                }
            }
            catch (Exception ex)
            {
                await context.PostAsync(MessagesResource.CourtesyError);

                context.Call(_dialogFactory.Create <GreetingDialog>(), Callback);
            }
        }