Class DonationAlertsCentrifugoApi

Donation Alerts Centrifugo API.

Provides methods to manage user subscriptions to Centrifugo private channels. These channels allow receiving real-time updates about specific events such as donations, goals, and polls.

Hierarchy

  • BaseApi
    • DonationAlertsCentrifugoApi

Methods

  • Subscribes a user to the specified Centrifugo private channels.

    Parameters

    • user: UserIdResolvable

      The Donation Alerts user ID.

    • clientId: string

      The Client ID obtained beforehand.

    • channels: string[]

      List of private channel names to subscribe the user to. Channel names should not include the user ID – the library will format them automatically if needed.

    • Optionaloptions: DonationAlertsCentrifugoSubscribeOptions

      Additional options for subscription, such as formatting channel names.

    • OptionalrateLimiterOptions: RateLimiterRequestOptions

      Options for controlling the request rate using a rate limiter.

    Returns Promise<DonationAlertsCentrifugoChannel[]>

    A promise resolving with a list of DonationAlertsCentrifugoChannel.

    To subscribe a user, you must first obtain the Client ID (UUIDv4) via WebSockets.

    The full subscription flow is described in the official documentation: https://www.donationalerts.com/apidoc#introduction__centrifugo

    Alternatively, the @donation-alerts/events library can simplify the process of subscribing and listening to events.

    HttpError If the HTTP status code is outside the range of 200–299.

    UnregisteredUserError If the user provided is not registered in the auth provider.

    const subscribedChannels = await apiClient.centrifugo.subscribeUserToPrivateChannels(userId, clientId, [
    '$alerts:donation',
    '$goals:goal'
    ]);
    subscribedChannels.forEach(channel =>
    console.log(`Subscribed to ${channel.channel}; token: ${channel.token}`)
    );