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

Commit

Permalink
[ITSM] replace enum prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Hualiang Xie committed Oct 31, 2019
1 parent e988dce commit 2761615
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public ShowTicketDialog(
}

var state = await StateAccessor.GetAsync(sc.Context, () => new SkillState());
state.AttributeType = (AttributeType)sc.Result;
Enum.TryParse((string)sc.Result, out AttributeType attributeType);
state.AttributeType = attributeType;
return await sc.NextAsync();
}

Expand Down Expand Up @@ -275,7 +276,7 @@ public ShowTicketDialog(
throw new Exception($"Invalid InterruptedIntent {state.InterruptedIntent}");
}

var intent = (GeneralLuis.Intent)sc.Result;
Enum.TryParse((string)sc.Result, out GeneralLuis.Intent intent);
if (intent == GeneralLuis.Intent.Reject)
{
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SharedResponses.ActionEnded));
Expand All @@ -301,7 +302,7 @@ public ShowTicketDialog(
}
}

protected async Task<bool> ShowNavigateValidator(PromptValidatorContext<GeneralLuis.Intent> promptContext, CancellationToken cancellationToken)
protected async Task<bool> ShowNavigateValidator(PromptValidatorContext<string> promptContext, CancellationToken cancellationToken)
{
if (promptContext.Recognized.Succeeded)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ protected async Task<DialogTurnResult> GetAuthToken(WaterfallStepContext sc, Can
}

var state = await StateAccessor.GetAsync(sc.Context, () => new SkillState());
state.AttributeType = (AttributeType)sc.Result;
Enum.TryParse((string)sc.Result, out AttributeType attributeType);
state.AttributeType = attributeType;
return await sc.NextAsync();
}

Expand Down Expand Up @@ -881,7 +882,7 @@ protected async Task<DialogTurnResult> GetAuthToken(WaterfallStepContext sc, Can

protected async Task<DialogTurnResult> IfKnowledgeHelp(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
{
var intent = (GeneralLuis.Intent)sc.Result;
Enum.TryParse((string)sc.Result, out GeneralLuis.Intent intent);
if (intent == GeneralLuis.Intent.Confirm)
{
await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SharedResponses.ActionEnded));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

namespace ITSMSkill.Prompts
{
public class AttributeWithNoPrompt : Prompt<AttributeType?>
public class AttributeWithNoPrompt : Prompt<string>
{
private readonly AttributeType[] attributes;

public AttributeWithNoPrompt(string dialogId, AttributeType[] attributes, PromptValidator<AttributeType?> validator = null, string defaultLocale = null)
public AttributeWithNoPrompt(string dialogId, AttributeType[] attributes, PromptValidator<string> validator = null, string defaultLocale = null)
: base(dialogId, validator)
{
this.attributes = attributes;
Expand Down Expand Up @@ -50,14 +50,14 @@ public AttributeWithNoPrompt(string dialogId, AttributeType[] attributes, Prompt
}
}

protected override async Task<PromptRecognizerResult<AttributeType?>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
protected override async Task<PromptRecognizerResult<string>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
{
if (turnContext == null)
{
throw new ArgumentNullException(nameof(turnContext));
}

var result = new PromptRecognizerResult<AttributeType?>();
var result = new PromptRecognizerResult<string>();
if (turnContext.Activity.Type == ActivityTypes.Message)
{
var message = turnContext.Activity.AsMessageActivity();
Expand All @@ -77,7 +77,7 @@ public AttributeWithNoPrompt(string dialogId, AttributeType[] attributes, Prompt
if (IsMessageAttributeMatch(text, attribute))
{
result.Succeeded = true;
result.Value = attribute;
result.Value = attribute.ToString();
break;
}
}
Expand Down
10 changes: 5 additions & 5 deletions skills/csharp/experimental/itsmskill/Prompts/GeneralPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

namespace ITSMSkill.Prompts
{
public class GeneralPrompt : Prompt<GeneralLuis.Intent>
public class GeneralPrompt : Prompt<string>
{
private readonly ISet<GeneralLuis.Intent> intents;
private readonly IStatePropertyAccessor<SkillState> stateAccessor;

public GeneralPrompt(string dialogId, ISet<GeneralLuis.Intent> intents, IStatePropertyAccessor<SkillState> stateAccessor, PromptValidator<GeneralLuis.Intent> validator = null, string defaultLocale = null)
public GeneralPrompt(string dialogId, ISet<GeneralLuis.Intent> intents, IStatePropertyAccessor<SkillState> stateAccessor, PromptValidator<string> validator = null, string defaultLocale = null)
: base(dialogId, validator)
{
this.intents = intents;
Expand Down Expand Up @@ -49,21 +49,21 @@ public GeneralPrompt(string dialogId, ISet<GeneralLuis.Intent> intents, IStatePr
}
}

protected override async Task<PromptRecognizerResult<GeneralLuis.Intent>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
protected override async Task<PromptRecognizerResult<string>> OnRecognizeAsync(ITurnContext turnContext, IDictionary<string, object> state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
{
if (turnContext == null)
{
throw new ArgumentNullException(nameof(turnContext));
}

var result = new PromptRecognizerResult<GeneralLuis.Intent>();
var result = new PromptRecognizerResult<string>();

var skillState = await stateAccessor.GetAsync(turnContext);

if (intents.Contains(skillState.GeneralIntent))
{
result.Succeeded = true;
result.Value = skillState.GeneralIntent;
result.Value = skillState.GeneralIntent.ToString();
}

return await Task.FromResult(result);
Expand Down

0 comments on commit 2761615

Please sign in to comment.