try {
    var result = { tags: {} },
        params = JSON.parse(value),
        req = new HttpRequest(),
        resp = '';

    if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
        req.setProxy(params.HTTPProxy);
    }
    var alertSourceKey = params['.ILERT.ALERT.SOURCE.KEY'];
    if (!alertSourceKey || (typeof alertSourceKey === 'string' && alertSourceKey.trim() === '')) {
        throw 'incorrect value for variable "ILERT.ALERT.SOURCE.KEY". The value must be a non-empty string.';
    }
    delete params['.ILERT.ALERT.SOURCE.KEY'];
    
    var ilertApiBaseURL = "https://api.ilert.com";
    var reqURL = encodeURI(ilertApiBaseURL + "/api/v1/events/zabbix-mt/" + alertSourceKey)

    var incidentKey = "zabbix-" + params['EVENT.ID'];
    var incidentViewURL = ilertApiBaseURL + "/api/v1/incidents/resolve-ik/" + alertSourceKey + "/" + incidentKey;

    req.addHeader('Accept: application/json');
    req.addHeader('Content-Type: application/json');

    Zabbix.log(4, '[iLert Webhook] Sending request:' + JSON.stringify(params));
    resp = req.post(reqURL, JSON.stringify(params));
    Zabbix.log(4, '[iLert Webhook] Receiving response:' + resp);

    try {
        resp = JSON.parse(resp);
    }
    catch (error) {
        throw 'incorrect response. iLert returned a non-JSON object.';
    }

    if (req.getStatus() == 200) {
        result.tags.__ilert_incident_url = incidentViewURL;
        return JSON.stringify(result);
    }

    if (req.getStatus() == 400 && typeof resp === 'object' && typeof resp.code === 'string') {
        if (resp.code === 'NO_OPEN_INCIDENT_WITH_KEY') {
          return JSON.stringify(result);
        }
        if (resp.code === 'INCIDENT_ALREADY_ACCEPTED') {
          result.tags.__ilert_incident_url = incidentViewURL;
          return JSON.stringify(result);
        }
    }

    if (typeof resp === 'object' && typeof resp.message === 'string') {
        throw resp.message;
    }
    else {
        throw 'Unknown error.';
    }
}
catch (error) {
    Zabbix.log(3, '[iLert Webhook] Notification failed : ' + error);
    throw 'iLert notification failed : ' + error;
}