Skip to content
Helper library for rendering Slack messages in Atomist automations
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


atomist sdm goals npm version

Node.js module that helps to create well-formatted Slack messages sent through the @atomist bot from your software delivery machine (SDM). This module also facilitates adding actions to your Slack messages that execute SDM commands.

See the Atomist documentation for more information on what SDMs are and what they can do for you using the Atomist API for software.


Construct a message as a plain map following the Slack message formatting API.

import { SlackMessage } from "@atomist/slack-messages";
// A very simple message
const msg: SlackMessage = { text: "Simple message" };
import {
} from "@atomist/slack-messages";
// Here is an example of a message with a Slack action (button).
const msg: SlackMessage = {
    text: `${url(user.url, "@" +} opened issue: ${url(issue.url, issue.title)}`,
    attachments: [
            text: escape(issue.body),
            fallback: escape(issue.title),
            mrkdwn_in: ["text"],
            actions: [
                    text: "Close issue",
                    type: "button",
                    name: "closeissue",
                    value: "somebuttonid",
            callback_id: "cllbck1",

And then render the message with render(msg). This will construct a JSON string representation of the message:

import { render } from "@atomist/slack-messages"

const renderedMsg = render(msg);

or to produce a pretty JSON string:

const renderedMsg = render(msg, true);

This will produce the following JSON string (pretty version):

  "text": "<|@anna> opened issue: <|This issue title contains &lt;unsafe&gt; characters and &amp;>",
  "attachments": [
      "text": "This is a very important issue with body containing &lt;unsafe&gt; characters and even &amp;",
      "fallback": "This issue title contains &lt;unsafe&gt; characters and &amp;",
      "mrkdwn_in": [
      "callback_id": "cllbck1",
      "actions": [
          "text": "Close issue",
          "type": "button",
          "name": "rug",
          "value": "somebuttonid"

Note that the render function will automatically assign a unique callback_id to each attachments that has actions. But, if you provide your custom callback_id it will be preserved as is.

Additional helper functions

Special characters

escape("Slack requires you to escape <, > and &");
// => "Slack requires you to escape &lt;, &gt; and &amp;"


// Simple link
// => "<>"

// Link with label
url("", "atomist");
// => "<|atomist>"

User & channel links

// @some-user (Slack will display user name for provided user ID)
// => "<@U123>"

// #some-channel (Slack will display channel name for provided channel ID)
// => "<#C123>"

Special variables

// @channel
// => "<!channel>"

// @here
// => "<!here>"

// @everyone
// => "<!everyone>"


// => ":smile:";


Slack will render markdown if field where markdown is present is included in mrkdwn_in array.

bold("This text will appear bold");
// => "*This text will appear bold*"

italic("This text will appear italic");
// => "_This text will appear italic_"

strikethrough("This text will appear strike-through");
// => "~This text will appear strike-through~"

// Single line code block
codeLine("var a = new A();");
// =>  "`var a = new A();`"

// Multi line code block
codeBlock("var a = new A();\nvar b = new B();");
// => "```var a = new A();\nvar b = new B();```"

// List
listItem("Item 1");
// => "• Item 1"

GitHub to Slack markdown conversion

GitHub and Slack markdown are different enough to make your GitHub issues or GitHub PRs look quite bad in Slack by default. You can use the githubToSlack function from Markdown to convert text that uses GitHub markdown to text that will look good in Slack:

import { githubToSlack } from "@atomist/slack-messages"

githubToSlack("* list item 1\n* list item 2\n\**some bold text** and *some italic text* with a link [click here](");
// => "• list item 1\n• list item 2\n*some bold text* and _some italic text_ with a link <|click here>"


General support questions should be discussed in the #support channel in the Atomist community Slack workspace.

If you find a problem, please create an issue.


You will need to install Node.js to build and test this project.

Build and test

Install dependencies.

$ npm install

Use the build package script to compile, test, lint, and build the documentation.

$ npm run build


Releases are handled via the Atomist SDM. Just press the 'Approve' button in the Atomist dashboard or Slack.

Created by Atomist. Need Help? Join our Slack workspace.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.