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 - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0

24

CHANGELOG.md

@@ -8,8 +8,20 @@ # Change Log

## [Unreleased]
## [Unreleased][]
[Unreleased]: https://github.com/atomist/slack-messages/compare/0.11.0...HEAD
[Unreleased]: https://github.com/atomist/slack-messages/compare/0.12.0...HEAD
## [0.11.0] - 2017-08-17
## [0.12.0][] - 2017-09-20
[0.12.0]: https://github.com/atomist/slack-messages/compare/0.11.0...0.12.0
Rug removal release
### Removed
- **BREAKING** `rugButtonFrom` and `rugMenuFrom` have been removed as well as
any dependency to `@atomist/rug`. Similar functionality can now be found
in [`@atomist/automation-client`](https://github.com/atomist/automation-client-ts)
## [0.11.0][] - 2017-08-17
[0.11.0]: https://github.com/atomist/slack-messages/compare/0.10.0...0.11.0

@@ -23,3 +35,3 @@

## [0.10.0] - 2017-08-17
## [0.10.0][] - 2017-08-17

@@ -35,5 +47,5 @@ [0.10.0]: https://github.com/atomist/slack-messages/compare/0.9.0...0.10.0

## [0.9.0] - 2017-08-14
## [0.9.0][] - 2017-08-14
[0.8.0]: https://github.com/atomist/slack-messages/compare/0.8.0...0.9.0
[0.9.0]: https://github.com/atomist/slack-messages/compare/0.8.0...0.9.0

@@ -40,0 +52,0 @@ Standard messages

@@ -83,4 +83,3 @@ "use strict";

function convertFormat(text) {
return text.replace(/^(\s*)-(\s+)/mg, "$1•$2")
.replace(/^(\s*)\*(\s+)/mg, "$1•$2")
return text.replace(/^(\s*)[-*](\s+)/mg, "$1•$2")
.replace(/(\*|_)\1(\S|\S.*?\S)\1\1(?!\1)/g, "<bdmkd>$2<bdmkd>")

@@ -87,0 +86,0 @@ .replace(/(\*|_)(?!\1)(\S|\S.*?\S)\1(?!\1)/g, "<itmkd>$2<itmkd>")

{
"name": "@atomist/slack-messages",
"description": "utilities for creating Slack messages",
"version": "0.11.0",
"version": "0.12.0",
"author": "Atomist",

@@ -21,3 +21,2 @@ "license": "Apache-2.0",

"dependencies": {
"@atomist/rug": "^1.0.0-m.6",
"deprecated-decorator": "^0.1.6",

@@ -34,4 +33,6 @@ "lodash": "^4.17.4"

"supervisor": "^0.12.0",
"tslint": "^5.4.3",
"typescript": "^2.3.2"
"tslint": "^5.6.0",
"typedoc": "^0.8.0",
"typescript": "^2.5.1",
"typescript-formatter": "^6.0.0"
},

@@ -43,2 +44,3 @@ "directories": {

"autotest": "supervisor -q -n exit -x npm -- test",
"build": "npm run lint && npm run compile && npm test",
"clean": "npm run clean-js ; rm -rf build",

@@ -48,6 +50,8 @@ "clean-js": "find src test -type f -name '*.js' -print0 | xargs -0 rm -f",

"distclean": "npm run clean ; rm -rf node_modules",
"lint": "tslint '**/*.ts' --exclude 'node_modules/**' --exclude 'build/**' -t verbose",
"fmt": "tsfmt --replace",
"lint": "tslint --format verbose --project . --exclude '{build,node_modules}/**' '**/*.ts'",
"lint-fix": "npm run lint -- --fix",
"test": "mocha --compilers ts:espower-typescript/guess 'test/**/*.ts'"
"test": "mocha --compilers ts:espower-typescript/guess 'test/**/*.ts'",
"typedoc": "typedoc --mode modules --excludeExternals"
}
}

@@ -5,16 +5,17 @@ # @atomist/slack-messages

[Node][node] module [`@atomist/slack-messages`][slack-messages]
helps rendering well formatted [Slack][slack] messages sent by [`@atomist`][docs]
from your [Rug][rug] event and command handlers. This module also lets you add
actions to your [Slack][slack] messages that execute [Rug][rug] instructions.
See the [Atomist Documentation][docs] for more information.
[Node][node] module [`@atomist/slack-messages`][slack-messages] helps
rendering well formatted [Slack][slack] messages sent
by [`@atomist`][docs] from your [Rug][rug] event and command
handlers. This module also lets you add actions to your [Slack][slack]
messages that execute [Rug][rug] instructions. See
the [reference documentation][docs] for more information.
[node]: https://nodejs.org/en/
[slack]: https://slack.com/
[rug]: https://github.com/atomist/rug
[slack-messages]: https://www.npmjs.com/package/@atomist/slack-messages
[ts]: https://www.typescriptlang.org/
[docs]: http://docs.atomist.com/
[node]: https://nodejs.org/ (Node.js)
[slack]: https://slack.com/ (Slack)
[rug]: https://github.com/atomist/rug (Atomist Rug)
[slack-messages]: https://www.npmjs.com/package/@atomist/slack-messages (@atomist/slack-messages Node Module)
[ts]: https://www.typescriptlang.org/ (TypeScript)
[docs]: https://atomist.github.io/slack-messages/ (@atomist/slack-messages TypeDoc)
## Using Slack message builder
## Using

@@ -31,5 +32,3 @@ Construct a message as a plain map following the Slack message formatting API:

```typescript
// 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.
// Here is an example of a message with a Slack action (button).
const msg: SlackMessage = {

@@ -43,4 +42,10 @@ text: `${url(user.url, "@" + user.name)} opened issue: ${url(issue.url, issue.title)}`,

actions: [
rugButtonFrom({ text: "Close issue" }, instruction),
],
{
text: "Close issue",
type: "button",
name: "closeissue",
value: "somebuttonid",
},
],
callback_id: "cllbck1",
},

@@ -92,3 +97,4 @@ ],

**Special characters**
#### Special characters
```typescript

@@ -99,3 +105,4 @@ escape("Slack requires you to escape <, > and &");

**Links**
#### Links
```typescript

@@ -111,3 +118,4 @@ // Simple link

**User & channel links**
#### User & channel links
```typescript

@@ -123,3 +131,4 @@ // @some-user (Slack will display user name for provided user ID)

**Special variables**
#### Special variables
```typescript

@@ -139,3 +148,3 @@ // @channel

**Emoji**
#### Emoji

@@ -147,3 +156,3 @@ ```typescript

**Markdown**
#### Markdown

@@ -175,3 +184,3 @@ Slack will render markdown if field where markdown is present is included in `mrkdwn_in` array.

## GitHub to Slack markdown conversion
### GitHub to Slack markdown conversion

@@ -199,26 +208,15 @@ 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:

### Notable conventions ###
* [tslint](https://palantir.github.io/tslint/rules/) with a modified rule set
* [mocha](https://mochajs.org/) test example
* [power asserts](https://github.com/power-assert-js/power-assert) with proper configuration
* a directory structure separating source, test, and compiled .js
* [yarn](https://yarnpkg.com/en/).lock file
You will need to install [node][] to build and test this project.
You will need to install [npm](http://blog.npmjs.org/post/85484771375/how-to-install-npm), [yarn](https://yarnpkg.com/en/docs/install), and [TypeScript](https://www.typescriptlang.org/) so that you can run the following commands from the command line.
### Build and Test
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`)
Command | Reason
------- | ------
`npm install` | to install all the required packages
`npm run lint` | to run tslint against the TypeScript
`npm run compile` | to compile all TypeScript into JavaScript
`npm test` | to run tests and ensure everything is working
`npm run autotest` | run tests continuously (you may also need to run `tsc -w`)
`npm run clean` | remove stray compiled JavaScript files and build directory
### Test
Test using the standard approach for Node modules.
```
$ yarn test
```
### Release

@@ -245,2 +243,3 @@

---
Created by [Atomist][atomist].

@@ -247,0 +246,0 @@ Need Help? [Join our Slack team][slack].

@@ -1,7 +0,68 @@

import { ResponseMessage } from "@atomist/rug/operations/Handlers";
import { Attachment, SlackMessage } from "./SlackMessages";
import { Attachment, MessageMimeType, SlackMessage } from "./SlackMessages";
export declare const ErrorColor = "#D94649";
export declare const SuccessColor = "#45B254";
export declare const WarningColor = "#FFCC00";
export interface RugCoordinate {
readonly name: string;
readonly group: string;
readonly artifact: string;
}
export declare type InstructionKind = "generate" | "edit" | "execute" | "respond" | "command";
export interface Instruction<T extends InstructionKind> {
readonly name: string | RugCoordinate;
readonly parameters?: {};
readonly kind: T;
}
export interface PresentableGenerate extends Instruction<"generate"> {
project?: string;
}
export interface PresentableEdit extends Instruction<"edit"> {
project?: string;
}
export declare class Identifiable<T extends InstructionKind> {
instruction: Instruction<T> | PresentableGenerate | PresentableEdit;
parameterName?: string;
id?: string;
}
export declare type MessageKind = "response" | "directed";
export interface Message<T extends MessageKind> {
kind: T;
}
export declare class UserAddress {
username: string;
constructor(username: string);
}
export declare class ChannelAddress {
channelName: string;
constructor(channelName: string);
}
export declare type MessageAddress = UserAddress | ChannelAddress;
/**
* A Rug message parent class for response and direct messages.
*/
export declare abstract class LocallyRenderedMessage<T extends MessageKind> implements Message<T> {
kind: T;
contentType: MessageMimeType;
body: string;
instructions: Array<Identifiable<any>>;
}
/**
* Represents the response to the bot from a command.
*/
export declare class ResponseMessage extends LocallyRenderedMessage<"response"> {
kind: "response";
constructor(body: string, contentType?: MessageMimeType);
}
/**
* Message unrelated to extant communications with the bot.
*/
export declare class DirectedMessage extends LocallyRenderedMessage<"directed"> {
kind: "directed";
usernames: string[];
channelNames: string[];
constructor(body: string, address: MessageAddress, contentType?: MessageMimeType);
addAddress(address: MessageAddress): this;
addAction(instruction: Identifiable<any>): this;
}
/**
* Create a standard Slack error message. The attachment should

@@ -65,3 +126,3 @@ * contain at least a non-empty fallback property. The text property

export declare function warningResponse(attachment: Attachment): ResponseMessage;
export declare const renderError: (msg: string, correlationId?: string) => ResponseMessage;
export declare const renderError: (msg: string, correlationId?: string | undefined) => ResponseMessage;
export declare const renderSuccess: (msg: string) => ResponseMessage;

@@ -17,4 +17,13 @@ "use strict";

*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Handlers_1 = require("@atomist/rug/operations/Handlers");
var deprecated_decorator_1 = require("deprecated-decorator");

@@ -25,3 +34,84 @@ var SlackMessages_1 = require("./SlackMessages");

exports.WarningColor = "#FFCC00";
var Identifiable = /** @class */ (function () {
function Identifiable() {
}
return Identifiable;
}());
exports.Identifiable = Identifiable;
var UserAddress = /** @class */ (function () {
function UserAddress(username) {
this.username = username;
}
return UserAddress;
}());
exports.UserAddress = UserAddress;
var ChannelAddress = /** @class */ (function () {
function ChannelAddress(channelName) {
this.channelName = channelName;
}
return ChannelAddress;
}());
exports.ChannelAddress = ChannelAddress;
/**
* A Rug message parent class for response and direct messages.
*/
var LocallyRenderedMessage = /** @class */ (function () {
function LocallyRenderedMessage() {
this.contentType = SlackMessages_1.MessageMimeTypes.PlainText;
this.instructions = [];
}
return LocallyRenderedMessage;
}());
exports.LocallyRenderedMessage = LocallyRenderedMessage;
/**
* Represents the response to the bot from a command.
*/
var ResponseMessage = /** @class */ (function (_super) {
__extends(ResponseMessage, _super);
function ResponseMessage(body, contentType) {
var _this = _super.call(this) || this;
_this.kind = "response";
_this.body = body;
if (contentType) {
_this.contentType = contentType;
}
return _this;
}
return ResponseMessage;
}(LocallyRenderedMessage));
exports.ResponseMessage = ResponseMessage;
/**
* Message unrelated to extant communications with the bot.
*/
var DirectedMessage = /** @class */ (function (_super) {
__extends(DirectedMessage, _super);
function DirectedMessage(body, address, contentType) {
var _this = _super.call(this) || this;
_this.kind = "directed";
_this.usernames = [];
_this.channelNames = [];
_this.body = body;
if (contentType) {
_this.contentType = contentType;
}
_this.addAddress(address);
return _this;
}
DirectedMessage.prototype.addAddress = function (address) {
if (address instanceof UserAddress) {
this.usernames.push(address.username);
}
else {
this.channelNames.push(address.channelName);
}
return this;
};
DirectedMessage.prototype.addAction = function (instruction) {
this.instructions.push(instruction);
return this;
};
return DirectedMessage;
}(LocallyRenderedMessage));
exports.DirectedMessage = DirectedMessage;
/**
* Populate standard message attachment with defaults if value not set.

@@ -124,3 +214,3 @@ *

var slackMessage = errorMessage(attachment, correlationId);
return new Handlers_1.ResponseMessage(SlackMessages_1.render(slackMessage), Handlers_1.MessageMimeTypes.SLACK_JSON);
return new ResponseMessage(SlackMessages_1.render(slackMessage), SlackMessages_1.MessageMimeTypes.SlackJson);
}

@@ -130,3 +220,3 @@ catch (e) {

console.error("failed to render message '" + attachment + "':" + err.name + ":" + err.message + ":" + err.stack);
return new Handlers_1.ResponseMessage(attachment.fallback);
return new ResponseMessage(attachment.fallback);
}

@@ -145,3 +235,3 @@ }

var slackMessage = successMessage(attachment);
return new Handlers_1.ResponseMessage(SlackMessages_1.render(slackMessage), Handlers_1.MessageMimeTypes.SLACK_JSON);
return new ResponseMessage(SlackMessages_1.render(slackMessage), SlackMessages_1.MessageMimeTypes.SlackJson);
}

@@ -151,3 +241,3 @@ catch (e) {

console.error("failed to render message '" + attachment + "':" + err.name + ":" + err.message + ":" + err.stack);
return new Handlers_1.ResponseMessage(attachment.fallback);
return new ResponseMessage(attachment.fallback);
}

@@ -166,3 +256,3 @@ }

var slackMessage = warningMessage(attachment);
return new Handlers_1.ResponseMessage(SlackMessages_1.render(slackMessage), Handlers_1.MessageMimeTypes.SLACK_JSON);
return new ResponseMessage(SlackMessages_1.render(slackMessage), SlackMessages_1.MessageMimeTypes.SlackJson);
}

@@ -172,3 +262,3 @@ catch (e) {

console.error("failed to render message '" + attachment + "':" + err.name + ":" + err.message + ":" + err.stack);
return new Handlers_1.ResponseMessage(attachment.fallback);
return new ResponseMessage(attachment.fallback);
}

@@ -197,6 +287,6 @@ }

};
return new Handlers_1.ResponseMessage(SlackMessages_1.render(slackMessage), Handlers_1.MessageMimeTypes.SLACK_JSON);
return new ResponseMessage(SlackMessages_1.render(slackMessage), SlackMessages_1.MessageMimeTypes.SlackJson);
}
catch (ex) {
return new Handlers_1.ResponseMessage("Error rendering error message " + ex);
return new ResponseMessage("Error rendering error message " + ex);
}

@@ -210,3 +300,3 @@ });

var slackMessage = { text: msg };
return new Handlers_1.ResponseMessage(SlackMessages_1.render(slackMessage), Handlers_1.MessageMimeTypes.SLACK_JSON);
return new ResponseMessage(SlackMessages_1.render(slackMessage), SlackMessages_1.MessageMimeTypes.SlackJson);
}

@@ -213,0 +303,0 @@ catch (ex) {

/**
* Type defining the MIME types that the Slack message API accepts.
*/
export declare type MessageMimeType = "application/x-atomist-slack+json" | "text/plain";
/**
* Helper constants for the MIME types the Slack message API accepts.
*/
export declare abstract class MessageMimeTypes {
static SlackJson: MessageMimeType;
static PlainText: MessageMimeType;
}
/**
* Construct and render slack messages according to Slack message

@@ -122,25 +133,1 @@ * formatting: https://api.slack.com/docs/message-formatting. Customize

export declare type ActionType = "button" | "select";
export interface ButtonSpec {
text: string;
style?: string;
confirm?: ActionConfirmation;
}
export interface IdentifiableInstruction {
id: string;
}
export interface SelectableIdentifiableInstruction extends IdentifiableInstruction {
id: string;
parameterName: string;
}
export declare class ValidationError extends Error {
message: string;
constructor(message: string);
}
/** Construct Slack button that will execute provided rug instruction. */
export declare function rugButtonFrom(action: ButtonSpec, command: IdentifiableInstruction): Action;
export interface SelectSpec {
text: string;
options: SelectOption[] | DataSource | OptionGroup[];
}
/** Construct Slack menu that will execute provided rug instruction. */
export declare function rugMenuFrom(action: SelectSpec, command: SelectableIdentifiableInstruction): Action;

@@ -17,14 +17,16 @@ "use strict";

*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var _ = require("lodash");
/**
* Helper constants for the MIME types the Slack message API accepts.
*/
var MessageMimeTypes = /** @class */ (function () {
function MessageMimeTypes() {
}
MessageMimeTypes.SlackJson = "application/x-atomist-slack+json";
MessageMimeTypes.PlainText = "text/plain";
return MessageMimeTypes;
}());
exports.MessageMimeTypes = MessageMimeTypes;
/**
* Construct and render slack messages according to Slack message

@@ -118,3 +120,3 @@ * formatting: https://api.slack.com/docs/message-formatting. Customize

function hasItems(arr) {
return arr != null && arr.length > 0;
return !!arr && arr.length > 0;
}

@@ -125,9 +127,8 @@ /** Renders JSON representation of slack message. */

if (hasItems(message.attachments)) {
var idx = 1;
for (var _i = 0, _a = message.attachments; _i < _a.length; _i++) {
var att = _a[_i];
var idx_1 = 1;
_.forIn(message.attachments, function (att) {
if (hasItems(att.actions) && !att.callback_id) {
att.callback_id = "cllbck" + idx++;
att.callback_id = "cllbck" + idx_1++;
}
}
});
}

@@ -172,66 +173,2 @@ return JSON.stringify(message, null, pretty ? 4 : 0);

exports.listItem = listItem;
var ValidationError = (function (_super) {
__extends(ValidationError, _super);
function ValidationError(message) {
var _this = _super.call(this, message) || this;
_this.message = message;
return _this;
}
return ValidationError;
}(Error));
exports.ValidationError = ValidationError;
/** Construct Slack button that will execute provided rug instruction. */
function rugButtonFrom(action, command) {
if (!command.id) {
throw new ValidationError("Please provide a valid non-empty command id");
}
var button = {
text: action.text,
type: "button",
name: "rug",
value: command.id,
};
for (var attr in action) {
if (action.hasOwnProperty(attr)) {
button[attr] = action[attr];
}
}
return button;
}
exports.rugButtonFrom = rugButtonFrom;
/** Construct Slack menu that will execute provided rug instruction. */
function rugMenuFrom(action, command) {
if (!command.id) {
throw new ValidationError("SelectableIdentifiableInstruction must have id set");
}
if (!command.parameterName) {
throw new ValidationError("SelectableIdentifiableInstruction must have parameterName set");
}
var select = {
text: action.text,
type: "select",
name: "rug::" + command.id,
};
if (typeof action.options === "string") {
select.data_source = action.options;
}
else if (action.options.length > 0) {
var first = action.options[0];
if (first.value) {
// then it's normal options
select.options = action.options;
}
else {
// then it's option groups
select.option_groups = action.options;
}
}
for (var attr in action) {
if (action.hasOwnProperty(attr) && attr !== "options") {
select[attr] = action[attr];
}
}
return select;
}
exports.rugMenuFrom = rugMenuFrom;
//# sourceMappingURL=SlackMessages.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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