Example #1
0
        /// <summary>
        /// Asks the user to type a new question.
        /// </summary>
        /// <param name="stepContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <DialogTurnResult> AskForQuestionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;
            _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);
            var prompt     = dialogsMUI.AddQuestionDictionary["prompt"]; // Type Your question, please:
            var reprompt   = dialogsMUI.AddQuestionDictionary["reprompt"];

            var options = new PromptOptions()
            {
                Prompt      = MessageFactory.Text(prompt),
                RetryPrompt = MessageFactory.Text(reprompt),
                Style       = ListStyle.SuggestedAction
            };

            var message = options.Prompt.Text;
            var sender  = "bot";
            var time    = stepContext.Context.Activity.Timestamp.Value;

            _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

            return(await stepContext.PromptAsync(nameof(TextPrompt), options, cancellationToken));
        }
Example #2
0
        /// <summary>
        /// Asks the user did we finish dialog.
        /// </summary>
        /// <param name="stepContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <DialogTurnResult> DidWeFinishStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;
            var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);
            var choices    = new List <Choice>();

            var leaveFeedback = dialogsMUI.FinishDictionary["leave"];    // Leave feedback
            var answered      = dialogsMUI.FinishDictionary["answered"]; // Did I answer all your questions?

            {
                choices.Add(new Choice(dialogsMUI.MainDictionary["yes"]));
                choices.Add(new Choice(leaveFeedback));
                choices.Add(new Choice(dialogsMUI.MainDictionary["no"]));
            }

            var options = new PromptOptions()
            {
                Prompt  = MessageFactory.Text(answered),
                Choices = choices,
                Style   = ListStyle.SuggestedAction
            };

            var message = options.Prompt.Text;
            var sender  = "bot";
            var time    = stepContext.Context.Activity.Timestamp.Value;

            _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

            return(await stepContext.PromptAsync(nameof(ChoicePrompt), options, cancellationToken));
        }
Example #3
0
        /// <summary>
        /// Asks the user to choose some course.
        /// </summary>
        /// <param name="stepContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <DialogTurnResult> AskCourseStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;
            var courses = DecisionMaker.GetCourses(_DialogInfo.Language);

            {
                var choices = new List <Choice>();

                foreach (var course in courses)
                {
                    choices.Add(new Choice(course.Name));
                }
                var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);
                var prompt     = dialogsMUI.CoursesDictionary["prompt"];// "What you are interested in?";
                var reprompt   = dialogsMUI.CoursesDictionary["reprompt"];

                var options = new PromptOptions()
                {
                    Prompt      = MessageFactory.Text(prompt),
                    RetryPrompt = MessageFactory.Text(reprompt),
                    Choices     = choices,
                    Style       = ListStyle.SuggestedAction//.HeroCard
                };

                var message = options.Prompt.Text;
                var sender  = "bot";
                var time    = stepContext.Context.Activity.Timestamp.Value;

                _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

                return(await stepContext.PromptAsync(nameof(ChoicePrompt), options, cancellationToken));
            }
        }
Example #4
0
        /// <summary>
        /// Asks the user to select question/answer.
        /// </summary>
        /// <param name="stepContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <DialogTurnResult> AskSelectQAStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;

            var _QAs       = DecisionMaker.GetQAs(_DialogInfo.Language);
            var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);
            var prompt     = dialogsMUI.QAsDictionary["prompt"];
            var reprompt   = dialogsMUI.QAsDictionary["reprompt"];

            var choices = new List <Choice>();

            foreach (var q in _QAs.Keys)
            {
                choices.Add(new Choice(q));
            }

            var options = new PromptOptions()
            {
                Prompt      = MessageFactory.Text(prompt),   // Choose a question:
                Choices     = choices,
                RetryPrompt = MessageFactory.Text(reprompt), // Try one more time, please:
                Style       = ListStyle.SuggestedAction
            };

            var message = options.Prompt.Text;
            var sender  = "bot";
            var time    = stepContext.Context.Activity.Timestamp.Value;

            _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

            return(await stepContext.PromptAsync(nameof(ChoicePrompt), options, cancellationToken));
        }
