Documentation
¶
Index ¶
- type Option
- func WithClient(session *discordgo.Session) Option
- func WithContinueOnErr(continueOnErr bool) Option
- func WithDryRun(dryRun bool) Option
- func WithLogger(logger onelog.Logger) Option
- func WithMessageRenderer(builder func(conf *SendConfig) string) Option
- func WithName(name string) Option
- func WithRecipients(recipients ...string) Option
- type SendConfig
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option = func(*Service)
Option is a function that applies an option to the service.
func WithClient ¶
WithClient sets the discord client (session) to use for sending messages. Naming it WithClient to stay consistent with the other services.
func WithContinueOnErr ¶
WithContinueOnErr sets the continue on error flag. If set to true, the service will continue sending the message to the next recipient even if an error occurred.
func WithDryRun ¶
WithDryRun sets the dry run flag. If set to true, messages will not be sent.
func WithLogger ¶
WithLogger sets the logger. The default logger is a no-op logger.
func WithMessageRenderer ¶
func WithMessageRenderer(builder func(conf *SendConfig) string) Option
WithMessageRenderer sets the message renderer. The default function will put the subject and message on separate lines.
Example:
telegram.WithMessageRenderer(func(conf *SendConfig) string { var builder strings.Builder builder.WriteString(conf.subject) builder.WriteString("\n") builder.WriteString(conf.message) return builder.String() })
func WithRecipients ¶
WithRecipients sets the channel IDs or webhook URLs to send messages to. You can add more channel IDs or webhook URLs by calling Service.AddRecipients.
type SendConfig ¶
type SendConfig struct { Subject string Message string Attachments []notify.Attachment Metadata map[string]any DryRun bool ContinueOnErr bool }
SendConfig represents the configuration needed for sending a message.
This struct complies with the notify.SendConfig interface and allows you to alter the behavior of the send function. This can be achieved by either passing send options to the send function or by manipulating the fields of this struct in your custom message renderer.
All fields of this struct are exported to offer maximum flexibility to users. However, users must be aware that they are responsible for managing thread-safety and other similar concerns when manipulating these fields directly.
func (*SendConfig) SetAttachments ¶
func (c *SendConfig) SetAttachments(attachments ...notify.Attachment)
SetAttachments adds attachments to the message. This method is needed as part of the notify.SendConfig interface.
func (*SendConfig) SetContinueOnErr ¶
func (c *SendConfig) SetContinueOnErr(continueOnErr bool)
SetContinueOnErr sets the continue on error flag of the message. This method is needed as part of the notify.SendConfig interface.
func (*SendConfig) SetDryRun ¶
func (c *SendConfig) SetDryRun(dryRun bool)
SetDryRun sets the dry run flag of the message. This method is needed as part of the notify.SendConfig interface.
func (*SendConfig) SetMetadata ¶
func (c *SendConfig) SetMetadata(metadata map[string]any)
SetMetadata sets the metadata of the message. This method is needed as part of the notify.SendConfig interface.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service struct holds necessary data to communicate with the Discord API.
func NewWebhook ¶
NewWebhook creates a new Discord webhook service. The recipient string must be a webhook URL.
func (*Service) AddRecipients ¶
AddRecipients takes Service channel IDs or webhook URLs and adds them to the list of recipients. You can add more channel IDs or webhook URLs by calling AddRecipients again.