package slack
import "git.sr.ht/~shulhan/pakakeh.go/api/slack"
Package slack provide a simple API for sending message to Slack using only standard packages.
Index ¶
Examples ¶
Functions ¶
func PostWebhook ¶
PostWebhook send a message using "Incoming Webhook".
Code:
Example¶
{
webhookURL := os.Getenv("SLACK_WEBHOOK_URL")
if len(webhookURL) == 0 {
return
}
msg := &Message{
Channel: "test",
Username: "Test",
IconEmoji: ":ghost:",
Text: "Hello, world!",
}
err := PostWebhook(webhookURL, msg)
if err != nil {
log.Fatal(err)
}
//Output:
}
Types ¶
type Message ¶
type Message struct { Channel string `json:"channel,omitempty"` Username string `json:"username,omitempty"` IconEmoji string `json:"icon_emoji,omitempty"` IconURL string `json:"icon_url,omitempty"` Text string `json:"text"` }
Message define the standard message payload with JSON tags.
type WebhookClient ¶
WebhookClient for slack. Use this for long running program that post message every minutes or seconds.
func NewWebhookClient ¶
func NewWebhookClient(webhookURL, user, channel string) (wcl *WebhookClient, err error)
NewWebhookClient create new slack client that will write the message using webhook URL and optional user and channel.
func (*WebhookClient) Close ¶
func (wcl *WebhookClient) Close() (err error)
Close the client connection.
func (*WebhookClient) Post ¶
func (wcl *WebhookClient) Post(msg *Message) (err error)
Post the Message as is.
func (*WebhookClient) Write ¶
func (wcl *WebhookClient) Write(b []byte) (n int, err error)
Write wrap the raw bytes into Message with the user and channel previously defined when creating the client, and post it to slack.
Source Files ¶
message.go slack.go webhook_client.go
- Version
- v0.60.0 (latest)
- Published
- Feb 1, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 6 minutes ago –
Tools for package owners.