@atomist/slack-messages
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
const msg = { text: "Simple message" };
const msg = {
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 <unsafe> characters and &>",
"attachments": [
{
"text": "This is a very important issue with body containing <unsafe> characters and even &",
"fallback": "This issue title contains <unsafe> characters and &",
"mrkdwn_in": [
"text"
],
"actions": [
{
"text": "Close issue",
"type": "button",
"name": "rug",
"value": "somebuttonid"
}
]
}
]
}
Additional helper functions:
Special characters
escape("Slack requires you to escape <, > and &");
=> "Slack requires you to escape <, > and &"
Links
url("https://www.atomist.com");
=> "<https://www.atomist.com>"
url("https://www.atomist.com", "atomist");
=> "<https://www.atomist.com|atomist>"
User & channel links
user("U123");
=> "<@U123>"
channel("C123");
=> "<#C123>"
Special variables
atChannel();
=> "<!channel>"
atHere();
=> "<!here>"
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~"
codeLine("var a = new A();");
=> "`var a = new A();`"
codeBlock("var a = new A();\nvar b = new B();");
=> "```var a = new A();\nvar b = new B();```"
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.
Command | Reason |
---|
$ yarn | to install all the required packages |
$ tsc -w | to continually compile your TypeScript files (run in a different terminal) |
$ yarn test | to run tests and ensure everything is working |
$ yarn autotest | run 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.