Example #5
0
        private async Task <DialogTurnResult> FirstStepAsync(WaterfallStepContext stepContext,
                                                             CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;
            var dialogsMUI            = DecisionMaker.GetDialogsMui(_DialogInfo.Language);
            var conversationReference = stepContext.Context.Activity.GetConversationReference();

            userSubscription = _subscriptionManager.GetUserSubscriptions(conversationReference.User.Id);

            if (userSubscription != null && userSubscription.Count != 0)
            {
                var subs = userSubscription.ToList();

                await stepContext.Context.SendActivityAsync(MessageFactory.Text(dialogsMUI.SubscriptionDictionary["subscriptions"]));

                var message = "";

                for (var i = 0; i < subs.Count; i++)
                {
                    var courseInfo = _subscriptionManager.GetCourseInfo(subs[i].CourseId.ToString());
                    message +=
                        $"\n\n**{i+1}** {dialogsMUI.SubscriptionDictionary["name"]} {courseInfo.Name}," +
                        $" {dialogsMUI.SubscriptionDictionary["registrationStarts"]} {courseInfo.RegistrationStartDate.ToShortDateString()}," +
                        $" {dialogsMUI.SubscriptionDictionary["courseStarts"]} {courseInfo.StartDate.Date.ToShortDateString()};";
                }

                await stepContext.Context.SendActivityAsync(MessageFactory.Text(message), cancellationToken);

                var unsubQuestion = dialogsMUI.SubscriptionDictionary["unsubQuestion"];

                return(await stepContext.PromptAsync(nameof(ChoicePrompt),
                                                     new PromptOptions()
                {
                    Prompt = MessageFactory.Text(unsubQuestion),
                    Choices = new List <Choice> {
                        new Choice(dialogsMUI.MainDictionary["yes"]), new Choice(dialogsMUI.MainDictionary["no"])
                    }
                },
                                                     cancellationToken));
            }

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(dialogsMUI.SubscriptionDictionary["noSubs"]), cancellationToken);

            return(await stepContext.ReplaceDialogAsync(nameof(ChooseOptionDialog), "begin", cancellationToken));
        }
Example #6
0
        /// <summary>
        /// Asks the user what to do next.
        /// </summary>
        /// <param name="stepContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <DialogTurnResult> FirstStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;

            _chooseOptionList = DecisionMaker.GetChooseOptions(_DialogInfo.Language);

            var choices = new List <Choice>();

            var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);

            var mainMenu      = dialogsMUI.ChooseOptionDictionary["mainMenu"];      // "Main Menu";
            var sendEmail     = dialogsMUI.ChooseOptionDictionary["sendEmail"];     // "Send conversation to email";
            var subscriptions = dialogsMUI.ChooseOptionDictionary["subscriptions"]; // "My subscriptions";

            var ch1 = mainMenu;
            var ch2 = sendEmail;
            var ch3 = subscriptions;
            {
                choices.Add(new Choice(ch1));
                choices.Add(new Choice(ch2));
                choices.Add(new Choice(ch3));
            }
            var stepOptions = stepContext.Options.ToString().ToLower();

            if (stepOptions == "qa")
            {
                var ch4 = dialogsMUI.ChooseOptionDictionary["questions/answers"]; // "Questions/Answers";
                var ch5 = dialogsMUI.ChooseOptionDictionary["proposeQuestion"];;  // "Propose a new question";

                choices.Add(new Choice(ch4));
                choices.Add(new Choice(ch5));
            }

            {
                var ch6 = dialogsMUI.ChooseOptionDictionary["endDialog"]; // "End dialog";
                choices.Add(new Choice(ch6));
            }

            var msg      = dialogsMUI.ChooseOptionDictionary["next"]; // "What to do next?";
            var retryMsg = dialogsMUI.MainDictionary["reprompt"];     // "Try one more time, please:";

            var options = new PromptOptions()
            {
                Prompt      = MessageFactory.Text(msg),
                RetryPrompt = MessageFactory.Text(retryMsg),
                Choices     = choices,
                Style       = ListStyle.SuggestedAction
            };

            var message = options.Prompt.Text;
            var sender  = "bot";
            var time    = stepContext.Context.Activity.Timestamp.Value;

            _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

            return(await stepContext.PromptAsync(nameof(ChoicePrompt), options, cancellationToken));
        }
Example #7
0
        /// <summary>
        /// Generates new QuestionAndAnswerModel and returns ChoicePrompt
        /// or passes on not modified QuestionAndAnswerModel to the next step.
        /// </summary>
        /// <param name="stepContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <DialogTurnResult> GetCountryStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;
            var _country = new Country();



            {
                var _countries = DecisionMaker.GetCountries(_DialogInfo.Language);
                var choices    = new List <Choice>();

                foreach (var country in _countries)
                {
                    choices.Add(new Choice(country.CountryName));
                }

                var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);

                var prompt   = dialogsMUI.LocationDictionary["promptCountry"]; // "Choose needed country, please.";
                var reprompt = dialogsMUI.MainDictionary["reprompt"];          // "Try one more time, please:";

                var options = new PromptOptions()
                {
                    Prompt      = MessageFactory.Text(prompt),
                    RetryPrompt = MessageFactory.Text(reprompt),
                    Choices     = choices,
                    Style       = ListStyle.SuggestedAction
                };

                var message = options.Prompt.Text;
                var sender  = "bot";
                var time    = stepContext.Context.Activity.Timestamp.Value;

                _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

                //await _dialogInfoStateProperty.SetAsync(stepContext.Context, _DialogInfo);

                return(await stepContext.PromptAsync(nameof(ChoicePrompt), options, cancellationToken));
            }
        }
