WebSocket EventBus
Subscribe to real-time OnlyFans events — new messages, tips, subscribers, online status — across all managed accounts over a single WebSocket connection. Part of the BetterFans Link SDK, the infrastructure behind OFManager.
The BetterFans Link SDK EventBus gives you a real-time stream of OnlyFans events across all your managed accounts. New messages, tips, subscriptions, online status changes — they all arrive as typed events over a single WebSocket connection.
import { OfWsClient } from "@betterfans/link-sdk"
const ws = new OfWsClient({
apiKey: process.env.BFL_API_KEY,
wsToken: process.env.BFL_WS_TOKEN,
subscribe: ["chat_message", "tip", "new_subscriber"],
})
ws.on("chat_message", (event) => {
console.log(`Message from account ${event.accountId}`)
})
ws.connect()Authentication
The EventBus uses your API key and a WS token for authentication. Both are available on the API Keys page in your OFManager dashboard.
The WS token is a derived credential specifically for WebSocket connections — it's separate from your API key for security isolation.
Prop
Type
Subscribing to events
Use the subscribe option to specify which event types you want to
receive. If omitted or empty, you receive all events.
const ws = new OfWsClient({
apiKey: process.env.BFL_API_KEY,
wsToken: process.env.BFL_WS_TOKEN,
subscribe: ["chat_message", "tip", "new_subscriber"],
})Filtering by account
If you only care about events from specific accounts, use the filter
option:
const ws = new OfWsClient({
apiKey: process.env.BFL_API_KEY,
wsToken: process.env.BFL_WS_TOKEN,
subscribe: ["chat_message"],
filter: {
accountIds: ["111111111", "222222222"],
},
})Events from other accounts are silently dropped server-side.
Listening for events
Register handlers with .on() for specific events:
ws.on("chat_message", (event) => {
console.log(event.accountId, event.text)
})
ws.on("new_subscriber", (event) => {
console.log(`New sub on ${event.accountId}: user ${event.userId}`)
})
ws.on("tip", (event) => {
console.log(`Tip: $${event.amount} on ${event.accountId}`)
})Or use .onAny() to receive all events:
ws.onAny((eventName, payload) => {
console.log(`[${eventName}]`, payload)
})Register multiple handlers at once with .subscribe():
ws.subscribe({
chat_message: (event) => { /* ... */ },
tip: (event) => { /* ... */ },
new_subscriber: (event) => { /* ... */ },
})Connection lifecycle
// Connect
ws.connect()
// Check state
console.log(ws.state) // "connecting" | "connected" | "reconnecting" | "disconnected"
console.log(ws.connected) // boolean
// Disconnect
ws.disconnect()Reconnection
The client reconnects automatically on connection drops. Configure the reconnection behavior:
Prop
Type
State changes
Monitor connection state transitions:
const ws = new OfWsClient({
apiKey: process.env.BFL_API_KEY,
wsToken: process.env.BFL_WS_TOKEN,
onStateChange: (state) => {
console.log(`Connection state: ${state}`)
// "connecting" | "connected" | "reconnecting" | "disconnected"
},
onError: (event, payload, error) => {
console.error(`Handler error for "${event}":`, error)
},
})Removing handlers
// Remove a specific handler
ws.off("chat_message")