Code Monkey home page Code Monkey logo

npm-slack-log2md's Introduction

slack-log2md

Support Node of LTS npm version test code style: prettier

Slack log file (JSON) to Markdown file.

Installation

$ npm install slack-log2md

Usage

Markdown file is generated from Slack log file JSON by running CLI or Node.js API.

Markdown

The generated Markdown file has the following format.

# 2019-10-31

|Time|Icon|Name|Message|
|---|---|---|---|
|13:43|![](https://example.com/test/72.png)|test|`@test` has joined the channel|
|07:02|![](https://example.com/test/72.png)|test|`@test` `#general` Sample message<br>Sample<br><br>Sample|
|07:02|![](https://example.com/bot/72.png)|Sample Bot|๐Ÿ‡ฌ๐Ÿ‡ง: Sample message.|
|15:22|![](https://example.com/test/72.png)|test|Quote: <br><blockquote>Sample<br>Text</blockquote>Please read the above.|
|18:09|![](https://example.com/test/72.png)|test|Code: <br><pre>const value = 'code';<br>console.log(value);</pre><br>Please read the above.|
|18:09|![](https://example.com/test/72.png)|test|Files.<br>https://example.com/files/sample.jpg<br>https://example.com/files/sample.md|
|18:09|![](https://example.com/test/72.png)|test|Sample.<br>Pre-text<blockquote>[sample/example] Text</blockquote><br><blockquote><!here> Text</blockquote>|
  • The message is output as a <table> tag.
  • If a profile image is set for the user, the URL is referenced and displayed.
  • The user will use the display name if there is one, otherwise it will be the account name.
  • The time is always UTC.
  • @user and #channel in the body text enclose the target name in <code> tags.
  • Emoji code (e.g. :smile:, :flag-gb:, ...etc) is converted to the corresponding Unicode character.
  • Convert line breaks \n to <br> tags.
  • Convert quotes (> text, &gt; text on log) to <blockquote> tags.
  • Convert code block to <pre> tags.

CLI

Usage:  slack-log2md [options]

Slack log file (JSON) to Markdown file.

Options:
  -i, --input <Path>          Directory path of the JSON file exported from Slack.
  -o, --output <Path>         Directory path to output Markdown file converted from JSON.
  -r, --report                Display the process reports, default is disable.
  --grouping-same-day-by-utc  Output Markdown grouped on the same day as UTC date.
  --github-wiki               Support output for GitHub Wiki. e.g. `general/2019-11-16.md` -> `slack-general-2019-11-16.md`
  --add-unique-message-id     Add unique identifier for a message. Set the time in the Time field to `<span id ="XXXX">21:34</span>`.
  --ignore-channel-login      Ignore channel login messages.
  -v, --version               output the version number
  -h, --help                  output usage information

Examples:
  $ slack-log2md -i ./logs -o ./dist -r

See also:
  https://github.com/akabekobeko/npm-slack-log2md

Node.js API

slackLog2Md(src, dest, options)

Converts Slack log JSON in the specified workspace directory to Markdown.

Parameters:

Parameter Type Default Description
src String Directory path of log file exported from Slack.
dest String Directory path to output Markdown file converted from log. If a nonexistent directory is specified, the same location as input is selected.
options Options {}

Options:

Parameter Type Default Description
report Boolean false true to display the processing status of the tool to stdout.
groupingSameDayByUTC Boolean false true if messages in the channel are grouped by the same day in UTC. If false, the group is the output log file unit.
githubWiki Boolean false true if support output for GitHub Wiki. Single directory, all file names are unique, avoid conflicts with existing page names. e.g. general/2019-11-16.md -> slack-general-2019-11-16.md.
addUniqueMessageId Boolean false Add unique identifier for a message. Set the time in the Time field to <span id ="XXXX">21:34</span>.
ignore.channelLogin Boolean false Specifies the type of message to ignore.

Sample code:

const slackLog2Md = require('slack-log2md');

const options = {
  report: true,
  groupingSameDayByUTC: true,
  githubWiki: true,
  addUniqueMessageId: false,
  ignore: {
    channelLogin: true
  }
};

slackLog2Md('./logs', './dest', options).catch((err) => {
  console.error(err)
});

ChangeLog

License

npm-slack-log2md's People

Contributors

akabekobeko avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

toiyy

npm-slack-log2md's Issues

crash on user parse

Caused by calling the String method for undefined.

Slack's JSON is resolved dynamically. Therefore, undefined can be specified even if it is non-optional in TypeScript.

TypeError: Cannot read property 'replace' of undefined
    at unescapeStr (.../npm-slack-log2md/src/lib/user.ts:109:14)
    at parseProfile (.../npm-slack-log2md/src/lib/user.ts:139:16)
    at Object.parseUser [as default] (.../npm-slack-log2md/src/lib/user.ts:175:14)
    at Object.exports.readUsers (.../npm-slack-log2md/src/lib/log2md.ts:120:27)
    at Object.log2Md [as default] (.../npm-slack-log2md/src/lib/log2md.ts:188:17)

Support the files

Supports download and link attachments (files). It seems that it is better to make it an optional function because a huge file may be attached.

Support Slack bot image

The image of the current message posting user is obtained from the user information corresponding to the identifier specified in message.user. But Slack bot can't find the image because message.user doesn't exist.

To solve this, add a user search process for Slack bot.

Output Markdown in UTC date/time units

Slack's log JSON file is probably output with the time in San Francisco, where it is located. So if convert the time of the message to UTC, it will cross the day.

To solve this problem, concatenating logs in memory, Markdown outputs in UTC date and time units.

Support the attachments

  • Display messages that have data only in attachments.
  • Display attachments information in normal messages

User in the message is always the speaker

User in the message is always the speaker. Caused by createBody in markdown.ts.

// Replace `<@USERID>` to `@user`
body = body.replace(/<@(.*?)>/g, (_, $1) => {
  const user = users.get($1)
  if (user) {
    return `\`@${username}\``
  }
  return `\`@${$1}\``
})

Support GitHub Wiki

Support output for GitHub Wiki.

  • Single directory
  • All file names are unique
  • Avoid conflicts with existing page names

e.g. general/2019-11-16.md -> slack-general-2019-11-16.md

Support the code block

Supports code block as in #22. If <code> tag is used, <br> can be included.

<code>const value = 'code';<br>console.log(value);</code>

Generate log index markdown

Generate log index markdown.

# Channel Name

- [2019-11-01](./2019-11-01.md)
- [2019-10-31](./2019-10-31.md)

Specifications:

  • File name is index.md
  • Output directory is a target channel directory.
  • The index is in descending order based on the log file name (date and time, e.g. 2019-11-01).

Support the blockquote

Markdown does not parse > in the table. However, GFM supports HTML and uses <br> for line breaks. So quotes with > are converted to <blockquote>.

> aaa
> bbb

to

<blockquote>aaa<br>bbb</blockquote>

Change user image from 24 to 72

At the beginning of development, Markdown was set to a list instead of a table, so a small user image was created according to the characters. However, since it is currently a table, the layout does not collapse even with a larger image.

The size is 72 because it can be obtained from user_profile.image_72 from the message.

Date and time string is local

Build #2 - akabekobeko/npm-slack-log2md - Travis CI

messagesToMarkdown โ€บ Create markdown

    expect(received).toBe(expected) // Object.is equality

    - Expected
    + Received

    - |![](https://example.com/24.png) **test** 22:43|
    + |![](https://example.com/24.png) **test** 13:43|

      |`@test` has joined the channel|
    - |![](https://example.com/24.png) **test** 16:02|
    + |![](https://example.com/24.png) **test** 07:02|
      |`@test` `#general` Sample message<br>Sample<br><br>Sample|
    - |**Sample Bot** 16:02|
    + |**Sample Bot** 07:02|
      |:flag-gb::  Sample message.|

There is a time difference between UTC and JST (UTC + 0900). Since the Slack log file is output in UTC date and time units, the time must also be fixed to UTC.

Add unique identifier for a message

  • Make a message linkable when the page is published on the web.
  • Set the time in the Time field to <span id =" XXXX "> 21:34 </ span>.
  • It should become hash # when published on GitHub Wiki etc. by id attribute
  • This feature is optional because want to avoid HTML as much as possible by default. e.g. --add-unique-message-id.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.