Пример #1
0
        public static Activity Welcome(Activity activity, IMessagesService messagesService)
        {
            var attachments = new List <Attachment>();

            var reply = activity.CreateReply();

            if (activity.From.Properties.Count > 0)
            {
                attachments.Add(WelcomeProfile(messagesService));
            }
            else
            {
                attachments.Add(WelcomeLogin(messagesService));
            }

            #region RecipeSearch

            string recipeSearchCB = messagesService.Get(MessagesKey.Key.RecipeSearchCB.ToString()).Value;
            string recipeSearch   = messagesService.Get(MessagesKey.Key.RecipeSearch.ToString()).Value;

            var Buttons = new List <CardAction> {
                new CardAction(ActionTypes.ImBack, value: recipeSearchCB, title: recipeSearch)
            };
            var Images = new List <CardImage> {
                new CardImage {
                    Alt = url + "welcome_recipe.jpg", Url = url + "welcome_recipe.jpg"
                }
            };

            attachments.Add(GetHeroCard(recipeSearch, string.Empty, string.Empty, null, Buttons, Images));
            #endregion

            #region Recipe Allergy Search

            string recipeAllergySearchCB = messagesService.Get(MessagesKey.Key.RecipeAllergySearchCB.ToString()).Value;
            string recipeAllergySearch   = messagesService.Get(MessagesKey.Key.RecipeAllergySearch.ToString()).Value;

            Buttons = new List <CardAction> {
                new CardAction(ActionTypes.ImBack, value: recipeAllergySearchCB, title: recipeAllergySearch)
            };
            Images = new List <CardImage> {
                new CardImage {
                    Alt = url + "welcome_allergy.jpeg", Url = url + "welcome_allergy.jpeg"
                }
            };

            attachments.Add(GetHeroCard(recipeAllergySearch, string.Empty, string.Empty, null, Buttons, Images));
            #endregion

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments      = attachments;
            reply.Text             = messagesService.Get(MessagesKey.Key.WelcomeExtend.ToString()).Value;

            return(reply);
        }
Пример #2
0
        private async Task <DialogTurnResult> InterruptAsync(DialogContext innerDc, CancellationToken cancellationToken)
        {
            var cancelMessage = messagesService.Get(MessagesKey.Key.Cancel.ToString());

            if (innerDc.Context.Activity.Type == ActivityTypes.Message)
            {
                var conversation = await conversationStateAccessor.GetAsync(innerDc.Context, () => new ConversationData());

                var luisResult = conversation.LuisResult;

                if (luisResult.TopScoringIntent.Score < 0.9)
                {
                    return(null);
                }

                switch (luisResult.TopScoringIntent.Intent)
                {
                case Luis.Welcome_Intent:
                    await innerDc.Context.SendActivityAsync(HeroCards.Welcome(innerDc.Context.Activity, messagesService));

                    return(await innerDc.CancelAllDialogsAsync());
                }
            }
            return(null);
        }
Пример #3
0
        private async Task <DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var conversation = await conversationStateAccessor.GetAsync(stepContext.Context, () => new ConversationData());

            var allergiesEntities = conversation.LuisResult.Entities.Where(x => x.Type.Equals(Luis.AllergyEntity)).ToList();

            if (conversation.User != null)
            {
                if (allergiesEntities.Count() > 0)
                {
                    var allergies = new List <string>();

                    foreach (var item in allergiesEntities)
                    {
                        allergies.Add(LuisHelper.GetNormalizedValueFromEntity(item));
                    }

                    return(await stepContext.NextAsync(allergies));
                }

                return(await stepContext.NextAsync());
            }

            var message = messagesService.Get(MessagesKey.Key.RemoveAllergy_Error.ToString()).Value;

            await stepContext.Context.SendActivityAsync(message);

            return(await stepContext.EndDialogAsync());
        }
Пример #4
0
        private async Task <DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var conversation = await conversationStateAccessor.GetAsync(stepContext.Context, () => new ConversationData());

            if (conversation.User != null)
            {
                return(await stepContext.NextAsync());
            }

            var reply = MessageFactory.Text(messagesService.Get(MessagesKey.Key.Profile_notlogged.ToString()).Value);

            var login = messagesService.Get(MessagesKey.Key.Login.ToString()).Value;

            var loginAction = new CardAction {
                Title = login, Value = login, Type = ActionTypes.ImBack
            };

            reply.SuggestedActions = new SuggestedActions {
                Actions = new List <CardAction> {
                    loginAction
                }
            };

            await stepContext.Context.SendActivityAsync(reply);

            return(await stepContext.EndDialogAsync());
        }
Пример #5
0
        private async Task <DialogTurnResult> NameStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var message = messagesService.Get(MessagesKey.Key.RecipeSearch_askname.ToString()).Value;

            var reply = MessageFactory.Text(message);

            var promptOptions = new PromptOptions
            {
                Prompt = reply,
                Style  = ListStyle.Auto
            };

            return(await stepContext.PromptAsync(recipePrompt, promptOptions, cancellationToken));
        }
Пример #6
0
        protected override async Task OnMembersAddedAsync(IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
        {
            var message = messagesService.Get(MessagesKey.Key.Welcome.ToString());

            foreach (var member in membersAdded)
            {
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text(message.Value), CancellationToken.None);

                    await turnContext.SendActivityAsync(HeroCards.Welcome((Activity)turnContext.Activity, messagesService));
                }
            }
        }
Пример #7
0
        private async Task <DialogTurnResult> SelectAllergiesStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var conversation = await conversationStateAccessor.GetAsync(stepContext.Context, () => new ConversationData());

            if (stepContext.Result != null && !stepContext.Result.ToString().Equals("Sí"))
            {
                var allergies = (List <string>)stepContext.Result;

                var added = messagesService.Get(MessagesKey.Key.AddAllergy_Added.ToString()).Value;

                await stepContext.Context.SendActivityAsync(string.Format(added, string.Join(", ", allergies)));

                conversation.User.Allergies.AddRange(allergies);

                conversation.User.Allergies = conversation.User.Allergies.Distinct().ToList();

                return(await stepContext.NextAsync());
            }

            var allAllergies = Luis.ValidAllergies;

            var message = messagesService.Get(MessagesKey.Key.AddAllergy_Inital.ToString()).Value;

            if (conversation.User.Allergies.Count() > 0)
            {
                conversation.User.Allergies.ForEach(x => allAllergies.Remove(x));
            }

            var options = new PromptOptions
            {
                Prompt  = MessageFactory.Text(message),
                Choices = ChoiceFactory.ToChoices(allAllergies),
                Style   = ListStyle.SuggestedAction
            };

            return(await stepContext.PromptAsync(AllergyPrompt, options, cancellationToken));
        }
Пример #8
0
        public static async Task <DialogTurnResult> Router(WaterfallStepContext stepContext, IStatePropertyAccessor <ConversationData> _conversationStateAccessor, IMessagesService messagesService)
        {
            var message = messagesService.Get(MessagesKey.Key.ResultIntent.ToString());

            var conversationData = await _conversationStateAccessor.GetAsync(stepContext.Context, () => new ConversationData());

            LuisResult lr = conversationData.LuisResult;

            var subdialog = GetSubdialog(lr);

            if (!string.IsNullOrEmpty(subdialog))
            {
                return(await stepContext.BeginDialogAsync(subdialog));
            }

            string nextDialog = string.Empty;

            switch (lr.TopScoringIntent.Intent)
            {
            case Luis.ProfileAddAllergy_Intent:
                nextDialog = nameof(AddAllergyDialog);
                break;

            case Luis.ProfileDeleteAllergy_Intent:
                nextDialog = nameof(DeleteAllergyDialog);
                break;

            case Luis.ProfileMyAllergies_Intent:
                nextDialog = nameof(ProfileDialog);
                break;

            case Luis.RecipeSearch_Intent:
                nextDialog = nameof(SearchRecipeDialog);
                break;

            default:
                await stepContext.Context.SendActivityAsync(string.Format(message.Value, lr.TopScoringIntent.Intent));

                break;
            }

            if (!string.IsNullOrEmpty(nextDialog))
            {
                return(await stepContext.BeginDialogAsync(nextDialog));
            }

            return(await stepContext.EndDialogAsync());
        }
Пример #9
0
        public static Attachment WelcomeLogin(IMessagesService messagesService)
        {
            string login = messagesService.Get(MessagesKey.Key.Login.ToString()).Value;

            var Buttons = new List <CardAction> {
                new CardAction(ActionTypes.ImBack, value: login, title: login)
            };

            var Images = new List <CardImage> {
                new CardImage {
                    Alt = url + "welcome_login.jpg", Url = url + "welcome_login.jpg"
                }
            };

            return(GetHeroCard(login, string.Empty, string.Empty, null, Buttons, Images));
        }
Пример #10
0
        private static Attachment WelcomeProfile(IMessagesService messagesService)
        {
            string profile = messagesService.Get(MessagesKey.Key.Profile.ToString()).Value;

            var Buttons = new List <CardAction> {
                new CardAction(ActionTypes.ImBack, value: profile, title: profile)
            };

            var Images = new List <CardImage> {
                new CardImage {
                    Alt = url + "welcome_login.jpg", Url = url + "welcome_login.jpg"
                }
            };

            return(GetHeroCard(profile, string.Empty, string.Empty, null, Buttons, Images));
        }
Пример #11
0
        private async Task <DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var conversationState = await conversationStateAccessor.GetAsync(stepContext.Context, () => new ConversationData());

            if (conversationState.User != null)
            {
                var message = messagesService.Get(MessagesKey.Key.Logged.ToString()).Value;

                await stepContext.Context.SendActivityAsync(string.Format(message, conversationState.User.Name));

                return(await stepContext.EndDialogAsync());
            }

            return(await stepContext.NextAsync());
        }
Пример #12
0
 public ActionResult Index()
 {
     return(View(_messagesService.Get()));
 }
Пример #13
0
 public IEnumerable <Messages> Get()
 {
     return(_messagesService.Get());
 }
Пример #14
0
        public static Activity Recipe(Activity activity, List <EdamamRecipe> recipes, IMessagesService messagesService)
        {
            var result = new List <Attachment>();

            var reply = activity.CreateReply();

            foreach (var item in recipes)
            {
                var body = new List <AdaptiveContainer>();

                #region Tittle
                var tittle = new AdaptiveTextBlock
                {
                    Text   = item.label,
                    Weight = AdaptiveTextWeight.Bolder,
                    Size   = AdaptiveTextSize.Medium
                };

                body.Add(new AdaptiveContainer {
                    Items = new List <AdaptiveElement> {
                        tittle
                    }
                });
                #endregion

                #region Imagen
                var imagen = new AdaptiveImage {
                    Url = new Uri(item.image), Size = AdaptiveImageSize.Large, AltText = item.label
                };

                body.Add(new AdaptiveContainer {
                    Items = new List <AdaptiveElement> {
                        imagen
                    }
                });
                #endregion

                #region Allergies
                string allergyText = string.Empty;

                foreach (var allergy in item.healthLabels)
                {
                    allergyText += messagesService.Get(allergy).Value;
                }

                var allergyEmojis = new AdaptiveTextBlock
                {
                    Text   = allergyText,
                    Weight = AdaptiveTextWeight.Bolder,
                    Size   = AdaptiveTextSize.Medium
                };

                body.Add(new AdaptiveContainer {
                    Items = new List <AdaptiveElement> {
                        allergyEmojis
                    }
                });
                #endregion

                #region Ingredients
                var ingredientContainer = new AdaptiveContainer()
                {
                    Items = new List <AdaptiveElement>()
                };

                ingredientContainer.Items.Add(new AdaptiveTextBlock {
                    Text = "Ingredientes:", Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Medium,
                });

                foreach (var ingredient in item.ingredientLines)
                {
                    ingredientContainer.Items.Add(new AdaptiveTextBlock {
                        Text = ingredient, Weight = AdaptiveTextWeight.Default, Size = AdaptiveTextSize.Default
                    });
                }

                body.Add(ingredientContainer);
                #endregion

                #region Button
                var action = new AdaptiveOpenUrlAction {
                    Title = "ver mas", Url = new Uri(item.url),
                };

                List <AdaptiveAction> actions = new List <AdaptiveAction> {
                    action
                };
                #endregion

                result.AddRange(CreateAdaptiveCard(body, actions));
            }

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;

            reply.Attachments = result;

            reply.Text = messagesService.Get(MessagesKey.Key.RecipeSearch_result.ToString()).Value;

            return(reply);
        }
Пример #15
0
 public async Task <List <Message> > GetListByMessageId(string messageId)
 {
     return(await _messagesService.Get(messageId));
 }
Пример #16
0
 public async Task <ActionResult <MessageDetailsResponse> > Get(int userId, int id)
 {
     return(await _serv.Get(userId, id));
 }