Skip to content

Instantly share code, notes, and snippets.

@Tsarpf
Created March 25, 2025 17:50
Show Gist options
  • Save Tsarpf/26d3e360e1852edabe58f37a387a5b33 to your computer and use it in GitHub Desktop.
Save Tsarpf/26d3e360e1852edabe58f37a387a5b33 to your computer and use it in GitHub Desktop.
Download all slack custom emojis.
#!/bin/bash
# This script retrieves the full list of custom Slack emoji and downloads them locally.
# Prerequisites: curl and jq
# --- Configuration: update these variables ---
WORKSPACE="something.slack.com"
# Replace with your token, look at the request headers from your browser
TOKEN="xoxc-something-something-etc"
# Replace YOUR_SLACK_COOKIE_HERE with your actual cookie string from your browser session.
COOKIE="YOUR_SLACK_COOKIE_HERE"
# --- Setup export folder ---
EXPORT_DIR="slack_emoji_export"
mkdir -p "$EXPORT_DIR"
# File to store all emoji entries (one JSON object per line)
ALL_EMOJI_FILE="$EXPORT_DIR/all_emojis.jsonl"
> "$ALL_EMOJI_FILE"
# --- Fetch all pages of emoji ---
page=1
while true; do
echo "Fetching page $page..."
RESPONSE=$(curl -s \
-H "Cookie: $COOKIE" \
-F "token=$TOKEN" \
-F "page=$page" \
-F "count=100" \
-F "sort_by=name" \
-F "sort_dir=asc" \
-F "_x_reason=customize-emoji-next-page" \
-F "_x_mode=online" \
"https://$WORKSPACE/api/emoji.adminList")
# Check if the response is valid
ok=$(echo "$RESPONSE" | jq -r '.ok')
if [ "$ok" != "true" ]; then
echo "Error fetching page $page. Response:"
echo "$RESPONSE"
exit 1
fi
# Save this page’s JSON for reference
echo "$RESPONSE" > "$EXPORT_DIR/emoji_page_$page.json"
# Append each emoji entry (one per line) to our aggregate file
echo "$RESPONSE" | jq -c '.emoji[]' >> "$ALL_EMOJI_FILE"
# Check pagination details
current_page=$(echo "$RESPONSE" | jq -r '.paging.page')
total_pages=$(echo "$RESPONSE" | jq -r '.paging.pages')
if [ "$current_page" -ge "$total_pages" ]; then
echo "Reached the last page ($current_page of $total_pages)."
break
fi
page=$((page + 1))
done
echo "Finished fetching emoji list. Now starting download of individual emoji images..."
# --- Download each emoji image ---
downloaded=0
failed=0
while IFS= read -r line; do
# Extract the emoji name and URL from the JSON line
name=$(echo "$line" | jq -r '.name')
url=$(echo "$line" | jq -r '.url')
# Extract the file extension (trim any URL query parameters if needed)
extension="${url##*.}"
extension="${extension%%\?*}"
target_file="$EXPORT_DIR/${name}.${extension}"
echo "Downloading '$name' -> $target_file"
curl -s -o "$target_file" "$url"
if [ $? -eq 0 ]; then
downloaded=$((downloaded + 1))
else
echo "Failed to download $url"
failed=$((failed + 1))
fi
done < "$ALL_EMOJI_FILE"
echo "Download complete: $downloaded emoji downloaded, $failed failures."
@Tsarpf
Copy link
Author

Tsarpf commented Mar 25, 2025

https://emar10.dev/posts/export-slack-emoji/

essentially the same as in that link, but this script also handles fetching the N pages from the emoji adminList thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment