Microsoft Teams and Watcher

(Ron-3) #1

We're trying to alert to MS teams via a Watcher Webhook, we've played with this a few ways without any luck.

Based on our research you really just need 3 values to post to teams.

In Headers

  • "Content-Type": "application/json"

In the body

  • "summary" : "Alert",
  • "text" : "bad stuff happened "

The issue is, putting the values in they body. Most everything we've found says that the "Body" field is a string and you can't use json it . When we try some mash of {{#toJson}}ctx.payload.however_you_named_it{{/toJson}} it fails hard when we try to put summary and text in the payload.

Our example action (of maybe how it should work):

"actions": {
    "MS_Teams": {
        "webhook": {
            "method": "POST",
            "host": "",
            "port": 443,
            "path": "/LONG_KEY_GOES HERE",
            "headers": {
                "Content-Type": "application/json"
            "body": {
                "summary": "Alert",
                "text": "stuff that happened"



(Alexander Reelsen) #2


so indeed your solution to go with #toJson is the correct one, as the body field from the webhook only supports a string.

The correct way would be to use a transform in your action to properly create the payload via a painless script then just have {{#toJson}}ctx.payload{{/toJson}} in your body field.

your transform would be something like

"transform" : {
  "script" : "result = [:], result.summary = ctx.payload... ; result.text = 'My text' ; return result"

hope this helps!

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.