Example #8
0
        private async Task <DialogTurnResult> CheckForEmailStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;
            var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);

            userEmail = _db.GetUserEmail(_DialogInfo);

            if (!string.IsNullOrEmpty(userEmail))
            {
                var promptMessage = $"{dialogsMUI.MailingDictionary["prompt"]}\n**{userEmail}**";

                var message = promptMessage;
                var sender  = "bot";
                var time    = stepContext.Context.Activity.Timestamp.Value;

                _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

                return(await stepContext.PromptAsync(nameof(ChoicePrompt),
                                                     new PromptOptions()
                {
                    Prompt = MessageFactory.Text(promptMessage),
                    Choices = new List <Choice> {
                        new Choice(dialogsMUI.MainDictionary["yes"]), new Choice(dialogsMUI.MainDictionary["no"])
                    }
                },
                                                     cancellationToken));
            }

            return(await stepContext.NextAsync("í³", cancellationToken));
        }
Example #9
0
        private async Task <DialogTurnResult> ShowHelpAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);
            var helpMsg    = dialogsMUI.HelpDictionary["commands"];
            var message    = string.Join("\n\n", helpMsg);

            await stepContext.Context.SendActivityAsync(message);

            var sender = "bot";
            var time   = stepContext.Context.Activity.Timestamp.Value;

            _Logger.LogMessage(message, sender, time, _DialogInfo.DialogId);

            return(await stepContext.ReplaceDialogAsync(nameof(ChooseOptionDialog), "begin",
                                                        cancellationToken : cancellationToken));
        }
Example #10
0
        /// <summary>
        /// Generates new QuestionAndAnswerModel and returns ChoicePrompt
        /// or passes on not modified QuestionAndAnswerModel to the next step.
        /// </summary>
        /// <param name="stepContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <DialogTurnResult> GetMenuItemsStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);//new DialogState()

            _DialogInfo.LastDialogName = this.Id;
            {
                _menuItems = DecisionMaker.GetMainMenuItems(_DialogInfo.Language);
                //_menuItemsNeutral = DecisionMaker.GetMainMenuItemsNeutral();

                var choices = new List <Choice>();

                foreach (var item in _menuItems)
                {
                    choices.Add(new Choice(item.Name));
                }

                var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);

                var prompt = dialogsMUI.MainMenuDictionary["prompt"];// "What you are interested in?";

                var options = new PromptOptions()
                {
                    Prompt      = MessageFactory.Text(prompt),
                    RetryPrompt = MessageFactory.Text(dialogsMUI.MainDictionary["reprompt"]),
                    Choices     = choices,
                    Style       = ListStyle.SuggestedAction
                };

                var message = options.Prompt.Text;
                var sender  = "bot";
                var time    = stepContext.Context.Activity.Timestamp.Value;

                _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

                return(await stepContext.PromptAsync(nameof(ChoicePrompt), options, cancellationToken));
            }
        }
