How the Crosspost API works
mainThe Crosspost API is built around two main components:
- Strategies: Individual implementations for specific services (e.g.,
TwitterStrategy,MastodonStrategy). Each strategy requires service-specific configuration parameters (like API keys or access tokens). - Client: A central
Clientclass that orchestrates posting. You instantiate aClientby passing an array of configured strategy instances to itsstrategiesoption. Once configured, the client can broadcast a single message to all registered services or target specific ones.
Supported strategies include:
BlueskyStrategyMastodonStrategyTwitterStrategyLinkedInStrategyDiscordStrategyDiscordWebhookStrategyTelegramStrategyDevtoStrategyNostrStrategy(requires Node.js v22+)
import {
Client,
TwitterStrategy,
MastodonStrategy,
// ... other strategies
} from "@humanwhocodes/crosspost";
const mastodon = new MastodonStrategy({
accessToken: "your-access-token",
host: "mastodon.host",
});
const client = new Client({
strategies: [mastodon],
});
await client.post("Hello world!");