Transforming the data is taking the extracted data, that could look like this:
{"url": "https://www.monitored-website.com/some/page","entries": {"title": {"html": "<h1>VR Headset</h1>","text": "VR Headset","selector": "h1""attributes": []},"price": {"html": "<span id="price-value" class="featured">45 €</span>","text": "450€","selector": "#price-value""attributes": [{name: "class",value: "featured"}]}}}
And using a javascript function, transform it into this:
{"text": "VR Headset price is 450€"}
Several webhook providers, such as Slack, Microsoft Teams and others require a specific format for the data.
Using a transformation, you can create the exact format of the data that your provider requires, as well as customize what you send to it.
The previous example is compatible with incoming webhooks from Slack and other communication tools, and will send "VR Headset price is 450€" as a message in the channel of your choice (depending on your configuration in Slack and other 3rd party products).
When you create a monitor, and after you extract the data, tick the "Transform using Javascript" checkbox to enable the code editor.
Inside the code editor, you have access to the data
variable that contains the extracted data.
In order to return your transformed data, just add return yourData;
at the end of the transformation.
yourData
here references the result of your transformation, and could be any valid Javascript expression.
A transform to generate the example output from above could look like this:
const message = `${data.entries.title.text} price is ${data.entries.price.text}`;return {text: message}
Transforms should be synchronous and should not take too long to execute, otherwise the transformation will fail and the monitor will show an error, or return empty / invalid data.