-
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
# API
[[toc]]
## `function parse(message)`
Parses Slack message and returns a tree ([`Node`](#interface-node)).
### Arguments
| Name | Type | Description |
| ------- | ------ | ------------------------ |
| message | String | a Slack message to parse |
### Returns
| Type | Description |
| ---- | -------------------------------------- |
| Root | A root node of the parsed message tree |
## `interface Node`
Represents each parts of the message, its type and properties.
Every node at least have one property, `type`.
| Name | Type | Description |
| ------ | ---------------- | ---------------------- |
| type | Number(NodeType) | Type of the node |
| source | String | Raw string of the node |
You can test the type with `NodeType` object (which is actually TypeScript enum).
```js
import { NodeType } from "slack-message-parser";
switch (node.type) {
case NodeType.Text:
// ...
case NodeType.ChannelLink:
// ...
}
```
The names of Node and NodeType are one-to-one equivalent (e.g. `Text` node have `type` property that the value is `NodeType.Text`).
### `Root` node
A node sits on top of the tree. Every parse result have this node as its root node.
#### Properties
| Name | Type | Description |
| -------- | ------ | ----------- |
| children | Node[] | Child nodes |
### `Text` node
Texts.
#### Properties
| Name | Type | Description |
| ---- | ------ | ------------ |
| text | String | Text content |
### `ChannelLink` node
Link to a channel.
#### Properties
| Name | Type | Description |
| --------- | ------------------- | -------------------------- |
| channelID | String | An ID of the channel |
| label | Node[] \| undefined | Display texts for the link |
### `UserLink` node
Link to a user.
#### Properties
| Name | Type | Description |
| ------ | ------------------- | -------------------------- |
| userId | String | An ID of the user |
| label | Node[] \| undefined | Display texts for the user |
### `URL` node
Link other than channels and users (e.g. `https://foo.bar`, `mailto:foo@bar`).
#### Properties
| Name | Type | Description |
| ----- | ------------------- | -------------------------- |
| url | String | A link url |
| label | Node[] \| undefined | Display texts for the link |
### `Command` node
Special commands like `<!date>`, `<!everyone>`, `<!subteam^id|@handle>`, and more.
For more details, please refer [Formatting messages | Slack](https://api.slack.com/docs/message-formatting).
#### Properties
| Name | Type | Description |
| --------- | ------------------- | -------------------------------------------------------------------------- |
| name | String | A name of the command |
| arguments | String[] | Command arguments(prefixed by `^`, `ID` is an argument of `<!subteam^ID>`) |
| label | Node[] \| undefined | Display texts for the link |
### `Emoji` node
Emojis!
#### Properties
| Name | Type | Description |
| --------- | ------------------- | ------------------------------------------------ |
| name | String | A name of the emoji (the text between both `:`s) |
| variation | String \| undefined | Emoji variation, currently `skin-tone-` only |
### `PreText` node
Code block. Multi-line codes.
#### Properties
| Name | Type | Description |
| ---- | ------ | ------------ |
| text | String | Text content |
### `Code` node
Inline code.
#### Properties
| Name | Type | Description |
| ---- | ------ | ------------ |
| text | String | Text content |
### `Italic`/`Bold`/`Strike`/`Quote` node
Represents text decorations. Each nodes just have decoration information, so it acts as container (does not hold texts directly).
#### Properties
| Name | Type | Description |
| -------- | ------ | ----------- |
| children | Node[] | Child nodes |