-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>API | slack-message-parser</title>
<meta name="generator" content="VuePress 1.9.7">
<meta name="description" content="Documentation for slack-message-parser">
<link rel="preload" href="/slack-message-parser/assets/css/0.styles.beacc222.css" as="style"><link rel="preload" href="/slack-message-parser/assets/js/app.6af6d04a.js" as="script"><link rel="preload" href="/slack-message-parser/assets/js/2.b590321b.js" as="script"><link rel="preload" href="/slack-message-parser/assets/js/8.3c327106.js" as="script"><link rel="prefetch" href="/slack-message-parser/assets/js/3.bb4afb51.js"><link rel="prefetch" href="/slack-message-parser/assets/js/4.752b9ce9.js"><link rel="prefetch" href="/slack-message-parser/assets/js/5.e4342579.js"><link rel="prefetch" href="/slack-message-parser/assets/js/6.6b2cbcba.js"><link rel="prefetch" href="/slack-message-parser/assets/js/7.f1c79f2c.js">
<link rel="stylesheet" href="/slack-message-parser/assets/css/0.styles.beacc222.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/slack-message-parser/" class="home-link router-link-active"><!----> <span class="site-name">slack-message-parser</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/slack-message-parser/" class="nav-link">
Guide
</a></div><div class="nav-item"><a href="/slack-message-parser/api/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
API
</a></div><div class="nav-item"><a href="https://github.com/pocka/slack-message-parser" target="_blank" rel="noopener noreferrer" class="nav-link external">
GitHub
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/slack-message-parser/" class="nav-link">
Guide
</a></div><div class="nav-item"><a href="/slack-message-parser/api/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
API
</a></div><div class="nav-item"><a href="https://github.com/pocka/slack-message-parser" target="_blank" rel="noopener noreferrer" class="nav-link external">
GitHub
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/slack-message-parser/" aria-current="page" class="sidebar-link">Guide</a></li><li><a href="/slack-message-parser/api/" aria-current="page" class="active sidebar-link">API</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/slack-message-parser/api/#function-parse-message" class="sidebar-link">function parse(message)</a></li><li class="sidebar-sub-header"><a href="/slack-message-parser/api/#interface-node" class="sidebar-link">interface Node</a></li></ul></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="api"><a href="#api" class="header-anchor">#</a> API</h1> <p></p><div class="table-of-contents"><ul><li><a href="#function-parse-message">function parse(message)</a><ul><li><a href="#arguments">Arguments</a></li><li><a href="#returns">Returns</a></li></ul></li><li><a href="#interface-node">interface Node</a><ul><li><a href="#root-node">Root node</a></li><li><a href="#text-node">Text node</a></li><li><a href="#channellink-node">ChannelLink node</a></li><li><a href="#userlink-node">UserLink node</a></li><li><a href="#url-node">URL node</a></li><li><a href="#command-node">Command node</a></li><li><a href="#emoji-node">Emoji node</a></li><li><a href="#pretext-node">PreText node</a></li><li><a href="#code-node">Code node</a></li><li><a href="#italic-bold-strike-quote-node">Italic/Bold/Strike/Quote node</a></li></ul></li></ul></div><p></p> <h2 id="function-parse-message"><a href="#function-parse-message" class="header-anchor">#</a> <code>function parse(message)</code></h2> <p>Parses Slack message and returns a tree (<a href="#interface-node"><code>Node</code></a>).</p> <h3 id="arguments"><a href="#arguments" class="header-anchor">#</a> Arguments</h3> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>message</td> <td>String</td> <td>a Slack message to parse</td></tr></tbody></table> <h3 id="returns"><a href="#returns" class="header-anchor">#</a> Returns</h3> <table><thead><tr><th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>Root</td> <td>A root node of the parsed message tree</td></tr></tbody></table> <h2 id="interface-node"><a href="#interface-node" class="header-anchor">#</a> <code>interface Node</code></h2> <p>Represents each parts of the message, its type and properties.</p> <p>Every node at least have one property, <code>type</code>.</p> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>type</td> <td>Number(NodeType)</td> <td>Type of the node</td></tr> <tr><td>source</td> <td>String</td> <td>Raw string of the node</td></tr></tbody></table> <p>You can test the type with <code>NodeType</code> object (which is actually TypeScript enum).</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> NodeType <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'slack-message-parser'</span>
<span class="token keyword">switch</span> <span class="token punctuation">(</span>node<span class="token punctuation">.</span>type<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">case</span> NodeType<span class="token punctuation">.</span>Text<span class="token operator">:</span>
<span class="token comment">// ...</span>
<span class="token keyword">case</span> NodeType<span class="token punctuation">.</span>ChannelLink<span class="token operator">:</span>
<span class="token comment">// ...</span>
<span class="token punctuation">}</span>
</code></pre></div><p>The names of Node and NodeType are one-to-one equivalent (e.g. <code>Text</code> node have <code>type</code> property that the value is <code>NodeType.Text</code>).</p> <h3 id="root-node"><a href="#root-node" class="header-anchor">#</a> <code>Root</code> node</h3> <p>A node sits on top of the tree. Every parse result have this node as its root node.</p> <h4 id="properties"><a href="#properties" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>children</td> <td>Node[]</td> <td>Child nodes</td></tr></tbody></table> <h3 id="text-node"><a href="#text-node" class="header-anchor">#</a> <code>Text</code> node</h3> <p>Texts.</p> <h4 id="properties-2"><a href="#properties-2" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>text</td> <td>String</td> <td>Text content</td></tr></tbody></table> <h3 id="channellink-node"><a href="#channellink-node" class="header-anchor">#</a> <code>ChannelLink</code> node</h3> <p>Link to a channel.</p> <h4 id="properties-3"><a href="#properties-3" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>channelID</td> <td>String</td> <td>An ID of the channel</td></tr> <tr><td>label</td> <td>Node[] | undefined</td> <td>Display texts for the link</td></tr></tbody></table> <h3 id="userlink-node"><a href="#userlink-node" class="header-anchor">#</a> <code>UserLink</code> node</h3> <p>Link to a user.</p> <h4 id="properties-4"><a href="#properties-4" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>userId</td> <td>String</td> <td>An ID of the user</td></tr> <tr><td>label</td> <td>Node[] | undefined</td> <td>Display texts for the user</td></tr></tbody></table> <h3 id="url-node"><a href="#url-node" class="header-anchor">#</a> <code>URL</code> node</h3> <p>Link other than channels and users (e.g. <code>https://foo.bar</code>, <code>mailto:foo@bar</code>).</p> <h4 id="properties-5"><a href="#properties-5" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>url</td> <td>String</td> <td>A link url</td></tr> <tr><td>label</td> <td>Node[] | undefined</td> <td>Display texts for the link</td></tr></tbody></table> <h3 id="command-node"><a href="#command-node" class="header-anchor">#</a> <code>Command</code> node</h3> <p>Special commands like <code><!date></code>, <code><!everyone></code>, <code><!subteam^id|@handle></code>, and more.
For more details, please refer <a href="https://api.slack.com/docs/message-formatting" target="_blank" rel="noopener noreferrer">Formatting messages | Slack<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>.</p> <h4 id="properties-6"><a href="#properties-6" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>name</td> <td>String</td> <td>A name of the command</td></tr> <tr><td>arguments</td> <td>String[]</td> <td>Command arguments(prefixed by <code>^</code>, <code>ID</code> is an argument of <code><!subteam^ID></code>)</td></tr> <tr><td>label</td> <td>Node[] | undefined</td> <td>Display texts for the link</td></tr></tbody></table> <h3 id="emoji-node"><a href="#emoji-node" class="header-anchor">#</a> <code>Emoji</code> node</h3> <p>Emojis!</p> <h4 id="properties-7"><a href="#properties-7" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>name</td> <td>String</td> <td>A name of the emoji (the text between both <code>:</code>s)</td></tr> <tr><td>variation</td> <td>String | undefined</td> <td>Emoji variation, currently <code>skin-tone-</code> only</td></tr></tbody></table> <h3 id="pretext-node"><a href="#pretext-node" class="header-anchor">#</a> <code>PreText</code> node</h3> <p>Code block. Multi-line codes.</p> <h4 id="properties-8"><a href="#properties-8" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>text</td> <td>String</td> <td>Text content</td></tr></tbody></table> <h3 id="code-node"><a href="#code-node" class="header-anchor">#</a> <code>Code</code> node</h3> <p>Inline code.</p> <h4 id="properties-9"><a href="#properties-9" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>text</td> <td>String</td> <td>Text content</td></tr></tbody></table> <h3 id="italic-bold-strike-quote-node"><a href="#italic-bold-strike-quote-node" class="header-anchor">#</a> <code>Italic</code>/<code>Bold</code>/<code>Strike</code>/<code>Quote</code> node</h3> <p>Represents text decorations. Each nodes just have decoration information, so it acts as container (does not hold texts directly).</p> <h4 id="properties-10"><a href="#properties-10" class="header-anchor">#</a> Properties</h4> <table><thead><tr><th>Name</th> <th>Type</th> <th>Description</th></tr></thead> <tbody><tr><td>children</td> <td>Node[]</td> <td>Child nodes</td></tr></tbody></table></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
←
<a href="/slack-message-parser/" class="prev router-link-active">
Guide
</a></span> <!----></p></div> </main></div><div class="global-ui"></div></div>
<script src="/slack-message-parser/assets/js/app.6af6d04a.js" defer></script><script src="/slack-message-parser/assets/js/2.b590321b.js" defer></script><script src="/slack-message-parser/assets/js/8.3c327106.js" defer></script>
</body>
</html>