From 0e53807aa5f0a48e9823473777a0b5d154175b4c Mon Sep 17 00:00:00 2001 From: Carl Mercier Date: Mon, 2 Jun 2025 23:28:45 -0500 Subject: [PATCH] Add --include-channels functionality --- .gitignore | 3 ++- README.md | 9 +++++---- src/cli.ts | 5 +++++ src/config.ts | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index beb798d..0049f8c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ slack-archive .DS_Store *.log .token -lib \ No newline at end of file +lib +.env diff --git a/README.md b/README.md index 09f50b2..07a3e00 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ npx slack-archive --use-previous-channel-config: Fetch messages from channels selected in previous run instead of prompting. --channel-types Comma-separated list of channel types to fetch messages from. (public_channel, private_channel, mpim, im) +--include-channels Comma-separated list of channels to include, in automatic mode --exclude-channels Comma-separated list of channels to exclude, in automatic mode --no-backup: Don't create backups. Not recommended. --no-search: Don't create a search file, saving disk space. @@ -53,7 +54,7 @@ This will be mostly painless, I promise. Head over to https://api.slack.com/apps and `Create New App`. Select `From scratch`. Give it a name and choose the workspace you'd like to export. -Then, from the `Features` menu on the left, select `OAuth & Permission`. +Then, from the `Features` menu on the left, select `OAuth & Permission`. As a redirect URL, enter something random that doesn't actually exist, or a domain you control. For instace: @@ -100,9 +101,9 @@ https://notarealurl.com/?code={code}&state= Copy everything between `?code=` and `&state`. This is your `code`. We'll need it in the next step. -Next, we'll exchange your code for a token. To do so, we'll also need your `client secret` -from the first step when we created your app. In a browser, open this URL - replacing -`{your-team-name}`, `{your-client-id}`, `{your-code}` and `{your-client-secret}` with +Next, we'll exchange your code for a token. To do so, we'll also need your `client secret` +from the first step when we created your app. In a browser, open this URL - replacing +`{your-team-name}`, `{your-client-id}`, `{your-code}` and `{your-client-secret}` with your values. ``` diff --git a/src/cli.ts b/src/cli.ts index d54d62d..6578fe5 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -19,6 +19,7 @@ import { EMOJIS_DATA_PATH, NO_SLACK_CONNECT, EXCLUDE_CHANNELS, + INCLUDE_CHANNELS, } from "./config.js"; import { downloadExtras } from "./messages.js"; import { downloadMessages } from "./messages.js"; @@ -116,6 +117,10 @@ async function selectChannels( })); if (AUTOMATIC_MODE || NO_SLACK_CONNECT) { + if (INCLUDE_CHANNELS) { + const includeChannels = INCLUDE_CHANNELS.split(','); + return channels.filter((channel) => includeChannels.includes(channel.name || '')); + } if (EXCLUDE_CHANNELS) { const excludeChannels = EXCLUDE_CHANNELS.split(','); return channels.filter((channel) => !excludeChannels.includes(channel.name || '')); diff --git a/src/config.ts b/src/config.ts index 67a52f8..810ea33 100644 --- a/src/config.ts +++ b/src/config.ts @@ -45,6 +45,7 @@ export const FORCE_HTML_GENERATION = findCliParameter( "--force-html-generation" ); export const EXCLUDE_CHANNELS = getCliParameter("--exclude-channels"); +export const INCLUDE_CHANNELS = getCliParameter("--include-channels"); export const BASE_DIR = process.cwd(); export const OUT_DIR = path.join(BASE_DIR, "slack-archive"); export const TOKEN_FILE = path.join(OUT_DIR, ".token");