Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Constructors

Properties

Methods

Constructors

constructor

  • Create a new webhook client instance

    Parameters

    • Optional authorization: string

      Webhook authorization to verify requests

    • options: WebhookOptions = {}

    Returns Webhook

Properties

options

Methods

listener

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

    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>

    An express request handler

      • (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

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

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method

Generated using TypeDoc