···11+Copyright (c) 2024 Juliet Philippe <notjuliet@riseup.net>
22+Copyright (c) 2024 Alice <aliceisjustplaying@gmail.com>
33+44+Permission to use, copy, modify, and/or distribute this software for any
55+purpose with or without fee is hereby granted.
66+77+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
88+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
99+AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1010+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1111+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1212+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1313+PERFORMANCE OF THIS SOFTWARE.
+57
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+Create the necessary posts from the labeler account, fill out `src/constants.ts` with the related post rkeys ([record keys](https://atproto.com/specs/record-key)), label IDs and so on, then run `bunx tsx src/set-labels.ts` to create/update all labels at once.
3434+3535+Alternatively, use `bunx @skyware/labeler label add` and edit `src/constants.ts` after.
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 is a public instance available at `wss://jetstream.atproto.tools/subscribe`.
3838+3939+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/)):
4040+4141+```Caddyfile
4242+labeler.example.com {
4343+ reverse_proxy 127.0.0.1:4002
4444+}
4545+```
4646+4747+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/).
4848+4949+Start the project with `bun run start`.
5050+5151+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":[]}`.
5252+5353+## Credits
5454+5555+- [alice](https://bsky.app/profile/did:plc:by3jhwdqgbtrcc7q4tkkv3cf), creator of the [Zodiac Sign Labels](https://github.com/aliceisjustplaying/zodiacsigns)
5656+- [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
5757+- [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