···11+Copyright (c) 2024 Alice <aliceisjustplaying@gmail.com>
22+33+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44+55+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66+77+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+64
README.md
···11+# Bluesky Labeler Starter Kit
22+33+Use this repository to get started with your own Bluesky Labeler. Click the "Use this template" button above to create a new repository, and then follow the instructions below.
44+55+As an example, this repository includes a labeler for setting your favorite of the five elements (Earth, Fire, Air, Water, Love) to your profile. You can edit the labels, descriptions, and other parameters in the `src/constants.ts` file.
66+77+## Prerequisites
88+99+- [Node.js](https://nodejs.org/) 21 or later
1010+- [Bun](https://bun.sh/)
1111+1212+## Setup
1313+1414+Clone the repo and run `bun i` to install the dependencies. This project uses [Bun](https://bun.sh/) for package management.
1515+1616+Run `bunx @skyware/labeler setup` to convert an existing account into a labeler. You can exit after converting the account; there's no need to add the labels with the wizard. We'll do that from code.
1717+1818+Copy the `.env.example` file to `.env` and fill in the values:
1919+2020+```Dotenv
2121+DID=did:plc:xxx
2222+SIGNING_KEY=xxx
2323+BSKY_IDENTIFIER=xxx
2424+BSKY_PASSWORD=xxx
2525+PORT=4002
2626+METRICS_PORT=4102
2727+FIREHOSE_URL=wss://jetstream.atproto.tools/subscribe
2828+CURSOR_UPDATE_INTERVAL=10000
2929+```
3030+3131+A `cursor.txt` file containing the time in microseconds also needs to be present. If it doesn't exist, it will be created with the current time.
3232+3333+Fill out the label IDs, names, descriptions etc. in `src/constants.ts` to your heart's desire. Run `bun set-posts` to create/update all posts at once, then copy/paste the related post rkeys ([record keys](https://atproto.com/specs/record-key)) into `src/constants.ts`. Run `bun set-labels` to create/update all labels at once.
3434+3535+Alternatively, create the posts by hand, edit `src/constants.ts` and use `bunx @skyware/labeler label add` to add the labels.
3636+3737+The server connects to [Jetstream](https://github.com/bluesky-social/jetstream), which provides a WebSocket endpoint that emits ATProto events in JSON. There are [many public instances](https://github.com/bluesky-social/jetstream/blob/main/README.md#public-instances) available:
3838+3939+| Hostname | Region |
4040+| --------------------------------- | ------- |
4141+| `jetstream1.us-east.bsky.network` | US-East |
4242+| `jetstream2.us-east.bsky.network` | US-East |
4343+| `jetstream1.us-west.bsky.network` | US-West |
4444+| `jetstream2.us-west.bsky.network` | US-West |
4545+4646+The server needs to be reachable outside your local network using the URL you provided during the account setup (typically using a reverse proxy such as [Caddy](https://caddyserver.com/)):
4747+4848+```Caddyfile
4949+labeler.example.com {
5050+ reverse_proxy 127.0.0.1:4002
5151+}
5252+```
5353+5454+Metrics are exposed on the defined `METRICS_PORT` for [Prometheus](https://prometheus.io/). [This dashboard](https://grafana.com/grafana/dashboards/11159-nodejs-application-dashboard/) can be used to visualize the metrics in [Grafana](https://grafana.com/grafana/).
5555+5656+Start the project with `bun run start`.
5757+5858+You can check that the labeler is reachable by checking the `/xrpc/com.atproto.label.queryLabels` endpoint of your labeler's server. A new, empty labeler returns `{"cursor":"0","labels":[]}`.
5959+6060+## Credits
6161+6262+- [alice](https://bsky.app/profile/did:plc:by3jhwdqgbtrcc7q4tkkv3cf), creator of the [Zodiac Sign Labels](https://github.com/aliceisjustplaying/zodiacsigns)
6363+- [Juliet](https://bsky.app/profile/did:plc:b3pn34agqqchkaf75v7h43dk), author of the [Pronouns labeler](https://github.com/notjuliet/pronouns-bsky), whose code my labelers were originally based on
6464+- [futur](https://bsky.app/profile/did:plc:uu5axsmbm2or2dngy4gwchec), creator of the [skyware libraries](https://skyware.js.org/) which make it easier to build things for Bluesky