slack-message-parser

JavaScript library for parsing Slack message format (mrkdwn)

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Guide | 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/7.f1c79f2c.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/8.3c327106.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/" aria-current="page" class="home-link router-link-exact-active 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/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  Guide
</a></div><div class="nav-item"><a href="/slack-message-parser/api/" class="nav-link">
  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/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  Guide
</a></div><div class="nav-item"><a href="/slack-message-parser/api/" class="nav-link">
  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="active sidebar-link">Guide</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/slack-message-parser/#installation" class="sidebar-link">Installation</a></li><li class="sidebar-sub-header"><a href="/slack-message-parser/#quick-start" class="sidebar-link">Quick Start</a></li><li class="sidebar-sub-header"><a href="/slack-message-parser/#supported-message-features" class="sidebar-link">Supported Message Features</a></li><li class="sidebar-sub-header"><a href="/slack-message-parser/#examples" class="sidebar-link">Examples</a></li></ul></li><li><a href="/slack-message-parser/api/" class="sidebar-link">API</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="guide"><a href="#guide" class="header-anchor">#</a> Guide</h1> <p>slack-message-parser is a JavaScript library which parses the message returned by Slack API and give you a tree object (imagine AST).
You could use the result tree to create a message viewer (HTML, React component, etc...) or whatever you want 😃</p> <h2 id="installation"><a href="#installation" class="header-anchor">#</a> Installation</h2> <p>The package is available as <code>slack-message-parser</code> on npm.</p> <div class="language-sh extra-class"><pre class="language-sh"><code><span class="token function">yarn</span> <span class="token function">add</span> slack-message-parser
<span class="token comment"># npm i --save slack-message-parser</span>
</code></pre></div><h2 id="quick-start"><a href="#quick-start" class="header-anchor">#</a> Quick Start</h2> <p>Just parse the message!</p> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">import</span> slackMessageParser <span class="token keyword">from</span> <span class="token string">'slack-message-parser'</span>

<span class="token keyword">const</span> tree <span class="token operator">=</span> <span class="token function">slackMessageParser</span><span class="token punctuation">(</span><span class="token string">'Slack *message* ~to~ _parse_'</span><span class="token punctuation">)</span>

<span class="token builtin">console</span><span class="token punctuation">.</span><span class="token function">dir</span><span class="token punctuation">(</span>tree<span class="token punctuation">)</span>
</code></pre></div><h2 id="supported-message-features"><a href="#supported-message-features" class="header-anchor">#</a> Supported Message Features</h2> <ul><li>Plain text</li> <li>Links
<ul><li>Channels (<code>#channel</code>)</li> <li>User (<code>@someone</code>)</li> <li>URL (<code>https://foo.bar</code>, <code>mailto:foo@bar</code>)</li> <li>Commands (Represented as <code>&lt;!foo&gt;</code>, more detail <a href="https://api.slack.com/docs/message-formatting" target="_blank" rel="noopener noreferrer">here<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>)</li></ul></li> <li>Emojis 😍</li> <li>Code block</li> <li>Inline code (<code>`foo`</code>)</li> <li>Italic (<code>_foo_</code>)</li> <li>Bold (<code>*foo*</code>)</li> <li>Strikethrough (<code>~foo~</code>)</li> <li>Quotes (<code>&gt; foo</code>)</li></ul> <h2 id="examples"><a href="#examples" class="header-anchor">#</a> Examples</h2> <h3 id="plain-html-with-typescript"><a href="#plain-html-with-typescript" class="header-anchor">#</a> Plain HTML with TypeScript</h3> <iframe src="https://codesandbox.io/embed/gracious-rgb-kmqbu?fontsize=14&amp;module=%2Fsrc%2Findex.ts&amp;view=editor" title="slack-message-parser--ts-vanilla" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" style="width:100%;height:500px;border:0;border-radius:4px;overflow:hidden;"></iframe> <h3 id="react-with-typescript"><a href="#react-with-typescript" class="header-anchor">#</a> React with TypeScript</h3> <iframe src="https://codesandbox.io/embed/condescending-heyrovsky-y5jw3?fontsize=14&amp;module=%2Fsrc%2FSlackMessage.tsx" title="slack-message-parser--react-ts" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" style="width:100%;height:500px;border:0;border-radius:4px;overflow:hidden;"></iframe></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/slack-message-parser/api/">
        API
      </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/7.f1c79f2c.js" defer></script>
  </body>
</html>