Skip to content

Commit

Permalink
docs formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
juni-b-queer committed May 17, 2024
1 parent 005b812 commit a317154
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 87 deletions.
171 changes: 85 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# bsky-event-handlers


An easy package to use for making bluesky bots with validators and handler actions

[![GitHub Actions Test Status](https://img.shields.io/github/actions/workflow/status/juni-b-queer/bsky-event-handlers/testandlint.yml?logo=github&label=Tests)](https://github.com/juni-b-queer/bsky-event-handlers/actions/workflows/testandlint.yml?query=branch%3Amain)
Expand All @@ -14,23 +13,24 @@ An easy package to use for making bluesky bots with validators and handler actio

Scaffold a new project with this package using: \
[![create-bsky-bot](https://img.shields.io/badge/create--bsky--bot-white.svg?logo=npm&color=blue)](https://www.npmjs.com/package/create-bsky-bot)

# Table of contents

**There is a lot of work left to be done for likes, reskeets, and follows, but is mostly complete for handling new
skeets**

- [Quickstart](#quickstart)
- [Overview](#overview)
- [Agent](./src/agent/README.md)
- [Validators](./src/validations/README.md)
- [Actions](./src/actions/README.md)
- [Handlers](./src/handlers/README.md)
- [Record Handlers](./src/handlers/README.md)
- [Pre-made Handlers](./src/handlers/premade-handlers/README.md)
- [Jetsteam Firehose Subscription](./src/firehose/README.md)
- [Utility Functions](./src/utils/README.md)
- [Jetstream Types](./src/types/README.md)
- [Credits](#credits)
- [Quickstart](#quickstart)
- [Overview](#overview)
- [Agent](./src/agent/README.md)
- [Validators](./src/validations/README.md)
- [Actions](./src/actions/README.md)
- [Handlers](./src/handlers/README.md)
- [Record Handlers](./src/handlers/README.md)
- [Pre-made Handlers](./src/handlers/premade-handlers/README.md)
- [Jetsteam Firehose Subscription](./src/firehose/README.md)
- [Utility Functions](./src/utils/README.md)
- [Jetstream Types](./src/types/README.md)
- [Credits](#credits)

[npm Package](https://www.npmjs.com/package/bsky-event-handlers)

Expand Down Expand Up @@ -61,9 +61,9 @@ Create your bsky agent and prepare your jetstreamSubscription variable

```typescript
const testAgent = new HandlerAgent(
'test-bot',
<string>Bun.env.TEST_BSKY_HANDLE,
<string>Bun.env.TEST_BSKY_PASSWORD
'test-bot',
<string>Bun.env.TEST_BSKY_HANDLE,
<string>Bun.env.TEST_BSKY_PASSWORD
);

let jetstreamSubscription: JetstreamSubscription;
Expand All @@ -73,28 +73,28 @@ Initialize your handlers

```typescript
const handlers: JetstreamSubscriptionHandlers = {
post: {
c: [
new CreateSkeetHandler(
[new InputEqualsValidator('Hello')],
[new ReplyToSkeetAction('World!')],
testAgent
),
],
d: [],
},
like: {
c: [],
d: [],
},
follow: {
c: [],
d: [],
},
repost: {
c: [],
d: [],
},
post: {
c: [
new CreateSkeetHandler(
[new InputEqualsValidator('Hello')],
[new ReplyToSkeetAction('World!')],
testAgent
),
],
d: [],
},
like: {
c: [],
d: [],
},
follow: {
c: [],
d: [],
},
repost: {
c: [],
d: [],
},
};
```

Expand All @@ -104,15 +104,15 @@ for our example, we'll only be acting upon post creations, so our handlers will

```typescript
const handlers: JetstreamSubscriptionHandlers = {
post: {
c: [
new CreateSkeetHandler(
[new InputEqualsValidator('Hello')],
[new ReplyToSkeetAction('World!')],
testAgent
),
],
},
post: {
c: [
new CreateSkeetHandler(
[new InputEqualsValidator('Hello')],
[new ReplyToSkeetAction('World!')],
testAgent
),
],
},
};
```

Expand All @@ -123,69 +123,69 @@ Then in out `initialize` function, we authenticate the agent, and create the Jet

```typescript
async function initialize() {
await testAgent.authenticate();
DebugLog.info('INIT', 'Initialized!');
await testAgent.authenticate();
DebugLog.info('INIT', 'Initialized!');

jetstreamSubscription = new JetstreamSubscription(
handlers,
<string>Bun.env.JETSTREAM_URL
);
jetstreamSubscription = new JetstreamSubscription(
handlers,
<string>Bun.env.JETSTREAM_URL
);
}
```

Then finally, we call initialize, then start the subscription to listen for events

```typescript
initialize().then(() => {
jetstreamSubscription.createSubscription();
jetstreamSubscription.createSubscription();
});
```

All together, a simple bot index.ts would look like

```typescript
import {
HandlerAgent,
JetstreamSubscriptionHandlers,
JetstreamSubscription,
CreateSkeetHandler,
InputEqualsValidator,
ReplyToSkeetAction,
DebugLog,
HandlerAgent,
JetstreamSubscriptionHandlers,
JetstreamSubscription,
CreateSkeetHandler,
InputEqualsValidator,
ReplyToSkeetAction,
DebugLog,
} from 'bsky-event-handlers';

const testAgent = new HandlerAgent(
'test-bot',
<string>Bun.env.TEST_BSKY_HANDLE,
<string>Bun.env.TEST_BSKY_PASSWORD
'test-bot',
<string>Bun.env.TEST_BSKY_HANDLE,
<string>Bun.env.TEST_BSKY_PASSWORD
);

let jetstreamSubscription: JetstreamSubscription;

const handlers: JetstreamSubscriptionHandlers = {
post: {
c: [
new CreateSkeetHandler(
[new InputEqualsValidator('Hello')],
[new ReplyToSkeetAction('World!')],
testAgent
),
],
},
post: {
c: [
new CreateSkeetHandler(
[new InputEqualsValidator('Hello')],
[new ReplyToSkeetAction('World!')],
testAgent
),
],
},
};

async function initialize() {
await testAgent.authenticate();
DebugLog.info('INIT', 'Initialized!');
await testAgent.authenticate();
DebugLog.info('INIT', 'Initialized!');

jetstreamSubscription = new JetstreamSubscription(
handlers,
<string>Bun.env.JETSTREAM_URL
);
jetstreamSubscription = new JetstreamSubscription(
handlers,
<string>Bun.env.JETSTREAM_URL
);
}

initialize().then(() => {
jetstreamSubscription.createSubscription();
jetstreamSubscription.createSubscription();
});
```

Expand Down Expand Up @@ -224,13 +224,12 @@ your bot in response to defined triggers, enhancing your bot's interactivity, fl

## Packages/dependencies used

- [@atproto/api](https://www.npmjs.com/package/@atproto/api)
- [Jetstream](https://github.com/ericvolp12/jetstream) (Though I use
a [forked version](https://github.com/juni-b-queer/jetstream) to include the CID and build/publish the docker
container)

- [@atproto/api](https://www.npmjs.com/package/@atproto/api)
- [Jetstream](https://github.com/ericvolp12/jetstream) (Though I use
a [forked version](https://github.com/juni-b-queer/jetstream) to include the CID and build/publish the docker
container)

## Contact me

[![discord](https://img.shields.io/badge/junib33-7289da.svg?logo=discord)](#contact-me)
[![bsky](https://img.shields.io/badge/Juni!_on_Bluesky-5BCEFA.svg?logo=bluesky)](https://bsky.app/profile/did:plc:wpp4lklhvmopw6zcy6qb42ru)
[![bsky](https://img.shields.io/badge/Juni!_on_Bluesky-5BCEFA.svg?logo=bluesky)](https://bsky.app/profile/did:plc:wpp4lklhvmopw6zcy6qb42ru)
1 change: 0 additions & 1 deletion src/handlers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ CreateSkeetHandler.make(
handlerAgent
);
```

0 comments on commit a317154

Please sign in to comment.