notify

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 4 Imported by: 0

README

Notify

The notify package provides an easy-to-use interface for sending, editing, and deleting notifications across multiple messaging platforms, including Discord and Telegram. It abstracts the underlying API interactions, allowing developers to integrate messaging functionalities seamlessly into their Go applications.

Features

  • Discord Integration: Send, edit, and delete messages via Discord webhooks.
  • Telegram Integration: Send, edit, and delete messages using the Telegram Bot API.
  • Unified Interface: Consistent methods for different platforms.
  • Markdown Support: Utilize Markdown for message formatting where supported.

Installation

To install the notify package, use go get:

go get github.com/woozymasta/notify

Usage

Discord
package main

import (
  "fmt"
  "log"

  "github.com/woozymasta/notify"
)

func main() {
  // Initialize Discord notifier
  discordWebhookID := "your_discord_webhook_id"
  discordWebhookToken := "your_discord_webhook_token"
  discordClient := notify.NewDiscord(discordWebhookID, discordWebhookToken)

  // Send a message
  messageID, err := discordClient.Send("Hello, **Discord**!")
  if err != nil {
    log.Fatalf("Failed to send Discord message: %v", err)
  }

  // Edit the message
   if err = discordClient.Edit(messageID, "Bye, *Discord*!"); err != nil {
    log.Fatalf("Failed to edit Discord message: %v", err)
  }

  // Delete the message
  if err = discordClient.Delete(messageID); err != nil {
    log.Fatalf("Failed to delete Discord message: %v", err)
  }
}
Telegram
package main

import (
  "fmt"
  "log"

  "github.com/woozymasta/notify"
)

func main() {
  // Initialize Telegram notifier
  telegramBotToken := "your_telegram_bot_token"
  telegramChatID := "your_telegram_chat_id"
  telegramClient := notify.NewTelegram(telegramBotToken, telegramChatID)

  // Send a message
  messageID, err := telegramClient.Send("Hello, *Telegram*!")
  if err != nil {
    log.Fatalf("Failed to send Telegram message: %v", err)
  }

  // Edit the message
  if err = telegramClient.Edit(messageID, "Bye, *Telegram*!"); err != nil {
    log.Fatalf("Failed to edit Telegram message: %v", err)
  }

  // Delete the message
  if err = telegramClient.Delete(messageID); err != nil {
    log.Fatalf("Failed to delete Telegram message: %v", err)
  }
}

Testing

Ensure you have the necessary environment variables set before running tests:

  • DISCORD_ID: Discord webhook ID.
  • DISCORD_TOKEN: Discord webhook token.
  • TELEGRAM_ID: Telegram chat ID.
  • TELEGRAM_TOKEN: Telegram bot token.

Run the tests using:

go test ./...

Documentation

Overview

Package notify provides functionality to send, edit, and delete notifications in various messaging platforms, including Discord and Telegram.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Discord

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

Discord represents a client for interacting with Discord webhooks.

func NewDiscord

func NewDiscord(webhookID, webhookToken string) *Discord

NewDiscord creates a new instance of a Discord client.

Parameters:

  • webhookID: The Discord webhook ID.
  • webhookToken: The Discord webhook token.

Returns:

  • A pointer to a Discord instance.

func (*Discord) Delete

func (d *Discord) Delete(id uint64) error

Delete removes an existing message from a Discord channel.

Parameters:

  • id: The ID of the message to delete.

Returns:

  • An error if the operation fails.

func (*Discord) Edit

func (d *Discord) Edit(id uint64, msg string) error

Edit modifies an existing message in a Discord channel.

Parameters:

  • id: The ID of the message to edit.
  • msg: The new message content.

Returns:

  • An error if the operation fails.

func (*Discord) Send

func (d *Discord) Send(msg string) (uint64, error)

Send sends a message to a Discord channel using the webhook.

Parameters:

  • msg: The message content to send.

Returns:

  • The ID of the sent message.
  • An error if the operation fails.

type Telegram

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

Telegram represents a client for interacting with the Telegram Bot API.

func NewTelegram

func NewTelegram(chatID, botToken string) *Telegram

NewTelegram creates a new instance of a Telegram client.

Parameters:

  • chatID: The chat ID where messages will be sent.
  • botToken: The Telegram bot token.

Returns:

  • A pointer to a Telegram instance.

func (*Telegram) Delete

func (t *Telegram) Delete(id uint64) error

Delete removes an existing message from a Telegram chat.

Parameters:

  • id: The ID of the message to delete.

Returns:

  • An error if the operation fails.

func (*Telegram) Edit

func (t *Telegram) Edit(id uint64, msg string) error

Edit modifies an existing message in a Telegram chat.

Parameters:

  • id: The ID of the message to edit.
  • msg: The new message content.

Returns:

  • An error if the operation fails.

func (*Telegram) Send

func (t *Telegram) Send(msg string) (uint64, error)

Send sends a message to a Telegram chat.

Parameters:

  • msg: The message content to send.

Returns:

  • The ID of the sent message.
  • An error if the operation fails.

Jump to

Keyboard shortcuts

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