Class Webhook

Top.gg Webhook

Example

const express = require("express");
const { Webhook } = require("@top-gg/sdk");

const app = express();
const wh = new Webhook("webhookauth123");

app.post("/dblwebhook", wh.listener((vote) => {
// vote is your vote object e.g
console.log(vote.user); // => 321714991050784770
}));

app.listen(80);

// In this situation, your TopGG Webhook dashboard should look like
// URL = http://your.server.ip:80/dblwebhook
// Authorization: webhookauth123

Link

Webhook Data Schema

Link

Webhook Documentation

Hierarchy

  • Webhook

Constructors

Properties

Methods

Constructors

  • Create a new webhook client instance

    Parameters

    • Optional authorization: string

      Webhook authorization to verify requests

    • options: WebhookOptions = {}

    Returns Webhook

Properties

Methods

  • Listening function for handling webhook requests

    Parameters

    • fn: ((payload, req?, res?, next?) => void | Promise<void>)

      Vote handling function, this function can also throw an error to allow for the webhook to resend from Top.gg

        • (payload, req?, res?, next?): void | Promise<void>
        • Parameters

          • payload: WebhookPayload
          • Optional req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
          • Optional res: Response<any, Record<string, any>>
          • Optional next: NextFunction

          Returns void | Promise<void>

    Returns ((req, res, next) => Promise<void>)

    An express request handler

      • (req, res, next): Promise<void>
      • Parameters

        • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
        • res: Response<any, Record<string, any>>
        • next: NextFunction

        Returns Promise<void>

    Example

    app.post("/webhook", wh.listener((vote) => {
    console.log(vote.user); // => 395526710101278721
    }));

    Example

    // Throwing an error to resend the webhook
    app.post("/webhook/", wh.listener((vote) => {
    // for example, if your bot is offline, you should probably not handle votes and try again
    if (bot.offline) throw new Error('Bot offline');
    }));
  • Middleware function to pass to express, sets req.vote to the payload

    Returns ((req, res, next) => Promise<void>)

      • (req, res, next): Promise<void>
      • Parameters

        • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
        • res: Response<any, Record<string, any>>
        • next: NextFunction

        Returns Promise<void>

    Deprecated

    Use the new .listener() function

    Example

    app.post("/dblwebhook", wh.middleware(), (req, res) => {
    // req.vote is your payload e.g
    console.log(req.vote.user); // => 395526710101278721
    });

Generated using TypeDoc