Socket
Book a DemoInstallSign in
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

to
0.8.0

23

CHANGELOG.md

@@ -12,2 +12,17 @@ # Change Log

### Fixed
- Improved Markdown to Slack markup conversion [#17][17]
[17]: https://github.com/atomist/slack-messages/issues/17
### Added
- Standard Slack success, error, and warning messages and colors
### Deprecated
- renderError and renderSuccess have been replaced by errorResponse
and successResponse
## [0.7.0] - 2017-07-04

@@ -28,3 +43,3 @@

### Fixed
- Enforce message validation to ensure rendered buttons can be clicked:
- Enforce message validation to ensure rendered buttons can be clicked:
[#10](https://github.com/atomist/slack-messages/issues/10)

@@ -63,3 +78,3 @@

before: `import { ... } from "@atomist/slack-messages/build/src/RugMessages";`
after: `import { ... } from "@atomist/slack-messages/RugMessages";`

@@ -79,3 +94,3 @@

### Changed
- **BREAKING** `Action` fields `name` and `type` are now required in order
- **BREAKING** `Action` fields `name` and `type` are now required in order
to match Slack required fields

@@ -105,2 +120,2 @@

- Add Slack message rendering and most common rendering helper functions
- Add support for Slack action buttons that execute rug instructions
- Add support for Slack action buttons that execute rug instructions

@@ -0,1 +1,45 @@

/**
* Replace named Markdown links with parenthesized links.
*
* @param text string which may have named Markdown links
* @return string with explicit links
*/
export declare function convertNamedLinks(text: string): string;
/**
* Replace <img> tags with just the image URL.
*
* @param text string which may have img tags
* @return string with img tags replaced
*/
export declare function convertInlineImages(text: string): string;
/**
* Replace Markdown image links with just the image URL.
*
* @param text string with Markdown
* @return string with image URLs
*/
export declare function convertImageLinks(text: string): string;
/**
* Replace Markdown links with Slack markup links.
*
* @param text string with Markdown
* @return string with Slack markup
*/
export declare function convertLinks(text: string): string;
/**
* Replace Markdown bold, italic, and unordered lists with their Slack
* markup equivalent.
*
* @param text string with Markdown
* @return string with Slack markup
*/
export declare function convertFormat(text: string): string;
/**
* Convert GitHub-flavored Markdown to Slack message markup. This is
* not a complete implementation of a Markdown parser, but it does its
* level best.
*
* @param text string containing markdown
* @return string with Slack markup
*/
export declare function githubToSlack(text: string): string;

179

Markdown.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Common_1 = require("./Common");
var codeBlockSeparator = "```";
var codeLineSeparator = "`";
function textBlock(text) {
return {
type: "text",
text: text,
};
var _ = require("lodash");
/**
* Try to handle adjacent HTML and Markdown elements that cannot be
* adjacent in Slack markup. Used a the function in replace.
*
* @param match the full match
* @param url the URL
* @param space trailing space, if it exists
* @return properly padded replacement string
*/
function trailingSpace(match, url, space, offset, full) {
var pad = (offset + match.length === full.length) ? "" : " ";
return (space) ? url + space : url + pad;
}
function closeBlock(text, block) {
var position = text.indexOf(block.separator);
if (position >= 0) {
block.text = text.substr(0, position);
var remainingText = text.substr(position + block.separator.length);
return [block, remainingText];
/**
* Replace named Markdown links with parenthesized links.
*
* @param text string which may have named Markdown links
* @return string with explicit links
*/
function convertNamedLinks(text) {
var namedLinksRegExp = /^\[(.+?)\]:\s*(https?:\/\/\S+).*\n/mg;
var matches;
var links = {};
// tslint:disable-next-line:no-conditional-assignment
while (matches = namedLinksRegExp.exec(text)) {
var name_1 = matches[1];
var url = matches[2];
links[name_1] = url;
}
else {
return [textBlock(block.separator + text), null];
}
var linked = text;
_.forEach(links, function (u, n) {
var nameRegExp = new RegExp("\\[(.+?)\\]\\[" + n + "\\]|\\[" + n + "\\]\\[\\]", "g");
linked = linked.replace(nameRegExp, function (m, ln) {
var linkName = (ln) ? ln : n;
return "[" + linkName + "](" + u + ")";
});
});
return linked.replace(namedLinksRegExp, "");
}
function startBlock(text) {
var codeBlockStart = text.indexOf(codeBlockSeparator);
var codeLineStart = text.indexOf(codeLineSeparator);
if (codeBlockStart >= 0 || codeLineStart >= 0) {
var _a = (codeLineStart < 0) || (codeBlockStart >= 0 && codeBlockStart <= codeLineStart)
? [codeBlockSeparator, codeBlockStart] : [codeLineSeparator, codeLineStart], separator = _a[0], position = _a[1];
var plainText = text.substr(0, position);
var remainingText = text.substr(position + separator.length);
return [plainText, { type: "code", separator: separator }, remainingText];
}
else {
return null;
}
}
function toTextBlocks(text, currentBlock, blocks) {
if (!Common_1.emptyString(text)) {
if (currentBlock) {
var _a = closeBlock(text, currentBlock), codeBlock = _a[0], remainingText = _a[1];
blocks.push(codeBlock);
return toTextBlocks(remainingText, null, blocks);
}
else {
var newBlock = startBlock(text);
if (newBlock) {
var plainText = newBlock[0], codeBlock = newBlock[1], remainingText = newBlock[2];
blocks.push(textBlock(plainText));
return toTextBlocks(remainingText, codeBlock, blocks);
}
else {
blocks.push(textBlock(text));
return blocks;
}
}
}
else {
return blocks;
}
}
exports.convertNamedLinks = convertNamedLinks;
/**
* Replace <img> tags with just the image URL.
*
* @param text string which may have img tags
* @return string with img tags replaced
*/
function convertInlineImages(text) {
return text.replace(/<img .*src=\"([^\"]+)\".*>/g, "$1")
.replace(/&lt;img .*src=\"([^\"]+)\".*&gt;/g, "$1");
var regex = /(?:&lt;|<)img\s[\S\s]*?\bsrc="(\S+?)"[\S\s]*?(?:&gt;|>)(\s?)/g;
return text.replace(regex, trailingSpace);
}
exports.convertInlineImages = convertInlineImages;
/**
* Replace Markdown image links with just the image URL.
*
* @param text string with Markdown
* @return string with image URLs
*/
function convertImageLinks(text) {
return text.replace(/"\!\[image\]\((.*)\)/g, "$1");
return text.replace(/!\[.*?\]\((.+?)\)(\s?)/g, trailingSpace);
}
exports.convertImageLinks = convertImageLinks;
/**
* Replace Markdown links with Slack markup links.
*
* @param text string with Markdown
* @return string with Slack markup
*/
function convertLinks(text) {
return text.replace(/\[([^\[]+)\]\(([^\(]+)\)/g, "<$2|$1>");
return text.replace(/\[(.+?)\]\((.+?)\)/g, "<$2|$1>");
}
exports.convertLinks = convertLinks;
/**
* Replace Markdown bold, italic, and unordered lists with their Slack
* markup equivalent.
*
* @param text string with Markdown
* @return string with Slack markup
*/
function convertFormat(text) {
return text.replace(/^(\s*)-(\s+)/mg, "$1•$2")
.replace(/^(\s*)\*(\s+)/mg, "$1•$2")
.replace(/(\*|_)\1(\S|\S.*?\S)\1\1(?!\1)/g, "<bdmkd>$2<bdmkd>")
.replace(/(\*|_)(?!\1)(\S|\S.*?\S)\1(?!\1)/g, "<itmkd>$2<itmkd>")
.replace(/<bdmkd>/g, "*")
.replace(/<itmkd>/g, "_");
}
exports.convertFormat = convertFormat;
/**
* Convert sections of text from GitHub-flavored Markdown to Slack
* message markup. This function should not be passed inline code or
* code blocks. The ordering of the functions called is significant.
*
* @param text string containing Markdown
* @return string converted to Slack markup
*/
function convertMarkdown(text) {
try {
var converted = text
.replace(/(\n\s*)-(\s+)/g, "$1•$2")
.replace(/(^\s*)-(\s+)/g, "$1•$2")
.replace(/(\n\s*)\*(\s+)/g, "$1•$2")
.replace(/(^\s*)\*(\s+)/g, "$1•$2")
.replace(/\*\*([^\*]+)\*\*/g, "<bdmkd>$1<bdmkd>")
.replace(/\*([^\*]+)\*/g, "<itmkd>$1<itmkd>")
.replace(/<bdmkd>/g, "*")
.replace(/<itmkd>/g, "_");
return convertLinks(convertImageLinks(convertInlineImages(converted)));
return convertLinks(convertImageLinks(convertInlineImages(convertNamedLinks(convertFormat(text)))));
}
catch (e) {
var err = e;
console.error("replace failed:" + err.name + ":" + err.message + ":" + err.stack);
return text;
}
}
function handleMarkdown(block) {
return block.type === "text" ?
convertMarkdown(block.text) :
block.separator + block.text + block.separator;
}
/**
* Convert GitHub-flavored Markdown to Slack message markup. This is
* not a complete implementation of a Markdown parser, but it does its
* level best.
*
* @param text string containing markdown
* @return string with Slack markup
*/
function githubToSlack(text) {
return toTextBlocks(text, null, []).map(handleMarkdown).join("");
var splitRegex = /(```[\S\s]*?```(?!`)|`.*?`)/mg;
var hunks = text.split(splitRegex);
for (var i = 0; i < hunks.length; i += 2) {
hunks[i] = convertMarkdown(hunks[i]);
}
return hunks.join("");
}
exports.githubToSlack = githubToSlack;
//# sourceMappingURL=Markdown.js.map
{
"name": "@atomist/slack-messages",
"version": "0.7.0",
"author": "Atomist, Inc",
"directories": {
"test": "build/test"
},
"scripts": {
"test": "tsc -p . && mocha --require intelli-espower-loader --recursive build/test",
"cleantest": "rm -rf build && tsc -p . && mocha --require intelli-espower-loader --recursive build/test",
"autotest": "supervisor -q -n exit -x ./node_modules/.bin/mocha -- --require intelli-espower-loader --recursive build/test"
},
"description": "utilities for creating Slack messages",
"version": "0.8.0",
"author": "Atomist",
"license": "Apache-2.0",
"homepage": "https://github.com/atomist/slack-messages#readme",
"repository": {

@@ -18,23 +13,37 @@ "type": "git",

"keywords": [
"Atomist"
"atomist",
"rug",
"slack"
],
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/atomist/slack-messages/issues"
},
"homepage": "https://github.com/atomist/slack-messages#readme",
"dependencies": {
"@atomist/rug": "^1.0.0-m.5",
"deprecated-decorator": "^0.1.6",
"lodash": "^4.17.4"
},
"devDependencies": {
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.18",
"@types/power-assert": "^1.4.29",
"intelli-espower-loader": "^1.0.1",
"mocha": "^3.4.1",
"power-assert": "^1.4.2",
"espower-typescript": "^8.0.0",
"mocha": "^3.4.2",
"power-assert": "^1.4.4",
"supervisor": "^0.12.0",
"tslint": "^5.1.0",
"tslint": "^5.4.3",
"typescript": "^2.3.2"
},
"dependencies": {
"@atomist/rug": "^1.0.0-m.3"
"directories": {
"test": "test"
},
"scripts": {
"autotest": "supervisor -q -n exit -x npm -- test",
"clean": "npm run clean-js ; rm -rf build",
"clean-js": "find src test -type f -name '*.js' -print0 | xargs -0 rm -f",
"compile": "tsc -p .",
"distclean": "npm run clean ; rm -rf node_modules",
"lint": "tslint '**/*.ts' --exclude 'node_modules/**' --exclude 'build/**' -t verbose",
"lint-fix": "npm run lint -- --fix",
"test": "mocha --compilers ts:espower-typescript/guess 'test/**/*.ts'"
}
}
# @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/)

@@ -165,2 +164,11 @@ [Node][node] module [`@atomist/slack-messages`][slack-messages]

## 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 `githubToSlack` function from `Markdown` to convert text that uses GitHub markdown to text that will look good in Slack:
```typescript
githubToSlack("* list item 1\n* list item 2\n\**some bold text** and *some italic text* with a link [click here](http://someplace.com)");
=> "• list item 1\n• list item 2\n*some bold text* and _some italic text_ with a link <http://someplace.com|click here>"
```
## Support

@@ -167,0 +175,0 @@

import { ResponseMessage } from "@atomist/rug/operations/Handlers";
import { Attachment, SlackMessage } from "./SlackMessages";
export declare const ErrorColor = "#D94649";
export declare const SuccessColor = "#45B254";
export declare const WarningColor = "#FFCC00";
/**
* Create a standard Slack error message. The attachment should
* contain at least a non-empty fallback property. The text property
* will be augmented with information about getting help. If the text
* property is not provided, the fallback is used as a base for the
* fallback. Title icons and message will be added if they are not
* present.
*
* @param attachment message content
* @param correlationId correlation ID for transaction that failed,
* which will appear in the footer if it is not already set
* @return a Slack error message using attachments which will need to be `render`ed
*/
export declare function renderError(msg: string, correlationId?: string): ResponseMessage;
export declare function renderSuccess(msg: string): ResponseMessage;
export declare function errorMessage(attachment: Attachment, correlationId?: string): SlackMessage;
/**
* Create a standard Slack success message. The attachment should
* contain at least a non-empty fallback property. If the text
* property is not provided, the fallback is used. Title icons and
* message will be added if they are not present.
*
* @param attachment message content
* @return a Slack success message using attachments which will need to be `render`ed
*/
export declare function successMessage(attachment: Attachment): SlackMessage;
/**
* Create a standard Slack warning message. The attachment should
* contain at least a non-empty fallback property. If the text
* property is not provided, the fallback is used. Title icons and
* message will be added if they are not present.
*
* @param attachment message content
* @return a Slack warning message using attachments which will need to be `render`ed
*/
export declare function warningMessage(attachment: Attachment): SlackMessage;
/**
* Create a Rug error ResponseMessage. If rendering fails, a text
* response message of attachment.fallback is returned.
*
* @param msg text of Slack message
* @param correlationId correlation ID of transaction that failed
* @return Rug error ResponseMessage
*/
export declare function errorResponse(attachment: Attachment, correlationId?: string): ResponseMessage;
/**
* Create a Rug success ResponseMessage. If rendering fails, a text
* response message of attachment.fallback is returned.
*
* @param msg text of Slack message
* @return Rug success ResponseMessage
*/
export declare function successResponse(attachment: Attachment): ResponseMessage;
/**
* Create a Rug warning ResponseMessage. If rendering fails, a text
* response message of attachment.fallback is returned.
*
* @param msg text of Slack message
* @return Rug warning ResponseMessage
*/
export declare function warningResponse(attachment: Attachment): ResponseMessage;
export declare const renderError: (msg: string, correlationId?: string) => ResponseMessage;
export declare const renderSuccess: (msg: string) => ResponseMessage;
"use strict";
/*
* Copyright © 2017 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var Common_1 = require("./Common");
var Handlers_1 = require("@atomist/rug/operations/Handlers");
var deprecated_decorator_1 = require("deprecated-decorator");
var SlackMessages_1 = require("./SlackMessages");
var Handlers_1 = require("@atomist/rug/operations/Handlers");
exports.ErrorColor = "#D94649";
exports.SuccessColor = "#45B254";
exports.WarningColor = "#FFCC00";
/**
* Populate standard message attachment with defaults if value not set.
*
* @param a attachment to ensure populated, possibly modified by this function
* @param sm default values
* @return populated attachment
*/
function renderError(msg, correlationId) {
function standardAttachment(a, sm) {
a.fallback = a.fallback || sm.kind + "!";
a.text = a.text || a.fallback;
a.author_name = a.author_name || sm.kind + ": " + a.fallback;
a.author_icon = a.author_icon || sm.image;
a.color = a.color || sm.color;
a.mrkdwn_in = a.mrkdwn_in || ["text"];
return a;
}
/**
* Create a standard Slack error message. The attachment should
* contain at least a non-empty fallback property. The text property
* will be augmented with information about getting help. If the text
* property is not provided, the fallback is used as a base for the
* fallback. Title icons and message will be added if they are not
* present.
*
* @param attachment message content
* @param correlationId correlation ID for transaction that failed,
* which will appear in the footer if it is not already set
* @return a Slack error message using attachments which will need to be `render`ed
*/
function errorMessage(attachment, correlationId) {
var defaults = {
kind: "Error",
image: "https://images.atomist.com/rug/error-circle.png",
color: exports.ErrorColor,
};
attachment = standardAttachment(attachment, defaults);
var supportUrl = "https://atomist-community.slack.com/messages/C29GYTYDC/";
attachment.text += "\nPlease contact " + SlackMessages_1.url(supportUrl, "Atomist support");
if (!attachment.footer && correlationId) {
attachment.text += ", providing the correlation ID below";
attachment.footer = "Correlation ID: " + correlationId;
}
attachment.text += ". Sorry for the inconvenience.";
var message = { attachments: [attachment] };
return message;
}
exports.errorMessage = errorMessage;
/**
* Create a standard Slack success message. The attachment should
* contain at least a non-empty fallback property. If the text
* property is not provided, the fallback is used. Title icons and
* message will be added if they are not present.
*
* @param attachment message content
* @return a Slack success message using attachments which will need to be `render`ed
*/
function successMessage(attachment) {
var defaults = {
kind: "Success",
image: "https://images.atomist.com/rug/check-circle.png",
color: exports.SuccessColor,
};
attachment = standardAttachment(attachment, defaults);
var message = { attachments: [attachment] };
return message;
}
exports.successMessage = successMessage;
/**
* Create a standard Slack warning message. The attachment should
* contain at least a non-empty fallback property. If the text
* property is not provided, the fallback is used. Title icons and
* message will be added if they are not present.
*
* @param attachment message content
* @return a Slack warning message using attachments which will need to be `render`ed
*/
function warningMessage(attachment) {
var defaults = {
kind: "Warning",
image: "https://images.atomist.com/rug/error-square.png",
color: exports.WarningColor,
};
attachment = standardAttachment(attachment, defaults);
var message = { attachments: [attachment] };
return message;
}
exports.warningMessage = warningMessage;
/**
* Create a Rug error ResponseMessage. If rendering fails, a text
* response message of attachment.fallback is returned.
*
* @param msg text of Slack message
* @param correlationId correlation ID of transaction that failed
* @return Rug error ResponseMessage
*/
function errorResponse(attachment, correlationId) {
try {
var slackMessage = errorMessage(attachment, correlationId);
return new Handlers_1.ResponseMessage(SlackMessages_1.render(slackMessage), Handlers_1.MessageMimeTypes.SLACK_JSON);
}
catch (e) {
var err = e;
console.error("failed to render message '" + attachment + "':" + err.name + ":" + err.message + ":" + err.stack);
return new Handlers_1.ResponseMessage(attachment.fallback);
}
}
exports.errorResponse = errorResponse;
/**
* Create a Rug success ResponseMessage. If rendering fails, a text
* response message of attachment.fallback is returned.
*
* @param msg text of Slack message
* @return Rug success ResponseMessage
*/
function successResponse(attachment) {
try {
var slackMessage = successMessage(attachment);
return new Handlers_1.ResponseMessage(SlackMessages_1.render(slackMessage), Handlers_1.MessageMimeTypes.SLACK_JSON);
}
catch (e) {
var err = e;
console.error("failed to render message '" + attachment + "':" + err.name + ":" + err.message + ":" + err.stack);
return new Handlers_1.ResponseMessage(attachment.fallback);
}
}
exports.successResponse = successResponse;
/**
* Create a Rug warning ResponseMessage. If rendering fails, a text
* response message of attachment.fallback is returned.
*
* @param msg text of Slack message
* @return Rug warning ResponseMessage
*/
function warningResponse(attachment) {
try {
var slackMessage = warningMessage(attachment);
return new Handlers_1.ResponseMessage(SlackMessages_1.render(slackMessage), Handlers_1.MessageMimeTypes.SLACK_JSON);
}
catch (e) {
var err = e;
console.error("failed to render message '" + attachment + "':" + err.name + ":" + err.message + ":" + err.stack);
return new Handlers_1.ResponseMessage(attachment.fallback);
}
}
exports.warningResponse = warningResponse;
/* tslint:disable:no-shadowed-variable */
exports.renderError = deprecated_decorator_1.deprecated({
alternative: "errorResponse",
version: "0.8.0",
}, function renderError(msg, correlationId) {
try {
var error = {

@@ -19,3 +183,3 @@ text: msg,

};
if (!Common_1.emptyString(correlationId)) {
if (correlationId) {
error.footer = "Correlation ID: " + correlationId;

@@ -31,5 +195,7 @@ }

}
}
exports.renderError = renderError;
function renderSuccess(msg) {
});
exports.renderSuccess = deprecated_decorator_1.deprecated({
alternative: "successResponse",
version: "0.8.0",
}, function renderSuccess(msg) {
try {

@@ -40,6 +206,5 @@ var slackMessage = { text: msg };

catch (ex) {
return renderError("Error rendering success message " + ex);
return exports.renderError("Error rendering success message " + ex);
}
}
exports.renderSuccess = renderSuccess;
});
//# sourceMappingURL=RugMessages.js.map

@@ -0,1 +1,9 @@

/**
* Construct and render slack messages according to Slack message
* formatting: https://api.slack.com/docs/message-formatting. Customize
* messages with rug actions.
*/
/**
* Escapes special Slack characters.
*/
export declare function escape(text: string): string;

@@ -10,2 +18,6 @@ /**

* When userName is provided will add readable user name.
*
* @param userId Slack user ID
* @param userName alternative user name, which Slack seems to ignore
* @return properly formatted Slack user mention
*/

@@ -45,2 +57,4 @@ export declare function user(userId: string, userName?: string): string;

attachments?: Attachment[];
unfurl_links?: boolean;
unfurl_media?: boolean;
}

@@ -47,0 +61,0 @@ /**

"use strict";
/**
* Construct and render slack messages according to Slack message
* formatting: https://api.slack.com/docs/message-formatting. Customize
* messages with rug actions.
/*
* Copyright © 2017 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@@ -19,7 +29,11 @@ var __extends = (this && this.__extends) || (function () {

/**
* Construct and render slack messages according to Slack message
* formatting: https://api.slack.com/docs/message-formatting. Customize
* messages with rug actions.
*/
/**
* Escapes special Slack characters.
*/
var Common_1 = require("./Common");
function escape(text) {
if (!Common_1.emptyString(text)) {
if (text) {
return text

@@ -40,6 +54,6 @@ .replace(/&/g, "&amp;")

function url(fullUrl, label) {
if (!Common_1.emptyString(fullUrl) && !Common_1.emptyString(label)) {
if (fullUrl && label) {
return "<" + fullUrl + "|" + escape(label) + ">";
}
else if (!Common_1.emptyString(fullUrl)) {
else if (fullUrl) {
return "<" + fullUrl + ">";

@@ -55,8 +69,12 @@ }

* When userName is provided will add readable user name.
*
* @param userId Slack user ID
* @param userName alternative user name, which Slack seems to ignore
* @return properly formatted Slack user mention
*/
function user(userId, userName) {
if (!Common_1.emptyString(userId) && !Common_1.emptyString(userName)) {
if (userId && userName) {
return "<@" + userId + "|" + userName + ">";
}
else if (!Common_1.emptyString(userId)) {
else if (userId) {
return "<@" + userId + ">";

@@ -75,6 +93,6 @@ }

function channel(channelId, channelName) {
if (!Common_1.emptyString(channelId) && !Common_1.emptyString(channelName)) {
if (channelId && channelName) {
return "<#" + channelId + "|" + channelName + ">";
}
else if (!Common_1.emptyString(channelId)) {
else if (channelId) {
return "<#" + channelId + ">";

@@ -112,3 +130,3 @@ }

var att = _a[_i];
if (hasItems(att.actions) && att.callback_id == null) {
if (hasItems(att.actions) && !att.callback_id) {
att.callback_id = "cllbck" + idx++;

@@ -123,3 +141,3 @@ }

function emoji(name) {
return ":" + name + ":";
return (name) ? ":" + name + ":" : "";
}

@@ -129,8 +147,3 @@ exports.emoji = emoji;

function bold(text) {
if (!Common_1.emptyString(text)) {
return "*" + text + "*";
}
else {
return "";
}
return (text) ? "*" + text + "*" : "";
}

@@ -140,8 +153,3 @@ exports.bold = bold;

function italic(text) {
if (!Common_1.emptyString(text)) {
return "_" + text + "_";
}
else {
return "";
}
return (text) ? "_" + text + "_" : "";
}

@@ -151,8 +159,3 @@ exports.italic = italic;

function strikethrough(text) {
if (!Common_1.emptyString(text)) {
return "~" + text + "~";
}
else {
return "";
}
return (text) ? "~" + text + "~" : "";
}

@@ -162,8 +165,3 @@ exports.strikethrough = strikethrough;

function codeLine(text) {
if (!Common_1.emptyString(text)) {
return "`" + text + "`";
}
else {
return "";
}
return (text) ? "`" + text + "`" : "";
}

@@ -173,8 +171,3 @@ exports.codeLine = codeLine;

function codeBlock(text) {
if (!Common_1.emptyString(text)) {
return "```" + text + "```";
}
else {
return "";
}
return (text) ? "```" + text + "```" : "";
}

@@ -184,8 +177,3 @@ exports.codeBlock = codeBlock;

function listItem(item) {
if (!Common_1.emptyString(item)) {
return "\u2022 " + item;
}
else {
return "";
}
return (item) ? "\u2022 " + item : "";
}

@@ -205,3 +193,3 @@ exports.listItem = listItem;

function rugButtonFrom(action, command) {
if (Common_1.emptyString(command.id)) {
if (!command.id) {
throw new ValidationError("Please provide a valid non-empty command id");

@@ -208,0 +196,0 @@ }

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.