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

            stepContext.Values["SessionLang"] = userProfile.language;
            var reply = MessageFactory.Text("");

            if (userProfile.language.ToLower() == "english")
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Let's get to learning then!"));

                reply.Text = "Please select the subject that you want to explore.";
                List <dynamic>    unique_topics    = SaveConversationData.GetUniqueTopics();
                List <CardAction> childSuggestions = new List <CardAction>();
                foreach (string topic in unique_topics)
                {
                    childSuggestions.Add(new CardAction()
                    {
                        Title = topic, Type = ActionTypes.ImBack, Value = topic
                    });
                }
                childSuggestions.Add(new CardAction()
                {
                    Title = "Go Back", Type = ActionTypes.ImBack, Value = "Go Back"
                });
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = childSuggestions
                };
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text(await Translate.Translator("Let's get to learning then!", "ar")));

                reply.Text = await Translate.Translator("Please select the subject that you want to explore.", "ar");

                List <dynamic>    unique_topics    = SaveConversationData.GetUniqueTopics();
                List <CardAction> childSuggestions = new List <CardAction>();
                foreach (string topic in unique_topics)
                {
                    childSuggestions.Add(new CardAction()
                    {
                        Title = topic, Type = ActionTypes.ImBack, Value = topic
                    });
                }
                childSuggestions.Add(new CardAction()
                {
                    Title = await Translate.Translator("Go Back", "ar"), Type = ActionTypes.ImBack, Value = await Translate.Translator("Go Back", "ar")
                });
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = childSuggestions
                };
            }

            await stepContext.Context.SendActivityAsync(reply);

            return(await stepContext.PromptAsync("text", new PromptOptions { }, cancellationToken));
        }
예제 #2
0
        private async Task <DialogTurnResult> ProcessName(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Ok thanks! Now the boring stuff is out of the way we can get on to the good stuff!"));

            UserDataCollection userProfile = (UserDataCollection)stepContext.Values["User"];
            string             answer      = (string)stepContext.Result;

            userProfile.Name = answer;
            await SaveConversationData.SaveNewUser(stepContext.Context.Activity.From.Id, userProfile);

            await userStateAccessor.SetAsync(stepContext.Context, userProfile);

            AddDialog(new HowAreYou(userState));
            Debug.WriteLine("Sending to how");
            return(await stepContext.ReplaceDialogAsync(nameof(HowAreYou)));
        }
예제 #3
0
        private string[] CourseToInterest(List <UserCourse> past_courses)
        {
            string[]  subjects = new string[past_courses.Count];
            dynamic[] time     = new dynamic[past_courses.Count];
            for (int i = 0; i < past_courses.Count; i++)
            {
                string sub = SaveConversationData.CourseToSubject(past_courses[i].Name);
                subjects[i] = sub;
                time[i]     = past_courses[i].Date;
            }

            bool sorted = false;
            bool swap   = false;

            // bubble sort to sort the topics by most recent course taken (ie, most recent course topic at start of array)
            while (!sorted)
            {
                swap = false;
                dynamic last = time[0];
                for (int i = 1; i < subjects.Length; i++)
                {
                    if (time[i] < time[i - 1])
                    {
                        dynamic tmp = time[i];
                        time[i]         = time[i - 1];
                        time[i - 1]     = tmp;
                        tmp             = subjects[i];
                        subjects[i]     = subjects[i - 1];
                        subjects[i - 1] = tmp;
                        swap            = true;
                        break;
                    }
                }

                if (!swap)
                {
                    sorted = true;
                }
            }

            return(subjects);
        }
예제 #4
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)));
            }
        }
예제 #5
0
        private async Task <DialogTurnResult> StartDialogAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            Debug.WriteLine("in root");
            bool userExists = SaveConversationData.CheckUserExists(stepContext.Context.Activity.From.Id);

            // check if user is new (if so, send welcome message)
            if (!userExists)
            {
                AddDialog(new WelcomeDialog(userState));
                return(await stepContext.BeginDialogAsync(nameof(WelcomeDialog)));
            }
            else
            {
                UserDataCollection user = SaveConversationData.GetUserDataCollection(stepContext.Context.Activity.From.Id).Result;
                await _userStateAccessor.SetAsync(stepContext.Context, user);

                Debug.WriteLine("sending to how 1");
                AddDialog(new HowAreYou(userState));
                return(await stepContext.ReplaceDialogAsync(nameof(HowAreYou)));
            }
        }
