a cache for slack profile pictures and emojis
TypeScript 98.3%
Shell 1.3%
Other 0.4%
36 1 8

Clone this repository

https://tangled.org/dunkirk.sh/cachet
git@knot.dunkirk.sh:dunkirk.sh/cachet

For self-hosted knots, clone URLs may differ based on your setup.

README.md

Logo
Cachet

noun - A mark or quality, as of distinction, individuality, or authenticity.

#

#

What's this?#

Cachet is a cache / proxy for profile pictures and emojis on the hackclub slack! I made it because calling the slack api every time you want a profile image or emoji is expensive and annoying. Now you can just call the cachet api and get a link to the image or emoji you want! Best of all we are just linking to slack's cdn so it doesn't cost me much of anything (besides db space) to run!

How do I use it?#

Well first the question is how do I host it lol.

Hosting#

I'm hosting on nest so I just setup a systemd service file that runs bun run index.ts in the root dir of this repo. Then I setup caddy to reverse proxy cachet.dunkirk.sh to the app.

Your .env file should look like this:

SLACK_TOKEN=xoxb-123456789012-123456789012-123456789012-123456789012
SLACK_SIGNING_SECRET=12345678901234567890123456789012
DATABASE_PATH=/path/to/db.sqlite # Optional
PORT=3000 # Optional

The slack app can be created from the manifest.yaml in this repo. It just needs the emoji:read and users:read scopes.

I included a service file in this repo that you can use to run the app. Just copy it to ~/.config/systemd/ and then run systemctl --user enable cachet and systemctl --user start cachet to start the app.

cp cachet.service ~/.config/systemd/user/
mkdir data
systemctl --user enable cachet
systemctl --user start cachet

Now grab a free port from nest (nest get_port) and then link your domain to your nest user (nest caddy add cachet.dunkirk.sh) (don't for get to make a CNAME on the domain pointing to kierank.hackclub.app) and then after editing in a Caddyfile entry like the following you should be good to go! (Don't forget to restart caddy: systemctl restart --user caddy)

http://cachet.dunkirk.sh {
        bind unix/.cachet.dunkirk.sh.webserver.sock|777
        reverse_proxy :38453
}

Usage#

The api is pretty simple. You can get a profile picture by calling GET /profile/:id where :id is the slack user id. You can get an emoji by calling GET /emoji/:name where :name is the name of the emoji. You can also get a list of all emojis by calling GET /emojis. (WIP - subject to rapid change)

There are also complete swagger docs available at /swagger! They are dynamically generated from the code so they should always be up to date! (The types force me to keep them up to date ^_^)

How does it work?#

The app is honestly super simple. It's pretty much just a cache layer on top of the slack api. When you request a profile picture or emoji it first checks the cache. If the image is in the cache it returns the link to the image. If the image is not in the cache it calls the slack api to get the link to image and then stores that in the cache before returning the image link to you!

© 2024-present Kieran Klukas