Skip to content

AlejoG522/webhook-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webhook API Plugin

A SerenityJS plugin to create, manage, and send Discord webhooks easily in SerenityJS plugins. This plugin provides a simple interface to build rich messages with embeds, fields, avatars, usernames, and forum-style threads.


Features

  • Send messages via Discord webhooks.
  • Fully customizable message content.
  • Supports embeds with titles, descriptions, colors, authors, footers, images, thumbnails, and timestamps.
  • Add multiple fields to embeds.
  • Validation for URLs and message content before sending.

Installation

  1. Copy the webhook-api plugin folder into your plugins/ directory.

Usage

Sending a Basic Webhook

import { WebHook, Base } from "webhook-api";

WebHook.make(
  "YOUR_WEBHOOK_URL",
  Base.make()
    .setContent("Hello from another plugin!")
    .setUsername("MyBot")
).send();

Sending a Webhook with Embeds

import { WebHook, Base, EmbedManager, Field, EmbedColors } from "webhook-api";

WebHook.make(
  "YOUR_WEBHOOK_URL",
  Base.make()
    .setContent("Check out this embed!")
    .setUsername("EmbedBot")
    .addEmbed(
      EmbedManager.make("Embed Title", "This is an embed description", EmbedColors.Green)
        .addField(Field.make("Field Name", "Field Value", true))
        .addField(Field.make("Another Field", "Value", false))
    )
).send();

Components

Base

The main body of the message.
Methods:

  • setContent(content: string): Set message content.
  • setUsername(username: string): Set the webhook username.
  • setAvatar(avatarUrl: string): Set the webhook avatar URL.
  • setTextToSpeech(tts: boolean): Enable/disable TTS.
  • addEmbed(embed: EmbedManager): Add an embed to the message.
  • setForumTitle(title: string): Enable forum-style thread with a title.
  • build(): Validate the message before sending.
  • toJson(): Convert message to JSON for sending.

EmbedManager

Build rich embeds with multiple properties.
Methods:

  • setTitle(title: string)
  • setDescription(description: string)
  • setColor(color: number)
  • addField(field: Field)
  • setAuthor(author: Author)
  • setFooter(footer: Footer)
  • setThumbnail(thumbnail: Thumbnail)
  • setImage(image: Image)
  • setTimestamp(timestamp: Timestamp)

Field

Represents a name-value pair inside an embed.

  • make(name: string, value: string, inline?: boolean): Create a field.
  • inline indicates whether the field is displayed inline.

WebHook

Handles sending the message to Discord.
Methods:

  • make(url: string, body: Base): Create a webhook instance.
  • send(): Sends the webhook message.
  • setBody(body: Base): Update the body of the webhook.

Notes

  • All URLs (avatars, thumbnails, images) must be valid.
  • Each message must have either content or at least one embed.
  • Base.build() ensures messages are valid before sending.
  • Multiple embeds and fields are supported.
  • Supports TTS messages and forum-style threads.

Example with All Features

import { WebHook, Base, EmbedManager, Field, EmbedColors } from "webhook-api";

const embed = EmbedManager.make("Full Embed", "This embed has everything!", EmbedColors.Blue)
  .addField(Field.make("Inline Field", "Displayed inline", true))
  .addField(Field.make("Block Field", "Displayed in its own line", false));

WebHook.make(
  "YOUR_WEBHOOK_URL",
  Base.make()
    .setContent("A full-featured webhook!")
    .setUsername("AdvancedBot")
    .setAvatar("https://example.com/avatar.png")
    .addEmbed(embed)
    .setForumTitle("My Thread")
).send();

About

Discord WebHook API for SerenityJS Software

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published