Beispiel #1
0
        private LessonPlan.LessonPlan LoadLessonPlan()
        {
            string lessonPlanAPI = ConfigurationManager.AppSettings["LessonServiceAPI"];

            LessonPlan.LessonPlan lessonPlan = new LessonPlan.LessonPlan();
            List <BotCourseModel> lessons    = LessonPlanHelper.GetLessonPlanAsync <List <BotCourseModel> >(lessonPlanAPI).Result;

            foreach (BotCourseModel lesson in lessons)
            {
                lessonPlan.Lessons.Add(new Lesson()
                {
                    LessonTitle = lesson.Name, currentTopic = lesson.AssignmentId, APIUrl = lesson.APIUrl
                });
            }

            return(lessonPlan);
        }
        private async Task <bool> PostAdaptiveCard(IDialogContext context)
        {
            ExtendedWordCollection lessons = LessonPlanHelper.GetLessonPlanAsync <ExtendedWordCollection>(lesson.APIUrl).Result;

            foreach (var word in lessons.words)
            {
                Topic topic = new Topic()
                {
                    Question       = "Please tell me what the picture shows?",
                    CorrectAnswers = new List <string>()
                    {
                        word.word
                    },
                    CorrectAnswerBotResponse = "Correct! Now, can you type the word?",
                    WrongAnswerBotResponse   = "Sorry, incorrect, try again",
                    PronounciationPhrase     = "Good work! Here is how you say it, Repeat after me.",
                    ImageUrl = String.Format(ConfigurationManager.AppSettings["WordImageAPI"], word.image)
                };

                lesson.Topics.Add(topic);
            }

            var nextTopic = lesson.Topics.ElementAtOrDefault(lesson.currentTopic);

            if (nextTopic == null)
            {
                return(false);
            }

            List <ActionBase> answerOptions = PopulateActionBasesFromAnswerOptions(lessons.words, nextTopic.CorrectAnswers.FirstOrDefault());

            AdaptiveCard adaptiveCard = new AdaptiveCard()
            {
                Body = new List <CardElement>()
                {
                    new TextBlock()
                    {
                        Text = nextTopic.Question,
                        Wrap = true
                    },
                    new Image()
                    {
                        Size = ImageSize.Large,
                        Url  = nextTopic.ImageUrl,
                        HorizontalAlignment = HorizontalAlignment.Center
                    },
                },
                Actions = answerOptions
            };

            Attachment attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = adaptiveCard
            };

            var reply = context.MakeMessage();

            reply.Attachments.Add(attachment);

            await context.PostAsync(reply, CancellationToken.None);

            return(true);
        }