Skip to content

Commit

Permalink
feat: add new actions in samples (microsoft#2559)
Browse files Browse the repository at this point in the history
* Add foreach break and continue sample

* Add Goto action

* Add test cases

* ContinueLoop / BreakLoop

* Adds continue and break to looping

Co-authored-by: zeye <[email protected]>
Co-authored-by: Chris Whitten <[email protected]>
  • Loading branch information
3 people authored Apr 14, 2020
1 parent 5096a30 commit d9effa0
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 2 deletions.
13 changes: 13 additions & 0 deletions BotProject/Templates/CSharp/Tests/ControllingConversationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ await BuildTestFlow()
.Send("Yes")
.AssertReply("Do you want to repeat this dialog, yes to repeat, no to end this dialog (1) Yes or (2) No")
.Send("No")
.Send("08")
.AssertReply("In continue loop, which only outputs dual.")
.AssertReply("index: 1 value: 2")
.AssertReply("index: 3 value: 4")
.AssertReply("index: 5 value: 6")
.AssertReply("In break loop, which breaks when index > 2")
.AssertReply("index: 0 value: 1")
.AssertReply("index: 1 value: 2")
.AssertReply("index: 2 value: 3")
.AssertReply("done")
.Send("09")
.AssertReply("counter: 1")
.AssertReply("counter: 2")
.StartTestAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class VisualSDKDemo extends Component {
...dialogGroups[DialogGroup.RESPONSE].types,
...dialogGroups[DialogGroup.INPUT].types,
...dialogGroups[DialogGroup.BRANCHING].types,
...dialogGroups[DialogGroup.LOOPING].types,
...dialogGroups[DialogGroup.MEMORY].types,
...dialogGroups[DialogGroup.STEP].types,
...dialogGroups[DialogGroup.CODE].types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const buildEdgeMenuItemsFromClipboardContext = (
DialogGroup.RESPONSE,
DialogGroup.INPUT,
DialogGroup.BRANCHING,
DialogGroup.LOOPING,
DialogGroup.STEP,
DialogGroup.MEMORY,
DialogGroup.CODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export const NodeColors = {
themeColor: Colors.AzureGray3,
iconColor: Colors.AzureGray2,
},
[DialogGroup.LOOPING]: {
themeColor: Colors.AzureGray3,
iconColor: Colors.AzureGray2,
},
[DialogGroup.LOG]: {
themeColor: Colors.AzureGray3,
iconColor: Colors.AzureGray2,
Expand Down
6 changes: 6 additions & 0 deletions Composer/packages/lib/shared/src/labelMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export const ConceptLabels: { [key in ConceptLabelKey]?: LabelOverride } = {
[SDKKinds.ForeachPage]: {
title: formatMessage('Loop: for each page (multiple items)'),
},
[SDKKinds.ContinueLoop]: {
title: formatMessage('Continue loop'),
},
[SDKKinds.BreakLoop]: {
title: formatMessage('Break out of loop'),
},
[SDKKinds.HttpRequest]: {
title: formatMessage('Send an HTTP request'),
},
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/lib/shared/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export enum SDKKinds {
AgeEntityRecognizer = 'Microsoft.AgeEntityRecognizer',
AttachmentInput = 'Microsoft.AttachmentInput',
BeginDialog = 'Microsoft.BeginDialog',
BreakLoop = 'Microsoft.BreakLoop',
CancelAllDialogs = 'Microsoft.CancelAllDialogs',
ChoiceInput = 'Microsoft.ChoiceInput',
ConditionalSelector = 'Microsoft.ConditionalSelector',
ConfirmInput = 'Microsoft.ConfirmInput',
ConfirmationEntityRecognizer = 'Microsoft.ConfirmationEntityRecognizer',
ContinueLoop = 'Microsoft.ContinueLoop',
CurrencyEntityRecognizer = 'Microsoft.CurrencyEntityRecognizer',
DateTimeEntityRecognizer = 'Microsoft.DateTimeEntityRecognizer',
DateTimeInput = 'Microsoft.DateTimeInput',
Expand Down
8 changes: 7 additions & 1 deletion Composer/packages/lib/shared/src/viewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum DialogGroup {
STEP = 'STEP',
CODE = 'CODE',
LOG = 'LOG',
LOOPING = 'LOOPING',
EVENTS = 'EVENTS',
ADVANCED_EVENTS = 'ADVANCED_EVENTS',
MESSAGE_EVENTS = 'MESSAGE_EVENTS',
Expand Down Expand Up @@ -62,7 +63,11 @@ export const dialogGroups: DialogGroupsMap = {
},
[DialogGroup.BRANCHING]: {
label: 'Create a condition',
types: [SDKKinds.IfCondition, SDKKinds.SwitchCondition, SDKKinds.Foreach, SDKKinds.ForeachPage],
types: [SDKKinds.IfCondition, SDKKinds.SwitchCondition],
},
[DialogGroup.LOOPING]: {
label: 'Looping',
types: [SDKKinds.Foreach, SDKKinds.ForeachPage, SDKKinds.ContinueLoop, SDKKinds.BreakLoop],
},
[DialogGroup.MEMORY]: {
label: 'Manage properties',
Expand Down Expand Up @@ -265,6 +270,7 @@ export function getDialogGroupByType(type) {
case DialogGroup.INPUT:
case DialogGroup.RESPONSE:
case DialogGroup.BRANCHING:
case DialogGroup.LOOPING:
case DialogGroup.EVENTS:
case DialogGroup.ADVANCED_EVENTS:
dialogType = key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
{
"intent": "RepeatDialog",
"pattern": "RepeatDialog|07"
},
{
"intent": "ForeachWithBreakAndContinue",
"pattern": "ForeachWithBreakAndContinue|08"
},
{
"intent": "GotoAction",
"pattern": "GotoAction|09"
}
]
},
Expand Down Expand Up @@ -196,6 +204,38 @@
]
}
]
},
{
"$kind": "Microsoft.OnIntent",
"$designer": {
"id": "B9q55b"
},
"intent": "ForeachWithBreakAndContinue",
"actions": [
{
"$kind": "Microsoft.BeginDialog",
"$designer": {
"id": "h1y4y_"
},
"dialog": "foreachwithbreakandcontinue"
}
]
},
{
"$kind": "Microsoft.OnIntent",
"$designer": {
"id": "7yeKNd"
},
"intent": "GotoAction",
"actions": [
{
"$kind": "Microsoft.BeginDialog",
"$designer": {
"id": "jYHDqw"
},
"dialog": "gotoaction"
}
]
}
],
"generator": "controllingconversationflowsample.lg",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"$kind": "Microsoft.AdaptiveDialog",
"$designer": {
"id": "zzWd0o",
"name": "foreachwithbreakandcontinue"
},
"autoEndDialog": "true",
"defaultResultProperty": "dialog.result",
"triggers": [
{
"$kind": "Microsoft.OnBeginDialog",
"$designer": {
"name": "BeginDialog",
"id": "GrXVDj"
},
"actions": [
{
"$kind": "Microsoft.SetProperty",
"property": "dialog.todo",
"value": "=[]",
"$designer": {
"id": "eAGDyE"
}
},
{
"$kind": "Microsoft.EditArray",
"itemsProperty": "dialog.todo",
"changeType": "push",
"value": "=1",
"$designer": {
"id": "tb79kV"
}
},
{
"$kind": "Microsoft.EditArray",
"itemsProperty": "dialog.todo",
"changeType": "push",
"value": "=2",
"$designer": {
"id": "8HLtUh"
}
},
{
"$kind": "Microsoft.EditArray",
"itemsProperty": "dialog.todo",
"changeType": "push",
"value": "=3",
"$designer": {
"id": "b-Ce3D"
}
},
{
"$kind": "Microsoft.EditArray",
"itemsProperty": "dialog.todo",
"changeType": "push",
"value": "=4",
"$designer": {
"id": "bcQTV2"
}
},
{
"$kind": "Microsoft.EditArray",
"itemsProperty": "dialog.todo",
"changeType": "push",
"value": "=5",
"$designer": {
"id": "YbcSpP"
}
},
{
"$kind": "Microsoft.EditArray",
"itemsProperty": "dialog.todo",
"changeType": "push",
"value": "=6",
"$designer": {
"id": "vjA4WI"
}
},
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "MLnfkV"
},
"activity": "${bfdactivity-MLnfkV()}"
},
{
"$kind": "Microsoft.Foreach",
"$designer": {
"id": "IP5LgI"
},
"itemsProperty": "dialog.todo",
"actions": [
{
"$kind": "Microsoft.IfCondition",
"condition": "(dialog.foreach.value % 2) == 1",
"actions": [
{
"$kind": "Microsoft.ContinueLoop",
"$designer": {
"id": "9eRMEs"
}
}
],
"$designer": {
"id": "gqgGZZ"
}
},
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "_aqYPi"
},
"activity": "${bfdactivity-_aqYPi()}"
}
]
},
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "49S9ax"
},
"activity": "${bfdactivity-49S9ax()}"
},
{
"$kind": "Microsoft.Foreach",
"itemsProperty": "dialog.todo",
"actions": [
{
"$kind": "Microsoft.IfCondition",
"condition": "dialog.foreach.index > 2",
"actions": [
{
"$kind": "Microsoft.BreakLoop",
"$designer": {
"id": "fH83G4"
}
}
],
"$designer": {
"id": "d4Q17s"
}
},
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "Jz-Jjl"
},
"activity": "${bfdactivity-Jz-Jjl()}"
}
],
"$designer": {
"id": "UvAKgW"
}
},
{
"$kind": "Microsoft.SendActivity",
"$designer": {
"id": "8JDxhd"
},
"activity": "${bfdactivity-8JDxhd()}"
}
]
}
],
"generator": "foreachwithbreakandcontinue.lg"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[import](common.lg)


# bfdactivity-MLnfkV()
- In continue loop, which only outputs dual.
# bfdactivity-8JDxhd()
- done

# bfdactivity-49S9ax()
- In break loop, which breaks when index > 2


# bfdactivity-_aqYPi()
- index: ${dialog.foreach.index} value: ${dialog.foreach.value}
# bfdactivity-Jz-Jjl()
- index: ${dialog.foreach.index} value: ${dialog.foreach.value}
Loading

0 comments on commit d9effa0

Please sign in to comment.