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
@stefansundin
Copy link
Author

stefansundin commented Sep 12, 2019

This does not appear to work anymore (at least not with xoxc tokens).. I tried but wasn't able to figure out what I need to change.

Edit: The script has been updated.

@ltworf
Copy link

ltworf commented Feb 27, 2020

Hi. I was having the same issue for my slack irc gateway: https://github.com/ltworf/localslackirc

I solved it by sniffing the network traffic from the browser development tools and getting both token and cookies.

@OutsourcedGuru
Copy link

OutsourcedGuru commented Apr 3, 2020

Couldn't get this to work even with a valid token. Had to pull the list from a browser (using that token), creating a local emojilist.json from the earlier output. I then replaced curl -q -s "URL" with cat emojilist.json and it worked as expected.

@stefansundin
Copy link
Author

I updated the script and added better instructions. Let me know if anything isn't working.

@hjonessimple
Copy link

Worked perfectly for me. Thank you!

@jakobhans
Copy link

This worked great for me, thank you!

@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