webhook_go

package module
v0.0.0-...-4c40876 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 5 Imported by: 0

README

Webhook Go

GitHub Workflow Status GoDoc

Webhook-Go is a Go library for sending webhooks. With this library, you can send messages, and embeds to a using a webhook URL.

Table of Contents

Installation

To use this library in your Go project, you can install it using go get:

go get github.com/waxdred/webhook_go
import (
	wk "github.com/waxdred/webhook_go"
)

Usage

  • To use the Discord_webhook_go library, you first need to create a new Webhook object with the webhook URL:
  • You can also send an embed:

Exemple:

package main

import (
   wk "github.com/waxdred/webhook_go"
)

func main() {
   // Create a new WebhookClient with the URL of your webhook
   client := wk.WebhookClient{}
   url := "webhook url"
   client.New(url)

   // Call the Send function with a closure that constructs the message and returns it
   _, err := client.Send(func(m *wk.Message) *wk.Message {
   // Set the content, username, and avatar URL of the message
      m.Content("Hello, world!").
         Username("My Bot").
     	 AvatarURL("https://i.imgur.com/4m34hi2.png").
	 // Add an embed to the message
         Embed(func(embed *wk.Embed) {
	 // Set the title, author, URL, color, and description of the embed
         embed.Title("My Embed").
	 Author("waxdred", "https://i.imgur.com/4m34hi2.png", "https://i.imgur.com/R66g1Pe.jpg").
	 Url("https://google.com/").
	 Color(15258703).
	 Desc("This is an example embed!").
	 // Add some fields to the embed
	 Field("Field 1", "This is the first field", false).
	 Field("Field 2", "This is the second field", false).
	 Field("Field 3", "This is the third field", false).
	 Field("Inline Field", "This is an inline field", true).
	 // Set the thumbnail and image of the embed
	 Thumbnail("https://i.imgur.com/4m34hi2.png").
	 Image("https://i.imgur.com/4m34hi2.png").
	 // Set the footer of the embed
	 Footer("Created by My Bot", "")
	 })
      return m
   })
   if err != nil {
      panic(err)
   }
}

Message

  • content_s (string, optional): the content of the message
  • username_s (string, optional): the username that will be shown for the webhook message
  • avatarURL_s (string, optional): the URL of the image that will be shown for the webhook message
  • tts_s (bool, optional): whether the message should be sent as a text-to-speech message
  • embeds_s ([]Embed, optional): an array of Embed objects to include in the message
  • allowMentions_s (Allowed, optional): an object specifying which user mentions are allowed in the message

Embed

  • author_s (EmbedAuthor, optional): an object specifying the author of the embed
  • title_s (string, optional): the title of the embed
  • type_s (string, optional): the type of the embed
  • description_s (string, optional): the description of the embed
  • url_s (string, optional): the URL that the title should link to
  • timestamp_s (string, optional): a timestamp to show at the bottom of the embed
  • color_s (int64, optional): the color of the embed
  • fields_s ([]EmbedField, optional): an array of EmbedField objects to include in the embed
  • thumbnail_s (EmbedThumbnail, optional): an object specifying the thumbnail image of the embed
  • image_s (EmbedImage, optional): an object specifying the main image of the embed
  • video_s (EmbedVideo, optional): an object specifying a video to include in the embed
  • footer_s (EmbedFooter, optional): an object specifying the footer of the embed
  • provider_s (EmbedProvider, optional): an object specifying the provider of the embed

For more examples and detailed usage instructions, please see the GoDoc documentation.

Contributing If you find a bug or would like to contribute to this library, please open an issue or pull request on the GitHub repository.

License This library is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allowed

type Allowed struct {
	Parse       []AllowedMention `json:"parse,omitempty"`
	Roles       []Snowflake      `json:"roles,omitempty"`
	Users       []Snowflake      `json:"users,omitempty"`
	RepliedUser bool             `json:"replied_user"`
}

type AllowedMention

type AllowedMention string
const (
	RoleMention     AllowedMention = "roles"
	UserMention     AllowedMention = "users"
	EveryoneMention AllowedMention = "everyone"
)

type Embed

