Message Types
Per-channel message struct reference. All builder methods and fields.
Every channel has a Message struct you build with NewMessage() inside a To<Channel>() method. Builders use Set*/Add* verbs and return the message for chaining. This is the field reference for each.
mail.Message
import "github.com/gopackx/go-notification/channel/mail"
func (m *Message) SetFrom(addr string, name ...string) *Message
func (m *Message) AddTo(addr string, name ...string) *Message
func (m *Message) AddCC(addr string, name ...string) *Message
func (m *Message) AddBCC(addr string, name ...string) *Message
func (m *Message) AddReplyTo(addr string, name ...string) *Message
func (m *Message) SetSubject(s string) *Message
func (m *Message) SetText(s string) *Message
func (m *Message) SetHTML(s string) *Message
func (m *Message) SetPriority(p Priority) *Message
func (m *Message) AddHeader(k, v string) *Message
func (m *Message) AddTag(tags ...string) *Message
func (m *Message) SetMetadata(k, v string) *Message
func (m *Message) Attach(a Attachment) *Message
// Laravel-style body (auto-rendered to Text/HTML when those are empty):
func (m *Message) SetGreeting(s string) *Message
func (m *Message) Line(s string) *Message
func (m *Message) Action(label, url string) *Message
func (m *Message) SetSalutation(s string) *MessageSupporting types:
type Address struct {
Name string
Address string
}
type Attachment struct {
Filename string
ContentType string
Data []byte
Inline bool // attach as related part (e.g. CID images)
ContentID string
}
type Priority string
const (
PriorityNormal Priority = ""
PriorityHigh Priority = "high"
PriorityLow Priority = "low"
)Driver Config.From is a mail.Address. The per-message SetFrom is an
optional override. If a message sets no recipient, the channel falls back to
RouteNotificationFor("mail").
whatsapp.Message
import "github.com/gopackx/go-notification/channel/whatsapp"
func (m *Message) SetTo(to string) *Message
func (m *Message) SetText(t string) *Message
func (m *Message) SetImage(url, caption string) *Message
func (m *Message) SetVideo(url, caption string) *Message
func (m *Message) SetDocument(url, filename string) *Message
// Meta-approved business templates (Twilio, Meta Cloud API):
func (m *Message) SetTemplate(name, lang string, params ...string) *Messagesms.Message
import "github.com/gopackx/go-notification/channel/sms"
func (m *Message) SetTo(to string) *Message // E.164
func (m *Message) SetText(t string) *Message
func (m *Message) SetFrom(f string) *Message // override driver default senderpush.Message
import "github.com/gopackx/go-notification/channel/push"
func (m *Message) SetToken(t string) *Message
func (m *Message) SetTokens(t ...string) *Message // FCM multicast
func (m *Message) SetTopic(t string) *Message // topic delivery
func (m *Message) SetTitle(t string) *Message
func (m *Message) SetBody(b string) *Message
func (m *Message) SetImage(u string) *Message
func (m *Message) SetSound(s string) *Message
func (m *Message) SetBadge(b int) *Message
func (m *Message) SetData(k, v string) *Message // string→string only
func (m *Message) SetClickAction(a string) *MessageToken, Tokens, and Topic are mutually exclusive ways to target. Data values are strings.
chat.Message
Slack, Telegram, Discord, and Microsoft Teams all use this one type — there is no per-provider message struct. Set the common Text, then add provider-specific extras as needed.
import "github.com/gopackx/go-notification/channel/chat"
func (m *Message) SetText(t string) *Message
func (m *Message) SetTo(to string) *Message
func (m *Message) SetParseMode(p string) *Message
func (m *Message) AddSlackAttachment(a SlackAttachment) *Message
func (m *Message) AddDiscordEmbed(e DiscordEmbed) *MessageProvider-specific fields on the struct:
type Message struct {
To string
Text string
ParseMode string
// Slack
SlackAttachments []SlackAttachment
SlackBlocks []map[string]any
SlackThreadTS string
// Telegram
TelegramReplyToMessageID int
TelegramDisableWebPreview bool
// Discord
DiscordUsername string
DiscordEmbeds []DiscordEmbed
// Teams (MessageCard schema)
TeamsCard map[string]any
}
type SlackAttachment struct {
Color, Title, TitleLink, Text, Footer string
Fields []SlackField
Timestamp int64
}
type SlackField struct{ Title, Value string; Short bool }
type DiscordEmbed struct {
Title, Description, URL string
Color int
Fields []DiscordField
}
type DiscordField struct{ Name, Value string; Inline bool }webhook.Message
import "github.com/gopackx/go-notification/channel/webhook"
func (m *Message) SetURL(u string) *Message
func (m *Message) SetMethod(v string) *Message // default "POST"
func (m *Message) AddHeader(k, v string) *Message
func (m *Message) SetJSON(v any) *Message // BodyType "json" (default)
func (m *Message) SetForm(v map[string]string) *Message // BodyType "form"
func (m *Message) SetRaw(b []byte) *Message // BodyType "raw"database.Message
import "github.com/gopackx/go-notification/channel/database"
func (m *Message) SetType(t string) *Message // e.g. "order.shipped"
func (m *Message) SetTitle(t string) *Message
func (m *Message) SetBody(b string) *Message
func (m *Message) AddData(k string, v any) *Message
func (m *Message) SetData(data map[string]any) *Messagefunc (n OrderShipped) ToDatabase(u notification.Notifiable) *database.Message {
return database.NewMessage().
SetType("order.shipped").
SetTitle("Order shipped").
SetBody("Your order is on its way.").
AddData("order_id", n.OrderID)
}ToDatabase returns a *database.Message, not a map. Rows you read back are database.StoredNotification values (ID, Type, Title, Body, Data, ReadAt, CreatedAt, …). See Database Channel.