Documentation ¶
Index ¶
- Constants
- func SendWithParseMode(parseMode string) notify.SendOption
- type Option
- func WithClient(client *telegram.BotAPI) 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 WithParseMode(mode string) Option
- func WithRecipients(chatIDs ...int64) Option
- type SendConfig
- type Service
Constants ¶
const ( // ModeHTML is one of the modes for sending messages. ModeHTML = telegram.ModeHTML // ModeMarkdown is the default mode for sending messages. ModeMarkdown = telegram.ModeMarkdown )
Variables ¶
This section is empty.
Functions ¶
func SendWithParseMode ¶
func SendWithParseMode(parseMode string) notify.SendOption
SendWithParseMode is a send option that sets the parse mode of the message.
Types ¶
type Option ¶
type Option = func(*Service)
Option is a function that can be used to configure the telegram service.
func WithClient ¶
WithClient sets the telegram client. This is useful if you want to use a custom client.
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 WithParseMode ¶
WithParseMode sets the parse mode for sending messages. The default is ModeHTML.
func WithRecipients ¶
WithRecipients sets the chat IDs that should receive messages. You can add more chat IDs by calling AddRecipients.
type SendConfig ¶
type SendConfig struct { Subject string Message string Attachments []notify.Attachment Metadata map[string]any DryRun bool ContinueOnErr bool ParseMode string }
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 is the telegram service. It is used to send messages to Telegram chats.
func New ¶
New creates a new telegram service. It returns an error if the telegram client could not be created.
func (*Service) AddRecipients ¶
AddRecipients adds chat IDs that should receive messages.