Microsoft Teams webhook notification with variables

I am following this pattern from the docs to send a custom payload to an MS Teams channel webhook for alerting purposes.

Every time the hook is fired by an actual related condition, the card shows up in Teams but no variables are injected so it basically just delivers the template without any real data.

image

The only filter I have set up on this workflow is

policyName exactly_matches FOO

image

I am NOT using the old, unmaintained NewRelic integration on the Teams side. I am using the MS Teams vanilla webhook.

What am I doing wrong?

Hi, @robert.phillips: The example in the documentation is for New Relic’s legacy notification channels; the legacy webhook variables do not work with the updated workflows and destinations. There is a working example for the new system in this topic: Custom JSON payload works in Channels but not when sent from Workflows.

1 Like

@philweber Thank you very much for the response. I think my issue is really more on the teams side actually having to do with the way Teams wants to receive payloads for the various different types of cards they have in different ways.

I am going to circle back later today after I have it licked and post here for future me and others.

1 Like

It would be great if updating this post for the new Adaptive Cards could be on a NR list to be published. I am having problems getting anything other than my title to show up when paste over the code from the card designer UI.
https://newrelic.com/blog/how-to-relic/how-to-send-alerts-from-new-relic-to-microsoft-teams

my payload template example is below. I can’t get foo to show up on my card:

{
  "id": "1",
  "title": "OPS Alert",
  "summary": "OPS NOTIFICATION",
  "description": "{{json annotations.title.[0]}}",
  "incidentUrl": "{{json issuePageUrl}}",
  "priority": "{{json priority}}",
  "status": "{{json status}}",
  "totalIncidents": "{{totalIncidents}}",
  "createdAt": "1617881246260",
  "alertPolicyNames": "{{json accumulations.policyName}}",
  "alertConditionNames": "{{json accumulations.conditionName}}",
  "workflowName": "{{json workflowName}}",
  "properties": [
    {
      "key": "Product",
      "value": "OPS"
    },
    {
      "key": "Source",
      "value": "new_relic"
    },
    {
      "key": "Priority",
      "value": "{{json priority}}"
    },
    {
      "key": "Incident count",
      "value": "{{totalIncidents}}"
    }
  ],
  "type": "AdaptiveCard",
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.3",
  "body": [
    {
      "type": "TextBlock",
      "size": "medium",
      "weight": "bolder",
      "text": "foo"
    },
    {
      "type": "TextBlock",
      "text": "${description}"
    }
  ]
}

Is there a working example of a new relic workflow notifying teams via webhook using adaptive card? I can’t find it still…

Eventually I bailed on trying to use MS Teams Adaptive Cards (preferred). I could not find a working example of an MS Teams notification with one. I could only find examples using the older Office 365 Card format which I understand to be legacy/deprecated now… sad.

I ultimately used the New Relic example below (legacy):

Note: Teams considers this to be a legacy approach now favoring AdaptiveCards

Webhook variable use:

The next thing that was way too hard for me to figure out was that all these default “Webhook values” used in the aforementioned example don’t work and aren’t available with great new workflows feature. You need an entirely diff page which that one doesn’t mention or point to. I think it should. I can’t find “workflow” on the page right now… It shows up in the sidebar which is ok… but I think we can do better. Working examples and links from related legacy docs to the new/improved workflow docs.

Handlebars syntax:

Finally, there are different examples all over the place on NR docs and elsewhere… I had no exp w Handlebars but have done plenty of templating with Jekyll, Hugo, etc.

It was hard to get my head around but you can see what I had to do to get this right in one of my payloads below.
Is it

${{foo}}
${foo}
"${{foo}}"
"${foo}"
"{{json accumulations.policyName}}"
can you tell I beat my head against this trying combos??

Lists and iterating over them
When you are pulling variables like conditionName in workflows, we are piping through accumulations data for conditions… so there may be several conditions involved… so you need to be ready to iterate over that [list] using handlebars helper syntax #each to spread it out.

If you are getting that wrong, you will get an error from the New Relic payload input/config tool on your workflow saying “bad payload” but that’s it. Sometimes it will tell you that you are missing a key/value pair like “type” or “version” but not in this case. I am ashamed to say how long it took me to figure out how to do this.
I could/should have just tried to work it out using Postman but I always felt like I was getting close and resisted reaching for another tool… for too long.

{
  "@type": "MessageCard",
  "@context": "http://schema.org/extensions",
  "themeColor": "0076D7",
  "summary": "{{#each annotations.description}}{{this}}{{/each}}",
  "sections": [{
      "activityTitle": "{{#each accumulations.conditionName}}{{this}} {{/each}}",
      "activitySubtitle": "{{#each accumulations.policyName}}{{this}} {{/each}}",
      "activityImage": "https://www.pngkey.com/png/full/28-283771_donate-top-donation-icon.png",
      "facts": [{
          "name": "Timestamp",
          "value": "{{issueCreatedAtUtc}}"
        }, {
          "name": "Product",
          "value": "OPS"
        }, {
          "name": "Severity",
          "value": "{{priority}}"
        }, {
          "name": "State",
          "value": "{{state}}"
        }, {
          "name": "Details",
          "value": "{{#each accumulations.conditionDescription}}{{this}}<br>{{/each}}"
      }],
      "markdown": true
  }],
  "potentialAction": [{
      "@type": "OpenUri",
      "name": "View Incident",
      "targets": [{
        "os": "default",
        "uri": "{{issuePageUrl}}"
      }]
    }, {
      "@type": "OpenUri",
      "name": "Acknowledge",
      "targets": [{
        "os": "default",
        "uri": "{{issueAckUrl}}"
      }]
    }]
}

Hi @robert.phillips,

Can you please let me know if you are able to access the link.

MS teams payload example using webhook with workflow

https://new-relic.force.com/knowledgebase/s/article/MS-teams-payload-example-using-webhook-with-workflow ​​​​​​​.

I hope it helps.
Thanks,
Suman