@atomist/slack-messages (解剖学家)
节点.js 模块,有助于创建格式良好的
偷懒 通过 @atomist 从你的机器人
软件传送机(SDM). 此模块还有利于添加
执行 SDM 命令的 Slack 信件的动作.
对发送Slack Block消息的支持也得到了支持.
见 原子学文献 更多信息,请访问infofinland上的 sDM是什么,他们能为你做什么 使用原子学 API 软件.
使用
将信件建构为 : 错误消息 格式化 API。 。 。 .
import { SlackMessage } from "@atomist/slack-messages";
// A very simple message
const msg: SlackMessage = { text: "Simple message" };
import {
escape,
SlackMessage,
url,
} from "@atomist/slack-messages";
// Here is an example of a message with a Slack action (button).
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: [
{
text: "Close issue",
type: "button",
name: "closeissue",
value: "somebuttonid",
},
],
callback_id: "cllbck1",
},
],
};
然后将信息传递给 render(msg)这将构建一个
JSON 消息的字符串表示 :
import { render } from "@atomist/slack-messages"
const renderedMsg = render(msg);
或者制作一个漂亮的JSON字符串:
const renderedMsg = render(msg, true);
这将产生以下 JSON 字符串( 纯版) :
{
"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"
],
"callback_id": "cllbck1",
"actions": [
{
"text": "Close issue",
"type": "button",
"name": "rug",
"value": "somebuttonid"
}
]
}
]
}
注意 render 函数将自动指定一个唯一
callback_id 每个附件都有动作。 不过,如果你
提供您的自定义 callback_id 将保留下来.
其他帮助功能
特殊字符
escape("Slack requires you to escape <, > and &");
// => "Slack requires you to escape <, > and &"
链接
// 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>"
用户频道链接( T)
// @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>"
特殊变量
// @channel
atChannel();
// => "<!channel>"
// @here
atHere();
// => "<!here>"
// @everyone
atEveryone();
// => "<!everyone>"
爱莫吉
emoji("smile");
// => ":smile:";
标记
如果存在下限的字段, Slack 将会使标记降值
列入 mrkdwn_in 阵列.
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 到黑标记下转换
GitHub 和Slack markdown 都不同了 让你的GitHub
或 GitHub PRs 默认在 Slack 中看起来相当糟糕。 你用得着
页:1 githubToSlack 函数从 Markdown 转换使用的文本
GitHub 标记为在 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](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>"
支助
一般性支持问题应在缔约方会议 #help
频道 原子主义社区。 。 。 .
如果你发现问题,请创建 问题。 。 。 .
发展
您需要安装 节点.js 来建立和测试这个 项目.
构建和测试
安装依赖关系 .
$ npm install
使用 build 用于编译、测试、嵌入和构建
文档.
$ npm run build
释放
释放是通过 原子学家SDM按钮 在原子仪表板或Slack上的“证明”按钮.