-
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
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self';frame-src https://codesandbox.io;style-src https://pocka.github.io/slack-message-parser/styles.css https://rsms.me/inter/ https://cdn.jsdelivr.net/npm/hack-font@3.3.0/;font-src https://rsms.me/inter/ https://cdn.jsdelivr.net/npm/hack-font@3.3.0/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://rsms.me/inter/inter.css" rel="stylesheet" /><link href="https://cdn.jsdelivr.net/npm/hack-font@3.3.0/build/web/hack-subset.css" rel="stylesheet" />
<title>API | slack-message-parser</title>
<link rel="stylesheet" href="/slack-message-parser/styles.css" />
</head>
<!--
This site is generated using nano-jsx SSR, lightning-css, remark/rehype, Prism, and Deno.
Source code at https://github.com/pocka/slack-message-parser/tree/master/docs/site/
-->
<body>
<div class="layout__logo-wrapper layout__header"><a class="layout__logo" href="/slack-message-parser/">slack<br />message<br />parser</a></div><nav class="layout__nav layout__header"><ul class="nav__list"><li><a class="nav__link" href="/slack-message-parser/">Intro</a></li><li><a class="nav__link" href="/slack-message-parser/installation/">Install</a></li><li><a class="nav__link" href="/slack-message-parser/api/">API</a></li><li><a class="nav__link" href="/slack-message-parser/examples/">Examples</a></li><li><a class="nav__link" href="https://github.com/pocka/slack-message-parser">GitHub</a></li></ul></nav><div class="layout__header-fill layout__header"></div><aside class="layout__toc"><div class="toc__root"><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a class="toc-link toc-link-h1" href="#api">API</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a class="toc-link toc-link-h2" href="#function-parsemessage">function parse(message)</a><ol class="toc-level toc-level-3"><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#arguments">Arguments</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#returns">Returns</a></li></ol></li><li class="toc-item toc-item-h2"><a class="toc-link toc-link-h2" href="#interface-node">interface Node</a><ol class="toc-level toc-level-3"><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#root-node">Root node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#text-node">Text node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#channellink-node">ChannelLink node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#userlink-node">UserLink node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#url-node">URL node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#command-node">Command node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#emoji-node">Emoji node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#pretext-node">PreText node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#code-node">Code node</a></li><li class="toc-item toc-item-h3"><a class="toc-link toc-link-h3" href="#italicboldstrikequote-node">Italic/Bold/Strike/Quote node</a></li></ol></li></ol></li></ol></nav></div></aside><main class="layout__main"><div class="markdown__root"><h1 id="api">API</h1>
<h2 id="function-parsemessage"><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">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">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"><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>
<pre class="language-js"><code class="language-js"><span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">NodeType</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">"slack-message-parser"</span><span class="token punctuation">;</span>
<span class="token keyword control-flow">switch</span> <span class="token punctuation">(</span>node<span class="token punctuation">.</span><span class="token property-access">type</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">case</span> <span class="token maybe-class-name">NodeType</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Text</span></span><span class="token operator">:</span>
<span class="token comment">// ...</span>
<span class="token keyword">case</span> <span class="token maybe-class-name">NodeType</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">ChannelLink</span></span><span class="token operator">:</span>
<span class="token comment">// ...</span>
<span class="token punctuation">}</span>
</code></pre>
<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"><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">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"><code>Text</code> node</h3>
<p>Texts.</p>
<h4 id="properties-1">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"><code>ChannelLink</code> node</h3>
<p>Link to a channel.</p>
<h4 id="properties-2">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"><code>UserLink</code> node</h3>
<p>Link to a user.</p>
<h4 id="properties-3">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"><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-4">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"><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">Formatting messages | Slack</a>.</p>
<h4 id="properties-5">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"><code>Emoji</code> node</h3>
<p>Emojis!</p>
<h4 id="properties-6">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"><code>PreText</code> node</h3>
<p>Code block. Multi-line codes.</p>
<h4 id="properties-7">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"><code>Code</code> node</h3>
<p>Inline code.</p>
<h4 id="properties-8">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="italicboldstrikequote-node"><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-9">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></main>
</body>
</html>