-
Notifications
You must be signed in to change notification settings - Fork 7
feat: migrate CARD actions to LG #28
base: master
Are you sure you want to change the base?
Conversation
| "@types/supertest": "2.0.4", | ||
| "async-file": "^2.0.2", | ||
| "body-parser": "1.18.3", | ||
| "botbuilder": "4.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect these versions of botbuilder to all match, all be 4.7.0. Does botbuilder-lg fully work with 4.4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to defer this question to @coldplaying42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is only one public version 4.7.0 of botbuilder-lg, and botbuilder-lg depends on botbuilder-core pkg but not botbuilder pkg (notice that botbuilder also depends on botbuilder-core pkg ).
packages/sdk/src/TemplateProvider.ts
Outdated
| entityDisplayValues.forEach((value: string, key: string) => { renderingParameters[key] = value }) | ||
|
|
||
| // Load the template. Currently, we assume that each lg file only has one template. | ||
| const lgFilename = templateDirectory + "//" + templateName + ".lg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should construct paths using path library. path.join handles OS differences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this one when going through the code port, thanks.
packages/sdk/src/TemplateProvider.ts
Outdated
| templateBody = templateBody.replace("- ```\r\n", "").replace("```", "") | ||
| for (let symbol of engine.templates[1].parameters) { | ||
| let sourceText = '@{' + symbol + '}' | ||
| let replaceText = '{{' + symbol + '}}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks suspicious. I thought the point of using LG was to adopt their templating language instead of using custom mustasch syntax. Does the library not handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I find this chunk of code confusing also. I don't know why or in what contexts an LG filename would include AdaptiveCard (seems fragile), or why the @{} syntax needs to be changed to {{}}.
There's also an issue that AFAICT, the engine.templates[].parameters property is always empty. I've just been digging into this, and it appears to be why the UI for editing variables in the LG/CARD actions is never rendered.
@coldplaying42 - could you comment on these issues ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the hacking code to render the adaptive card for eye/preview icon. The reason why @{} syntax needs to be changed to {{}} is that in lg file we use @{} to refer to variables (e.g., "text": "@{question}"), while in json file we use {{}} to refer to variables (e.g., "text": "{{question}}"). I made this change to enable AdaptiveCardViewer process the templateString.
https://github.com/microsoft/ConversationLearner-UI/blob/master/src/components/modals/AdaptiveCardViewer/AdaptiveCardViewer.tsx
However, this hacking code could only deal with the rendering of AdaptiveCard. In the future, AdaptiveCardViewer should be replaced with ActivityViewer, which can use some functions in https://github.com/microsoft/BotFramework-WebChat to render all the activities (e.g., thumbnail card, hero card, video card) that LG supports. And this chunk of code could be discarded.
@tpmsr you could try the parameters-lg in https://github.com/coldplaying42/ConversationLearner-Samples/tree/zy_lg/lgs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you point me to the repo containing ActivityViewer please ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think starting from https://github.com/microsoft/BotFramework-WebChat/tree/master/packages/bundle/src/adaptiveCards might be helpful. I am not familiar with BotFramework-WebChat. You could contact with BotFramework-WebChat team by Vishwac. They could help you to solve the eye/preview rendering problem.
| public static async RenderTemplate(templateName: string, templateArguments: RenderedActionArgument[]): Promise<any | null> { | ||
| let template = this.GetTemplate(templateName) | ||
| if (template === null) { | ||
| public static async RenderTemplate(templateName: string, templateArguments: RenderedActionArgument[], entityDisplayValues: Map<string, string>): Promise<any | null> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be Record instead of Map. If I remember these entity value types were done when maps were just introduced to JavaScript and wasn't clear when to apply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to punt on this for this PR, since changing the method that populates this (getEntityDisplayValueMap in FilledEntity) would introduce several unrelated changes across Models, SDK, and UI.
| if (file.includes('AdaptiveCard')) { | ||
| templateBody = engine.templates[1].body | ||
| templateBody = templateBody.replace("- ```\r\n", "").replace("```", "") | ||
| for (const symbol of engine.templates[1].parameters) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coldplaying42 - why is this rewrite only done for AdaptiveCard templates ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that the format of other types of cards (e.g., hero, video, audio) is totally different with adaptivecard. For example, it looks like:
[HeroCard
title=Cheese gromit!
subtitle=@{type}
text=This is some text describing the card, it's cool because it's cool
image=https://memegenerator.net/img/instances/500x/73055378/cheese-gromit.jpg
buttons=Option 1| Option 2| Option 3
]
This format could not be directly parsed and rendered by AdaptiveCardViewer.
| const fileName = path.join(templateDirectory, `${file}.lg`) | ||
| const engine = new TemplateEngine().addFile(fileName) | ||
| let templateBody = '' | ||
| if (file.includes('AdaptiveCard')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coldplaying42 - in what conditions will filenames with this token be generated ? This seems fragile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the hacking way to detect the lg file with adaptivecard. If the lg file has the adaptivecard body, templateBody will be filled and sent to AdaptiveCardViewer for parsing and rendering. I think if the ActivityViewer is implemented, this block of codes could be removed.
Port and update of @coldplaying42 (Zongyang Ma's) changes to replace CARD actions with LG actions.
LG files should be in an
lgdirectory parallel to the previouscarddirectory.Limitations (will be addressed in a future PR) :
bfdactivity-12345Example thumbnail card :

Original changes :
Modifications from original changes :
lgrather thanlgsnullif directory is not found, rather than../../lg(s)