Skip to content

Modern Docker Management, Designed for Everyone

1.0 KB
Raw Blame
package notifications

import (
	"context"
	"errors"
	"fmt"

	"github.com/nicholas-fedor/shoutrrr/pkg/services/chat/discord"
)

// BuildDiscordURL converts DiscordConfig to Shoutrrr URL format using shoutrrr's Config
func BuildDiscordURL(config DiscordConfig) (string, error) {
	discordConfig := &discord.Config{
		WebhookID: config.WebhookID,
		Token:     config.Token,
		Username:  config.Username,
		Avatar:    config.AvatarURL,
	}

	url := discordConfig.GetURL()
	return url.String(), nil
}

// SendDiscord sends a message via Shoutrrr Discord using proper service configuration
func SendDiscord(ctx context.Context, config DiscordConfig, message string) error {
	if config.WebhookID == "" {
		return errors.New("discord webhook ID is empty")
	}
	if config.Token == "" {
		return errors.New("discord token is empty")
	}

	shoutrrrURL, err := BuildDiscordURL(config)
	if err != nil {
		return fmt.Errorf("failed to build shoutrrr Discord URL: %w", err)
	}

	return sendShoutrrrInternal("Discord", shoutrrrURL, message, nil)
}