public async Task <DialogTurnResult> AfterConfirmAttendee(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await _accessor.GetAsync(sc.Context); // result is null when just update the recipient name. show recipients page should be reset. if (sc.Result == null) { state.ShowAttendeesIndex = 0; return(await sc.BeginDialogAsync(Actions.ConfirmAttendee)); } else if (sc.Result.ToString() == Luis.General.Intent.Next.ToString()) { state.ShowAttendeesIndex++; return(await sc.BeginDialogAsync(Actions.ConfirmAttendee)); } else if (sc.Result.ToString() == Luis.General.Intent.Previous.ToString()) { if (state.ShowAttendeesIndex > 0) { state.ShowAttendeesIndex--; } return(await sc.BeginDialogAsync(Actions.ConfirmAttendee)); } else { var user = (sc.Result as FoundChoice)?.Value.Trim('*'); if (user != null) { var attendee = new EventModel.Attendee { DisplayName = user.Split(": ")[0], Address = user.Split(": ")[1], }; if (state.Attendees.All(r => r.Address != attendee.Address)) { state.Attendees.Add(attendee); } } state.ConfirmAttendeesNameIndex++; if (state.ConfirmAttendeesNameIndex < state.AttendeesNameList.Count) { return(await sc.BeginDialogAsync(Actions.ConfirmAttendee)); } else { return(await sc.EndDialogAsync(true)); } } } catch { await HandleDialogExceptions(sc); throw; } }
private async Task <DialogTurnResult> AfterConfirmEmailAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken); var options = sc.Options as FindContactDialogOptions; var confirmedPerson = state.MeetingInfo.ContactInfor.ConfirmedContact; var result = sc.Result as string; // Highest probability if (!(state.InitialIntent == CalendarLuis.Intent.CheckAvailability) && (string.IsNullOrEmpty(result) || !result.Equals(nameof(AfterSelectEmailAsync)))) { var name = confirmedPerson.DisplayName; var userString = string.Empty; if (!name.Equals(confirmedPerson.Emails.First().Address ?? confirmedPerson.UserPrincipalName)) { userString = name + " (" + (confirmedPerson.Emails.First().Address ?? confirmedPerson.UserPrincipalName) + ")"; } else { userString = confirmedPerson.Emails.First().Address ?? confirmedPerson.UserPrincipalName; } var activity = TemplateManager.GenerateActivityForLocale(FindContactResponses.PromptOneNameOneAddress, new { User = userString }); await sc.Context.SendActivityAsync(activity, cancellationToken); } var attendee = new EventModel.Attendee { DisplayName = confirmedPerson.DisplayName, Address = confirmedPerson.Emails.First().Address, UserPrincipalName = confirmedPerson.UserPrincipalName }; if (state.MeetingInfo.ContactInfor.Contacts.All(r => r.Address != attendee.Address)) { state.MeetingInfo.ContactInfor.Contacts.Add(attendee); } return(await sc.EndDialogAsync(cancellationToken : cancellationToken)); } catch (Exception ex) { await HandleDialogExceptionsAsync(sc, ex, cancellationToken); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
private async Task <DialogTurnResult> AfterConfirmEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); var options = sc.Options as FindContactDialogOptions; var confirmedPerson = state.MeetingInfor.ContactInfor.ConfirmedContact; var result = sc.Result as string; // Highest probability if (!options.Scenario.Equals(nameof(CheckAvailableDialog)) && (string.IsNullOrEmpty(result) || !result.Equals(nameof(AfterSelectEmail)))) { var name = confirmedPerson.DisplayName; var userString = string.Empty; if (!name.Equals(confirmedPerson.Emails.First().Address ?? confirmedPerson.UserPrincipalName)) { userString = name + " (" + (confirmedPerson.Emails.First().Address ?? confirmedPerson.UserPrincipalName) + ")"; } else { userString = confirmedPerson.Emails.First().Address ?? confirmedPerson.UserPrincipalName; } await sc.Context.SendActivityAsync(ResponseManager.GetResponse(FindContactResponses.PromptOneNameOneAddress, new StringDictionary() { { "User", $"{userString}" } })); } var attendee = new EventModel.Attendee { DisplayName = confirmedPerson.DisplayName, Address = confirmedPerson.Emails.First().Address, UserPrincipalName = confirmedPerson.UserPrincipalName }; if (state.MeetingInfor.ContactInfor.Contacts.All(r => r.Address != attendee.Address)) { state.MeetingInfor.ContactInfor.Contacts.Add(attendee); } return(await sc.EndDialogAsync()); } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
public async Task <DialogTurnResult> AfterConfirmEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); var confirmedPerson = state.ConfirmedPerson; var name = confirmedPerson.DisplayName; // it will be new retry whether the user set this attendee down or choose to retry on this one. state.FirstRetryInFindContact = true; if (!(sc.Result is bool) || (bool)sc.Result) { var attendee = new EventModel.Attendee { DisplayName = name, Address = confirmedPerson.Emails.First().Address }; if (state.Attendees.All(r => r.Address != attendee.Address)) { state.Attendees.Add(attendee); } return(await sc.EndDialogAsync()); } else { var options = sc.Options as FindContactDialogOptions; options.UpdateUserNameReason = FindContactDialogOptions.UpdateUserNameReasonType.ConfirmNo; return(await sc.ReplaceDialogAsync(Actions.ConfirmAttendee, options)); } } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
public async Task <DialogTurnResult> ConfirmEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { var state = await Accessor.GetAsync(sc.Context); var confirmedPerson = sc.Options as CustomizedPerson; var name = confirmedPerson.DisplayName; if (confirmedPerson.Emails.Count() == 1) { // Highest probability var attendee = new EventModel.Attendee { DisplayName = name, Address = confirmedPerson.Emails.First().Address }; if (state.Attendees.All(r => r.Address != attendee.Address)) { state.Attendees.Add(attendee); } return(await sc.PromptAsync(Actions.TakeFurtherAction, new PromptOptions { Prompt = sc.Context.Activity.CreateReply(FindContactResponses.PromptOneNameOneAddress, null, new StringDictionary() { { "UserName", name }, { "EmailAddress", confirmedPerson.Emails.First().Address } }), })); } else { var emailString = string.Empty; var emailList = confirmedPerson.Emails.ToList(); if (emailList.Count <= ConfigData.GetInstance().MaxDisplaySize) { return(await sc.PromptAsync(Actions.Choice, await GenerateOptionsForEmail(sc, confirmedPerson, sc.Context, true))); } else { return(await sc.PromptAsync(Actions.Choice, await GenerateOptionsForEmail(sc, confirmedPerson, sc.Context, false))); } } }
public async Task <DialogTurnResult> AfterUpdateUserName(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var userInput = sc.Result as string; var state = await Accessor.GetAsync(sc.Context); var options = (UpdateUserNameDialogOptions)sc.Options; if (string.IsNullOrEmpty(userInput) && options.Reason != UpdateUserNameDialogOptions.UpdateReason.Initialize) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(FindContactResponses.UserNotFoundAgain, new StringDictionary() { { "source", state.EventSource == EventSource.Microsoft ? "Outlook Calendar" : "Google Calendar" } })); return(await sc.EndDialogAsync()); } string currentRecipientName = string.IsNullOrEmpty(userInput) ? state.CurrentAttendeeName : userInput; state.CurrentAttendeeName = currentRecipientName; // if it's an email, add to attendee and kepp the state.ConfirmedPerson null if (!string.IsNullOrEmpty(currentRecipientName) && IsEmail(currentRecipientName)) { var attendee = new EventModel.Attendee { DisplayName = currentRecipientName, Address = currentRecipientName }; if (state.Attendees.All(r => r.Address != attendee.Address)) { state.Attendees.Add(attendee); } state.CurrentAttendeeName = string.Empty; state.ConfirmedPerson = null; return(await sc.EndDialogAsync()); } List <CustomizedPerson> unionList = new List <CustomizedPerson>(); if (CreateEventWhiteList.GetMyself(currentRecipientName)) { var me = await GetMe(sc); unionList.Add(new CustomizedPerson(me)); } else { var originPersonList = await GetPeopleWorkWithAsync(sc, currentRecipientName); var originContactList = await GetContactsAsync(sc, currentRecipientName); originPersonList.AddRange(originContactList); var originUserList = new List <PersonModel>(); try { originUserList = await GetUserAsync(sc, currentRecipientName); } catch { // do nothing when get user failed. because can not use token to ensure user use a work account. } (var personList, var userList) = FormatRecipientList(originPersonList, originUserList); // people you work with has the distinct email address has the highest priority if (personList.Count == 1 && personList.First().Emails.Any() && personList.First().Emails.First() != null) { unionList.Add(new CustomizedPerson(personList.First())); } else { personList.AddRange(userList); foreach (var person in personList) { if (unionList.Find(p => p.DisplayName == person.DisplayName) == null) { var personWithSameName = personList.FindAll(p => p.DisplayName == person.DisplayName); if (personWithSameName.Count == 1) { unionList.Add(new CustomizedPerson(personWithSameName.First())); } else { var unionPerson = new CustomizedPerson(personWithSameName.FirstOrDefault()); var curEmailList = new List <ScoredEmailAddress>(); foreach (var sameNamePerson in personWithSameName) { sameNamePerson.Emails.ToList().ForEach(e => { if (!string.IsNullOrEmpty(e)) { curEmailList.Add(new ScoredEmailAddress { Address = e }); } }); } unionPerson.Emails = curEmailList; unionList.Add(unionPerson); } } } } } unionList.RemoveAll(person => !person.Emails.Exists(email => email.Address != null)); unionList.RemoveAll(person => !person.Emails.Any()); state.UnconfirmedPerson = unionList; if (unionList.Count == 0) { return(await sc.ReplaceDialogAsync(Actions.UpdateName, new UpdateUserNameDialogOptions(UpdateUserNameDialogOptions.UpdateReason.NotFound))); } else if (unionList.Count == 1) { state.ConfirmedPerson = unionList.First(); return(await sc.EndDialogAsync()); } else { return(await sc.ReplaceDialogAsync(Actions.SelectPerson, sc.Options, cancellationToken)); } } catch (SkillException skillEx) { await HandleDialogExceptions(sc, skillEx); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
public async Task <DialogTurnResult> AfterConfirmEmail(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); var confirmedPerson = state.ConfirmedPerson; var name = confirmedPerson.DisplayName; if (sc.Result is bool) { if ((bool)sc.Result) { var attendee = new EventModel.Attendee { DisplayName = name, Address = confirmedPerson.Emails.First().Address }; if (state.Attendees.All(r => r.Address != attendee.Address)) { state.Attendees.Add(attendee); } state.FirstRetryInFindContact = true; state.ConfirmAttendeesNameIndex++; if (state.ConfirmAttendeesNameIndex < state.AttendeesNameList.Count) { return(await sc.ReplaceDialogAsync(Actions.ConfirmName, options : sc.Options, cancellationToken : cancellationToken)); } else { return(await sc.EndDialogAsync()); } } else { return(await sc.BeginDialogAsync(Actions.UpdateName, new UpdateUserNameDialogOptions(UpdateUserNameDialogOptions.UpdateReason.ConfirmNo))); } } var luisResult = state.LuisResult; var topIntent = luisResult?.TopIntent().intent; var generlLuisResult = state.GeneralLuisResult; var generalTopIntent = generlLuisResult?.TopIntent().intent; if (state.AttendeesNameList != null && state.AttendeesNameList.Count > 0) { if (sc.Result == null) { if (generalTopIntent == General.Intent.Next) { state.ShowAttendeesIndex++; } else if (generalTopIntent == General.Intent.Previous) { if (state.ShowAttendeesIndex > 0) { state.ShowAttendeesIndex--; } else { await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(FindContactResponses.AlreadyFirstPage)); } } else { // result is null when just update the recipient name. show recipients page should be reset. state.ShowAttendeesIndex = 0; } return(await sc.ReplaceDialogAsync(Actions.ConfirmEmail, confirmedPerson)); } var choiceResult = (sc.Result as FoundChoice)?.Value.Trim('*'); if (choiceResult != null) { // Find an recipient var attendee = new EventModel.Attendee { DisplayName = choiceResult.Split(": ")[0], Address = choiceResult.Split(": ")[1], }; if (state.Attendees.All(r => r.Address != attendee.Address)) { state.Attendees.Add(attendee); } state.ConfirmAttendeesNameIndex++; state.FirstRetryInFindContact = true; // Clean up data state.ShowAttendeesIndex = 0; state.ConfirmedPerson = new CustomizedPerson(); } } if (state.ConfirmAttendeesNameIndex < state.AttendeesNameList.Count) { return(await sc.ReplaceDialogAsync(Actions.ConfirmName, options : sc.Options, cancellationToken : cancellationToken)); } else { return(await sc.EndDialogAsync()); } } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
public async Task <DialogTurnResult> ConfirmName(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); if ((state.AttendeesNameList == null) || (state.AttendeesNameList.Count == 0)) { return(await sc.BeginDialogAsync(Actions.UpdateName, new UpdateUserNameDialogOptions(UpdateUserNameDialogOptions.UpdateReason.NotFound))); } var unionList = new List <CustomizedPerson>(); var emailList = new List <string>(); if (state.FirstEnterFindContact) { state.FirstEnterFindContact = false; foreach (var name in state.AttendeesNameList) { if (IsEmail(name)) { emailList.Add(name); } } if (state.AttendeesNameList.Count > 1) { var nameString = await GetReadyToSendNameListStringAsync(sc); await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(FindContactResponses.BeforeSendingMessage, null, new StringDictionary() { { "NameList", nameString } })); } } if (emailList.Count > 0) { foreach (var email in emailList) { var attendee = new EventModel.Attendee { DisplayName = email, Address = email }; if (state.Attendees.All(r => r.Address != attendee.Address)) { state.Attendees.Add(attendee); } } state.AttendeesNameList.RemoveAll(n => IsEmail(n)); if (state.AttendeesNameList.Count > 0) { return(await sc.ReplaceDialogAsync(Actions.ConfirmName, options : sc.Options, cancellationToken : cancellationToken)); } else { return(await sc.EndDialogAsync()); } } if (state.ConfirmAttendeesNameIndex < state.AttendeesNameList.Count) { var currentRecipientName = state.AttendeesNameList[state.ConfirmAttendeesNameIndex]; if (CreateEventWhiteList.GetMyself().Contains(currentRecipientName)) { var me = await GetMe(sc); unionList.Add(new CustomizedPerson(me)); } else { var originPersonList = await GetPeopleWorkWithAsync(sc, currentRecipientName); var originContactList = await GetContactsAsync(sc, currentRecipientName); originPersonList.AddRange(originContactList); var originUserList = new List <PersonModel>(); try { originUserList = await GetUserAsync(sc, currentRecipientName); } catch { // do nothing when get user failed. because can not use token to ensure user use a work account. } (var personList, var userList) = FormatRecipientList(originPersonList, originUserList); // people you work with has the distinct email address has the highest priority if (personList.Count == 1 && personList.First().Emails.Count == 1) { state.ConfirmedPerson = new CustomizedPerson(personList.First()); var highestPriorityPerson = new CustomizedPerson(personList.First()); return(await sc.ReplaceDialogAsync(Actions.ConfirmEmail, highestPriorityPerson)); } personList.AddRange(userList); foreach (var person in personList) { if (unionList.Find(p => p.DisplayName == person.DisplayName) == null) { var personWithSameName = personList.FindAll(p => p.DisplayName == person.DisplayName); if (personWithSameName.Count == 1) { unionList.Add(new CustomizedPerson(personWithSameName.First())); } else { var unionPerson = new CustomizedPerson(personWithSameName.FirstOrDefault()); var curEmailList = new List <ScoredEmailAddress>(); foreach (var sameNamePerson in personWithSameName) { sameNamePerson.Emails.ToList().ForEach(e => curEmailList.Add(new ScoredEmailAddress { Address = e })); } unionPerson.Emails = curEmailList; unionList.Add(unionPerson); } } } } } else { return(await sc.EndDialogAsync()); } state.UnconfirmedPerson = unionList; if (unionList.Count == 0) { return(await sc.BeginDialogAsync(Actions.UpdateName, new UpdateUserNameDialogOptions(UpdateUserNameDialogOptions.UpdateReason.NotFound))); } else if (unionList.Count == 1) { state.ConfirmedPerson = unionList.First(); return(await sc.ReplaceDialogAsync(Actions.ConfirmEmail, unionList.First())); } else { var nameString = string.Empty; if (unionList.Count <= ConfigData.GetInstance().MaxDisplaySize) { return(await sc.PromptAsync(Actions.Choice, await GenerateOptionsForName(sc, unionList, sc.Context, true))); } else { return(await sc.PromptAsync(Actions.Choice, await GenerateOptionsForName(sc, unionList, sc.Context, false))); } } } catch (SkillException skillEx) { await HandleDialogExceptions(sc, skillEx); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }