Slack: Post Chat (Incoming Webhook)
Send a message to Slack with Incoming Webhook.
https://support.questetra.com/addons/slack-chat-post-webhook/
2019-01-21 (C) Questetra, Inc. (MIT License)
Configs
  • C1: Incoming Webhook URL *
  • C2: Sending Text #{EL}
  • C3: Attachment Summary (In notifications when no sending text) #{EL}
  • C4: Attachment Color
  • C5: Attachment Title #{EL}
  • C6: Attachment Title Link #{EL}
  • C7: Attachment Text #{EL}
Script
main();
function main() {
  let jsonReq = {};
if (configs.get("Text") !== "" && configs.get("Text") !== null){
    jsonReq["text"] = configs.get("Text");
  }
  let attachment = {};
  attachAdd(attachment, "Fallback", "fallback");
  attachAdd(attachment, "Color", "color");
  attachAdd(attachment, "Title", "title");
  if (configs.get("Title") !== "" && configs.get("Title") !== null){
    attachAdd(attachment, "TitleLink", "title_link");
  }
  attachAdd(attachment, "AttachText", "text");
  if (attachment !== {}){
    jsonReq["attachments"] = [attachment];
  }
  if (attachment["title"] == null && attachment["text"] == null && jsonReq["text"] == null){
    throw "Message to send isn't set.";
  }
  const url = configs.get("Url");
  
  let response = httpClient.begin()
    .body(JSON.stringify(jsonReq), "application/json; charset=UTF-8")
    .post(url);

  const status = response.getStatusCode();
  const responseTxt = response.getResponseAsString();
  if (status >= 300) {
    const error = "Failed to send \n status:" + status + "\n" + responseTxt;
    throw error;
  }
  engine.log("status:" + status);
  engine.log(responseTxt);
}
function attachAdd(attachment, config, attachName){
  const value = configs.get(config);
  if (value !== "" && value !== null){
    attachment[attachName] = value;
  }
}

Download

slack-chat-post-webhook.xml

Capture

See also