diff --git a/Composer/packages/lib/shared/__tests__/copyUtils.test.ts b/Composer/packages/lib/shared/__tests__/copyUtils.test.ts index 5938033901..3cffbfd9ea 100644 --- a/Composer/packages/lib/shared/__tests__/copyUtils.test.ts +++ b/Composer/packages/lib/shared/__tests__/copyUtils.test.ts @@ -1,7 +1,7 @@ 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: '-hi' }]; const externalApi = { updateDesigner: data => { data.$designer = { id: '5678' }; @@ -72,7 +72,7 @@ describe('copyAdaptiveAction', () => { alwaysPrompt: false, allowInterruptions: 'true', outputFormat: 'none', - prompt: '[bfdactivity-1234]', + prompt: '[bfdprompt-1234]', }; expect(await copyAdaptiveAction(promptText, externalApi)).toEqual({ @@ -84,7 +84,7 @@ describe('copyAdaptiveAction', () => { alwaysPrompt: false, allowInterruptions: 'true', outputFormat: 'none', - prompt: '[bfdactivity-5678]', + prompt: '[bfdprompt-5678]', }); expect(await copyAdaptiveAction(promptText, externalApiWithFailure)).toEqual({ @@ -96,7 +96,7 @@ describe('copyAdaptiveAction', () => { alwaysPrompt: false, allowInterruptions: 'true', outputFormat: 'none', - prompt: '-hello', + prompt: '-hi', }); }); }); diff --git a/Composer/packages/lib/shared/src/copyUtils.ts b/Composer/packages/lib/shared/src/copyUtils.ts index f65e59144d..bf89ec879e 100644 --- a/Composer/packages/lib/shared/src/copyUtils.ts +++ b/Composer/packages/lib/shared/src/copyUtils.ts @@ -37,14 +37,30 @@ async function walkAdaptiveAction(input: any, visitor: (data: any) => Promise { if (!activity) return ''; - if (!isLgActivity(activity) || !lgApi) return activity; + if (!lgApi) return activity; + const lgTemplate = parseLgTemplate(activity); + if (!lgTemplate) return activity; + + const { templateType } = lgTemplate; const { getLgTemplates, updateLgTemplate } = lgApi; if (!getLgTemplates) return activity; @@ -60,7 +76,7 @@ async function copyLgActivity(activity: string, designerId: string, lgApi: any): if (currentLg) { // Create new lg activity. const newLgContent = currentLg.Body; - const newLgId = `bfdactivity-${designerId}`; + const newLgId = `bfd${templateType}-${designerId}`; try { await updateLgTemplate('common', newLgId, newLgContent); return `[${newLgId}]`; @@ -76,7 +92,12 @@ const overrideLgActivity = async (data, { lgApi }) => { }; const overrideLgPrompt = async (data, { lgApi }) => { - data.prompt = await copyLgActivity(data.prompt, data.$designer.id, lgApi); + const promptFields = ['prompt', 'unrecognizedPrompt', 'defaultValueResponse', 'invalidPrompt']; + for (const field of promptFields) { + if (isLgTemplate(data[field])) { + data[field] = await copyLgActivity(data[field], data.$designer.id, lgApi); + } + } }; // TODO: use $type from SDKTypes (after solving circular import issue).