Skip to content

Commit 327284c

Browse files
committed
Initial commit
0 parents  commit 327284c

17 files changed

+3412
-0
lines changed

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"denoland.vscode-deno",
4+
"streetsidesoftware.code-spell-checker"
5+
]
6+
}

.vscode/settings.json

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"deno.enable": true,
3+
"deno.unstable": true,
4+
"editor.detectIndentation": false,
5+
"editor.indentSize": 2,
6+
"editor.insertSpaces": true,
7+
"files.eol": "\n",
8+
"files.insertFinalNewline": true,
9+
"files.trimFinalNewlines": true,
10+
"[javascript]": {
11+
"editor.defaultFormatter": "denoland.vscode-deno",
12+
"editor.formatOnSave": true,
13+
"editor.codeActionsOnSave": {
14+
"source.sortImports": "always"
15+
}
16+
},
17+
"[javascriptreact]": {
18+
"editor.defaultFormatter": "denoland.vscode-deno",
19+
"editor.formatOnSave": true,
20+
"editor.codeActionsOnSave": {
21+
"source.sortImports": "always"
22+
}
23+
},
24+
"[json]": {
25+
"editor.defaultFormatter": "vscode.json-language-features",
26+
"editor.formatOnSave": true
27+
},
28+
"[jsonc]": {
29+
"editor.defaultFormatter": "vscode.json-language-features",
30+
"editor.formatOnSave": true
31+
},
32+
"[typescript]": {
33+
"editor.defaultFormatter": "denoland.vscode-deno",
34+
"editor.formatOnSave": true,
35+
"editor.codeActionsOnSave": {
36+
"source.sortImports": "always"
37+
}
38+
},
39+
"[typescriptreact]": {
40+
"editor.defaultFormatter": "denoland.vscode-deno",
41+
"editor.formatOnSave": true,
42+
"editor.codeActionsOnSave": {
43+
"source.sortImports": "always"
44+
}
45+
},
46+
"cSpell.words": [
47+
"activitypub",
48+
"botkit",
49+
"denokv",
50+
"Fedify",
51+
"fediverse",
52+
"halfyear",
53+
"logtape",
54+
"Minhee",
55+
"multikey",
56+
"nodeinfo",
57+
"phensley",
58+
"unfollowed",
59+
"uuidv7"
60+
]
61+
}

LICENSE

+661
Large diffs are not rendered by default.

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<img src="./logo.svg" alt="BotKit by Fedify" width="203" height="165">
2+
3+
BotKit by Fedify
4+
================
5+
6+
> [!NOTE]
7+
> BotKit is still in early development. The API may change in the future.
8+
> Although it currently supports only Deno, it will support Node.js and Bun
9+
> later.
10+
11+
BotKit is a framework for creating [ActivityPub] bots. It is powered by
12+
[Fedify], a lower-level library for creating ActivityPub server applications.
13+
Unlike Mastodon bots, BotKit is designed to create a standalone ActivityPub bot,
14+
which is a complete ActivityPub server in itself and not limited to Mastodon's
15+
capabilities (such as the 500-character limit per post).
16+
17+
BotKit's API is so simple and easy to use that you can create a complete bot in
18+
a single TypeScript file. Here's an example of a simple bot that just greets:
19+
20+
~~~~ typescript
21+
import { createBot, mention, text } from "@fedify/botkit";
22+
import { RedisKvStore } from "@fedify/redis";
23+
import { Redis } from "ioredis";
24+
25+
// Create a bot instance:
26+
const bot = createBot<void>({
27+
// The bot will have fediverse handle "@greetbot@mydomain":
28+
username: "greetbot",
29+
// Set the display name:
30+
name: "Greet Bot",
31+
// Set the profile icon (avatar):
32+
icon: new URL("https://mydomain/icon.png"),
33+
// Set the bio:
34+
summary: text`Hi, there! I'm a simple fediverse bot created by ${
35+
mention("@[email protected]")}.`,
36+
// Use Redis as a key-value store:
37+
kv: new RedisKvStore(new Redis()),
38+
// Use Redis as a message queue:
39+
queue: new RedisMessageQueue(() => new Redis()),
40+
});
41+
42+
// A bot can respond to a mention:
43+
bot.onMention(/hi|hello|what'?s\s+up/i, async (message) => {
44+
await message.reply(text`Hi, ${ctx.actor}!`);
45+
});
46+
47+
// Or, a bot also can actively publish a post:
48+
const session = bot.getSession(new URL("https://mydomain/"));
49+
setInterval(async () => {
50+
await session.publish(text`Hi, forks! It's an hourly greeting.`);
51+
}, 1000 * 60 * 60);
52+
53+
export default bot;
54+
~~~~
55+
56+
[ActivityPub]: https://activitypub.rocks/
57+
[Fedify]: https://fedify.dev/
58+
59+
<!-- cSpell: ignore greetbot mydomain -->

deno.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@fedify/botkit",
3+
"version": "0.1.0",
4+
"license": "AGPL-3.0-only",
5+
"unstable": [
6+
"kv",
7+
"temporal"
8+
],
9+
"exports": {
10+
".": "./src/mod.ts",
11+
"./bot": "./src/bot.ts",
12+
"./text": "./src/text.ts"
13+
},
14+
"imports": {
15+
"@fedify/fedify": "jsr:@fedify/fedify@^1.3.3",
16+
"@hongminhee/x-forwarded-fetch": "jsr:@hongminhee/x-forwarded-fetch@^0.2.0",
17+
"@logtape/logtape": "jsr:@logtape/logtape@^0.8.0",
18+
"@phensley/language-tag": "npm:@phensley/language-tag@^1.9.2",
19+
"@std/assert": "jsr:@std/assert@^1.0.10",
20+
"@std/html": "jsr:@std/html@^1.0.3",
21+
"@std/uuid": "jsr:@std/uuid@^1.0.4",
22+
"xss": "npm:xss@^1.0.15"
23+
},
24+
"exclude": [
25+
"*.md",
26+
".github",
27+
".vscode"
28+
],
29+
"tasks": {
30+
"check": "deno check src/ && deno lint && deno fmt --check",
31+
"test": "deno test --allow-net=hollo.social"
32+
}
33+
}

0 commit comments

Comments
 (0)