Slack: Post Chat (Incoming Webhook)

Slack: Post Chat (Incoming Webhook)

Slack: チャット投稿 (Incoming Webhook)

This item sends a message to Slack with Incoming Webhook.

Auto Step icon
Basic Configs
Step Name
Note
Configs for this Auto Step
Url
C1: Incoming Webhook URL *
Text
C2: Sending Text#{EL}
Fallback
C3: Attachment Summary (In notifications when no sending text)#{EL}
Color
C4: Attachment Color
Title
C5: Attachment Title#{EL}
TitleLink
C6: Attachment Title Link#{EL}
AttachText
C7: Attachment Text#{EL}

Capture

See also

Script (click to open)
  • An XML file that contains the code below is available to download
    • slack-chat-post-webhook.xml (C) Questetra, Inc. (MIT License)
    • If you are using Professional, you can modify the contents of this file and use it as your own add-on auto step

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 !== 200) {
  engine.log(`${responseTxt}`);
  throw `Failed to send. status: ${status}`;
    throw error;
  }
}
function attachAdd(attachment, config, attachName){
  const value = configs.get(config);
  if (value !== "" && value !== null){
    attachment[attachName] = value;
  }
}

1 thought on “Slack: Post Chat (Incoming Webhook)”

  1. Pingback: Posting Message to Slack – Questetra Support

Comments are closed.

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading