/
send_config.go
60 lines (49 loc) · 2.01 KB
/
send_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package telegram
import "github.com/nikoksr/notify/v2"
var _ notify.SendConfig = (*SendConfig)(nil)
// 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.
type SendConfig struct {
Subject string
Message string
Attachments []notify.Attachment
Metadata map[string]any
DryRun bool
ContinueOnErr bool
// Telegram specific fields
ParseMode string
}
// SetAttachments adds attachments to the message. This method is needed as part of the notify.SendConfig interface.
func (c *SendConfig) SetAttachments(attachments ...notify.Attachment) {
c.Attachments = attachments
}
// SetMetadata sets the metadata of the message. This method is needed as part of the notify.SendConfig interface.
func (c *SendConfig) SetMetadata(metadata map[string]any) {
c.Metadata = metadata
}
// SetDryRun sets the dry run flag of the message. This method is needed as part of the notify.SendConfig interface.
func (c *SendConfig) SetDryRun(dryRun bool) {
c.DryRun = dryRun
}
// SetContinueOnErr sets the continue on error flag of the message. This method is needed as part of the
// notify.SendConfig interface.
func (c *SendConfig) SetContinueOnErr(continueOnErr bool) {
c.ContinueOnErr = continueOnErr
}
// Send options
// SendWithParseMode is a send option that sets the parse mode of the message.
func SendWithParseMode(parseMode string) notify.SendOption {
return func(config notify.SendConfig) {
if typedConf, ok := config.(*SendConfig); ok {
typedConf.ParseMode = parseMode
}
}
}