Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 3a7ef2c

Browse files
ChengxianModarrenj
authored andcommitted
[Calendar] refine find contact flow (#939)
* refine find contact logic * fix some bug * fix skill exception and remove old code * add comments and refine some logic * revert some code
1 parent 745cca4 commit 3a7ef2c

File tree

9 files changed

+447
-341
lines changed

9 files changed

+447
-341
lines changed

solutions/Virtual-Assistant/src/csharp/skills/calendarskill/calendarskill/CalendarSkillState.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public CalendarSkillState()
3838
NewStartDateTime = null;
3939
EventSource = EventSource.Other;
4040
AttendeesNameList = new List<string>();
41+
CurrentAttendeeName = string.Empty;
4142
ConfirmAttendeesNameIndex = 0;
4243
DialogName = string.Empty;
4344
ShowAttendeesIndex = 0;
@@ -131,6 +132,8 @@ public CalendarSkillState()
131132

132133
public List<string> AttendeesNameList { get; set; }
133134

135+
public string CurrentAttendeeName { get; set; }
136+
134137
public int ConfirmAttendeesNameIndex { get; set; }
135138

136139
public string DialogName { get; set; }
@@ -214,6 +217,7 @@ public void Clear()
214217
NewStartDateTime = null;
215218
EventSource = EventSource.Other;
216219
AttendeesNameList = new List<string>();
220+
CurrentAttendeeName = string.Empty;
217221
ConfirmAttendeesNameIndex = 0;
218222
DialogName = string.Empty;
219223
ShowAttendeesIndex = 0;
@@ -305,6 +309,7 @@ public void ClearParticipants()
305309
{
306310
Attendees = new List<EventModel.Attendee>();
307311
AttendeesNameList = new List<string>();
312+
CurrentAttendeeName = string.Empty;
308313
ConfirmAttendeesNameIndex = 0;
309314
CreateHasDetail = true;
310315
RecreateState = RecreateEventState.Participants;

solutions/Virtual-Assistant/src/csharp/skills/calendarskill/calendarskill/Dialogs/CreateEvent/CreateEventDialog.cs

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ public CreateEventDialog(
5454
CreateEvent,
5555
};
5656

57-
var updateAddress = new WaterfallStep[]
58-
{
59-
UpdateAddress,
60-
AfterUpdateAddress,
61-
};
62-
6357
var updateStartDate = new WaterfallStep[]
6458
{
6559
UpdateStartDateForCreate,
@@ -86,7 +80,6 @@ public CreateEventDialog(
8680

8781
// Define the conversation flow using a waterfall model.
8882
AddDialog(new WaterfallDialog(Actions.CreateEvent, createEvent) { TelemetryClient = telemetryClient });
89-
AddDialog(new WaterfallDialog(Actions.UpdateAddress, updateAddress) { TelemetryClient = telemetryClient });
9083
AddDialog(new WaterfallDialog(Actions.UpdateStartDateForCreate, updateStartDate) { TelemetryClient = telemetryClient });
9184
AddDialog(new WaterfallDialog(Actions.UpdateStartTimeForCreate, updateStartTime) { TelemetryClient = telemetryClient });
9285
AddDialog(new WaterfallDialog(Actions.UpdateDurationForCreate, updateDuration) { TelemetryClient = telemetryClient });
@@ -199,7 +192,7 @@ public CreateEventDialog(
199192

200193
if (state.Attendees.Count == 0 && (!state.CreateHasDetail || state.RecreateState == RecreateEventState.Participants || state.AttendeesNameList.Count > 0))
201194
{
202-
return await sc.BeginDialogAsync(Actions.UpdateAddress, cancellationToken: cancellationToken);
195+
return await sc.BeginDialogAsync(nameof(FindContactDialog), options: sc.Options, cancellationToken: cancellationToken);
203196
}
204197
else
205198
{
@@ -494,72 +487,6 @@ public CreateEventDialog(
494487
}
495488
}
496489

497-
// update address waterfall steps
498-
public async Task<DialogTurnResult> UpdateAddress(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
499-
{
500-
try
501-
{
502-
var state = await Accessor.GetAsync(sc.Context, cancellationToken: cancellationToken);
503-
if (state.AttendeesNameList.Any())
504-
{
505-
return await sc.NextAsync(cancellationToken: cancellationToken);
506-
}
507-
508-
return await sc.PromptAsync(Actions.Prompt, new PromptOptions { Prompt = ResponseManager.GetResponse(CreateEventResponses.NoAttendees) }, cancellationToken);
509-
}
510-
catch (Exception ex)
511-
{
512-
await HandleDialogExceptions(sc, ex);
513-
return new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs);
514-
}
515-
}
516-
517-
public async Task<DialogTurnResult> AfterUpdateAddress(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
518-
{
519-
try
520-
{
521-
var state = await Accessor.GetAsync(sc.Context, cancellationToken: cancellationToken);
522-
if (state.AttendeesNameList.Any())
523-
{
524-
state.FirstEnterFindContact = true;
525-
return await sc.BeginDialogAsync(nameof(FindContactDialog), options: sc.Options, cancellationToken: cancellationToken);
526-
}
527-
528-
if (sc.Result != null)
529-
{
530-
sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
531-
var userInput = content != null ? content.ToString() : sc.Context.Activity.Text;
532-
if (state.EventSource != EventSource.Other)
533-
{
534-
if (userInput != null)
535-
{
536-
var nameList = userInput.Split(CreateEventWhiteList.GetContactNameSeparator(), StringSplitOptions.None)
537-
.Select(x => x.Trim())
538-
.Where(x => !string.IsNullOrWhiteSpace(x))
539-
.ToList();
540-
state.AttendeesNameList = nameList;
541-
}
542-
543-
state.FirstEnterFindContact = true;
544-
return await sc.BeginDialogAsync(nameof(FindContactDialog), options: sc.Options, cancellationToken: cancellationToken);
545-
}
546-
else
547-
{
548-
return await sc.BeginDialogAsync(Actions.UpdateAddress, new UpdateAddressDialogOptions(UpdateAddressDialogOptions.UpdateReason.NotAnAddress), cancellationToken);
549-
}
550-
}
551-
else
552-
{
553-
return await sc.NextAsync(cancellationToken: cancellationToken);
554-
}
555-
}
556-
catch (Exception ex)
557-
{
558-
await HandleDialogExceptions(sc, ex);
559-
return new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs);
560-
}
561-
}
562-
563490
// update start date waterfall steps
564491
public async Task<DialogTurnResult> UpdateStartDateForCreate(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
565492
{

0 commit comments

Comments
 (0)