private async Task AfterAppointmentDateTimeChoosen(IDialogContext context, IAwaitable <AppointmentRequest> result)
        {
            try
            {
                var appointmentRequest = await result;

                if (appointmentRequest.StartDateTime != DateTime.MinValue)
                {
                    var promptTodayConfirmation = new PromptDialog.PromptConfirm(
                        $"Can you confirm your appointment with {appointmentRequest.RequestedBarber} on {string.Format("{0} {1:m} at {1:t}", appointmentRequest.StartDateTime.ToString("ddd"), appointmentRequest.StartDateTime)}?",
                        "Sorry I didn't understand you. Can you choose an option below?",
                        2);
                    request.CopyFrom(appointmentRequest);
                    context.Call(promptTodayConfirmation, this.AfterAppointmentConfirmation);
                }
                else
                {
                    request.ResetDateTime();
                    context.Done(false);
                }
            }
            catch (TooManyAttemptsException)
            {
                context.Done(false);
            }
        }
Exemplo n.º 2
0
        private async Task AfterLocationCollected(IDialogContext context, IAwaitable <Place> result)
        {
            Place place = await result;

            if (place != null)
            {
                var    address = place.GetPostalAddress();
                string name    = address != null ?
                                 $"{address.StreetAddress}, {address.Locality}, {address.Region}, {address.Country} ({address.PostalCode})" :
                                 "the pinned location";

                if (address.PostalCode.ToUpper().StartsWith("L3"))
                {
                    await context.PostAsync($"It looks like there is an on going incident at the moment which is affecting {name}.  Our engineers have reported that they have found the cause of the problem and expect to have it resolved within the next 2 - 4 hours.");

                    var dialog = new PromptDialog.PromptConfirm("Would you like me to update you when new information about this incident becomes available?", "Would you like me to update you when new information about this incident becomes available? You can say Yes or No", 3);
                    context.Call(dialog, AfterIncidentUpdateCheck);
                }
                else
                {
                    await context.PostAsync($"It looks like there are no incidents affecting {name} right now");

                    context.Wait(MessageReceived);
                }
            }
            else
            {
                await context.PostAsync("OK, cancelled");

                context.Wait(MessageReceived);
            }
        }
