A Go library for sending notifications through various messaging platforms. Inspired by Symfony Notifier.
go get github.com/shyim/go-notifier| Platform | DSN Format |
|---|---|
| Telegram | telegram://BOT_TOKEN@default?channel=CHAT_ID |
| Slack | slack://BOT_TOKEN@default?channel=CHANNEL_ID |
| Discord | discord://WEBHOOK_TOKEN@default?webhook_id=WEBHOOK_ID |
| Gotify | gotify://APP_TOKEN@SERVER_HOST |
| Microsoft Teams | microsoftteams://default?webhook_url=WEBHOOK_URL |
package main
import (
"context"
"github.com/shyim/go-notifier"
_ "github.com/shyim/go-notifier/transport/telegram" // Auto-registers transport
)
func main() {
ctx := context.Background()
// Create transport from DSN
transport, _ := notifier.NewTransportFromDSN("telegram://bot_token@default?channel=chat_id")
// Send message
message := notifier.NewChatMessage("Hello World!")
_, _ = transport.Send(ctx, message)
}The Notifier manages multiple transports and routes messages appropriately:
package main
import (
"context"
"github.com/shyim/go-notifier"
_ "github.com/shyim/go-notifier/transport/telegram"
_ "github.com/shyim/go-notifier/transport/slack"
)
func main() {
ctx := context.Background()
// Create transports
telegramTransport, _ := notifier.NewTransportFromDSN("telegram://token@default?channel=123")
slackTransport, _ := notifier.NewTransportFromDSN("slack://xoxb-token@default?channel=C123")
// Create notifier with multiple transports
n := notifier.NewNotifier(telegramTransport, slackTransport)
// Send to first supporting transport
message := notifier.NewChatMessage("Hello!")
_, _ = n.Send(ctx, message)
// Or send to all transports
_, _ = n.SendAll(ctx, message)
}Create a single message with options for each transport:
import (
"github.com/shyim/go-notifier"
"github.com/shyim/go-notifier/transport/telegram"
"github.com/shyim/go-notifier/transport/slack"
"github.com/shyim/go-notifier/transport/discord"
)
// Create message with transport-specific options
message := notifier.NewChatMessage("Server alert!").
WithOptions("telegram", telegram.NewOptions().
ParseMode("HTML").
DisableNotification(false)).
WithOptions("slack", slack.NewOptions().
Username("AlertBot").
IconEmoji(":warning:")).
WithOptions("discord", discord.NewOptions().
Username("AlertBot").
AddEmbed(discord.NewEmbed().
Title("Alert").
Color(0xFF0000)))
// Each transport picks its own options automatically
n.SendAll(ctx, message)import (
"github.com/shyim/go-notifier"
"github.com/shyim/go-notifier/transport/telegram"
)
transport := telegram.NewTransport("bot_token", "chat_id", nil)
// Simple message
message := notifier.NewChatMessage("Hello!")
// With options
message := notifier.NewChatMessage("*Bold* message").
WithOptions("telegram", telegram.NewOptions().
ParseMode("MarkdownV2").
DisableNotification(true))
// With inline keyboard
keyboard := telegram.NewInlineKeyboard().
AddRow(
telegram.NewInlineKeyboardButton("Yes").CallbackData("yes"),
telegram.NewInlineKeyboardButton("No").CallbackData("no"),
)
message := notifier.NewChatMessage("Choose:").
WithOptions("telegram", telegram.NewOptions().ReplyMarkup(keyboard))import (
"github.com/shyim/go-notifier"
"github.com/shyim/go-notifier/transport/slack"
)
transport := slack.NewTransport("xoxb-token", "C123456", nil)
// Simple message
message := notifier.NewChatMessage("Hello Slack!")
// With blocks
message := notifier.NewChatMessage("Hello!").
WithOptions("slack", slack.NewOptions().
Username("MyBot").
IconEmoji(":robot_face:").
Block(slack.NewSectionBlock().Text("Section text")).
Block(slack.NewDividerBlock()))import (
"github.com/shyim/go-notifier"
"github.com/shyim/go-notifier/transport/discord"
)
transport := discord.NewTransport("webhook_id", "webhook_token", nil)
// Simple message
message := notifier.NewChatMessage("Hello Discord!")
// With embed
message := notifier.NewChatMessage("Check this embed").
WithOptions("discord", discord.NewOptions().
AddEmbed(discord.NewEmbed().
Title("Alert").
Description("Something happened!").
Color(0xFF0000)))import (
"github.com/shyim/go-notifier"
"github.com/shyim/go-notifier/transport/gotify"
)
transport := gotify.NewTransport("app_token", nil)
transport.SetHost("gotify.example.com")
// With priority
message := notifier.NewChatMessage("High priority alert!").
WithOptions("gotify", gotify.NewOptions().
Title("Important").
Priority(8))import (
"github.com/shyim/go-notifier"
"github.com/shyim/go-notifier/transport/microsoftteams"
)
transport := microsoftteams.NewTransport("https://outlook.office.com/webhook/...", nil)
// Simple message
message := notifier.NewChatMessage("Hello Teams!")
// With rich formatting
message := notifier.NewChatMessage("Important notification").
WithOptions("microsoftteams", microsoftteams.NewOptions().
Title("Alert").
ThemeColor("FF0000"))All transports accept a custom *http.Client for advanced configuration:
import (
"net/http"
"time"
"github.com/shyim/go-notifier/transport/telegram"
)
client := &http.Client{
Timeout: 30 * time.Second,
}
transport := telegram.NewTransport("token", "chat_id", client)_, err := transport.Send(ctx, message)
if err != nil {
// Errors are prefixed with transport name
// e.g., "telegram: send request: connection refused"
log.Printf("Failed to send: %v", err)
}MIT License - see LICENSE file.