notify
The notify package provides pluggable implementations for sending notifications via Email (SMTP), Slack, and Microsoft Teams (both Incoming Webhook and Graph API).
Features
- Send email with plain text, HTML, and attachments
- Post Slack messages with colored attachments
- Send Microsoft Teams messages via:
- Incoming webhook
- Graph API (channel messages)
- Configurable headers, TLS settings, and authentication
Package Overview
π Interfaces
| Interface |
Description |
Sender |
Common interface for all notifiers |
Dialer |
(Email) For abstracting SMTP setup |
HTTPDoer |
For mocking HTTP clients |
π¦ Subpackages
email β SMTP email sender with STARTTLS, auth, attachments
slack β Sends messages to Slack using chat.postMessage
msteams β Sends cards via Microsoft Teams webhook
msteamsgraph β Sends rich messages using Graph API
utils β Shared HTTP client abstraction
Usage
Email
cfg := email.SMTPConfig{
Host: "smtp.example.com",
Port: 587,
From: "noreply@example.com",
Username: "user",
Password: "pass",
}
client := email.New(cfg)
msg := email.Message{
To: []string{"recipient@example.com"},
Subject: "Hello",
Body: "This is a test email",
}
_ = client.Send(context.Background(), msg)
Slack
client := slack.NewWithToken("xoxb-your-token")
msg := slack.Slack{
Channel: "#alerts",
Attachments: []slack.Attachment{{
Color: "danger",
Title: "High Load",
Text: "CPU usage exceeds 90%",
}},
}
_, _ = client.Send(context.Background(), msg)
MS Teams (Webhook)
client := msteams.New()
msg := msteams.MSTeams{
Title: "Deployment Success",
Text: "The app was deployed successfully.",
}
_, _ = client.Send(context.Background(), msg, "https://outlook.office.com/webhook/...")
MS Teams (Graph API)
client := msteamsgraph.NewWithToken("BearerToken")
msg := msteamsgraph.Message{
Body: msteamsgraph.ItemBody{
ContentType: "html",
Content: "β
All systems operational.",
},
}
_, _ = client.SendChannel(context.Background(), "team-id", "channel-id", msg)
- All notifiers accept custom
utils.HTTPDoer for dependency injection and testability.
- Use mocks or replace
HttpClient to simulate behavior during unit tests.