Exemplo n.º 3
0
            async Task IDialog <bool> .StartAsync(IDialogContext context)
            {
                var confirm = new PromptDialog.PromptConfirm(options);

                context.Call(confirm, AfterConfirm);
            }
        protected override async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> activity)
        {
            try
            {
                var message       = await activity;
                var quitCondition = message.Text.ToLower().Contains("cancel");

                if (quitCondition)
                {
                    request.ResetDateTime();
                    context.Done(request);
                }
                else
                {
                    var recognizer    = new DateTimeRecognizer(message.Locale, DateTimeOptions.None, false);
                    var dateTimeModel = recognizer.GetDateTimeModel();
                    var results       = dateTimeModel.Parse(message.Text, PSTDateTime);

                    if (!results.Any())
                    {
                        request.ResetDateTime();
                        await context.PostAsync("Sorry, I didn't understand you, can you try again with a date and time?", message.Locale);

                        context.Wait(MessageReceivedAsync);
                        return;
                    }

                    List <Dictionary <string, string> > modelValuesDictionary = (List <Dictionary <string, string> >)results[0].Resolution["values"];
                    var modelResult = modelValuesDictionary.First();
                    if (modelResult["type"] == "time")
                    {
                        var parsedTime = DateTime.Parse(modelResult["value"]);
                        request.StartDateTime = parsedTime;
                        timeValue             = parsedTime.ToShortTimeString();
                        var response = await request.IsAvailableAsync();

                        if (response.IsAvailable)
                        {
                            var promptTodayConfirmation = new PromptDialog.PromptConfirm(
                                $"I assumed today and found {timeValue}, everything looks available at the moment but can confirm you that's what you meant?",
                                "Sorry I didn't understand you. Can you choose an option below?",
                                2);
                            context.Call(promptTodayConfirmation, this.AfterTodayConfirmation);
                        }
                        else
                        {
                            if (response.SuggestedRequest == null)
                            {
                                await context.PostAsync($"I looked at {request.ToSuggestionString()}, I couldn't give you a suggested appointment. {response.FormattedValidationMessage()} Can you suggest both date and time which would work for you?", context.Activity.AsMessageActivity().Locale);
                            }
                            else
                            {
                                suggestedAppointmentRequest = response.SuggestedRequest;
                                var promptSuggestionConfirmation = new PromptDialog.PromptConfirm(
                                    response.FormattedValidationMessage(),
                                    "Sorry I didn't understand you. Can you choose an option below?",
                                    2);
                                context.Call(promptSuggestionConfirmation, this.AfterSuggestionConfirmation);
                            }
                        }
                    }
                    else if (modelResult["type"] == "datetime")
                    {
                        var parsedTime = DateTime.Parse(modelResult["value"]);
                        parsedTime = DateTime.SpecifyKind(parsedTime, DateTimeKind.Local);
                        if (parsedTime.Date.Year < PSTDate.Year)
                        {
                            parsedTime = new DateTime(PSTDate.Year, parsedTime.Month, parsedTime.Day, parsedTime.Hour, parsedTime.Minute, 0);
                        }

                        if (parsedTime.Date < PSTDate)
                        {
                            // fix bias for past days of the week
                            var fix = parsedTime.Next(parsedTime.DayOfWeek);
                            parsedTime = new DateTime(PSTDate.Year, fix.Month, fix.Day, parsedTime.Hour, parsedTime.Minute, 0);
                        }

                        if (parsedTime.Date == PSTDate && parsedTime.Hour < PSTDateTime.Hour &&
                            (parsedTime.Hour >= 1 || parsedTime.Hour <= 9))
                        {
                            // fix bias for time of the day
                            parsedTime = parsedTime.AddHours(12);
                        }

                        timeValue             = parsedTime.ToShortTimeString();
                        request.StartDateTime = parsedTime;
                        var response = await request.IsAvailableAsync();

                        if (response.IsAvailable)
                        {
                            await context.PostAsync("Great, that will work.", message.Locale);

                            context.Done(request);
                        }
                        else
                        {
                            if (response.SuggestedRequest == null)
                            {
                                await context.PostAsync($"I looked at {request.ToSuggestionString()}, I couldn't give you a suggested appointment. {response.FormattedValidationMessage()} Can you suggest both date and time which would work for you?", context.Activity.AsMessageActivity().Locale);
                            }
                            else
                            {
                                suggestedAppointmentRequest = response.SuggestedRequest;
                                var promptSuggestionConfirmation = new PromptDialog.PromptConfirm(
                                    response.FormattedValidationMessage(),
                                    "Sorry I didn't understand you. Can you choose an option below?",
                                    2);
                                context.Call(promptSuggestionConfirmation, this.AfterSuggestionConfirmation);
                            }
                        }
                    }
                    else if (modelResult["type"] == "date")
                    {
                        var parsedDate = DateTime.Parse(modelResult["value"]);
                        if (parsedDate.Year < PSTDate.Year)
                        {
                            parsedDate = parsedDate.SafeCreateFromValue(PSTDate.Year, parsedDate.Month, parsedDate.Day);
                        }

                        if (parsedDate < PSTDate)
                        {
                            // fix bias for past Saturday/Sunday
                            var fix = parsedDate.Next(parsedDate.DayOfWeek);
                            parsedDate = fix.SafeCreateFromValue(PSTDate.Year, fix.Month, fix.Day);
                        }

                        request.StartDateTime = new DateTime(parsedDate.Year, parsedDate.Month, parsedDate.Day, PSTDateTime.Hour, PSTDateTime.Minute, 0, DateTimeKind.Local);
                        var response = await request.IsAvailableAsync();

                        if (response.IsAvailable)
                        {
                            var promptTodayConfirmation = new PromptDialog.PromptConfirm(
                                $"I found {request.ToSuggestionString()}, everything looks available at the moment but can you confirm that's what you meant?",
                                "Sorry I didn't understand you. Can you choose an option below?",
                                2);
                            context.Call(promptTodayConfirmation, this.AfterTimeConfirmation);
                        }
                        else
                        {
                            if (response.SuggestedRequest == null)
                            {
                                await context.PostAsync($"I looked at {request.ToSuggestionString()}, I couldn't give you a suggested appointment. Can you suggest both date and time which would work for you?", context.Activity.AsMessageActivity().Locale);
                            }
                            else
                            {
                                suggestedAppointmentRequest = response.SuggestedRequest;
                                await context.PostAsync($"I looked at {request.ToSuggestionString()}", context.Activity.AsMessageActivity().Locale);

                                var promptSuggestionConfirmation = new PromptDialog.PromptConfirm(
                                    response.FormattedValidationMessage().Replace("Sorry", "But sorry"),
                                    "Sorry I didn't understand you. Can you choose an option below?",
                                    2);
                                context.Call(promptSuggestionConfirmation, this.AfterSuggestionConfirmation);
                            }
                        }
                    }
                    else
                    {
                        request.ResetDateTime();
                        context.Done(request);
                    }
                }
            }
            catch (TooManyAttemptsException)
            {
                request.ResetDateTime();
                context.Done(request);
            }
        }