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

[Calendar] Add retry count limitation #2524

Merged
merged 6 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ protected async Task<DialogTurnResult> GetAuthToken(WaterfallStepContext sc, Can
{
state.ShowMeetingInfor.ShowingMeetings = sc.Result as List<EventModel>;
}
else
{
// user has tried 5 times but can't get result
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(CalendarSharedResponses.RetryTooManyResponse));
return await sc.CancelAllDialogsAsync();
}

return await sc.NextAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,17 @@ public ChangeEventStatusDialog(
return await sc.PromptAsync(Actions.GetEventPrompt, new GetEventOptions(calendarService, state.GetUserTimeZone())
{
Prompt = ResponseManager.GetResponse(ChangeEventStatusResponses.NoDeleteStartTime),
RetryPrompt = ResponseManager.GetResponse(ChangeEventStatusResponses.EventWithStartTimeNotFound)
RetryPrompt = ResponseManager.GetResponse(ChangeEventStatusResponses.EventWithStartTimeNotFound),
MaxReprompt = 5
KayMKM marked this conversation as resolved.
Show resolved Hide resolved
}, cancellationToken);
}
else
{
return await sc.PromptAsync(Actions.GetEventPrompt, new GetEventOptions(calendarService, state.GetUserTimeZone())
{
Prompt = ResponseManager.GetResponse(ChangeEventStatusResponses.NoAcceptStartTime),
RetryPrompt = ResponseManager.GetResponse(ChangeEventStatusResponses.EventWithStartTimeNotFound)
RetryPrompt = ResponseManager.GetResponse(ChangeEventStatusResponses.EventWithStartTimeNotFound),
MaxReprompt = 5
}, cancellationToken);
}
}
Expand Down
89 changes: 58 additions & 31 deletions skills/csharp/calendarskill/Dialogs/CreateEventDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@ public CreateEventDialog(
{
Prompt = ResponseManager.GetResponse(CreateEventResponses.NoStartDate),
RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartDateRetry),
TimeZone = state.GetUserTimeZone()
TimeZone = state.GetUserTimeZone(),
MaxReprompt = 5
}, cancellationToken);
}
catch (Exception ex)
Expand Down Expand Up @@ -705,8 +706,7 @@ public CreateEventDialog(

state.MeetingInfor.StartDate.Add(datetime);
}
else
if (sc.Result != null)
else if (sc.Result != null)
{
IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
foreach (var resolution in dateTimeResolutions)
Expand Down Expand Up @@ -736,6 +736,12 @@ public CreateEventDialog(
}
}
}
else
{
// user has tried 5 times but can't get result
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(CalendarSharedResponses.RetryTooManyResponse));
return await sc.CancelAllDialogsAsync();
}

return await sc.EndDialogAsync(cancellationToken: cancellationToken);
}
Expand All @@ -759,7 +765,8 @@ public CreateEventDialog(
Prompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTime),
RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTimeRetry),
NoSkipPrompt = ResponseManager.GetResponse(CreateEventResponses.NoStartTimeNoSkip),
TimeZone = state.GetUserTimeZone()
TimeZone = state.GetUserTimeZone(),
MaxReprompt = 5
}, cancellationToken);
}
else
Expand All @@ -779,30 +786,39 @@ public CreateEventDialog(
try
{
var state = await Accessor.GetAsync(sc.Context, cancellationToken: cancellationToken);
if (sc.Result != null && !state.MeetingInfor.StartTime.Any())
if (!state.MeetingInfor.StartTime.Any())
{
IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
foreach (var resolution in dateTimeResolutions)
if (sc.Result != null)
{
var dateTimeConvertType = resolution?.Timex;
var dateTimeValue = resolution?.Value;
if (dateTimeValue != null)
IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
foreach (var resolution in dateTimeResolutions)
{
try
var dateTimeConvertType = resolution?.Timex;
var dateTimeValue = resolution?.Value;
if (dateTimeValue != null)
{
var dateTime = DateTime.Parse(dateTimeValue);
try
{
var dateTime = DateTime.Parse(dateTimeValue);

if (dateTime != null)
if (dateTime != null)
{
state.MeetingInfor.StartTime.Add(dateTime);
}
}
catch (FormatException ex)
{
state.MeetingInfor.StartTime.Add(dateTime);
await HandleExpectedDialogExceptions(sc, ex);
}
}
catch (FormatException ex)
{
await HandleExpectedDialogExceptions(sc, ex);
}
}
}
else
{
// user has tried 5 times but can't get result
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(CalendarSharedResponses.RetryTooManyResponse));
return await sc.CancelAllDialogsAsync();
}
}

var userNow = TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, state.GetUserTimeZone());
Expand Down Expand Up @@ -852,10 +868,11 @@ public CreateEventDialog(
return await sc.NextAsync(cancellationToken: cancellationToken);
}

return await sc.PromptAsync(Actions.DurationPromptForCreate, new PromptOptions
return await sc.PromptAsync(Actions.DurationPromptForCreate, new CalendarPromptOptions
{
Prompt = ResponseManager.GetResponse(CreateEventResponses.NoDuration),
RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.NoDurationRetry)
RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.NoDurationRetry),
MaxReprompt = 5
}, cancellationToken);
}
catch (Exception ex)
Expand Down Expand Up @@ -923,15 +940,24 @@ public CreateEventDialog(
}
}

if (state.MeetingInfor.Duration <= 0 && sc.Result != null)
if (state.MeetingInfor.Duration <= 0)
{
sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);
if (sc.Result != null)
{
sc.Context.Activity.Properties.TryGetValue("OriginText", out var content);

IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
if (dateTimeResolutions.First().Value != null)
IList<DateTimeResolution> dateTimeResolutions = sc.Result as List<DateTimeResolution>;
if (dateTimeResolutions.First().Value != null)
{
int.TryParse(dateTimeResolutions.First().Value, out var duration);
state.MeetingInfor.Duration = duration;
}
}
else
{
int.TryParse(dateTimeResolutions.First().Value, out var duration);
state.MeetingInfor.Duration = duration;
// user has tried 5 times but can't get result
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(CalendarSharedResponses.RetryTooManyResponse));
return await sc.CancelAllDialogsAsync();
}
}

Expand Down Expand Up @@ -959,10 +985,11 @@ public CreateEventDialog(
{
try
{
return await sc.PromptAsync(Actions.GetRecreateInfoPrompt, new PromptOptions
return await sc.PromptAsync(Actions.GetRecreateInfoPrompt, new CalendarPromptOptions
{
Prompt = ResponseManager.GetResponse(CreateEventResponses.GetRecreateInfo),
RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.GetRecreateInfoRetry)
RetryPrompt = ResponseManager.GetResponse(CreateEventResponses.GetRecreateInfoRetry),
MaxReprompt = 5
}, cancellationToken);
}
catch (Exception ex)
Expand Down Expand Up @@ -1012,9 +1039,9 @@ public CreateEventDialog(
}
else
{
// should not go to this part. place an error handling for safe.
await HandleDialogExceptions(sc, new Exception("Get unexpect result in recreate."));
return new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs);
// user has tried 5 times but can't get result
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(CalendarSharedResponses.RetryTooManyResponse));
return await sc.CancelAllDialogsAsync();
}
}
catch (Exception ex)
Expand Down
3 changes: 2 additions & 1 deletion skills/csharp/calendarskill/Dialogs/JoinEventDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ private bool IsValidJoinTime(TimeZoneInfo userTimeZone, EventModel e)
return await sc.PromptAsync(Actions.GetEventPrompt, new GetEventOptions(calendarService, state.GetUserTimeZone())
{
Prompt = ResponseManager.GetResponse(JoinEventResponses.NoMeetingToConnect),
RetryPrompt = ResponseManager.GetResponse(JoinEventResponses.NoMeetingToConnect)
RetryPrompt = ResponseManager.GetResponse(JoinEventResponses.NoMeetingToConnect),
MaxReprompt = 5
}, cancellationToken);
}
}
Expand Down
10 changes: 7 additions & 3 deletions skills/csharp/calendarskill/Dialogs/UpdateEventDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public UpdateEventDialog(
return await sc.PromptAsync(Actions.GetEventPrompt, new GetEventOptions(calendarService, state.GetUserTimeZone())
{
Prompt = ResponseManager.GetResponse(UpdateEventResponses.NoUpdateStartTime),
RetryPrompt = ResponseManager.GetResponse(UpdateEventResponses.EventWithStartTimeNotFound)
RetryPrompt = ResponseManager.GetResponse(UpdateEventResponses.EventWithStartTimeNotFound),
MaxReprompt = 5
}, cancellationToken);
}
}
Expand Down Expand Up @@ -224,7 +225,8 @@ public UpdateEventDialog(
{
Prompt = ResponseManager.GetResponse(UpdateEventResponses.NoNewTime),
RetryPrompt = ResponseManager.GetResponse(UpdateEventResponses.NoNewTimeRetry),
TimeZone = state.GetUserTimeZone()
TimeZone = state.GetUserTimeZone(),
MaxReprompt = 5
}, cancellationToken);
}
catch (Exception ex)
Expand Down Expand Up @@ -356,7 +358,9 @@ public UpdateEventDialog(
}
else
{
return await sc.BeginDialogAsync(Actions.GetNewStartTime, new UpdateDateTimeDialogOptions(UpdateDateTimeDialogOptions.UpdateReason.NotADateTime));
// user has tried 5 times but can't get result
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(CalendarSharedResponses.RetryTooManyResponse));
return await sc.CancelAllDialogsAsync();
}
}
catch (Exception ex)
Expand Down
10 changes: 10 additions & 0 deletions skills/csharp/calendarskill/Prompts/DatePrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ namespace CalendarSkill.Prompts
{
public class DatePrompt : Prompt<IList<DateTimeResolution>>
{
internal const string AttemptCountKey = "AttemptCount";

private static TimeZoneInfo userTimeZone = null;

private static int maxReprompt = -1;

public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> validator = null, string defaultLocale = null)
: base(dialogId, validator)
{
Expand Down Expand Up @@ -54,6 +58,7 @@ public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
}

userTimeZone = ((DatePromptOptions)options).TimeZone;
maxReprompt = ((CalendarPromptOptions)options).MaxReprompt;
}

protected override async Task<PromptRecognizerResult<IList<DateTimeResolution>>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -76,6 +81,11 @@ public DatePrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> va
}
}

if (maxReprompt > 0 && Convert.ToInt32(state[AttemptCountKey]) >= maxReprompt)
{
result.Succeeded = true;
}

return await Task.FromResult(result);
}

Expand Down
12 changes: 12 additions & 0 deletions skills/csharp/calendarskill/Prompts/DurationPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CalendarSkill.Prompts.Options;
using CalendarSkill.Responses.Shared;
using CalendarSkill.Utilities;
using Microsoft.Bot.Builder;
Expand All @@ -14,6 +15,10 @@ namespace CalendarSkill.Prompts
{
public class DurationPrompt : Prompt<IList<DateTimeResolution>>
{
internal const string AttemptCountKey = "AttemptCount";

private static int maxReprompt = -1;

public DurationPrompt(string dialogId, PromptValidator<IList<DateTimeResolution>> validator = null, string defaultLocale = null)
: base(dialogId, validator)
{
Expand Down Expand Up @@ -44,6 +49,8 @@ public DurationPrompt(string dialogId, PromptValidator<IList<DateTimeResolution>
{
await turnContext.SendActivityAsync(options.Prompt, cancellationToken).ConfigureAwait(false);
}

maxReprompt = ((CalendarPromptOptions)options).MaxReprompt;
}

protected override async Task<PromptRecognizerResult<IList<DateTimeResolution>>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -67,6 +74,11 @@ public DurationPrompt(string dialogId, PromptValidator<IList<DateTimeResolution>
}
}

if (maxReprompt > 0 && Convert.ToInt32(state[AttemptCountKey]) >= maxReprompt)
{
result.Succeeded = true;
}

return await Task.FromResult(result);
}

Expand Down
10 changes: 10 additions & 0 deletions skills/csharp/calendarskill/Prompts/GetEventPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ namespace CalendarSkill.Prompts
/// </summary>
public class GetEventPrompt : Prompt<IList<EventModel>>
{
internal const string AttemptCountKey = "AttemptCount";

private static ICalendarService calendarService = null;
private static TimeZoneInfo userTimeZone = null;
private static int maxReprompt = -1;

public GetEventPrompt(string dialogId, PromptValidator<IList<EventModel>> validator = null, string defaultLocale = null)
: base(dialogId, validator)
Expand Down Expand Up @@ -62,6 +65,8 @@ public GetEventPrompt(string dialogId, PromptValidator<IList<EventModel>> valida
{
await turnContext.SendActivityAsync(options.Prompt, cancellationToken).ConfigureAwait(false);
}

maxReprompt = ((CalendarPromptOptions)options).MaxReprompt;
}

protected override async Task<PromptRecognizerResult<IList<EventModel>>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
Expand Down Expand Up @@ -99,6 +104,11 @@ public GetEventPrompt(string dialogId, PromptValidator<IList<EventModel>> valida
}
}

if (maxReprompt > 0 && Convert.ToInt32(state[AttemptCountKey]) >= maxReprompt)
{
result.Succeeded = true;
}

return await Task.FromResult(result);
}

Expand Down
12 changes: 12 additions & 0 deletions skills/csharp/calendarskill/Prompts/GetRecreateInfoPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using CalendarSkill.Prompts.Options;
using CalendarSkill.Responses.Shared;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
Expand All @@ -14,6 +15,10 @@ namespace CalendarSkill.Prompts
{
public class GetRecreateInfoPrompt : Prompt<RecreateEventState?>
{
internal const string AttemptCountKey = "AttemptCount";

private static int maxReprompt = -1;

public GetRecreateInfoPrompt(string dialogId, PromptValidator<RecreateEventState?> validator = null, string defaultLocale = null)
: base(dialogId, validator)
{
Expand Down Expand Up @@ -42,6 +47,8 @@ public GetRecreateInfoPrompt(string dialogId, PromptValidator<RecreateEventState
{
await turnContext.SendActivityAsync(options.Prompt, cancellationToken).ConfigureAwait(false);
}

maxReprompt = ((CalendarPromptOptions)options).MaxReprompt;
}

protected override async Task<PromptRecognizerResult<RecreateEventState?>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
Expand All @@ -64,6 +71,11 @@ public GetRecreateInfoPrompt(string dialogId, PromptValidator<RecreateEventState
}
}

if (maxReprompt > 0 && Convert.ToInt32(state[AttemptCountKey]) >= maxReprompt)
{
result.Succeeded = true;
}

return await Task.FromResult(result);
}

Expand Down
Loading