Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mattermost compatible export file generation #112

Merged
merged 10 commits into from
Aug 21, 2022
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Slack Dumper
- Join the discussion in Telegram_ or Slack_.
- `Read the overview on Medium.com`_
- |go ref|

- `Mattermost migration`_ steps
.. contents::
:depth: 2

Expand All @@ -30,7 +30,7 @@ There a three modes of operation (more on this in `User Guide`_) :

#. List users/channels
#. Dumping messages and threads
#. Creating a Slack Export.
#. Creating a Slack Export in Mattermost or Standard modes.

Slackdump accepts two types of input (see `Dumping Conversations`_ section):

Expand Down Expand Up @@ -188,6 +188,7 @@ Messages that were conveyed with the donations:
.. _`Go templating`: https://pkg.go.dev/html/template
.. _User Guide: doc/README.rst
.. _Dumping Conversations: doc/usage-channels.rst
.. _Mattermost migration: doc/usage-export.rst
.. _rusq/dlog: https://github.com/rusq/dlog
.. _logrus: https://github.com/sirupsen/logrus
.. _glog: https://github.com/golang/glog
Expand Down
4 changes: 1 addition & 3 deletions auth/auth_ui/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func (cl *CLI) RequestWorkspace(w io.Writer) (string, error) {
return workspace, nil
}

func (*CLI) Stop() {
return
}
func (*CLI) Stop() {}

