Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f080966
copy other lg fields
yeze322 Oct 22, 2019
be0202c
optmize
yeze322 Oct 22, 2019
88af3c7
Merge branch 'master' into zeye/fix-lg-copy
boydc2014 Oct 23, 2019
4b0b084
extract lgUtils out of copyUtils
yeze322 Oct 23, 2019
2f90434
update lg template regex
yeze322 Oct 23, 2019
ccb4763
refine copyLgActivity API
yeze322 Oct 23, 2019
fbb44ca
add type for copyLgTemplate
yeze322 Oct 23, 2019
92b2fed
move lgUtils to Shell
yeze322 Oct 23, 2019
9eb46a5
fix lgUtils return value format
yeze322 Oct 23, 2019
e12fcd6
rename input ap name to copyLgTemplate
yeze322 Oct 23, 2019
b9ce7b3
fix lgUtils test
yeze322 Oct 23, 2019
9bc39d0
pass down copyLgTemplate from Shell instead of in shared lib
yeze322 Oct 23, 2019
67e2dbd
rename lgUtils -> lgHandlers
yeze322 Oct 23, 2019
5f72af0
fix the format of newTemplateName
yeze322 Oct 23, 2019
a0a3733
change test name of lgHandlers
yeze322 Oct 23, 2019
237cb0c
group imports in ExtensionContainer
yeze322 Oct 23, 2019
79e470d
Merge branch 'master' into zeye/fix-lg-copy
yeze322 Oct 23, 2019
eabf7ce
update several ts types
yeze322 Oct 23, 2019
b2497a5
use lodash.cloneDeep in copyUtils
yeze322 Oct 23, 2019
237f6a1
move walker to another file
yeze322 Oct 23, 2019
bb62953
move copyUtils and walk to 'utils' folder
yeze322 Oct 23, 2019
e279a71
move copyUtils.test to sub folder
yeze322 Oct 23, 2019
d5094f0
add UT for 'walkAdaptiveAction'
yeze322 Oct 23, 2019
ce00b7b
fix async version walk + UT
yeze322 Oct 23, 2019
9462253
Merge branch 'master' into zeye/fix-lg-copy
boydc2014 Oct 23, 2019
91658bf
Merge branch 'master' into zeye/fix-lg-copy
boydc2014 Oct 23, 2019
2e2f050
Merge branch 'master' into zeye/fix-lg-copy
boydc2014 Oct 24, 2019
7ceec4e
Merge branch 'master' into zeye/fix-lg-copy
yeze322 Oct 25, 2019
db2016a
Merge branch 'master' into zeye/fix-lg-copy
boydc2014 Oct 28, 2019
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
15 changes: 11 additions & 4 deletions Composer/packages/lib/shared/__tests__/copyUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { copyAdaptiveAction } from '../src/copyUtils';

describe('copyAdaptiveAction', () => {
const lgTemplate = [{ Name: 'bfdactivity-1234', Body: '-hello' }];
const lgTemplate = [
{ Name: 'bfdactivity-1234', Body: '-hello' },
{ Name: 'bfdprompt-1234', Body: '-prompt' },
{ Name: 'bfdinvalidPrompt-1234', Body: '-invalid' },
];
const externalApi = {
updateDesigner: data => {
data.$designer = { id: '5678' };
Expand Down Expand Up @@ -72,7 +76,8 @@ describe('copyAdaptiveAction', () => {
alwaysPrompt: false,
allowInterruptions: 'true',
outputFormat: 'none',
prompt: '[bfdactivity-1234]',
prompt: '[bfdprompt-1234]',
invalidPrompt: '[bfdinvalidPrompt-1234]',
};

expect(await copyAdaptiveAction(promptText, externalApi)).toEqual({
Expand All @@ -84,7 +89,8 @@ describe('copyAdaptiveAction', () => {
alwaysPrompt: false,
allowInterruptions: 'true',
outputFormat: 'none',
prompt: '[bfdactivity-5678]',
prompt: '[bfdprompt-5678]',
invalidPrompt: '[bfdinvalidPrompt-5678]',
});

expect(await copyAdaptiveAction(promptText, externalApiWithFailure)).toEqual({
Expand All @@ -96,7 +102,8 @@ describe('copyAdaptiveAction', () => {
alwaysPrompt: false,
allowInterruptions: 'true',
outputFormat: 'none',
prompt: '-hello',
prompt: '-prompt',
invalidPrompt: '-invalid',
});
});
});
17 changes: 12 additions & 5 deletions Composer/packages/lib/shared/src/copyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ async function walkAdaptiveAction(input: any, visitor: (data: any) => Promise<an
}
}

const LgActivityRegex = /\[bfd.+-.+\]/;
function isLgActivity(activity: string) {
return activity && (activity.includes('bfdactivity-') || activity.includes('bfdprompt-'));
return activity && LgActivityRegex.test(activity);
}

async function copyLgActivity(activity: string, designerId: string, lgApi: any): Promise<string> {
async function copyLgActivity(activity: string, newLgId: string, lgApi: any): Promise<string> {
if (!activity) return '';
if (!isLgActivity(activity) || !lgApi) return activity;

Expand All @@ -60,7 +61,6 @@ async function copyLgActivity(activity: string, designerId: string, lgApi: any):
if (currentLg) {
// Create new lg activity.
const newLgContent = currentLg.Body;
const newLgId = `bfdactivity-${designerId}`;
try {
await updateLgTemplate('common', newLgId, newLgContent);
return `[${newLgId}]`;
Expand All @@ -72,11 +72,18 @@ async function copyLgActivity(activity: string, designerId: string, lgApi: any):
}

const overrideLgActivity = async (data, { lgApi }) => {
data.activity = await copyLgActivity(data.activity, data.$designer.id, lgApi);
const newLgId = `bfdactivity-${data.$designer.id}`;
data.activity = await copyLgActivity(data.activity, newLgId, lgApi);
};

const overrideLgPrompt = async (data, { lgApi }) => {
data.prompt = await copyLgActivity(data.prompt, data.$designer.id, lgApi);
for (const promptFieldKey of ['prompt', 'unrecognizedPrompt', 'invalidPrompt', 'defaultValueResponse']) {
const existingActivity = data[promptFieldKey];
const newLgId = `bfd${promptFieldKey}-${data.$designer.id}`;
if (existingActivity) {
data[promptFieldKey] = await copyLgActivity(existingActivity, newLgId, lgApi);
}
}
};

// TODO: use $type from SDKTypes (after solving circular import issue).
Expand Down