public async Task <DialogTurnResult> CollectContent(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { bool?isTitleSkipByDefault = false; isTitleSkipByDefault = Settings.DefaultValue?.CreateMeeting?.First(item => item.Name == "EventTitle")?.IsSkipByDefault; bool?isContentSkipByDefault = false; isContentSkipByDefault = Settings.DefaultValue?.CreateMeeting?.First(item => item.Name == "EventContent")?.IsSkipByDefault; var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken); if (sc.Result != null || (state.CreateHasDetail && isTitleSkipByDefault.GetValueOrDefault()) || state.RecreateState == RecreateEventState.Subject) { if (string.IsNullOrEmpty(state.Title)) { if (state.CreateHasDetail && isTitleSkipByDefault.GetValueOrDefault() && state.RecreateState != RecreateEventState.Subject) { state.Title = CreateEventWhiteList.GetDefaultTitle(); } else { sc.Context.Activity.Properties.TryGetValue("OriginText", out var content); var title = content != null?content.ToString() : sc.Context.Activity.Text; if (CreateEventWhiteList.IsSkip(title)) { state.Title = CreateEventWhiteList.GetDefaultTitle(); } else { state.Title = title; } } } } if (string.IsNullOrEmpty(state.Content) && (!(state.CreateHasDetail && isContentSkipByDefault.GetValueOrDefault()) || state.RecreateState == RecreateEventState.Content)) { return(await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = ResponseManager.GetResponse(CreateEventResponses.NoContent) }, cancellationToken)); } else { return(await sc.NextAsync(cancellationToken : cancellationToken)); } } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
private IList <DateTimeResolution> GetTimeFromMessage(string message, string culture) { if (CreateEventWhiteList.IsSkip(message)) { // Can not skip IsSkip = true; return(new List <DateTimeResolution>()); } IList <DateTimeResolution> results = RecognizeDateTime(message, culture); return(results); }
private IList <DateTimeResolution> GetDateFromMessage(string message, string culture) { if (CreateEventWhiteList.IsSkip(message)) { message = CalendarCommonStrings.TodayLower; // log is this one skip. may change logic in future. // no use for now IsSkip = true; } IList <DateTimeResolution> results = RecognizeDateTime(message, culture); return(results); }
private IList <DateTimeResolution> GetDurationFromMessage(string message, string culture) { if (CreateEventWhiteList.IsSkip(message)) { message = "half an hour"; // log is this one skip. may change logic in future. // no use for now IsSkip = true; } IList <DateTimeResolution> results = RecognizeDateTime(message, culture); return(results); }
private async Task <DialogTurnResult> AfterCollectLocationPromptAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { bool?isLocationSkipByDefault = false; isLocationSkipByDefault = Settings.DefaultValue?.CreateMeeting?.First(item => item.Name == "EventLocation")?.IsSkipByDefault; var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken); if (state.MeetingInfo.Location == null && sc.Result != null && (!(state.MeetingInfo.CreateHasDetail && isLocationSkipByDefault.GetValueOrDefault()) || state.MeetingInfo.RecreateState == RecreateEventState.Location)) { sc.Context.Activity.Properties.TryGetValue("OriginText", out var content); var luisResult = sc.Context.TurnState.Get <CalendarLuis>(StateProperties.CalendarLuisResultKey); var userInput = content != null?content.ToString() : sc.Context.Activity.Text; var topIntent = luisResult?.TopIntent().intent.ToString(); var promptRecognizerResult = ConfirmRecognizerHelper.ConfirmYesOrNo(userInput, sc.Context.Activity.Locale); // Enable the user to skip providing the location if they say something matching the Cancel intent, say something matching the ConfirmNo recognizer or something matching the NoLocation intent if (CreateEventWhiteList.IsSkip(userInput)) { state.MeetingInfo.Location = string.Empty; } else { state.MeetingInfo.Location = userInput; } } else if (state.MeetingInfo.CreateHasDetail && isLocationSkipByDefault.GetValueOrDefault()) { state.MeetingInfo.Location = CalendarCommonStrings.DefaultLocation; } return(await sc.EndDialogAsync(cancellationToken : cancellationToken)); } catch (Exception ex) { await HandleDialogExceptionsAsync(sc, ex, cancellationToken); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
public async Task <DialogTurnResult> CollectStartDate(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { bool?isContentSkipByDefault = false; isContentSkipByDefault = Settings.DefaultValue?.CreateMeeting?.First(item => item.Name == "EventContent")?.IsSkipByDefault; var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken); if (sc.Result != null && (!(state.CreateHasDetail && isContentSkipByDefault.GetValueOrDefault()) || state.RecreateState == RecreateEventState.Content)) { if (string.IsNullOrEmpty(state.Content)) { sc.Context.Activity.Properties.TryGetValue("OriginText", out var content); var merged_content = content != null?content.ToString() : sc.Context.Activity.Text; if (!CreateEventWhiteList.IsSkip(merged_content)) { state.Content = merged_content; } } } else if (state.CreateHasDetail && isContentSkipByDefault.GetValueOrDefault()) { state.Content = CalendarCommonStrings.DefaultContent; } if (!state.StartDate.Any()) { return(await sc.BeginDialogAsync(Actions.UpdateStartDateForCreate, new UpdateDateTimeDialogOptions(UpdateDateTimeDialogOptions.UpdateReason.NotFound), cancellationToken)); } else { return(await sc.NextAsync(cancellationToken : cancellationToken)); } } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
private async Task <DialogTurnResult> AfterCollectContentPromptAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { bool?isContentSkipByDefault = false; isContentSkipByDefault = Settings.DefaultValue?.CreateMeeting?.First(item => item.Name == "EventContent")?.IsSkipByDefault; var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken); if (sc.Result != null && (!(state.MeetingInfo.CreateHasDetail && isContentSkipByDefault.GetValueOrDefault()) || state.MeetingInfo.RecreateState == RecreateEventState.Content)) { if (string.IsNullOrEmpty(state.MeetingInfo.Content)) { sc.Context.Activity.Properties.TryGetValue("OriginText", out var content); var merged_content = content != null?content.ToString() : sc.Context.Activity.Text; if (!CreateEventWhiteList.IsSkip(merged_content)) { state.MeetingInfo.Content = merged_content; } } } else if (state.MeetingInfo.CreateHasDetail && isContentSkipByDefault.GetValueOrDefault()) { state.MeetingInfo.Content = CalendarCommonStrings.DefaultContent; } return(await sc.EndDialogAsync(cancellationToken : cancellationToken)); } catch (Exception ex) { await HandleDialogExceptionsAsync(sc, ex, cancellationToken); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
public async Task <DialogTurnResult> ConfirmBeforeCreate(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken); if (state.Location == null && sc.Result != null && (!state.CreateHasDetail || state.RecreateState == RecreateEventState.Location)) { sc.Context.Activity.Properties.TryGetValue("OriginText", out var content); var luisResult = state.LuisResult; var userInput = content != null?content.ToString() : sc.Context.Activity.Text; var topIntent = luisResult?.TopIntent().intent.ToString(); var promptRecognizerResult = ConfirmRecognizerHelper.ConfirmYesOrNo(userInput, sc.Context.Activity.Locale); // Enable the user to skip providing the location if they say something matching the Cancel intent, say something matching the ConfirmNo recognizer or something matching the NoLocation intent if (CreateEventWhiteList.IsSkip(userInput)) { state.Location = string.Empty; } else { state.Location = userInput; } } var source = state.EventSource; var newEvent = new EventModel(source) { Title = state.Title, Content = state.Content, Attendees = state.Attendees, StartTime = state.StartDateTime.Value, EndTime = state.EndDateTime.Value, TimeZone = TimeZoneInfo.Utc, Location = state.Location, ContentPreview = state.Content }; var attendeeConfirmString = string.Empty; if (state.Attendees.Count > 0) { var attendeeConfirmResponse = ResponseManager.GetResponse(CreateEventResponses.ConfirmCreateAttendees, new StringDictionary() { { "Attendees", state.Attendees.ToSpeechString(CommonStrings.And, li => li.DisplayName ?? li.Address) } }); attendeeConfirmString = attendeeConfirmResponse.Text; } var subjectConfirmString = string.Empty; if (!string.IsNullOrEmpty(state.Title)) { var subjectConfirmResponse = ResponseManager.GetResponse(CreateEventResponses.ConfirmCreateSubject, new StringDictionary() { { "Subject", string.IsNullOrEmpty(state.Title) ? CalendarCommonStrings.Empty : state.Title } }); subjectConfirmString = subjectConfirmResponse.Text; } var locationConfirmString = string.Empty; if (!string.IsNullOrEmpty(state.Location)) { var subjectConfirmResponse = ResponseManager.GetResponse(CreateEventResponses.ConfirmCreateLocation, new StringDictionary() { { "Location", string.IsNullOrEmpty(state.Location) ? CalendarCommonStrings.Empty : state.Location }, }); locationConfirmString = subjectConfirmResponse.Text; } var contentConfirmString = string.Empty; if (!string.IsNullOrEmpty(state.Content)) { var contentConfirmResponse = ResponseManager.GetResponse(CreateEventResponses.ConfirmCreateContent, new StringDictionary() { { "Content", string.IsNullOrEmpty(state.Content) ? CalendarCommonStrings.Empty : state.Content }, }); contentConfirmString = contentConfirmResponse.Text; } var startDateTimeInUserTimeZone = TimeConverter.ConvertUtcToUserTime(state.StartDateTime.Value, state.GetUserTimeZone()); var endDateTimeInUserTimeZone = TimeConverter.ConvertUtcToUserTime(state.EndDateTime.Value, state.GetUserTimeZone()); var tokens = new StringDictionary { { "AttendeesConfirm", attendeeConfirmString }, { "Date", startDateTimeInUserTimeZone.ToSpeechDateString(false) }, { "Time", startDateTimeInUserTimeZone.ToSpeechTimeString(false) }, { "EndTime", endDateTimeInUserTimeZone.ToSpeechTimeString(false) }, { "SubjectConfirm", subjectConfirmString }, { "LocationConfirm", locationConfirmString }, { "ContentConfirm", contentConfirmString }, }; var prompt = await GetDetailMeetingResponseAsync(sc, newEvent, CreateEventResponses.ConfirmCreate, tokens); var retryPrompt = ResponseManager.GetResponse(CreateEventResponses.ConfirmCreateFailed, tokens); return(await sc.PromptAsync(Actions.TakeFurtherAction, new PromptOptions { Prompt = prompt, RetryPrompt = retryPrompt }, cancellationToken)); } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
public async Task <DialogTurnResult> AfterConfirmNameList(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); // get name list from sc.result if (sc.Result != null) { sc.Context.Activity.Properties.TryGetValue("OriginText", out var content); var userInput = content != null?content.ToString() : sc.Context.Activity.Text; // if is skip. set the name list to be myself only. if (CreateEventWhiteList.IsSkip(userInput)) { state.AttendeesNameList = new List <string> { CalendarCommonStrings.MyselfConst }; } else if (state.EventSource != EventSource.Other) { if (userInput != null) { var nameList = userInput.Split(CreateEventWhiteList.GetContactNameSeparator(), StringSplitOptions.None) .Select(x => x.Trim()) .Where(x => !string.IsNullOrWhiteSpace(x)) .ToList(); state.AttendeesNameList = nameList; } } } if (state.AttendeesNameList.Any()) { if (state.AttendeesNameList.Count > 1) { var nameString = await GetReadyToSendNameListStringAsync(sc); await sc.Context.SendActivityAsync(ResponseManager.GetResponse(FindContactResponses.BeforeSendingMessage, new StringDictionary() { { "NameList", nameString } })); } // go to loop to go through all the names state.ConfirmAttendeesNameIndex = 0; return(await sc.ReplaceDialogAsync(Actions.LoopNameList, sc.Options, cancellationToken)); } state.AttendeesNameList = new List <string>(); state.CurrentAttendeeName = string.Empty; state.ConfirmAttendeesNameIndex = 0; return(await sc.EndDialogAsync()); } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
private async Task <DialogTurnResult> AfterConfirmNameListAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken); var options = sc.Options as FindContactDialogOptions; // get name list from sc.result if (sc.Result != null) { sc.Context.Activity.Properties.TryGetValue("OriginText", out var content); var userInput = content != null?content.ToString() : sc.Context.Activity.Text; // if is skip. set the name list to be myself only. if (CreateEventWhiteList.IsSkip(userInput)) { state.MeetingInfo.ContactInfor.ContactsNameList = new List <string> { CalendarCommonStrings.MyselfConst }; } else if (state.EventSource != EventSource.Other) { if (userInput != null) { var nameList = userInput.Split(CreateEventWhiteList.GetContactNameSeparator(), StringSplitOptions.None) .Select(x => x.Trim()) .Where(x => !string.IsNullOrWhiteSpace(x)) .ToList(); state.MeetingInfo.ContactInfor.ContactsNameList = nameList; } } } if (state.MeetingInfo.ContactInfor.ContactsNameList.Any()) { if (state.MeetingInfo.ContactInfor.ContactsNameList.Count > 1 && !(state.InitialIntent == CalendarLuis.Intent.CheckAvailability)) { var nameString = await GetReadyToSendNameListStringAsync(sc, cancellationToken); var activity = TemplateManager.GenerateActivityForLocale(FindContactResponses.BeforeSendingMessage, new { NameList = nameString }); await sc.Context.SendActivityAsync(activity, cancellationToken); } // go to loop to go through all the names state.MeetingInfo.ContactInfor.ConfirmContactsNameIndex = 0; return(await sc.ReplaceDialogAsync(Actions.LoopNameList, sc.Options, cancellationToken)); } // todo: state.MeetingInfo.ContactInfor.ContactsNameList = new List <string>(); state.MeetingInfo.ContactInfor.CurrentContactName = string.Empty; state.MeetingInfo.ContactInfor.ConfirmContactsNameIndex = 0; return(await sc.EndDialogAsync(cancellationToken : cancellationToken)); } catch (Exception ex) { await HandleDialogExceptionsAsync(sc, ex, cancellationToken); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }