Skip to content

Instantly share code, notes, and snippets.

@avegancafe
Last active October 8, 2021 14:26
Show Gist options
  • Save avegancafe/17483dc8efaa4ec8bd4786699817262c to your computer and use it in GitHub Desktop.
Save avegancafe/17483dc8efaa4ec8bd4786699817262c to your computer and use it in GitHub Desktop.
/*
*
* In order to run this:
* Get token to use with Slack API:
* 1. Go to the customize emojis admin page in slack (usually the URL is <instance-name>.slack.com/customize/emoji)
* 2. Open your networks tab and find the request to /api/emoji.adminList
* 3. Check the form data that's submitted and grab the value called "token"
*
* Use token in Slack API to get all emojis:
* 1. Go here: https://api.slack.com/methods/emoji.list/test
* 2. Paste in your "token" that you got from step 3 in the section called "Or, provide your own token"
* 3. Click "Test method" to fire the "test" API request
* 4. Copy *just* the object in the response with the mapping from emoji name to URL
* 5. Paste this object into a file in the same folder as this file called 'emojis.json'
* - This json file should be an object that maps from `name-of-emoji -> url-of-emoji`
* 6. Remove any records in this file who's URL has the word `alias`
* - These are whenever you alias an emoji to another emoji. These aren't necessary
*
* Run script to utilize `emojis.json` mapping and download all emojis
* 1. Create a folder called `images` next to this file
* 2. Make sure to install node-fetch from npm
* 3. Run this file with node. I used node v15.14.0
*
*/
import fetch from 'node-fetch'
import fs from 'fs'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const emojis = require('./emojis.json')
for (let emojiName of Object.keys(emojis)) {
const url = emojis[emojiName]
fetch(url).then((response) => {
const tmp = url.split('.')
const filetype = tmp[tmp.length - 1]
console.log(`saving images/${emojiName}.${filetype}`)
console.log(`url:`, url)
const stream = fs.createWriteStream(`./images/${emojiName}.${filetype}`)
stream.on('open', () => {
console.log('opened socket-- writing')
response.body.pipe(stream)
})
})
}
@Iron-Ham
Copy link

Iron-Ham commented Oct 8, 2021

dope

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