microsoft / AdaptiveCards

A new way for developers to exchange card content in a common and consistent way.
https://adaptivecards.io
MIT License
1.75k stars 550 forks source link

[MS Teams][Templating] Teams does not seem to support the Templating feature. #4924

Closed enzanki-ars closed 3 years ago

enzanki-ars commented 4 years ago

Platform

What platform is your issue or question related to? (Delete other platforms).

Author or host

Author

Version of SDK

None.

Details

When attempting to send a templated card as shown below, copied from the Adaptive Card Samples, none of the templated vaules are replaced:

$WebhookURL = '[REDACTED]'

$CardJSON = @'
{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.2",
    "$data": {
      "symbol": "MSFT",
      "companyName": "Microsoft Corporation",
      "primaryExchange": "Nasdaq Global Select",
      "sector": "Technology",
      "calculationPrice": "close",
      "open": 127.42,
      "openTime": 1556890200,
      "close": 128.9,
      "closeTime": 1556913600,
      "high": 129.43,
      "low": 127.25,
      "latestPrice": 128.9,
      "latestSource": "Close",
      "latestTime": "May 3, 2019",
      "latestUpdate": 1556913600,
      "latestVolume": 24835154,
      "iexRealtimePrice": null,
      "iexRealtimeSize": null,
      "iexLastUpdated": null,
      "delayedPrice": 128.9,
      "delayedPriceTime": 1556913600,
      "extendedPrice": 129.04,
      "extendedChange": 0.14,
      "extendedChangePercent": 0.00109,
      "extendedPriceTime": 1556917190,
      "previousClose": 126.21,
      "change": 2.69,
      "changePercent": 0.02131,
      "iexMarketPercent": null,
      "iexVolume": null,
      "avgTotalVolume": 22183270,
      "iexBidPrice": null,
      "iexBidSize": null,
      "iexAskPrice": null,
      "iexAskSize": null,
      "marketCap": 987737229888,
      "peRatio": 30.84,
      "week52High": 131.37,
      "week52Low": 93.96,
      "ytdChange": 0.30147812013916003
    },
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "${companyName}",
                    "size": "Medium",
                    "wrap": true
                },
                {
                    "type": "TextBlock",
                    "text": "${primaryExchange}: ${symbol}",
                    "isSubtle": true,
                    "spacing": "None",
                    "wrap": true
                },
                {
                    "type": "TextBlock",
                    "text": "{{DATE(${formatEpoch(latestUpdate, 'yyyy-MM-ddTHH:mm:ssZ')}, SHORT)}} {{TIME(${formatEpoch(latestUpdate, 'yyyy-MM-ddTHH:mm:ssZ')})}}"
                }
            ]
        },
        {
            "type": "Container",
            "spacing": "None",
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "Column",
                            "width": "stretch",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "${formatNumber(latestPrice, 2)} ",
                                    "size": "ExtraLarge"
                                }
                            ]
                        },
                        {
                            "type": "Column",
                            "width": "auto",
                            "items": [
                                {
                                    "type": "FactSet",
                                    "facts": [
                                        {
                                            "title": "Open",
                                            "value": "${open} "
                                        },
                                        {
                                            "title": "High",
                                            "value": "${high} "
                                        },
                                        {
                                            "title": "Low",
                                            "value": "${low} "
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}
'@

$WebhookBody= @"
{
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": $CardJSON
        }
    ]
}
"@

$Response = Invoke-RestMethod -Method Post -ContentType 'application/json; charset=utf-8' -Uri $WebhookURL -Body $WebhookBody -Verbose

Write-Host $Response

The code above results in: image

ghost commented 4 years ago

please review this issue for target Milestone, Inconsistencies & Priority upon triage.

enzanki-ars commented 4 years ago

Additional note:

In the original sample, the following block was included, but adding specifically the "color": "${if(change >= 0, 'good', 'attention')}" line results in MS Teams returning a 400 error. Because the platform does not return any message, I have no idea where the problem lies and why this is the case, but the web editor also seems to display the same issue there too.

{
    "type": "TextBlock",
    "text": "${if(change >= 0, '▲', '▼')} ${formatNumber(change,2)} USD (${formatNumber(changePercent * 100, 2)}%)",
    "color": "${if(change >= 0, 'good', 'attention')}",
    "spacing": "None"
}
Trinetra-MSFT commented 3 years ago

@enzanki-ars , Templating do works in adaptive card but when I checked this in power shell it is not working may be it is a Bug with powershell image

matthidinger commented 3 years ago

Hi folks, templating is not currently available directly within Teams so you would have to bind the template and data in PowerShell before sending it to Teams. I'm not entirely familiar with PowerShell but if you can consume .NET packages you should be able to use this SDK and API to handle the binding:

https://docs.microsoft.com/en-us/adaptive-cards/templating/sdk#net

Sorry about the confusion, please re-open if anything is unclear or if you need further assistance. We are still too far out from having a reliable timeline for when templating will be available in Teams