type Embed struct {
	Author_s      *EmbedAuthor    `json:"author,omitempty"`
	Title_s       *string         `json:"title,omitempty"`
	Type_s        *string         `json:"type,omitempty"`
	Description_s *string         `json:"description,omitempty"`
	URL_s         *string         `json:"url,omitempty"`
	Timestamp_s   *string         `json:"timestamp,omitempty"`
	Color_s       *int64          `json:"color,omitempty"`
	Fields_s      *[]EmbedField   `json:"fields,omitempty"`
	Thumbnail_s   *EmbedThumbnail `json:"thumbnail,omitempty"`
	Image_s       *EmbedImage     `json:"image,omitempty"`
	Video_s       *EmbedVideo     `json:"video,omitempty"`
	Footer_s      *EmbedFooter    `json:"footer,omitempty"`
	Provider_s    *EmbedProvider  `json:"provider,omitempty"`
}

Embed struct 

func (*Embed) Author

func (e *Embed) Author(name, url, icon_url interface{}) *Embed

func (*Embed) Color

func (e *Embed) Color(color interface{}) *Embed

AddColor method  color need be in decimal

func (*Embed) Desc

func (e *Embed) Desc(desc interface{}) *Embed

func (*Embed) Field

func (e *Embed) Field(name interface{}, value interface{}, inline bool) *Embed

func (*Embed) Footer

func (e *Embed) Footer(text, icon_url interface{}) *Embed

func (*Embed) Image

func (e *Embed) Image(url interface{}) *Embed

func (*Embed) Provider

func (e *Embed) Provider(name, url interface{}) *Embed

func (*Embed) Thumbnail

func (e *Embed) Thumbnail(url interface{}) *Embed

func (*Embed) Timestamp

func (e *Embed) Timestamp(timestamp interface{}) *Embed

func (*Embed) Title

func (e *Embed) Title(title interface{}) *Embed

func (*Embed) Type

func (e *Embed) Type(typestring interface{}) *Embed

func (*Embed) Url

func (e *Embed) Url(url interface{}) *Embed

func (*Embed) Video

func (e *Embed) Video(url interface{}) *Embed

type EmbedAuthor

type EmbedAuthor struct {
	Name     string `json:"name,omitempty"`
	Url      string `json:"url,omitempty"`
	Icon_url string `json:"icon_url,omitempty"`
}

type EmbedField

type EmbedField struct {
	Name   string `json:"name,omitempty"`
	Value  string `json:"value,omitempty"`
	Inline bool   `json:"inline,omitempty"`
}

type EmbedFooter

type EmbedFooter struct {
	Text     string `json:"text,omitempty"`
	Icon_url string `json:"icon_url,omitempty"`
}

type EmbedImage

type EmbedImage struct {
	Url string `json:"url,omitempty"`
}

type EmbedProvider

type EmbedProvider struct {
	Name string `json:"name,omitempty"`
	Url  string `json:"url,omitempty"`
}

type EmbedThumbnail

type EmbedThumbnail struct {
	Url string `json:"url,omitempty"`
}

type EmbedUrlSource

type EmbedUrlSource struct {
	Url string `json:"url,omitempty"`
}

type EmbedVideo

type EmbedVideo struct {
	Url string `json:"url,omitempty"`
}

type Message

type Message struct {
	Content_s       *string  `json:"content,omitempty"`
	Username_s      *string  `json:"username,omitempty"`
	AvatarURL_s     *string  `json:"avatar_url,omitempty"`
	TTS_s           bool     `json:"tts"`
	Embeds_s        *[]Embed `json:"embeds,omitempty"`
	AllowMentions_s *Allowed `json:"allowed_mentions,omitempty"`
}

func (*Message) AllowMentions

func (c *Message) AllowMentions(parse []AllowedMention, roles []Snowflake, users []Snowflake, repliedUser bool) *Message

func (*Message) AvatarURL

func (c *Message) AvatarURL(avatarURL interface{}) *Message

func (*Message) Content

func (c *Message) Content(content interface{}) *Message

func (*Message) Embed

func (c *Message) Embed(embedFunc func(*Embed)) *Message

func (*Message) TTS

func (c *Message) TTS(tts bool) *Message

func (*Message) Username

func (c *Message) Username(username interface{}) *Message

type Snowflake

type Snowflake string

type WebhookClient

type WebhookClient struct {
	// contains filtered or unexported fields
}

WebhookClient struct 

func (*WebhookClient) New

func (c *WebhookClient) New(url string)

New method 

func (*WebhookClient) Send

func (c *WebhookClient) Send(function func(*Message) *Message) (*http.Response, error)

Send method 

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL