Watcher sending custom payloads

Hello, i have the following watcher action, sending to MS Teams, everything works fine. But now i want to add some additional formatting to the payload and need to add keys with the @ symbol.

ie: How do i add pl.@type = "MessageCard"; and pl.@context = 'http://schema.org/extensions'; to the script transform pl object?

"actions": {
    "teams_webhook": {
      "transform":{
        "script":{
          "source":"""
            def pl = ctx.payload;
            def s = "";
            for (i in ctx.payload.aggregations.users.buckets) {
              s += '- ' + i.key + ' (' + i.doc_count + ')\\r'
            }
            pl.themeColor = "0076D7";
            pl.summary = "4625 User auth attempt with **expired** account!";
            pl.text = s;
            return pl; 
          """
        }
      },
       "webhook": {
        "scheme": "https",
        "host": "outlook.office.com",
        "port": 443,
        "method": "post",
        "path": "/webhook/id,
        "params": {},
        "headers": {
          "Content-Type": "application/json"
        },
        "body": "{{#toJson}}ctx.payload{{/toJson}}"
      }
    }
  }

try something like pl["@type"] = 'MessageCard';

Hi @spinscale, thank you, your syntax is correct.

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