-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port: Register missingProperties custom function to get all variables…
… the template contains (#3885) * init * init * fix issue * fix API extractor error * fix * fix comments * fix test:compat Co-authored-by: Josh Gummersall <jgummersall@microsoft.com>
- Loading branch information
Showing
18 changed files
with
476 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
...r-dialogs-adaptive-testing/tests/resources/ActionTests/Action_MissingProperty.test.dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
{ | ||
"$schema": "../../../tests.schema", | ||
"$kind": "Microsoft.Test.Script", | ||
"dialog": { | ||
"$kind": "Microsoft.AdaptiveDialog", | ||
"id": "planningTest", | ||
"generator": "main.lg", | ||
"triggers": [ | ||
{ | ||
"$kind": "Microsoft.OnBeginDialog", | ||
"actions": [ | ||
{ | ||
"$kind": "Microsoft.SetProperty", | ||
"property": "user.missingProperties", | ||
"value": "=missingProperties('${dialog.first} and ${dialog.second}')" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Foreach", | ||
"itemsProperty": "user.missingProperties", | ||
"actions": [ | ||
{ | ||
"$kind": "Microsoft.IfCondition", | ||
"condition": "empty(getProperty(dialog.foreach.value))", | ||
"actions": [ | ||
{ | ||
"$kind": "Microsoft.TextInput", | ||
"property": "=dialog.foreach.value", | ||
"prompt": "Hello, please input ${dialog.foreach.value}" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"$kind": "Microsoft.SendActivity", | ||
"activity": "You finish all slot filling. And get result: ${dialog.first} and ${dialog.second}" | ||
}, | ||
{ | ||
"$kind": "Microsoft.SetProperty", | ||
"property": "user.missingProperties", | ||
"value": "=missingProperties('${nameAndAge()}')" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Foreach", | ||
"itemsProperty": "user.missingProperties", | ||
"actions": [ | ||
{ | ||
"$kind": "Microsoft.IfCondition", | ||
"condition": "empty(getProperty(dialog.foreach.value))", | ||
"actions": [ | ||
{ | ||
"$kind": "Microsoft.TextInput", | ||
"property": "=dialog.foreach.value", | ||
"prompt": "Hello, please input ${dialog.foreach.value}" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"$kind": "Microsoft.SendActivity", | ||
"activity": "You finish all slot filling. And get result: ${nameAndAge()}" | ||
}, | ||
{ | ||
"$kind": "Microsoft.SetProperty", | ||
"property": "user.missingProperties", | ||
"value": "=missingProperties('${nameAndAge()}')" | ||
}, | ||
{ | ||
"$kind": "Microsoft.SendActivity", | ||
"activity": "${count(user.missingProperties)}" | ||
}, | ||
{ | ||
"$kind": "Microsoft.BeginDialog", | ||
"options": {}, | ||
"dialog": { | ||
"$kind": "Microsoft.AdaptiveDialog", | ||
"generator": "sub.lg", | ||
"triggers": [ | ||
{ | ||
"$kind": "Microsoft.OnBeginDialog", | ||
"actions": [ | ||
{ | ||
"$kind": "Microsoft.SetProperty", | ||
"property": "user.missingProperties", | ||
"value": "=missingProperties('${showPetName()}')" | ||
}, | ||
{ | ||
"$kind": "Microsoft.SendActivity", | ||
"activity": "${count(user.missingProperties)}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"$kind": "Microsoft.SetProperty", | ||
"property": "user.missingProperties", | ||
"value": "=missingProperties('${nameAndAge()}')" | ||
}, | ||
{ | ||
"$kind": "Microsoft.SendActivity", | ||
"activity": "${count(user.missingProperties)}" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"script": [ | ||
{ | ||
"$kind": "Microsoft.Test.UserConversationUpdate" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "Hello, please input dialog.first" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.UserSays", | ||
"text": "1" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "Hello, please input dialog.second" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.UserSays", | ||
"text": "2" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "You finish all slot filling. And get result: 1 and 2" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "Hello, please input user.name" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.UserSays", | ||
"text": "Jack" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "Hello, please input user.age" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.UserSays", | ||
"text": "20" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "You finish all slot filling. And get result: my name is Jack and my age is 20" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "2" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "1" | ||
}, | ||
{ | ||
"$kind": "Microsoft.Test.AssertReply", | ||
"text": "2" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ | |
|
||
# length | ||
- length in main | ||
|
||
# nameAndAge | ||
- my name is ${user.name} and my age is ${user.age} |
2 changes: 2 additions & 0 deletions
2
libraries/botbuilder-dialogs-adaptive-testing/tests/resources/ActionTests/sub.lg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# showPetName | ||
- the pet's name is ${petName} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
libraries/botbuilder-dialogs-adaptive/src/functions/missingPropertiesFunction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @module botbuilder-dialogs-adaptive | ||
*/ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { | ||
Expression, | ||
ExpressionEvaluator, | ||
FunctionUtils, | ||
MemoryInterface, | ||
Options, | ||
ReturnType, | ||
ValueWithError, | ||
} from 'adaptive-expressions'; | ||
import { LanguageGenerator } from '../languageGenerator'; | ||
|
||
import { DialogContext, DialogStateManager } from 'botbuilder-dialogs'; | ||
/** | ||
* Defines missingProperties(template) expression function. | ||
* This expression will get all variables the template contains. | ||
* | ||
* @example missingProperties('${a} ${b}') | ||
*/ | ||
export class MissingPropertiesFunction extends ExpressionEvaluator { | ||
/** | ||
* Function identifier name. | ||
*/ | ||
public static readonly functionName = 'missingProperties'; // `name` is reserved in JavaScript. | ||
|
||
private static readonly generatorPath = 'dialogclass.generator'; | ||
|
||
private static dialogContext: DialogContext; | ||
|
||
/** | ||
* Intializes a new instance of the [MissingProperties](xref:botbuilder-dialogs-adaptive.MissingProperties) class. | ||
* | ||
* @param context dialog context. | ||
*/ | ||
public constructor(context: DialogContext) { | ||
super( | ||
MissingPropertiesFunction.functionName, | ||
MissingPropertiesFunction.function, | ||
ReturnType.Array, | ||
FunctionUtils.validateUnaryString | ||
); | ||
|
||
MissingPropertiesFunction.dialogContext = context; | ||
} | ||
|
||
private static function(expression: Expression, state: MemoryInterface, options: Options): ValueWithError { | ||
const { args, error } = FunctionUtils.evaluateChildren(expression, state, options); | ||
if (error != null) { | ||
return { value: undefined, error }; | ||
} | ||
|
||
const templateBody = args[0].toString(); | ||
|
||
const generator = (state as DialogStateManager).getValue<LanguageGenerator>(MissingPropertiesFunction.generatorPath); | ||
if (generator) { | ||
return { | ||
value: generator.missingProperties( | ||
MissingPropertiesFunction.dialogContext, | ||
templateBody, | ||
state, | ||
options | ||
), | ||
error: undefined, | ||
}; | ||
} | ||
return { value: undefined, error: undefined }; | ||
} | ||
} |
Oops, something went wrong.