slack

package
v0.54.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package slack provide a simple API for sending message to Slack using only standard packages.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PostWebhook

func PostWebhook(webhookURL string, msg *Message) (err error)

PostWebhook send a message using "Incoming Webhook".

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

type WebhookClient struct {
	*libhttp.Client
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL