Wework API Webhook

var weixin = { 
  key: null, 
  message: null, 
  msgtype: "markdown", 
  proxy: null, 
sendMessage: function () { 
    var params = { 
       msgtype: weixin.msgtype, 
       markdown: { 
          content: weixin.message 
        }, 
      }, 
      data, 
      response, 
      request = new HttpRequest(), 
      url = 
        "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + 
        weixin.key; 
    if (weixin.proxy) { 
      request.setProxy(weixin.proxy); 
    } 
    request.addHeader('Content-Type: application/json');
    data = JSON.stringify(params); 
    // Remove replace() function if you want to see the exposed key in the log file. 
    Zabbix.Log( 
      4, 
      "[weixin Webhook] URL: " + url.replace(weixin.key, "<BOT KEY>") 
    ); 
    Zabbix.Log(4, "[weixin Webhook] params: " + data); 
    response = request.post(url, data); 
    Zabbix.Log(4, "[weixin Webhook] HTTP code: " + request.getStatus()); 
    try { 
      response = JSON.parse(response); 
    } catch (error) { 
      response = null; 
    } 
    if (request.getStatus() !== 200 || response.errcode !== 0) { 
      if (typeof response.errmsg === "string") { 
        throw response.errmsg; 
      } else { 
        throw "Unknown error. Check debug log for more information."; 
      } 
    }
  }, 
}; 
try { 
  var params = JSON.parse(value); 
  if (typeof params.Key === "undefined") { 
    throw 'Incorrect value is given for parameter "Key": parameter is missing'; 
  } 
  weixin.key = params.Key; 
  if (params.HTTPProxy) { 
    weixin.proxy = params.HTTPProxy; 
  } 
  weixin.to = params.To; 
  weixin.message = params.Subject + "\n" + params.Message; 
  weixin.sendMessage(); 
  return "OK"; 
} catch (error) { 
  Zabbix.Log(4, "[weixin Webhook] notification failed: " + error); 
  throw "Sending failed: " + error + "."; 
}

无标签
评论区
头像