Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return invalid state instead of throwing exceptions for non-string input of TextInput action #4966

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -47,8 +47,12 @@ public TextInput([CallerFilePath] string callerPath = "", [CallerLineNumber] int
/// <returns>InputState which reflects whether input was recognized as valid or not.</returns>
protected override Task<InputState> OnRecognizeInputAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
var input = dc.State.GetValue<string>(VALUE_PROPERTY);

var input = dc.State.GetValue<object>(VALUE_PROPERTY);
if (!(input is string strInput))
{
return Task.FromResult(InputState.Invalid);
}

if (this.OutputFormat != null)
{
var (outputValue, error) = this.OutputFormat.TryGetValue(dc.State);
Expand All @@ -57,7 +61,7 @@ public TextInput([CallerFilePath] string callerPath = "", [CallerLineNumber] int
if (!string.IsNullOrWhiteSpace(outputValue))
{
// if the result is null or empty string, ignore it.
input = outputValue.ToString();
strInput = outputValue.ToString();
}
}
else
Expand All @@ -66,8 +70,8 @@ public TextInput([CallerFilePath] string callerPath = "", [CallerLineNumber] int
}
}

dc.State.SetValue(VALUE_PROPERTY, input);
return input.Length > 0 ? Task.FromResult(InputState.Valid) : Task.FromResult(InputState.Unrecognized);
dc.State.SetValue(VALUE_PROPERTY, strInput);
return strInput.Length > 0 ? Task.FromResult(InputState.Valid) : Task.FromResult(InputState.Unrecognized);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ public async Task Action_TextInputWithInvalidPrompt()
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer);
}

[Fact]
public async Task Action_TextInputWithNonStringInput()
{
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer);
}

[Fact]
public async Task Action_TextInputWithValueExpression()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"id": "planningTest",
"triggers": [
{
"$kind": "Microsoft.OnUnknownIntent",
"actions": [
{
"$kind": "Microsoft.SetProperty",
"property": "dialog.firstName",
"value": "lu"
},
{
"$kind": "Microsoft.SetProperty",
"property": "dialog.lastName",
"value": "han"
},
{
"$kind": "Microsoft.IfCondition",
"condition": "(user.name == null)",
"actions": [
{
"$kind": "Microsoft.TextInput",
"property": "user.name",
"prompt": "Hello, what is your name?",
"unrecognizedPrompt": "How should I call you?",
"invalidPrompt": "That does not soud like a name",
"value": "=json(`{'foo': '$firstName','item': '$lastName'}`)"
}
]
}
]
}
],
"autoEndDialog": true,
"defaultResultProperty": "dialog.result"
},
"script": [
{
"$kind": "Microsoft.Test.UserSays",
"text": "hi"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "That does not soud like a name"
}
]
}