Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template expand issues with string() and jsonStringify() #6186

Closed
i-knezevic-milan opened this issue Feb 10, 2022 · 7 comments
Closed

Template expand issues with string() and jsonStringify() #6186

i-knezevic-milan opened this issue Feb 10, 2022 · 7 comments
Assignees
Labels
Area: Adaptive expression The issue is related to Adaptive expressions Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository.

Comments

@i-knezevic-milan
Copy link

Version

.NET SDK 6
AdaptiveCards.Templating 1.2.2

Describe the bug

  1. When using literally ${string({'name': 'Sophie Owen'})} in a template as text of text block (or anywhere else) calling template.Expand does not execute this expression
  2. When using ${string(myObject)} where myObject is a variable passed to Expand method, template is expanded, but the way it is expanded makes the expanded template an invalid JSON.

e.g.

{\"type\":\"TextBlock\",\"id\":\"textBlock1\",\"text\":\"{\"name\":\"Sophie Owen\"}\"}

Same errors can be seen when using jsonStringify

@i-knezevic-milan i-knezevic-milan added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Feb 10, 2022
@stevkan stevkan added Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-reported Issue is created by anyone that is not a collaborator in the repository. labels Feb 10, 2022
@dmvtech
Copy link

dmvtech commented Feb 15, 2022

hi @i-knezevic-milan

This looks like a known issue with Adaptive Card templating and Adaptive Expressions (both of which use $) in which there is a type of collision.

Please see this issue for further info:
microsoft/BotFramework-Composer#8798

@boydc2014 I'm going to assign this one to you as well. Feel free to close whichever is more appropriate and leave the other for tracking the issue.

@dmvtech dmvtech added customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. and removed needs-triage The issue has just been created and it has not been reviewed by the team. labels Feb 15, 2022
@dmvtech dmvtech assigned boydc2014 and unassigned dmvtech Feb 15, 2022
@dmvtech dmvtech added the Area: Adaptive expression The issue is related to Adaptive expressions label Feb 15, 2022
@boydc2014 boydc2014 assigned mrivera-ms and unassigned boydc2014 Feb 18, 2022
@boydc2014
Copy link
Contributor

Thanks @dmvtech, i'm routing this to Monica as owner.

@johnataylor johnataylor assigned dmvtech and unassigned mrivera-ms Feb 28, 2022
@johnataylor
Copy link
Member

@dmvtech investigate further - understand if there is an appropriate escape sequence

@dmvtech
Copy link

dmvtech commented Mar 1, 2022

Hi @i-knezevic-milan

Since it appears that Adaptive Card templating is not currently implemented within the SDK, you are likely going to have to handle this in a specific manner. i.e. it may have to escape characters at certain points, etc. I believe you will have to do the adaptive expressions evaluation before passing it to the adaptive card template .expand()

If you can share your json card template, that will give more for us to go on and give any suggestions, etc.

@i-knezevic-milan
Copy link
Author

i-knezevic-milan commented Mar 1, 2022

Data

JsonConvert.DeserializeObject("{'person': {'name': 'Sophie Owen'}}")

1. Hardcoded with "

Template

{
    "type":"AdaptiveCard",
    "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
    "version":"1.4",
    "id":"adaptiveCard1",
    "title":"Server side object string",
    "body":[
        {
            "type":"TextBlock",
            "id":"textBlock1",
            "text":"${string({\"name\": \"Sophie Owen\"})}"
        }
    ]
}

Expanded template (didn't expand)

"{\"type\":\"AdaptiveCard\",\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"version\":\"1.4\",\"id\":\"adaptiveCard1\",\"title\":\"Server side object string\",\"body\":[{\"type\":\"TextBlock\",\"id\":\"textBlock1\",\"text\":\"${string({\\\"name\\\": \\\"Sophie Owen\\\"})}\"}]}"

2. Hardcoded with '

Template

{
    "type":"AdaptiveCard",
    "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
    "version":"1.4",
    "id":"adaptiveCard1",
    "title":"Server side object string",
    "body":[
        {
            "type":"TextBlock",
            "id":"textBlock1",
            "text":"${string({'name': 'Sophie Owen'})}"
        }
    ]
}

Expanded template (didn't expand)

"{\"type\":\"AdaptiveCard\",\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"version\":\"1.4\",\"id\":\"adaptiveCard1\",\"title\":\"Server side object string\",\"body\":[{\"type\":\"TextBlock\",\"id\":\"textBlock1\",\"text\":\"${string({'name': 'Sophie Owen'})}\"}]}"

3. Referenced as object

Template

{
    "type":"AdaptiveCard",
    "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
    "version":"1.4",
    "id":"adaptiveCard1",
    "title":"Server side object string",
    "body":[
        {
            "type":"TextBlock",
            "id":"textBlock1",
            "text":"${string(person)}"
        }
    ]
}

Expanded template

"{\"type\":\"AdaptiveCard\",\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"version\":\"1.4\",\"id\":\"adaptiveCard1\",\"title\":\"Server side object string\",\"body\":[{\"type\":\"TextBlock\",\"id\":\"textBlock1\",\"text\":\"{\"name\":\"Sophie Owen\"}\"}]}"

Notice that this time referenced object (person) was expanded, but "text":"{"name":"Sophie Owen"}" part is not a valid JSON because of quotes

@dmvtech
Copy link

dmvtech commented Mar 16, 2022

Thank you @i-knezevic-milan

calling template.Expand

Can you confirm the method you're using ExpandTemplate() (there is no Expand())?

If you are intending the value of text to be an object, you do not need to have the expression ${} surrounded with double quotes ". While it is not valid json, it is valid lg. As you don't need the surrounding double quotes, you do not need to escape the double quotes inside the string prebuilt function:

# AnAdaptiveCard
- ```{
    {
        "type":"AdaptiveCard",
        "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
        "version":"1.4",
        "id":"adaptiveCard1",
        "title":"Server side object string",
        "body":[
            {
                "type":"TextBlock",
                "id":"textBlock1",
                "text":${string({"name": "Sophie Owen"})}
            }
        ]
    }   
}```

Using the above in testing.lg, and the following in code:

_templates = Templates.ParseFile(@"C:\testing.lg");
var expandedlg = _templates.ExpandTemplate("AnAdaptiveCard");

I get the following:

{
    {
        "type":"AdaptiveCard",
        "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
        "version":"1.4",
        "id":"adaptiveCard1",
        "title":"Server side object string",
        "body":[
            {
                "type":"TextBlock",
                "id":"textBlock1",
                "text":{"name":"Sophie Owen"}
            }
        ]
    }
}

If that's not what you are looking for, my apologies. Please give me further info and more specific steps on what you are doing and what the output should be.

@dmvtech
Copy link

dmvtech commented Mar 29, 2022

Closing due to inactivity. If you still need assistance, please comment or reopen and we can continue to work on this.

@dmvtech dmvtech closed this as completed Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Adaptive expression The issue is related to Adaptive expressions Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository.
Projects
None yet
Development

No branches or pull requests

6 participants