func readln(r io.Reader) (string, error) {
line, err := bufio.NewReader(r).ReadString('\n')
Expand Down
44 changes: 38 additions & 6 deletions cmd/slackdump/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/AlecAivazis/survey/v2"
"github.com/rusq/slackdump/v2/export"
"github.com/rusq/slackdump/v2/internal/app"
"github.com/rusq/slackdump/v2/internal/app/ui"
"github.com/rusq/slackdump/v2/internal/structures"
Expand Down Expand Up @@ -96,28 +97,59 @@ func surveyList(p *params) error {

func surveyExport(p *params) error {
var err error
p.appCfg.ExportName, err = ui.MustString(

p.appCfg.ExportType, err = questExportType()
if err != nil {
return err
}

p.appCfg.ExportName, err = ui.StringRequire(
"Output directory or ZIP file: ",
"Enter the output directory or ZIP file name. Add \".zip\" to save to zip file",
"Enter the output directory or ZIP file name. Add \".zip\" extension to save to a zip file.\nFor Mattermost, zip file is recommended.",
)
if err != nil {
return err
}
p.appCfg.Input.List, err = questConvoList()
p.appCfg.Input.List, err = questConversationList()
if err != nil {
return err
}
p.appCfg.Options.DumpFiles, err = ui.Confirm("Export files?", true)
if err != nil {
return err
}
return nil
}

func questExportType() (export.ExportType, error) {
mode := &survey.Select{
Message: "Export type: ",
Options: []string{export.TMattermost.String(), export.TStandard.String()},
Description: func(value string, index int) string {
descr := []string{
"Mattermost bulk upload compatible export (see doc)",
"Standard export format",
}
return descr[index]
},
}
var resp string
if err := survey.AskOne(mode, &resp); err != nil {
return 0, err
}
var t export.ExportType
t.Set(resp)
return t, nil
}

func surveyDump(p *params) error {
var err error
p.appCfg.Input.List, err = questConvoList()
p.appCfg.Input.List, err = questConversationList()
return err
}

// questConvoList enquires the channel list.
func questConvoList() (*structures.EntityList, error) {
// questConversationList enquires the channel list.
func questConversationList() (*structures.EntityList, error) {
for {
chanStr, err := ui.String(
"List conversations: ",
Expand Down
5 changes: 4 additions & 1 deletion cmd/slackdump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/slack-go/slack"

"github.com/rusq/slackdump/v2"
"github.com/rusq/slackdump/v2/export"
"github.com/rusq/slackdump/v2/internal/app"
"github.com/rusq/slackdump/v2/internal/structures"
"github.com/rusq/slackdump/v2/logger"
Expand Down Expand Up @@ -232,7 +233,8 @@ func parseCmdLine(args []string) (params, error) {

var p = params{
appCfg: app.Config{
Options: slackdump.DefOptions,
Options: slackdump.DefOptions,
ExportType: export.TStandard,
},
}

Expand All @@ -248,6 +250,7 @@ func parseCmdLine(args []string) (params, error) {
fs.BoolVar(&p.appCfg.ListFlags.Users, "list-users", false, "list users and their IDs. ")
// - export
fs.StringVar(&p.appCfg.ExportName, "export", "", "`name` of the directory or zip file to export the Slack workspace to."+zipHint)
fs.Var(&p.appCfg.ExportType, "export-type", "set the export type: 'standard' or 'mattermost' (default: standard)")

// input-ouput options
fs.StringVar(&p.appCfg.Output.Filename, "o", "-", "Output `filename` for users and channels.\nUse '-' for the Standard Output.")
Expand Down
127 changes: 114 additions & 13 deletions doc/usage-export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,128 @@ Creating Slack Export

.. contents::

Exporting Slack Workspace
~~~~~~~~~~~~~~~~~~~~~~~~~
This feature allows one to create a slack export of the Slack workspace in
standard or Mattermost compatible format.

This feature allows one to create a slack export of the slack workspace. To
run in Slack Export mode, one must start Slackdump specifying the
slack export directory, i.e.::
By default, it generates the Standard type Export.

slackdump -export my-workspace
The export file or directory will include emails and attachments (if
``-download`` flag is specified).

Or, if you want to save export as a ZIP file::
Mattermost export
~~~~~~~~~~~~~~~~~
Mattermost mode is currently in alpha-stage. Export is generated in the
format that can be imported using Mattermost "bulk" import mode format using
``mmetl/mmctl`` tools (see quick guide below).

slackdump -export my-workspace.zip
The ``mattermost import slack`` command is not yet supported.

Slackdump will export the whole workspace. If ' ``-f``' flag is specified,
all files will be saved under the channel's '``attachments``' directory.
Mattermost export quick guide
+++++++++++++++++++++++++++++

To export to Mattermost, Slackdump should be started with ``-export-type
mattermost`` flag. Mattermost tools would require a ZIP file.

Steps to export from Slack and import to Mattermost:

#. Run Slackdump in mattermost mode to export the workspace::

slackdump -export my-workspace.zip -export-type mattermost -download

optionally, you can specify list of conversation to export::

slackdump -export my-workspace.zip -export-type mattermost -download C12301120 D4012041

#. Download the ``mmetl`` tool for your architecture from `mmetl
github page`_. In the example we'll be using the Linux version::

curl -LO https://github.com/mattermost/mmetl/releases/download/0.0.1/mmetl.linux-amd64.tar.gz

Unpack::

tar zxf mmetl.linux-amd64.tar.gz

#. Run the ``mmetl`` tool to generate the mattermost bulk import
JSONL file::

./mmetl transform slack -t Your_Team_Name -d bulk-export-attachments -f test.zip -o mattermost_import.jsonl

For example, if your Mattermost team is "slackdump"::

./mmetl transform slack -t slackdump -d bulk-export-attachments -f test.zip -o mattermost_import.jsonl

This will generate a directory ``bulk-export-attachments`` and
``mattermost_import.jsonl`` file in the current directory.

#. Create a zip archive in bulk format. Please ensure that the
``bulk-export-attachments`` directory is placed inside ``data``
directory by following the steps below::

mkdir data
mv bulk-export-attachments data
zip -r bulk_import.zip data mattermost_import.jsonl

#. Copy the resulting file to the mattermost server, and upload it using ``mmctl`` tool::

mmctl import upload ./bulk_import.zip

This will upload the zip file into the Mattermost.

List all import files to find out the filename that will be used to
start the import process::

mmctl import list available

The output will print the file with an ID prefix::

9zgyay5wupdyzc1kqdin5re77e_bulk_import.zip

#. Start the import process::

mmctl import process <filename>

For example::

mmctl import process 9zgyay5wupdyzc1kqdin5re77e_bulk_import.zip

#. To monitor the status of the job or to see if there are any
errors::

mmctl import job list

and::

mmctl import job show <JOB ID> --json

After following all these steps, you should see the data in your
Mattermost team.

More detailed instructions can be found in the `Mattermost
documentation`_

Standard export
~~~~~~~~~~~~~~~

To run in Slack Export standard mode, one must start Slackdump
specifying the slack export directory or zip file, i.e.::

slackdump -export my-workspace -export-type standard

< OR, for a ZIP file >

slackdump -export my-workspace.zip -export-type standard

Slackdump will export the whole workspace. If ' ``-download``' flag is
specified, all files will be saved under the channel's '``attachments``'
directory.

Inclusive and Exclusive export
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It is possible to **include** or **exclude** channels in/from the Export.

Exporting only the channels you need
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
++++++++++++++++++++++++++++++++++++

To **include** only those channels you're interested in, use the following
syntax::
Expand All @@ -36,15 +135,15 @@ syntax::
The command above will export ONLY channels ``C12401724`` and ``C4812934``.

Exporting everything except some unwanted channels
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
++++++++++++++++++++++++++++++++++++++++++++++++++

To **exclude** one or more channels from the export, prefix the channel with "^"
character. For example, you want to export everything except channel C123456::

slackdump -export my-workspace.zip ^C123456

Providing the list in a file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
++++++++++++++++++++++++++++

You can specify the filename instead of listing all the channels on the command
line. To include the channels from the file, use the "@" character prefix. The
Expand Down Expand Up @@ -111,3 +210,5 @@ slack-like GUI.

.. _`Scumbag Steve`: https://www.google.com/search?q=Scumbag+Steve
.. _Index: README.rst
.. _mmetl github page: https://github.com/mattermost/mmetl
.. _Mattermost documentation: https://docs.mattermost.com/onboard/migrating-to-mattermost.html#migrating-from-slack-using-the-mattermost-mmetl-tool-and-bulk-import
Loading