Documentation
¶
Overview ¶
Package slack provides a client for Slack Incoming Webhooks API. See https://api.slack.com/docs/messages for details of the API.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Send ¶
Send sends the message to Slack via Incomming Webhook API. It returns an error if a HTTP client returned non-2xx status or network error.
Example ¶
package main
import (
"fmt"
"github.com/int128/slack"
)
const webhook = "https://hooks.slack.com/services/..."
func main() {
if err := slack.Send(webhook, &slack.Message{
Username: "mybot",
IconEmoji: ":star:",
Text: "Hello World!",
}); err != nil {
panic(fmt.Errorf("Could not send the message to Slack: %s", err))
}
}
Types ¶
type Attachment ¶
type Attachment struct {
Fallback string `json:"fallback,omitempty"`
Color string `json:"color,omitempty"`
Pretext string `json:"pretext,omitempty"`
AuthorName string `json:"author_name,omitempty"`
AuthorLink string `json:"author_link,omitempty"`
AuthorIcon string `json:"author_icon,omitempty"`
Title string `json:"title,omitempty"`
TitleLink string `json:"title_link,omitempty"`
Text string `json:"text,omitempty"`
Fields []AttachmentField `json:"fields,omitempty"`
ImageURL string `json:"image_url,omitempty"`
ThumbURL string `json:"thumb_url,omitempty"`
Timestamp int64 `json:"ts,omitempty"`
MrkdwnIn []string `json:"mrkdwn_in,omitempty"` // pretext, text, fields
}
Attachment represents an attachment of a message. See https://api.slack.com/docs/message-attachments for details.
type AttachmentField ¶
type AttachmentField struct {
Title string `json:"title,omitempty"`
Value string `json:"value,omitempty"`
Short bool `json:"short,omitempty"`
}
AttachmentField represents a field in an attachment. See https://api.slack.com/docs/message-attachments for details.
type Client ¶
type Client struct {
WebhookURL string // Webhook URL (mandatory)
HTTPClient *http.Client // Default to http.DefaultClient
}
Client provides a client for Slack Incoming Webhook API.
type Message ¶
type Message struct {
Username string `json:"username,omitempty"`
IconEmoji string `json:"icon_emoji,omitempty"`
IconURL string `json:"icon_url,omitempty"`
Text string `json:"text,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
}
Message represents a message sent via Incoming Webhook API. See https://api.slack.com/docs/message-formatting for details.