Skip to content

Instantly share code, notes, and snippets.

@dahlia
Created December 29, 2024 04:46
Show Gist options
  • Save dahlia/f849188a967445b27fb7818c4c7f2e12 to your computer and use it in GitHub Desktop.
Save dahlia/f849188a967445b27fb7818c4c7f2e12 to your computer and use it in GitHub Desktop.
Fedify BotKit brainstorming
import { createBot, mention, text } from "@fedify/botkit";
import { RedisKvStore } from "@fedify/redis";
import { Redis } from "ioredis";
// Create a bot instance:
const bot = createBot({
// The bot will have fediverse handle "@greetbot@mydomain":
username: "greetbot",
// Set the profile icon (avatar):
icon: new URL("https://mydomain/icon.png"),
// Set the bio:
bio: text`Hi, there! I'm a simple fediverse bot created by ${mention("@[email protected]").}`,
// Use Redis as a key-value store:
kv: new RedisKvStore(new Redis()),
// Use Redis as a message queue:
queue: new RedisMessageQueue(() => new Redis()),
});
// A bot can respond to a mention:
bot.on(/hi|hello|what'?s\s+up/i, (ctx) => {
return ctx.reply(text`Hi, ${ctx.actor}!`);
});
// Or, a bot also can actively publish a post:
setInterval(async () => {
await bot.publish(text`Hi, forks! It's an hourly greeting.`);
}, 1000 * 60 * 60);
export default bot;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment