Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
A framework for creating ActivityPub bots
Classes
A repository for storing bot data using a key-value store.
- addFollowee(): Promise<void>followeeId: URL,follow: FollowNo documentation available
- addFollower(): Promise<void>followRequestId: URL,follower: ActorNo documentation available
- addMessage(): Promise<void>id: Uuid,activity: Create | AnnounceNo documentation available
- addSentFollow(): Promise<void>id: Uuid,follow: FollowNo documentation available
- countFollowers(): Promise<number>No documentation available
- countMessages(): Promise<number>No documentation available
- countVoters(messageId: Uuid): Promise<number>No documentation available
- countVotes(messageId: Uuid): Promise<Readonly<Record<string, number>>>No documentation available
- getFollowee(followeeId: URL): Promise<Follow | undefined>No documentation available
- getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>No documentation available
- getKeyPairs(): Promise<CryptoKeyPair[] | undefined>No documentation available
- getMessage(id: Uuid): Promise<Create | Announce | undefined>No documentation available
- getMessages(options?: RepositoryGetMessagesOptions): AsyncIterable<Create | Announce>No documentation available
- getSentFollow(id: Uuid): Promise<Follow | undefined>No documentation available
- hasFollower(followerId: URL): Promise<boolean>No documentation available
- kv: KvStoreNo documentation available
- prefixes: KvStoreRepositoryPrefixesNo documentation available
- removeFollowee(followeeId: URL): Promise<Follow | undefined>No documentation available
- removeFollower(): Promise<Actor | undefined>followRequestId: URL,actorId: URLNo documentation available
- removeMessage(id: Uuid): Promise<Create | Announce | undefined>No documentation available
- removeSentFollow(id: Uuid): Promise<Follow | undefined>No documentation available
- setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>No documentation available
- updateMessage(): Promise<boolean>id: Uuid,updater: (existing: Create | Announce) =>Create
| Announce
| undefined
| Promise<Create | Announce | undefined>No documentation available - vote(): Promise<void>messageId: Uuid,voterId: URL,option: stringNo documentation available
A repository decorator that adds an in-memory cache layer on top of another repository. This is useful for improving performance by reducing the number of accesses to the underlying persistent storage, but it increases memory usage. The cache is not persistent and will be lost when the process exits.
- addFollowee(): Promise<void>followeeId: URL,follow: FollowNo documentation available
- addFollower(): Promise<void>followId: URL,follower: ActorNo documentation available
- addMessage(): Promise<void>id: Uuid,activity: Create | AnnounceNo documentation available
- addSentFollow(): Promise<void>id: Uuid,follow: FollowNo documentation available
- cache: MemoryRepositoryNo documentation available
- countFollowers(): Promise<number>No documentation available
- countMessages(): Promise<number>No documentation available
- countVoters(messageId: Uuid): Promise<number>No documentation available
- countVotes(messageId: Uuid): Promise<Readonly<Record<string, number>>>No documentation available
- getFollowee(followeeId: URL): Promise<Follow | undefined>No documentation available
- getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>No documentation available
- getKeyPairs(): Promise<CryptoKeyPair[] | undefined>No documentation available
- getMessage(id: Uuid): Promise<Create | Announce | undefined>No documentation available
- getMessages(options?: RepositoryGetMessagesOptions): AsyncIterable<Create | Announce>No documentation available
- getSentFollow(id: Uuid): Promise<Follow | undefined>No documentation available
- hasFollower(followerId: URL): Promise<boolean>No documentation available
- removeFollowee(followeeId: URL): Promise<Follow | undefined>No documentation available
- removeFollower(): Promise<Actor | undefined>followId: URL,followerId: URLNo documentation available
- removeMessage(id: Uuid): Promise<Create | Announce | undefined>No documentation available
- removeSentFollow(id: Uuid): Promise<Follow | undefined>No documentation available
- setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>No documentation available
- underlying: RepositoryNo documentation available
- updateMessage(): Promise<boolean>id: Uuid,updater: (existing: Create | Announce) =>Create
| Announce
| undefined
| Promise<Create | Announce | undefined>No documentation available - vote(): Promise<void>messageId: Uuid,voterId: URL,option: stringNo documentation available
A repository for storing bot data in memory. This repository is not persistent and is only suitable for testing or development.
- addFollowee(): Promise<void>followeeId: URL,follow: FollowNo documentation available
- addFollower(): Promise<void>followId: URL,follower: ActorNo documentation available
- addMessage(): Promise<void>id: Uuid,activity: Create | AnnounceNo documentation available
- addSentFollow(): Promise<void>id: Uuid,follow: FollowNo documentation available
- countFollowers(): Promise<number>No documentation available
- countMessages(): Promise<number>No documentation available
- countVoters(messageId: Uuid): Promise<number>No documentation available
- countVotes(messageId: Uuid): Promise<Readonly<Record<string, number>>>No documentation available
- followRequests: Record<string, string>No documentation available
- followees: Record<string, Follow>No documentation available
- followers: Map<string, Actor>No documentation available
- getFollowee(followeeId: URL): Promise<Follow | undefined>No documentation available
- getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>No documentation available
- getKeyPairs(): Promise<CryptoKeyPair[] | undefined>No documentation available
- getMessage(id: Uuid): Promise<Create | Announce | undefined>No documentation available
- getMessages(options?: RepositoryGetMessagesOptions): AsyncIterable<Create | Announce>No documentation available
- getSentFollow(id: Uuid): Promise<Follow | undefined>No documentation available
- hasFollower(followerId: URL): Promise<boolean>No documentation available
- keyPairs: CryptoKeyPair[]No documentation available
- messages: Map<Uuid, Create | Announce>No documentation available
- polls: Record<Uuid, Record<string, Set<string>>>No documentation available
- removeFollowee(followeeId: URL): Promise<Follow | undefined>No documentation available
- removeFollower(): Promise<Actor | undefined>followId: URL,followerId: URLNo documentation available
- removeMessage(id: Uuid): Promise<Create | Announce | undefined>No documentation available
- removeSentFollow(id: Uuid): Promise<Follow | undefined>No documentation available
- sentFollows: Record<string, Follow>No documentation available
- setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>No documentation available
- updateMessage(): Promise<boolean>id: Uuid,updater: (existing: Create | Announce) =>Create
| Announce
| undefined
| Promise<Create | Announce | undefined>No documentation available - vote(): Promise<void>messageId: Uuid,voterId: URL,option: stringNo documentation available
Functions
Renders a custom emoji. You can use this function to create a CustomEmojiText tree.
Applies <em> tag to a text. You can use this function to create an
EmText tree.
Creates a hashtag. You can use this function to create a HashtagText tree.
A type guard that checks if a value is a single emoji character.
Creates a link to the given href with the label. You can use this
function to create a LinkText tree.
Mentions an actor by its fediverse handle. You can use this function to create a MentionText tree. The label of the mention will be the same as the handle.
A function that creates a PlainText tree. It only does two simple things:
Applies <strong> tag to a text. You can use this function to create a
StrongText tree.
Interfaces
A bot that can interact with the ActivityPub network.
- addCustomEmojis<TEmojiName extends string>(emojis: Readonly<Record<TEmojiName, CustomEmoji>>): Readonly<Record<TEmojiName, DeferredCustomEmoji<TContextData>>>
Defines custom emojis for the bot. The custom emojis are used for rendering the bot's profile and posts. The custom emojis are defined by their names, and the names are used as the keys of the emojis.
- federation: Federation<TContextData>
An internal Fedify federation instance. Normally you don't need to access this directly.
- fetch(): Promise<Response>request: Request,contextData: TContextData
The fetch API for handling HTTP requests. You can pass this to an HTTP server (e.g.,
Deno.serve(),Bun.serve()) to handle incoming requests. - getSession(): Session<TContextData>origin: string | URL,contextData: TContextData
Gets a new session to control the bot for a specific origin and context data.
- identifier: string
The internal identifier for the bot actor. It is used for the actor URI.
- onAcceptFollow: AcceptEventHandler<TContextData>
An event handler invoked when a follow request the bot sent is accepted.
- onFollow: FollowEventHandler<TContextData>
An event handler for a follow request to the bot.
- onLike: LikeEventHandler<TContextData>
An event handler for a like of a message.
- onMention: MentionEventHandler<TContextData>
An event handler for a message mentioned to the bot.
- onMessage: MessageEventHandler<TContextData>
An event handler for a message shown to the bot's timeline. To listen to this event, your bot needs to follow others first.
- onQuote: QuoteEventHandler<TContextData>
An event handler for a quote of the bot's message.
- onReact: ReactionEventHandler<TContextData>
An event handler for an emoji reaction to a message.
- onRejectFollow: RejectEventHandler<TContextData>
An event handler invoked when a follow request the bot sent is rejected.
- onReply: ReplyEventHandler<TContextData>
An event handler for a reply to the bot.
- onSharedMessage: SharedMessageEventHandler<TContextData>
An event handler for a message shared to the bot. To listen to this event, your bot needs to follow others first.
- onUnfollow: UnfollowEventHandler<TContextData>
An event handler for an unfollow event from the bot.
- onUnlike: UnlikeEventHandler<TContextData>
An event handler for an undoing of a like of a message.
- onUnreact: UndoneReactionEventHandler<TContextData>
An event handler for an undoing of an emoji reaction to a message.
- onVote: VoteEventHandler<TContextData>
An event handler for a vote in a poll. This event is only triggered when the bot is the author of the poll, and the vote is made by another actor. If the poll allows multiple selections, this event is triggered multiple times, once for each option selected by the actor.
A specialized Bot tpe that doesn't require context data.
- fetch(request: Request): Promise<Response>
The fetch API for handling HTTP requests. You can pass this to an HTTP server (e.g.,
Deno.serve(),Bun.serve()) to handle incoming requests. - getSession(): Session<void>origin: string | URL,contextData: void
Gets a new session to control the bot for a specific origin and context data.
Options for creating a bot.
- behindProxy: boolean
Whether to trust
X-Forwarded-*headers. If your bot application is behind an L7 reverse proxy, turn it on. - class: Service | Application
The type of the bot actor. It should be either
ServiceorApplication. - followerPolicy: "accept" | "reject" | "manual"
How to handle incoming follow requests. Note that this behavior can be overridden by manually invoking FollowRequest.accept or FollowRequest.reject in the Bot.onFollow event handler.
- icon: URL | Image
The avatar URL of the bot. It can be changed after the bot is federated.
- identifier: string
The internal identifier of the bot. Since it is used for the actor URI, it should not be changed after the bot is federated.
- image: URL | Image
The header image URL of the bot. It can be changed after the bot is federated.
- kv: KvStore
The underlying key-value store to use for storing data.
- name: string
The display name of the bot. It can be changed after the bot is federated.
- pages: PagesOptions
The options for the web pages of the bot. If omitted, the default options will be used.
- properties: Record<string, Text<"block" | "inline", TContextData>>
The custom properties of the bot. It can be changed after the bot is federated.
- queue: MessageQueue
The underlying message queue to use for handling incoming and outgoing activities. If omitted, incoming activities are processed immediately, and outgoing activities are sent immediately.
- repository: Repository
The underlying repository to use for storing data. If omitted, KvRepository will be used.
- software: Software
The software information of the bot. If omitted, the NodeInfo protocol will be unimplemented.
- summary: Text<"block", TContextData>
The description of the bot. It can be changed after the bot is federated.
- username: string
The username of the bot. It will be a part of the fediverse handle. It can be changed after the bot is federated.
A follow request to the bot.
A message in the ActivityPub network. It is a thin wrapper around
a Fedify object: an Article, a ChatMessage, a Note, or a Question.
- actor: Actor
The actor who published the message.
- attachments: readonly Document[]
The media attachments of the message.
- hashtags: readonly Hashtag[]
The hashtags used in the message.
- html: string
The HTML content of the message.
- id: URL
The URI of the message.
- language: LanguageTag
The language of the message if the content is tagged with a language.
- like(): Promise<AuthorizedLike<TContextData>>
Likes the message.
- mentions: readonly Actor[]
The actors mentioned in the message.
- published: Temporal.Instant
The published time of the message.
- quoteTarget: Message<MessageClass, TContextData>
The message quoted by this message, if any.
- raw: T
The underlying raw message object.
- react(emoji: Emoji | CustomEmoji | DeferredCustomEmoji<TContextData>): Promise<AuthorizedReaction<TContextData>>
Reacts to the message with a Unicode emoji or a custom emoji.
- reply(): Promise<AuthorizedMessage<Note, TContextData>>text: Text<"block", TContextData>,options?: SessionPublishOptions<TContextData>
Publishes a reply to the message.
- replyTarget: Message<MessageClass, TContextData>
The original message in reply to, if the message is a reply.
- share(options?: MessageShareOptions): Promise<AuthorizedSharedMessage<T, TContextData>>
Shares the message.
- text: string
The plain text content of the message.
- updated: Temporal.Instant
The updated time of the message, if it is updated.
- visibility: MessageVisibility
The visibility of the message.
Options for the web pages of the bot.
- color:"amber"
| "azure"
| "blue"
| "cyan"
| "fuchsia"
| "green"
| "grey"
| "indigo"
| "jade"
| "lime"
| "orange"
| "pink"
| "pumpkin"
| "purple"
| "red"
| "sand"
| "slate"
| "violet"
| "yellow"
| "zinc"The color of the theme. It will be used for the theme color of the web pages. The default color is
"green". - css: string
The CSS code for the bot. It will be used for the custom CSS of the web pages.
An emoji reaction to a message. It is a thin wrapper around an
EmojiReact, which is a Fedify object.
- actor: Actor
The actor who reacted to the message.
- emoji: Emoji | CustomEmoji
The emoji that was used in the reaction. It can be either a Unicode emoji or a custom emoji.
- id: URL
The URI of the reaction activity.
- message: Message<MessageClass, TContextData>
The message that was reacted.
- raw: RawLike | EmojiReact
The underlying raw
LikeorEmojiReactactivity.
A repository for storing bot data.
- addFollowee(): Promise<void>followeeId: URL,follow: Follow
Adds a followee to the repository.
- addFollower(): Promise<void>followId: URL,follower: Actor
Adds a follower to the repository.
- addMessage(): Promise<void>id: Uuid,activity: Create | Announce
Adds a message to the repository.
- addSentFollow(): Promise<void>id: Uuid,follow: Follow
Adds a sent follow request to the repository.
- countFollowers(): Promise<number>
Counts the number of followers in the repository.
- countMessages(): Promise<number>
Counts the number of messages in the repository.
- countVoters(messageId: Uuid): Promise<number>
Counts the number of voters in a poll. Even if the poll allows multiple selections, each voter is counted only once.
- countVotes(messageId: Uuid): Promise<Readonly<Record<string, number>>>
Counts the votes for each option in a poll. If the poll allows multiple selections, each option is counted separately, and the same voter can vote for multiple options.
- getFollowee(followeeId: URL): Promise<Follow | undefined>
Gets a followee from the repository.
- getFollowers(options?: RepositoryGetFollowersOptions): AsyncIterable<Actor>
Gets followers from the repository.
- getKeyPairs(): Promise<CryptoKeyPair[] | undefined>
Gets the key pairs of the bot actor.
- getMessage(id: Uuid): Promise<Create | Announce | undefined>
Gets a message from the repository.
- getMessages(options?: RepositoryGetMessagesOptions): AsyncIterable<Create | Announce>
Gets messages from the repository.
- getSentFollow(id: Uuid): Promise<Follow | undefined>
Gets a sent follow request from the repository.
- hasFollower(followerId: URL): Promise<boolean>
Checks if the repository has a follower.
- removeFollowee(followeeId: URL): Promise<Follow | undefined>
Removes a followee from the repository.
- removeFollower(): Promise<Actor | undefined>followId: URL,followerId: URL
Removes a follower from the repository.
- removeMessage(id: Uuid): Promise<Create | Announce | undefined>
Removes a message from the repository.
- removeSentFollow(id: Uuid): Promise<Follow | undefined>
Removes a sent follow request from the repository.
- setKeyPairs(keyPairs: CryptoKeyPair[]): Promise<void>
Sets the key pairs of the bot actor.
- updateMessage(): Promise<boolean>id: Uuid,updater: (existing: Create | Announce) =>Create
| Announce
| undefined
| Promise<Create | Announce | undefined>Updates a message in the repository.
- vote(): Promise<void>messageId: Uuid,voterId: URL,option: string
Records a vote in a poll. If the same voter had already voted for the same option in a poll, the vote will be silently ignored.
A session to control the bot.
- actorHandle: `@${string}@${string}`
The fediverse handle of the bot actor. It starts with
@. - actorId: URL
The URI of the bot actor.
- bot: Bot<TContextData>
The bot to which the session belongs.
- context: Context<TContextData>
The Fedify context of the session.
- follow(actor: Actor | URL | string): Promise<void>
Send a follow request to the specified actor.
- follows(actor: Actor | URL | string): Promise<boolean>
Checks whether the bot is following the specified actor.
- getActor(): Promise<Actor>
Gets the
Actorobject of the bot. - getOutbox(options?: SessionGetOutboxOptions): AsyncIterable<AuthorizedMessage<MessageClass, TContextData>>
Gets messages from the bot's outbox.
- publish(): Promise<AuthorizedMessage<Note, TContextData>>content: Text<"block", TContextData>,options?: SessionPublishOptions<TContextData>
Publishes a message attributed to the bot.
- unfollow(actor: Actor | URL | string): Promise<void>
Unfollow the specified actor.
Options for getting messages from the bot's outbox.
- limit: number
The maximum number of messages to get. If omitted, no limit will be applied.
- order: "oldest" | "newest"
The order of the messages. If omitted,
"newest"will be used. - since: Temporal.Instant
The timestamp to get messages created at or after this time. If omitted, no limit will be applied.
- until: Temporal.Instant
The timestamp to get messages created at or before this time. If omitted, no limit will be applied.
Options for publishing a message.
- attachments: Document[]
The media attachments of the published message.
- language: string | LanguageTag
The language of the published message.
- quoteTarget: Message<MessageClass, TContextData>
The message to quote in the published message.
- visibility: Exclude<MessageVisibility, "unknown">
The visibility of the published message. If omitted,
"public"will be used.
Options for publishing a message with a specific class.
- class: T extends Article ? Article : T extends ChatMessage ? ChatMessage : T extends Note ? Note : T extends Question ? Question : never
The class of the published message. If omitted,
Notewill be used.
A tree structure representing a text with formatting. It does not only render the text but also extract tags (e.g., mentions) from it.
- getCachedObjects(): Object[]
Gets cached objects. The result of this method depends on whether getHtml or getTags has been called before. It's used for optimizing the post rendering process, e.g., reusing once fetched remote objects.
- getHtml(session: Session<TContextData>): AsyncIterable<string>
Render a text tree as HTML.
- getTags(session: Session<TContextData>): AsyncIterable<Link | Object>
Extract tags (e.g., mentions) from a text tree.
- type: TType
The type of the text. It can be either
"block"or"inline".
An interface representing a vote in a poll. Note that if the poll allows multiple selections, the options are represented as multiple Vote objects, each with a single option.
- actor: Actor
The actor who voted.
- message: Message<Question, TContextData>
The question to which the poll belongs.
- option: string
The options selected by the actor. Note that this is a string even if the poll allows multiple selections. If the poll allows multiple selections, the options are represented as multiple Vote objects.
- poll: Poll
The poll to which the vote belongs.
- raw: Note
The underlying raw note object.
Type Aliases
An event handler invoked when a follow request the bot sent is accepted.
A definition of a custom emoji. It can be either a remote image URL or a local image file.
A deferred Emoji (provided by Fedify), which is a function that
takes a Session and returns an Emoji. This is useful for
creating emojis that depend on the session data.
A branded type for a single emoji character (more exactly, a single Unicode grapheme cluster of emoji). This is used to represent a single emoji in a string format. It is not a full-fledged emoji object, but rather a string that is guaranteed to be a single emoji.
An event handler for a follow request to the bot.
An event handler for a like of a message.
An event handler for a message mentioned to the bot.
A possible message class.
An event handler for a message shown to the bot's timeline. To listen to this event, your bot needs to follow others first.
The visibility of a message.
An event handler for a quote of the bot's message.
An event handler for an emoji reaction to a message.
An event handler invoked when a follow request the bot sent is rejected.
An event handler for a reply to the bot.
An event handler for undoing an emoji reaction to a message.
An event handler for an unfollow event from the bot.
An event handler for undoing a like of a message.
An event handler for a vote in a poll. This event is only triggered when the bot is the author of the poll, and the vote is made by another actor. Note that if the poll allows multiple selections, this event is triggered multiple times, once for each option selected by the actor.
Add Package
deno add jsr:@fedify/botkit
Import symbol
import * as mod from "@fedify/botkit";
Import directly with a jsr specifier
import * as mod from "jsr:@fedify/botkit";