Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atomist/slack-messages

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atomist/slack-messages

[![Build Status](https://travis-ci.org/atomist/slack-messages.svg?branch=master)](https://travis-ci.org/atomist/slack-messages) [![Slack Status](https://join.atomist.com/badge.svg)](https://join.atomist.com/)

  • 0.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.1K
decreased by-63.96%
Maintainers
1
Weekly downloads
 
Created
Source

@atomist/slack-messages

Build Status Slack Status

Node module @atomist/slack-messages helps rendering well formatted Slack messages sent by @atomist from your Rug event and command handlers. This module also lets you add actions to your Slack messages that execute Rug instructions. See the Atomist Documentation for more information.

Using Slack message builder

Construct message as a plain map following Slack message formatting API:

https://api.slack.com/docs/message-formatting

// A very simple message
const msg: SlackMessage = { text: "Simple message" };
// Here is an example of a message with a Slack action (button) that launches
// a rug instruction when clicked.
// This assumes user, issue and instruction objects are defined elsewhere.
const msg: SlackMessage = {
                text: `${url(user.url, "@" + user.name)} opened issue: ${url(issue.url, issue.title)}`,
                attachments: [
                    {
                        text: escape(issue.body),
                        fallback: escape(issue.title),
                        mrkdwn_in: ["text"],
                        actions: [
                            rugButtonFrom({ text: "Close issue" }, instruction),
                        ],
                    },
                ],
            };

And then simply render message. This will construct JSON string representation of the message:

const renderedMsg = render(msg);

Or to produce pretty JSON string:

const renderedMsg = render(msg, true);

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

{
    "text": "<https://github.com/anna|@anna> opened issue: <https://github.com/someorg/somerepo/issues/484|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": [
                "text"
            ],
            "callback_id": "cllbck1",
            "actions": [
                {
                    "text": "Close issue",
                    "type": "button",
                    "name": "rug",
                    "value": "somebuttonid"
                }
            ]
        }
    ]
}

Note that render function will automatically assign 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;"

Links

// Simple link
url("https://www.atomist.com");
  => "<https://www.atomist.com>"

// Link with label
url("https://www.atomist.com", "atomist");
  => "<https://www.atomist.com|atomist>"

User & channel links

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

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

Special variables

// @channel
atChannel();
  => "<!channel>"

// @here
atHere();
  => "<!here>"

// @everyone
atEveryone();
  => "<!everyone>"

Emoji

emoji("smile");
  => ":smile:";

Markdown

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"

Support

General support questions should be discussed in the #support channel on our community Slack team at atomist-community.slack.com.

If you find a problem, please create an issue.

Development

Notable conventions

  • tslint with a modified rule set
  • mocha test example
  • power asserts with proper configuration
  • a directory structure separating source, test, and compiled .js
  • yarn.lock file

You will need to install npm, yarn, and TypeScript so that you can run the following commands from the command line.

CommandReason
$ yarnto install all the required packages
$ tsc -wto continually compile your TypeScript files (run in a different terminal)
$ yarn testto run tests and ensure everything is working
$ yarn autotestrun tests continuously (you also need to run tsc -w)

Test

Test using the standard approach for Node modules.

$ yarn test

Release

To create a new release of the project, simply push a tag of the form M.N.P where M, N, and P are integers that form the next appropriate semantic version for release. The version in the package.json is replaced by the build and is totally ignored! For example:

$ git tag -a 1.2.
$ git push --tags

The Travis CI build (see badge at the top of this page) will publish the NPM module and automatically create a GitHub release using the tag name for the release and the comment provided on the annotated tag as the contents of the release notes.


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

Keywords

FAQs

Package last updated on 04 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc