# Watcher sending custom payloads

**URL:** <https://discuss.elastic.co/t/watcher-sending-custom-payloads/203214>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting, painless\
**Created:** [October 11, 2019, 10:44am UTC](https://discuss.elastic.co/t/watcher-sending-custom-payloads/203214 "2019-10-11T10:44:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajhstn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ajhstn/32/24629_2.png) [@ajhstn](https://discuss.elastic.co/u/ajhstn)\
**Post date:** [October 11, 2019, 10:44am UTC](https://discuss.elastic.co/t/watcher-sending-custom-payloads/203214/1 "2019-10-11T10:44:36Z")

</div>

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}}"
      }
    }
  }
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 11, 2019, 12:00pm UTC](https://discuss.elastic.co/t/watcher-sending-custom-payloads/203214/2 "2019-10-11T12:00:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ajhstn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ajhstn/32/24629_2.png) [@ajhstn](https://discuss.elastic.co/u/ajhstn)\
**Post date:** [October 13, 2019, 9:10pm UTC](https://discuss.elastic.co/t/watcher-sending-custom-payloads/203214/3 "2019-10-13T21:10:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 10, 2019, 9:10pm UTC](https://discuss.elastic.co/t/watcher-sending-custom-payloads/203214/4 "2019-11-10T21:10:38Z")

</div>

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