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

Properties

Methods

  • Listening function for handling webhook requests

    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');
    }));

    Returns

    An express request handler

    Parameters

    • fn: ((payload: WebhookPayload, req?: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res?: Response<any, Record<string, any>>, next?: NextFunction) => void | Promise<void>)

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

        • (payload: WebhookPayload, req?: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res?: Response<any, Record<string, any>>, next?: NextFunction): 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: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction) => Promise<void>)

      • (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction): Promise<void>
      • Parameters

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

        Returns Promise<void>

  • Middleware function to pass to express, sets req.vote to the payload

    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
    });

    Returns ((req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction) => Promise<void>)

      • (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction): Promise<void>
      • Parameters

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

        Returns Promise<void>

Generated using TypeDoc