예제 #6
0
        private async Task <DialogTurnResult> ConfirmCourse(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string             choice      = (string)stepContext.Result;
            UserDataCollection userProfile = await _userStateAccessor.GetAsync(stepContext.Context, () => new UserDataCollection());

            string     language = userProfile.language;
            CourseList course   = (CourseList)stepContext.Values["CurrentCourse"];

            if (choice.ToLower() == "take course")
            {
                UserCourse user_course = new UserCourse()
                {
                    Name       = course.courseName,
                    NameArabic = course.courseNameArabic,
                    Complete   = false,
                    Date       = DateTime.Now,
                    InProgress = false,
                    Queried    = false,
                    Rating     = 0,
                    Taken      = false
                };

                await SaveConversationData.SaveUserCourse(stepContext.Context.Activity.From.Id, user_course);

                AddDialog(new LearningDialog(userState, null));
                return(await stepContext.ReplaceDialogAsync(nameof(LearningDialog)));
            }
            else if (choice.ToLower() == "go back")
            {
                stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 3;
                return(await stepContext.NextAsync());
            }
            else
            {
                AddDialog(new LuisDialog(userState));
                return(await stepContext.ReplaceDialogAsync(nameof(LuisDialog)));
            }
        }
예제 #7
0
        private async Task <DialogTurnResult> CheckCourses(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            UserDataCollection user = await SaveConversationData.GetUserDataCollection(stepContext.Context.Activity.From.Id);

            List <UserCourse> courses        = user.PastCourses;
            UserCourse        current_course = new UserCourse();
            Random            rnd            = new Random();
            int  start  = user.PastCourses.Count - 1;
            int  random = 0;
            bool found  = false;

            while (start >= 0)
            {
                random         = rnd.Next(0, start);
                current_course = courses[random];
                courses.RemoveAt(random);
                courses.Add(current_course);
                start--;
                DateTime now  = DateTime.Now;
                TimeSpan diff = now - current_course.Date;

                if (!current_course.InProgress && !current_course.Taken && !current_course.Queried && diff.TotalDays >= 700)
                {
                    found = true;

                    break;
                }
            }

            if (found)
            {
                // return await stepContext.BeginDialogAsync(nameof(CheckCourseDialog));
                // stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
                // return await stepContext.NextAsync();
            }

            return(await stepContext.NextAsync());
        }
