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

Post to Microsoft Teams is using MessageCard (Legacy) format instead of AdaptiveCard #1530

Open
kengibous opened this issue Jul 9, 2024 · 8 comments

Comments

@kengibous
Copy link

Step template

Microsoft Teams - Post a message - 110a8b1e-4da4-498a-9209-ef8929c31168

Step version

24

Octopus version

2024.2.9274

Step template parameter inputs

image

What happened

The message does indeed post to the teams channel when use the soon to be deprecated Office 365 connectors - https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/. The successor which is to use Microsoft Teams workflows (Power Automate) - it appears that the messages should be in the AdaptiveCard format - https://learn.microsoft.com/en-us/connectors/teams/?tabs=text1#microsoft-teams-webhook.

Reproduction steps

Complete the necessary parameters and the webhook will use the MessageCard (legacy) format.

More Information

I believe some changes to the Powershell script can be made to adopt the AdaptiveCard format. I am happy to submit a PR as well.

@delphe
Copy link
Contributor

delphe commented Jul 18, 2024

Instead of using the AdaptiveCard format I left it as MessageCard and was able to get the Teams notification to come through using Workflows with the new webhook URL. The trick in the workflow was to...

  1. Change "Send each adaptive card" to "Post message in a chat or channel"
  2. Post as User for private channels or Flow bot for public ones.
  3. Use text, & themeColor from the json body in the message... Example:
    <p style="border-top:@{triggerBody()?['themeColor']} solid;border-bottom:grey thin solid;border-left:grey thin solid;border-right:grey thin solid;padding-left:4px;padding-right:4px;">@{triggerBody()?['text']}</p>
  4. Use title from the json body in the subject... Example: @{triggerBody()?['title']}

The problem I see with this approach, and one that I'm not sure AdaptiveCard would solve, is that it doesn't handle markdown properly. In the message body example above using [runbook details](...) it will not turn into a hyperlink... I was thinking about handling this by passing in a URL parameter in the json and then have the Workflow convert it to a hyperlink using html. Example <a href="@{triggerBody()?['url']}">runbook details</a>

@kengibous
Copy link
Author

@delphe valid point, I suppose using the AdaptiveCard format is not absolutely necessary depending on how you configure a PowerAutomate workflow

@kengibous
Copy link
Author

@tbolon
Copy link
Contributor

tbolon commented Jul 25, 2024

I was able to just update the webhook url to migrate to the logic app url.

Then, using Post As User, using this json:

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.4",
    "type": "AdaptiveCard",
    "fallbackText": "@{triggerBody()?['title']}",
    "body": [
        {
            "type": "TextBlock",
            "text": "@{triggerBody()?['text']}",
            "wrap": true
        }
    ]
}

And @{triggerBody()?['title']} as the subject, as suggested before.

@delphe
Copy link
Contributor

delphe commented Jul 26, 2024

Thanks @tbolon ! I went back to using "Post card in a chat or channel" and tried that JSON, which resolved my issue with using markdown. I played around with using @{triggerBody()?['themeColor']} and came up with the following...

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.4",
    "type": "AdaptiveCard",
    "fallbackText": "@{triggerBody()?['title']}",
    "body": [
        {
            "type": "TextBlock",
            "text": "@{triggerBody()?['text']}",
            "wrap": true,
             "color": "@{triggerBody()?['themeColor']}"
        }
    ]
}

Although, the only acceptable "colors" found in adaptive-cards schema are:
"default",
"dark",
"light",
"accent",
"good",
"warning",
"attention"

@jasonlmorris
Copy link

glad I found this today, thank you all for contributing. I don't like that it posts as "firstname lastname via workflows". I see there's a way to add a bot via copilot, but I don't appear to have a license to use copilot software. Any suggestions?

@tbolon
Copy link
Contributor

tbolon commented Aug 26, 2024

I will certainly migrate out of using adaptive cards, as it seems they are extremely limited in number of chars, and my release messages are quite long.

Because they only accept HTML, I have alread switched my changelog generator to output HTML instead of markdown. Now I will try to use the post message action.

@Zunair
Copy link
Contributor

Zunair commented Nov 20, 2024

#1572 should cover this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants