Skip to content

Instantly share code, notes, and snippets.

@stefansundin
Last active February 9, 2023 15:05
Show Gist options
  • Star 30 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save stefansundin/ecf51b0dad7fee535df0d0f385f86647 to your computer and use it in GitHub Desktop.
Save stefansundin/ecf51b0dad7fee535df0d0f385f86647 to your computer and use it in GitHub Desktop.
Download all of your Team's custom Slack emojis.
#!/bin/bash -eo pipefail
# Log in to Slack in a web browser and open the network tools to inspect the traffic.
# Filter the requests with "/api/" and pick one to inspect.
# You need the xoxc token from the request body, and a copy of the cookies. It is the "d" cookie that is important, but you can copy all of them. Make sure that the cookie value is percent encoded!
# Paste the values below.
# You need to have curl and jq installed.
# You can also get the xoxc token from localStorage. Run this in the JavaScript console:
# Object.entries(JSON.parse(localStorage.localConfig_v2)["teams"]).reduce((o,e) => Object.assign(o, { [e[1]["name"]]: e[1]["token"] }), {})
SLACK_TOKEN="xoxc-...."
COOKIES="d=...."
data=$(curl -q -sS -b "$COOKIES" "https://slack.com/api/emoji.list?token=$SLACK_TOKEN")
if echo "$data" | jq -e '.error?' > /dev/null; then
echo "$data"
exit 1
fi
echo "$data" > data.json
echo "$data" | jq -Mr '.emoji | to_entries | .[] | select(.value | startswith("http")) | "\(.key) \(.value)"' | sort | while read name url; do
fn="$name.${url##*.}"
[[ -f "$fn" ]] && continue
echo "$fn"
curl -q -sS -o "$fn" "$url"
done
@donnels
Copy link

donnels commented Aug 2, 2021

I get an
{
"ok": false,
"error": "invalid_auth"
}
for:
curl -q -sS -b "$COOKIES" "https://slack.com/api/emoji.list?token=$SLACK_TOKEN"
I used the sniffed xoxc (q=JSON.parse(localStorage.localConfig_v2)["teams"]; q[Object.keys(q)[0]]["token"]) and the d cookie but no joy.
Any hints?

@stefansundin
Copy link
Author

@donnels I suspect your cookie value is not encoded. It does seem like curl needs the data to already be percent encoded. I'll update the instructions to note this.

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