Send Notifications to Slack

Mango allows us to customize event handling through custom scripts. Sometimes we want to receive a notification from Mango in several channels besides email. So, in this article we will explain how to send notifications to Slack.

The first thing that we need to do is to create an incoming webhook to to a Slack channel. You have to go to custom integrations in:


We go to incoming webhooks and create a new one. This will create an unique url where you can make POST requests to send custom messages, like this:

In Mango, you will need to create a global script where you will define a method to send notifications to Slack.

function notifyToSlack(text, attachments) {
    var url = "";
    var headers = {
        "Content-Type": "application/json"
    var data = {
        "text": text,
        "attachments": attachments
    };, headers, data).err(function(status, headers, data) {

        throw "Script failed with HTTP status : " + status;

    }).resp(function(status, headers, data) {



Once you define this global function, you will be able to use it in an event handler script.

var attachments = [
            "fallback": "alarm",
            "color": "#F44336",
            "author_name": "Mango Automation",
            "author_link": "",
            "author_icon": "",
            "title": "DANGER! High Current Value",
            "text": "Device1 Amps",
            "fields": [
                    "title": "Priority",
                    "value": "High",
                    "short": false
            "image_url": "",
            "thumb_url": "",
            "footer": "Mango Automation",
            "footer_icon": "",
            "ts": 123456789

notifyToSlackWithAttachments("This is a Test", attachments);


You have to setup the event handler as Set point type and you will need to add a target, but if you don’t want to change the target value, at the end of the script you have to add return UNCHANGED; line.

You can customize Slack messages and test how will be showed following the Slack documentation.

Finally, you should receive a notification in Slack when an event is triggered.