Coder Social home page Coder Social logo

slack-emojinator's Introduction

Slack Emojinator

Bulk upload emoji into Slack

Want to create a custom Slack emoji for every pokemon? Slack doesn't currently expose an API endpoint for creating emoji, probably to prevent users from doing exactly what I'm doing, but here's a way to do it anyway.

Creating Emoji

You'll need Python and pip to get started. I recommend using pipenv.

Prepare a directory that contains an image for each emoji you want to create. Remember to respect Slack's specifications for valid emoji images: no greater than 128px in width or height, no greater than 64K in image size. The base filename of each image file should be the name of the emoji (the bit you'll type inside : to display it).

Clone the project and install its prereqs:

libxml is required on your system, if you'd like to use the bulk export script.

git clone https://github.com/smashwilson/slack-emojinator.git
cd slack-emojinator
pipenv install

You'll need to provide your team name (the bit before ".slack.com" in your admin URL) and your session cookie (grab it from your browser). Copy .env.example, fill them in, and source it.

To grab your Slack session cookie:

  • Open your browser's dev tools and copy the value of document.cookie.
  • Go to the Network tab.
  • Re-load your workspace's https://{teamname}.slack.com/customize/emoji page.
  • Find the call to emoji (it is most likely the very top request).
  • Scroll to Request-Headers, copy the value of "Cookie," and add to your .env file.
cp .env.example .env
${EDITOR} .env
source .env

Now you're ready to go. Use a shell glob to invoke upload.py with the emoji files as ARGV:

pipenv run python upload.py ${EMOJI_DIR}/*.png

Exporting Emoji

To export emoji, use export.py and specify an emoji directory:

source .env
pipenv run python export.py path-to-destination/

slack-emojinator's People

Contributors

abn avatar chief-tyrol avatar d-lord avatar denbeigh2000 avatar dependabot[bot] avatar kvarga avatar manos avatar matsu-chara avatar smashwilson avatar stavxyz avatar vmarkovtsev avatar zhilins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack-emojinator's Issues

lxml 4.1.0 from Pipfile.lock not compatible with Python 3.7 or above

Was scratching my head over this issue for a while, so documenting it to benefit others.

The current version of lxml in Pipfile.lock (4.1.0) was released on 2017-10-13, and doesn't appear to be compatible with Python versions 3.7 or newer.

Minimal example showing the issue

Succeeds

git clone [email protected]:smashwilson/slack-emojinator.git
cd slack-emojinator/
docker run --rm -w=/workdir -v "$(pwd)":/workdir python:3.6 sh -c 'pip install pipenv; pipenv install'

Fails

git clone [email protected]:smashwilson/slack-emojinator.git
cd slack-emojinator/
docker run --rm -w=/workdir -v "$(pwd)":/workdir python:3.7 sh -c 'pip install pipenv; pipenv install'

(I also tried with Python 3.8, and got the same error)

I've attached the output of the failing example here: error_log.txt

Suggested Remediation

Short term, just making a note in the README that Python 3.6 is required is probably sufficient, long term upgrading lxml would likely fix the issue

Upload is not working.

It's just what the title says. By following the instructions, I haven't been able to upload emojis.
Maybe it is my SLACK_COOKIE that is wrong.
The document.cookie value is b=.bwasdwerpu04gg8wcogkcg0kg. I have tried with the quotes, without b=, without the dot, everything, but it doesn't work.
Can anyone help me out? Please post your working example, I should be missing something

Fails silently when uploading.

I've followed the instructions and sourced the env file, tried to upload a folder and apparently all went well...

Processing test/facepalm1.jpg.
test/facepalm1.jpg upload complete.
Processing test/facepalm2.png.
test/facepalm2.png upload complete.

Uploaded 2 emojis. (0 already existed)

checking on slack, the emojis aren't there. so I started mucking with the environment file.
if i put a bogus team name it fails as expected.
but whatever value i put in there for the session cookie it runs through the uploading giving the same result as before, so fails while saying it succeeded.

any ideas on how to fix or any other info i can provide?

Fails to upload; possible 302 redirect from slack?

I've been plugging away at this for a bit and can't get it to work. I think I've got a proper cookie set up (via #2), but my uploads simply fail to go through. Looking at this traffic through Runscope vs an in-browser request with Chrome, it looks like Slack is returning a 302 to the main request the script makes.

If I toggle allow_redirects to allow_redirects=True, I get a <Response [200]> after r.raise_for_status(), but the upload itself is still not working. Any ideas on how to debug this further?

API Token can no longer be parsed from document.cookie

Looks like it is no longer included, or is encoded somehow.

$ pipenv run python export.py --concurrent-requests 3 github/
Loading .env environment variables…
Traceback (most recent call last):
  File "export.py", line 179, in <module>
    loop.run_until_complete(main())
  File "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
    return future.result()
  File "export.py", line 161, in main
    token = await _fetch_api_token(session, base_url)
  File "export.py", line 102, in _fetch_api_token
    raise Exception("Could not parse API token from remote data! Regex requires updating.")
Exception: Could not parse API token from remote data! Regex requires updating.

Possible `fix` for the Slack Emoji update?

👋 @smashwilson

I won't claim to be a developer but since Slack changed / removed the ability for us to use this awesome hack I wanted to see if this was a possible fix (or at least give some ideas on how to get it working again)

So this exists: https://chrome.google.com/webstore/detail/neutral-face-emoji-tools/anchoacphlfbdomdlomnbbfhcmcdmjej

Which injects itself into the xxx.slack.com/customize/emoji page to look like this
image

and it will create and upload custom emoji based on filenames.

Is this something that can be iterated on to get your hack working again?

༼ つ ◕ᴗ◕ ༽つ 🥞

New emoji page has probably broken download

Slack just updated the /customize/emoji page and the download script probably doesn't work any more. Need to investigate & probably change the parsing. (and figure out how to trigger the loading-on-scroll? 😱)

See also #26.

Session Cookie?

Can you leave the name of the session cookie?

I've been trying the instructions over and over with all the data from different cookies put into the .env and then running the script, but I can't get it to work.

export.py relies on idna-ssl, but it's not declared in the pipenv file

Noticed this while I was working on #36 (prior to my changes 😄), but didn't get around to documenting it previously.

Minimal example showing the issue

Fails

git clone [email protected]:smashwilson/slack-emojinator.git
cd slack-emojinator/
docker run --rm -w=/workdir -v "$(pwd)":/workdir python:3.6 sh -c 'pip install pipenv; pipenv install; pipenv run python export.py --help'
Traceback (most recent call last):
  File "export.py", line 6, in <module>
    import aiohttp
  File "/root/.local/share/virtualenvs/workdir-tL8tMG2Q/lib/python3.6/site-packages/aiohttp/__init__.py", line 6, in <module>
    from .client import BaseConnector as BaseConnector
  File "/root/.local/share/virtualenvs/workdir-tL8tMG2Q/lib/python3.6/site-packages/aiohttp/client.py", line 32, in <module>
    from . import hdrs, http, payload
  File "/root/.local/share/virtualenvs/workdir-tL8tMG2Q/lib/python3.6/site-packages/aiohttp/http.py", line 7, in <module>
    from .http_parser import HeadersParser as HeadersParser
  File "/root/.local/share/virtualenvs/workdir-tL8tMG2Q/lib/python3.6/site-packages/aiohttp/http_parser.py", line 15, in <module>
    from .helpers import NO_EXTENSIONS, BaseTimerContext
  File "/root/.local/share/virtualenvs/workdir-tL8tMG2Q/lib/python3.6/site-packages/aiohttp/helpers.py", line 59, in <module>
    import idna_ssl
ModuleNotFoundError: No module named 'idna_ssl'

Succeeds

git clone [email protected]:smashwilson/slack-emojinator.git
cd slack-emojinator/
docker run --rm -w=/workdir -v "$(pwd)":/workdir python:3.6 sh -c 'pip install pipenv; pipenv install; pipenv install idna-ssl; pipenv run python export.py --help'

README needs GIFs

To help motivate the hilarious insanity utility of this project, put the pokemon bulk upload front and center as the most sensible use case. Even better if in GIF form.

NameError: name is not defined

(slack-emojinator) C:\Users\User\Development\slack-emojinator>python upload.py C:\Users\User\Downloads\*

Please enter the team name: testingname

Traceback (most recent call last):
  File "upload.py", line 15, in <module>
    team_name = input("Please enter the team name: ")
  File "<string>", line 1, in <module>
NameError: name 'testingname' is not defined

(slack-emojinator) C:\Users\User\Development\slack-emojinator>

In the above example, I am using testingname as my team name however anything there produces the same error.

My .env is as follows:

export SLACK_TEAM=testingname
export SLACK_COOKIE=a-37688960194=fBw5FWZp....HIDDEN...1823224420.1471300460

I have redacted the Cookie for obvious reasons... and again using testingname to not disclose our team name.

SLACK_TOKEN ??

What is exactly this SLACK_TOKEN?
In the instructions you gave, there are 4 cookies in the request. I have tried all of them but it doesnt work to upload the emojis. export works fine though

Upload not working

The slack upload emoji page has changed, meaning this method no longer works in order to upload emotes.

I run this:
$ pipenv run python upload.py emojis/+2-thumbs-up.png

I get this:

Loading .env environment variables...
Processing emojis/+2-thumbs-up.png.
Traceback (most recent call last):
  File "upload.py", line 127, in <module>
    main()
  File "upload.py", line 90, in main
    upload_emoji(session, emoji_name, filename)
  File "upload.py", line 108, in upload_emoji
    crumb = soup.find("input", attrs={"name": "crumb"})["value"]
TypeError: 'NoneType' object is not subscriptable

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.