예제 #1
0
        private async Task <DialogTurnResult> SelectCourse(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string             choice      = (string)stepContext.Result;
            UserDataCollection userProfile = await _userStateAccessor.GetAsync(stepContext.Context, () => new UserDataCollection());

            string     language = userProfile.language;
            CourseList course   = SaveConversationData.GetCourseByName(choice);

            stepContext.Values["CurrentCourse"] = course;
            if (course != null)
            {
                await DisplayFinalCourse(stepContext, course);

                return(await stepContext.NextAsync());
            }
            else
            {
                AddDialog(new LuisDialog(userState));
                return(await stepContext.ReplaceDialogAsync(nameof(LuisDialog)));
            }
        }
예제 #2
0
        private async Task <DialogTurnResult> DisplayFinalCourse(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string choice   = (string)stepContext.Result;
            string language = (string)stepContext.Values["SessionLang"];

            if (String.IsNullOrEmpty(choice))
            {
                choice = (string)stepContext.Values["currentCourse"];
            }
            else
            {
                stepContext.Values["currentCourse"] = choice;
            }
            if (choice.ToLower() == "go back")
            {
                stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 3;
                return(await stepContext.NextAsync());
            }
            CourseList course = SaveConversationData.GetCourseByName(choice);

            if (course == null)
            {
                return(await stepContext.ReplaceDialogAsync(nameof(LuisDialog)));
            }
            string courseInfo = "";
            var    options    = MessageFactory.Text("");

            if (language == "english")
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Good choice! This is what I know about the course {course.courseName}"));

                if (course.selfPaced)
                {
                    courseInfo += "This is a self-paced course, taking approximately " + course.approxDuration.ToString() + " hours\n\n";
                }
                else
                {
                    courseInfo += "This is a scheduled-learning course, taking approximately " + course.approxDuration.ToString() + " hours\n\n";
                }
                if (course.accreditationOption)
                {
                    courseInfo += "There is an option for accreditation available for this course, although a charge may apply\n\n";
                }
                else
                {
                    courseInfo += "There is no option for accreditation available\n\n";
                }
                if (course.financialAid)
                {
                    courseInfo += "Financial aid is available and can be applied for\n\n";
                }
                else
                {
                    courseInfo += "There is no financial aid available\n\n";
                }
                courseInfo += "The course description is here:\n";
                courseInfo += course.description;
                await stepContext.Context.SendActivityAsync(courseInfo);
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text(await Translate.Translator($"Good choice! This is what I know about the course {course.courseName}", "ar")));

                courseInfo = "";
                if (course.selfPaced)
                {
                    courseInfo += await Translate.Translator("This is a self-paced course, taking approximately " + course.approxDuration.ToString() + " hours\n\n", "ar");
                }
                else
                {
                    courseInfo += await Translate.Translator("This is a scheduled-learning course, taking approximately " + course.approxDuration.ToString() + " hours\n\n", "ar");
                }
                if (course.accreditationOption)
                {
                    courseInfo += await Translate.Translator("There is an option for accreditation available for this course, although a charge may apply\n\n", "ar");
                }
                else
                {
                    courseInfo += await Translate.Translator("There is no option for accreditation available\n\n", "ar");
                }
                if (course.financialAid)
                {
                    courseInfo += await Translate.Translator("Financial aid is available and can be applied for\n\n", "ar");
                }
                else
                {
                    courseInfo += await Translate.Translator("There is no financial aid available\n\n", "ar");
                }
                courseInfo += await Translate.Translator("The course description is here:\n", "ar");

                courseInfo += course.description;

                await stepContext.Context.SendActivityAsync(courseInfo);

                options.Text = await Translate.Translator("Would you like to take this course?", "ar");

                options.SuggestedActions = new SuggestedActions()
                {
                    Actions = new List <CardAction>()
                    {
                        new CardAction()
                        {
                            Title = await Translate.Translator("Take Course", "ar"), Type = ActionTypes.ImBack, Value = await Translate.Translator("Take Course", "ar")
                        },
                        new CardAction()
                        {
                            Title = await Translate.Translator("Go Back", "ar"), Type = ActionTypes.ImBack, Value = await Translate.Translator("Go Back", "ar")
                        }
                    }
                };
            }
            await stepContext.Context.SendActivityAsync(courseInfo);

            options.Text = "Would you like to take this course?";

            options.SuggestedActions = new SuggestedActions()
            {
                Actions = new List <CardAction>()
                {
                    new CardAction()
                    {
                        Title = "Take Course", Type = ActionTypes.ImBack, Value = "Take Course"
                    },
                    new CardAction()
                    {
                        Title = "Go Back", Type = ActionTypes.ImBack, Value = "Go Back"
                    }
                }
            };

            await stepContext.Context.SendActivityAsync(options);

            return(await stepContext.EndDialogAsync());
        }