Example #11
0
        private async Task <DialogTurnResult> FirstStepAsync(WaterfallStepContext stepContext,
                                                             CancellationToken cancellationToken)
        {
            var _DialogInfo = await _dialogInfoStateProperty.GetAsync(stepContext.Context);

            _DialogInfo.LastDialogName = this.Id;

            userEmail = _db.GetUserEmail(_DialogInfo);
            var dialogsMUI = DecisionMaker.GetDialogsMui(_DialogInfo.Language);

            if (string.IsNullOrEmpty(userEmail))
            {
                var msg      = dialogsMUI.EmailDictionary["msg"];
                var prompt   = dialogsMUI.EmailDictionary["prompt"];//Хочете додати email?
                var reprompt = dialogsMUI.MainDictionary["reprompt"];
                var yes      = dialogsMUI.MainDictionary["yes"];
                var no       = dialogsMUI.MainDictionary["no"];

                var optionsAddEmail = new PromptOptions()
                {
                    Prompt      = MessageFactory.Text(prompt),
                    RetryPrompt = MessageFactory.Text(reprompt),
                    Choices     = new List <Choice> {
                        new Choice(yes), new Choice(no)
                    },
                };

                var messageAdd = msg + "\n" + optionsAddEmail.Prompt.Text;
                var senderAdd  = "bot";
                var timeAdd    = stepContext.Context.Activity.Timestamp.Value;

                _myLogger.LogMessage(messageAdd, senderAdd, timeAdd, _DialogInfo.DialogId);

                await stepContext.Context.SendActivityAsync(MessageFactory.Text(msg), cancellationToken);

                return(await stepContext.PromptAsync(nameof(ChoicePrompt), optionsAddEmail, cancellationToken));
            }

            var currentEmail = dialogsMUI.EmailDictionary["currentEmail"];
            await stepContext.Context.SendActivityAsync(MessageFactory.Text($"{currentEmail} **{userEmail}**"));

            var promptNext  = dialogsMUI.EmailDictionary["promptNext"];  //Що Ви хочете зробити?
            var changeEmail = dialogsMUI.EmailDictionary["changeEmail"]; //Змінити адресу
            var deleteEmail = dialogsMUI.EmailDictionary["deleteEmail"]; //Видалити пошту
            var back        = dialogsMUI.EmailDictionary["back"];        //Назад

            var optionsManageEmail = new PromptOptions()
            {
                Prompt      = MessageFactory.Text(promptNext),
                RetryPrompt = MessageFactory.Text(dialogsMUI.MainDictionary["reprompt"]),
                Choices     = new List <Choice>
                {
                    new Choice(changeEmail),
                    new Choice(deleteEmail),
                    new Choice(back)
                },
                Style = ListStyle.SuggestedAction
            };

            var message = optionsManageEmail.Prompt.Text;
            var sender  = "bot";
            var time    = stepContext.Context.Activity.Timestamp.Value;

            _myLogger.LogMessage(message, sender, time, _DialogInfo.DialogId);

            return(await stepContext.PromptAsync(nameof(ChoicePrompt), optionsManageEmail, cancellationToken));
        }
        public async Task Get()
        {
            var courses = _db.Courses.Where(s => s.RegistrationStartDate.ToShortDateString() == DateTime.Today.ToShortDateString());

            if (courses.Any())
            {
                foreach (var course in courses)
                {
                    // This is for notification on email and chat
                    var matchedCourses = _db.UserCourses.Where(item => item.CourseId == course.Id);

                    if (matchedCourses.Any())
                    {
                        foreach (var matchedCourse in matchedCourses)
                        {
                            var user = _db.User.First(u => u.Id == matchedCourse.UserId);

                            if (!matchedCourse.Notified)
                            {
                                var language     = user.Language;
                                var dialogsMUI   = _decisionMaker.GetDialogsMui(language);
                                var courseByName = _decisionMaker.GetCourses(language)
                                                   .First(item => item.Name == matchedCourse.Course.Name);

                                var msg = $"<h3>{dialogsMUI.SubscriptionDictionary["title"]}</h3> <br>" +
                                          $"<h5>{dialogsMUI.SubscriptionDictionary["info"]} {matchedCourse.Course.Name}," +
                                          $" {dialogsMUI.SubscriptionDictionary["registrationStarts"]} {matchedCourse.Course.RegistrationStartDate.ToShortDateString()}" +
                                          $" {dialogsMUI.SubscriptionDictionary["courseStarts"]} {matchedCourse.Course.StartDate.ToShortDateString()}. <br> </h5>" +
                                          $"{courseByName.Resources}";

                                // Notifying into the chat
                                if (!string.IsNullOrEmpty(user.ConversationReference))
                                {
                                    message = $"**{dialogsMUI.SubscriptionDictionary["subject"]}**\n\n" +
                                              $"{dialogsMUI.SubscriptionDictionary["title"]}\n\n" +
                                              $"{dialogsMUI.SubscriptionDictionary["info"]} {matchedCourse.Course.Name}," +
                                              $" {dialogsMUI.SubscriptionDictionary["registrationStarts"]} {matchedCourse.Course.RegistrationStartDate.ToShortDateString()}" +
                                              $" {dialogsMUI.SubscriptionDictionary["courseStarts"]} {matchedCourse.Course.StartDate.ToShortDateString()}.\n\n" +
                                              $"{courseByName.Resources}";

                                    var conversationReference = JsonConvert.DeserializeObject <ConversationReference>(user.ConversationReference);
                                    await((BotAdapter)_adapter).ContinueConversationAsync(_appId, conversationReference, BotCallback, default(CancellationToken));
                                }

                                message = string.Empty;

                                // Notifying into the mail
                                if (!string.IsNullOrEmpty(user.Email))
                                {
                                    await _emailSender.SendEmailAsync(matchedCourse.User.Email,
                                                                      dialogsMUI.SubscriptionDictionary["subject"],
                                                                      msg);
                                }

                                matchedCourse.Notified = true;
                                _db.SaveChanges();

                                Console.WriteLine("-----------------\n" +
                                                  "Notification sent!!!\n" +
                                                  "-----------------");
                            }
                        }
                    }
                }
            }
        }