slack-message-parser

JavaScript library for parsing Slack message format (mrkdwn)

  1. 1
(window.webpackJsonp=window.webpackJsonp||[]).push([[8],{283:function(t,e,a){"use strict";a.r(e);var r=a(14),v=Object(r.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"api"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#api"}},[t._v("#")]),t._v(" API")]),t._v(" "),e("p"),e("div",{staticClass:"table-of-contents"},[e("ul",[e("li",[e("a",{attrs:{href:"#function-parse-message"}},[t._v("function parse(message)")]),e("ul",[e("li",[e("a",{attrs:{href:"#arguments"}},[t._v("Arguments")])]),e("li",[e("a",{attrs:{href:"#returns"}},[t._v("Returns")])])])]),e("li",[e("a",{attrs:{href:"#interface-node"}},[t._v("interface Node")]),e("ul",[e("li",[e("a",{attrs:{href:"#root-node"}},[t._v("Root node")])]),e("li",[e("a",{attrs:{href:"#text-node"}},[t._v("Text node")])]),e("li",[e("a",{attrs:{href:"#channellink-node"}},[t._v("ChannelLink node")])]),e("li",[e("a",{attrs:{href:"#userlink-node"}},[t._v("UserLink node")])]),e("li",[e("a",{attrs:{href:"#url-node"}},[t._v("URL node")])]),e("li",[e("a",{attrs:{href:"#command-node"}},[t._v("Command node")])]),e("li",[e("a",{attrs:{href:"#emoji-node"}},[t._v("Emoji node")])]),e("li",[e("a",{attrs:{href:"#pretext-node"}},[t._v("PreText node")])]),e("li",[e("a",{attrs:{href:"#code-node"}},[t._v("Code node")])]),e("li",[e("a",{attrs:{href:"#italic-bold-strike-quote-node"}},[t._v("Italic/Bold/Strike/Quote node")])])])])])]),e("p"),t._v(" "),e("h2",{attrs:{id:"function-parse-message"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#function-parse-message"}},[t._v("#")]),t._v(" "),e("code",[t._v("function parse(message)")])]),t._v(" "),e("p",[t._v("Parses Slack message and returns a tree ("),e("a",{attrs:{href:"#interface-node"}},[e("code",[t._v("Node")])]),t._v(").")]),t._v(" "),e("h3",{attrs:{id:"arguments"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#arguments"}},[t._v("#")]),t._v(" Arguments")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("message")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("a Slack message to parse")])])])]),t._v(" "),e("h3",{attrs:{id:"returns"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#returns"}},[t._v("#")]),t._v(" Returns")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("Root")]),t._v(" "),e("td",[t._v("A root node of the parsed message tree")])])])]),t._v(" "),e("h2",{attrs:{id:"interface-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#interface-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("interface Node")])]),t._v(" "),e("p",[t._v("Represents each parts of the message, its type and properties.")]),t._v(" "),e("p",[t._v("Every node at least have one property, "),e("code",[t._v("type")]),t._v(".")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("type")]),t._v(" "),e("td",[t._v("Number(NodeType)")]),t._v(" "),e("td",[t._v("Type of the node")])]),t._v(" "),e("tr",[e("td",[t._v("source")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("Raw string of the node")])])])]),t._v(" "),e("p",[t._v("You can test the type with "),e("code",[t._v("NodeType")]),t._v(" object (which is actually TypeScript enum).")]),t._v(" "),e("div",{staticClass:"language-js extra-class"},[e("pre",{pre:!0,attrs:{class:"language-js"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" NodeType "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v("'slack-message-parser'")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("switch")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("node"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("type"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n  "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" NodeType"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Text"),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n  "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ...")]),t._v("\n  "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" NodeType"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ChannelLink"),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n  "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ...")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("The names of Node and NodeType are one-to-one equivalent (e.g. "),e("code",[t._v("Text")]),t._v(" node have "),e("code",[t._v("type")]),t._v(" property that the value is "),e("code",[t._v("NodeType.Text")]),t._v(").")]),t._v(" "),e("h3",{attrs:{id:"root-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#root-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("Root")]),t._v(" node")]),t._v(" "),e("p",[t._v("A node sits on top of the tree. Every parse result have this node as its root node.")]),t._v(" "),e("h4",{attrs:{id:"properties"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("children")]),t._v(" "),e("td",[t._v("Node[]")]),t._v(" "),e("td",[t._v("Child nodes")])])])]),t._v(" "),e("h3",{attrs:{id:"text-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#text-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("Text")]),t._v(" node")]),t._v(" "),e("p",[t._v("Texts.")]),t._v(" "),e("h4",{attrs:{id:"properties-2"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-2"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("text")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("Text content")])])])]),t._v(" "),e("h3",{attrs:{id:"channellink-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#channellink-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("ChannelLink")]),t._v(" node")]),t._v(" "),e("p",[t._v("Link to a channel.")]),t._v(" "),e("h4",{attrs:{id:"properties-3"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-3"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("channelID")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("An ID of the channel")])]),t._v(" "),e("tr",[e("td",[t._v("label")]),t._v(" "),e("td",[t._v("Node[] | undefined")]),t._v(" "),e("td",[t._v("Display texts for the link")])])])]),t._v(" "),e("h3",{attrs:{id:"userlink-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#userlink-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("UserLink")]),t._v(" node")]),t._v(" "),e("p",[t._v("Link to a user.")]),t._v(" "),e("h4",{attrs:{id:"properties-4"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-4"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("userId")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("An ID of the user")])]),t._v(" "),e("tr",[e("td",[t._v("label")]),t._v(" "),e("td",[t._v("Node[] | undefined")]),t._v(" "),e("td",[t._v("Display texts for the user")])])])]),t._v(" "),e("h3",{attrs:{id:"url-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#url-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("URL")]),t._v(" node")]),t._v(" "),e("p",[t._v("Link other than channels and users (e.g. "),e("code",[t._v("https://foo.bar")]),t._v(", "),e("code",[t._v("mailto:foo@bar")]),t._v(").")]),t._v(" "),e("h4",{attrs:{id:"properties-5"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-5"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("url")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("A link url")])]),t._v(" "),e("tr",[e("td",[t._v("label")]),t._v(" "),e("td",[t._v("Node[] | undefined")]),t._v(" "),e("td",[t._v("Display texts for the link")])])])]),t._v(" "),e("h3",{attrs:{id:"command-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#command-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("Command")]),t._v(" node")]),t._v(" "),e("p",[t._v("Special commands like "),e("code",[t._v("<!date>")]),t._v(", "),e("code",[t._v("<!everyone>")]),t._v(", "),e("code",[t._v("<!subteam^id|@handle>")]),t._v(", and more.\nFor more details, please refer "),e("a",{attrs:{href:"https://api.slack.com/docs/message-formatting",target:"_blank",rel:"noopener noreferrer"}},[t._v("Formatting messages | Slack"),e("OutboundLink")],1),t._v(".")]),t._v(" "),e("h4",{attrs:{id:"properties-6"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-6"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("name")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("A name of the command")])]),t._v(" "),e("tr",[e("td",[t._v("arguments")]),t._v(" "),e("td",[t._v("String[]")]),t._v(" "),e("td",[t._v("Command arguments(prefixed by "),e("code",[t._v("^")]),t._v(", "),e("code",[t._v("ID")]),t._v(" is an argument of "),e("code",[t._v("<!subteam^ID>")]),t._v(")")])]),t._v(" "),e("tr",[e("td",[t._v("label")]),t._v(" "),e("td",[t._v("Node[] | undefined")]),t._v(" "),e("td",[t._v("Display texts for the link")])])])]),t._v(" "),e("h3",{attrs:{id:"emoji-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#emoji-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("Emoji")]),t._v(" node")]),t._v(" "),e("p",[t._v("Emojis!")]),t._v(" "),e("h4",{attrs:{id:"properties-7"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-7"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("name")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("A name of the emoji (the text between both "),e("code",[t._v(":")]),t._v("s)")])]),t._v(" "),e("tr",[e("td",[t._v("variation")]),t._v(" "),e("td",[t._v("String | undefined")]),t._v(" "),e("td",[t._v("Emoji variation, currently "),e("code",[t._v("skin-tone-")]),t._v(" only")])])])]),t._v(" "),e("h3",{attrs:{id:"pretext-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#pretext-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("PreText")]),t._v(" node")]),t._v(" "),e("p",[t._v("Code block. Multi-line codes.")]),t._v(" "),e("h4",{attrs:{id:"properties-8"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-8"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("text")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("Text content")])])])]),t._v(" "),e("h3",{attrs:{id:"code-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#code-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("Code")]),t._v(" node")]),t._v(" "),e("p",[t._v("Inline code.")]),t._v(" "),e("h4",{attrs:{id:"properties-9"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-9"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("text")]),t._v(" "),e("td",[t._v("String")]),t._v(" "),e("td",[t._v("Text content")])])])]),t._v(" "),e("h3",{attrs:{id:"italic-bold-strike-quote-node"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#italic-bold-strike-quote-node"}},[t._v("#")]),t._v(" "),e("code",[t._v("Italic")]),t._v("/"),e("code",[t._v("Bold")]),t._v("/"),e("code",[t._v("Strike")]),t._v("/"),e("code",[t._v("Quote")]),t._v(" node")]),t._v(" "),e("p",[t._v("Represents text decorations. Each nodes just have decoration information, so it acts as container (does not hold texts directly).")]),t._v(" "),e("h4",{attrs:{id:"properties-10"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#properties-10"}},[t._v("#")]),t._v(" Properties")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Name")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Description")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("children")]),t._v(" "),e("td",[t._v("Node[]")]),t._v(" "),e("td",[t._v("Child nodes")])])])])])}),[],!1,null,null,null);e.default=v.exports}}]);