예제 #8
0
        private async Task <DialogTurnResult> StartAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            UserDataCollection user = await SaveConversationData.GetUserDataCollection(stepContext.Context.Activity.From.Id);

            UserDataCollection userProfile = await _userStateAccessor.GetAsync(stepContext.Context, () => new UserDataCollection());

            string            language     = userProfile.language;
            List <CourseList> course       = new List <CourseList>();
            List <string>     interest     = user.interests;
            List <UserCourse> past_courses = user.PastCourses;

            if (past_courses.Count > 0)
            {
                string[] course_to_sub = CourseToInterest(past_courses);

                interest.AddRange(course_to_sub);
            }

            if (interest.Count == 0)
            {
                // If no interest present, then recommend the most populaar course (or random course)
                // RecommendMostPopular();
                // return;
            }


            Random rnd = new Random();

            int restrictive = 0;
            List <CourseList> course_current = new List <CourseList>();

            // make sure all interests have a chance to be checked for courses
            // we will cull the list down later at random so it doesn't get too long for the user
            for (int i = 0; i < interest.Count; i++)
            {
                // only select element from all the 'live' elements
                int index = rnd.Next(i, interest.Count);

                string current_interest = interest[index];
                // if an interest has been 'used' move to the front of list, element is now dead and will not be considered by the rng
                interest.Insert(0, interest[index]);
                interest.RemoveAt(index + 1);

                course_current = SaveConversationData.TryMatchCourse(current_interest, user.accreditation, user.delivery, true, user.PreferedLang, user.education, restrictive);

                course.AddRange(course_current);

                if (i == interest.Count - 1 && course.Count == 0)
                {
                    if (restrictive == 3)
                    {
                        // we've had 3 failed passes, give up without finding any courses
                        // later we should instead recommend the most popular course (collabartive filtering)

                        break;
                    }
                    // first 'pass' has failed to find any courses, start a new 'pass' with less restrictive parameters
                    i = 0;
                    i--; // cancel out the i++
                    restrictive++;
                }
            }

            course = ReduceLength(course);

            // string language = context.UserData.GetValue<string>("inputLanguage");
            if (course.Count == 0)
            {
                //RecommendMostPopular();
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Sorry, I couldn't find any courses for you, but you can look through all the topics and subtopics I know about if you like."));

                //context.Done(true);
            }
            else
            {
                string text = "Based on some of the preferences you have shared with me, here are all the courses I think you might like";
                if (restrictive != 0)
                {
                    await stepContext.Context.SendActivityAsync(MessageFactory.Text("I couldn't find any courses that exactly matched you preferences so I had to leave out the following preferences during my search: "));

                    switch (restrictive)
                    {
                    case 1:
                        await stepContext.Context.SendActivityAsync("\u2022 Your education level");

                        goto case 2;

                    case 2:
                        await stepContext.Context.SendActivityAsync("\u2022 Your prefered language");

                        goto case 3;

                    case 3:
                        await stepContext.Context.SendActivityAsync("\u2022 Your self paced preference");

                        break;

                    default:
                        break;
                    }
                }
                // var reply = context.MakeMessage();

                var reply = stepContext.Context.Activity.CreateReply();
                List <CardAction> course_suggestions = new List <CardAction>();
                for (int i = 0; i < course.Count; i++)
                {
                    if (course[i] == null)
                    {
                        break;
                    }

                    if (language.ToLower() == "english")
                    {
                        course_suggestions.Add(new CardAction()
                        {
                            Title = course[i].courseName, Type = ActionTypes.ImBack, Value = course[i].courseName
                        });
                    }
                    else
                    {
                        course_suggestions.Add(new CardAction()
                        {
                            Title = course[i].courseNameArabic, Type = ActionTypes.ImBack, Value = course[i].courseNameArabic
                        });
                    }
                }
                if (language.ToLower() == "english")
                {
                    reply.Text = "Based on some of the preferences you have shared with me, here are all the courses I think you might like";
                    course_suggestions.Add(new CardAction()
                    {
                        Title = "Start Over", Type = ActionTypes.ImBack, Value = "Start Over"
                    });
                }
                else
                {
                    reply.Text = "استنادًا إلى بعض التفضيلات التي قمت بمشاركتها معي ، إليك جميع الدورات التدريبية التي قد تعجبك";
                    course_suggestions.Add(new CardAction()
                    {
                        Title = "ابدأ من جديد", Type = ActionTypes.ImBack, Value = "ابدأ من جديد"
                    });
                }
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = course_suggestions
                };
                await stepContext.Context.SendActivityAsync(reply);
            }

            return(await stepContext.EndDialogAsync());
        }
예제 #9
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());
        }
예제 #10
0
        private async Task <DialogTurnResult> DisplayCourses(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string choice = (string)stepContext.Result;

            Debug.WriteLine($"Choice: {choice}");
            string language = (string)stepContext.Values["SessionLang"];

            if (String.IsNullOrEmpty(choice))
            {
                choice = (string)stepContext.Values["currentSubTopic"];
            }
            else
            {
                stepContext.Values["currentSubTopic"] = choice;
            }
            if (choice.ToLower() == "go back")
            {
                stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 3;
                return(await stepContext.NextAsync());
            }
            List <CourseList> course_by_sub = SaveConversationData.MatchCourseBySubTopic(choice);

            if (course_by_sub.Count == 0)
            {
                AddDialog(new LuisDialog(userState));
                return(await stepContext.ReplaceDialogAsync(nameof(LuisDialog)));
            }

            var reply = MessageFactory.Text("");

            if (language.ToLower() == "english")
            {
                reply.Text = $"Here are all the courses I know on {choice}";

                List <CardAction> childSuggestions = new List <CardAction>();
                foreach (CourseList c in course_by_sub)
                {
                    childSuggestions.Add(new CardAction()
                    {
                        Title = c.courseName, Type = ActionTypes.ImBack, Value = c.courseName
                    });
                }
                childSuggestions.Add(new CardAction()
                {
                    Title = "Go Back", Type = ActionTypes.ImBack, Value = "Go Back"
                });
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = childSuggestions
                };
            }
            else
            {
                reply.Text = await Translate.Translator($"Here are all the courses I know on {choice}", "ar");

                List <CardAction> childSuggestions = new List <CardAction>();
                foreach (CourseList c in course_by_sub)
                {
                    childSuggestions.Add(new CardAction()
                    {
                        Title = await Translate.Translator(c.courseName, "ar"), Type = ActionTypes.ImBack, Value = await Translate.Translator(c.courseName, "ar")
                    });
                }
                childSuggestions.Add(new CardAction()
                {
                    Title = await Translate.Translator("Go Back", "ar"), Type = ActionTypes.ImBack, Value = await Translate.Translator("Go Back", "ar")
                });
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = childSuggestions
                };
            }
            await stepContext.Context.SendActivityAsync(reply);

            return(await stepContext.PromptAsync("text", new PromptOptions()));
        }
예제 #11
0
        private async Task <DialogTurnResult> DisplaySubTopics(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            UserDataCollection userProfile = await _userStateAccessor.GetAsync(stepContext.Context, () => new UserDataCollection());

            stepContext.Values["SessionLang"] = userProfile.language;

            string choice = (string)stepContext.Result;

            if (String.IsNullOrEmpty(choice) && stepContext.Values.ContainsKey("CurrentTopic"))
            {
                choice = (string)stepContext.Values["currentTopic"];
            }
            else if (String.IsNullOrEmpty(choice))
            {
                choice = start;
            }
            else
            {
                stepContext.Values["currentTopic"] = choice;
            }
            if (choice.ToLower() == "go back")
            {
                stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 3;
                return(await stepContext.NextAsync());
            }
            List <dynamic> unique_subtopics = SaveConversationData.GetUniqueSubTopics(choice);

            if (unique_subtopics.Count == 0)
            {
                AddDialog(new LuisDialog(userState));
                return(await stepContext.ReplaceDialogAsync(nameof(LuisDialog)));
            }
            var reply = MessageFactory.Text("");

            if (userProfile.language.ToLower() == "english")
            {
                reply.Text = "Selected the sub-topic you wish to explore";

                List <CardAction> childSuggestions = new List <CardAction>();
                foreach (string topic in unique_subtopics)
                {
                    childSuggestions.Add(new CardAction()
                    {
                        Title = topic, Type = ActionTypes.ImBack, Value = topic
                    });
                }
                childSuggestions.Add(new CardAction()
                {
                    Title = "Go Back", Type = ActionTypes.ImBack, Value = "Go Back"
                });
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = childSuggestions
                };
            }
            else
            {
                reply.Text = await Translate.Translator("Selected the sub-topic you wish to explore", "ar");

                List <CardAction> childSuggestions = new List <CardAction>();
                foreach (string topic in unique_subtopics)
                {
                    childSuggestions.Add(new CardAction()
                    {
                        Title = await Translate.Translator(topic, "ar"), Type = ActionTypes.ImBack, Value = await Translate.Translator(topic, "ar")
                    });
                }
                childSuggestions.Add(new CardAction()
                {
                    Title = await Translate.Translator("Go Back", "ar"), Type = ActionTypes.ImBack, Value = await Translate.Translator("Go Back", "ar")
                });
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = childSuggestions
                };
            }
            await stepContext.Context.SendActivityAsync(reply);

            return(await stepContext.PromptAsync("text", new PromptOptions()));
        }