Version: v0.0.0-...-3960e4a Latest Latest

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

Go to latest
Published: May 10, 2018 License: BSD-2-Clause Imports: 1 Imported by: 0



Package chat implements the types needed to post chat messages to slack.




View Source
const (
	// PostMessageEndpoint is the slack URL endpoint for chat post Message
	PostMessageEndpoint = ""


View Source
var (
	// ShortFieldLen is the length of a field value which is to be deemed short.
	ShortFieldLen = 20


This section is empty.


type Attachment

type Attachment struct {
	// Fallback is the plain-text summary of the attachment.
	Fallback string `json:"fallback"`

	// Color is a color indicating the classification of the message.
	Color string `json:"color"`

	// PreText is optional text that appears above the message attachment block.
	PreText string `json:"pretext,omitempty"`

	// AuthorName is the small text used to display the author's name.
	AuthorName string `json:"author_name,omitempty"`

	// AuthorLink is a valid URL that will hyperlink the author_name text mentioned above.
	AuthorLink string `json:"author_link,omitempty"`

	// AuthorIcon is a valid URL that displays a small 16x16px image to the left of the author_name text.
	AuthorIcon string `json:"author_icon,omitempty"`

	// Title is displayed as larger, bold text near the top of a message attachment.
	Title string `json:"title,omitempty"`

	// TitleLink is the optional url of the hyperlink to be used for the title.
	TitleLink string `json:"title_link,omitempty"`

	// Text is the main text of the attachment.
	Text string `json:"text,omitempty"`

	// Fields contains optional fields to be displayed in the in a table inside the attachment.
	Fields []*Field `json:"fields,omitempty"`

	// MarkdownIn enables Markdown support. Valid values are ["pretext", "text", "fields"].
	// Setting "fields" will enable markup formatting for the value of each field.
	MarkdownIn []string `json:"mrkdwn_in,omitempty"`

	// ImageURL is the URL to an image file that will be displayed inside the attachment.
	ImageURL string `json:"image_url"`

	// ThumbURL is the URL to an image file that will be displayed as a thumbnail on the right side of a attachment.
	ThumbURL string `json:"ThumbURL"`

	// Footer is optional text to help contextualize and identify an attachment (300 chars max).
	Footer string `json:"footer"`

	// FooterIcon is the URL to a small icon beside your footer text.
	FooterIcon string `json:"footer_icon"`

	// TimeStamp if set is the epoch time that will display as part of the attachment's footer.
	TimeStamp int `json:"ts,omitempty"`

Attachment is a slack chat message attachment. See:

func (*Attachment) AddField

func (a *Attachment) AddField(f *Field)

AddField adds f to the attachments fields.

func (*Attachment) NewField

func (a *Attachment) NewField(title, value string) *Field

NewField creates a new field, adds it to the attachment and then returns it.

type Field

type Field struct {
	// Title is shown as a bold heading above the value text.
	// It cannot contain markup and will be escaped for you.
	Title string `json:"title"`

	// Value is the text value of the field.
	// It may contain standard message markup and must be escaped as normal.
	// May be multi-line.
	Value string `json:"value"`

	// Short is an optional flag indicating whether the value is short enough to be displayed side-by-side with other values.
	Short bool `json:"short"`

Field will be displayed in a table inside the message attachment.

func NewField

func NewField(title, value string) *Field

NewField returns a fully initialised field with Short set to true if the length of value is less than ShortFieldLen.

type Message

type Message struct {
	// Token is the Authentication token (Requires scope: chat:write:bot or chat:write:user).
	Token string `json:"token,omitempty"`

	// Channel is the channel, private group, or IM channel to send message to.
	Channel string `json:"channel,omitempty"`

	// Text of the message to send.
	Text string `json:"text,omitempty"`

	// Markdown enables Markdown support.
	Markdown bool `json:"mrkdwn,omitempty"`

	// Parse changes how messages are treated.
	Parse string `json:"parse,omitempty"`

	// LinkNames causes link channel names and usernames to be found and linked.
	LinkNames int `json:"link_name,omitempty"`

	// Attachments is structured message attachments
	Attachments []*Attachment `json:"attachments,omitempty"`

	// UnfurLinks enables unfurling of primarily text-based content.
	UnfurlLinks bool `json:"unfurl_links,omitempty"`

	// UnfurlMedia if set to false disables unfurling of media content.
	UnfurlMedia bool `json:"unfurl_media,omitempty"`

	// Username set your bot's user name.
	// Must be used in conjunction with AsUser set to false, otherwise ignored.
	Username string `json:"username,omitempty"`

	// AsUser pass true to post the message as the authed user, instead of as a bot.
	AsUser bool `json:"as_user"`

	// IconURL is the URL to an image to use as the icon for this message.
	// Must be used in conjunction with AsUser set to false, otherwise ignored.
	IconURL string `json:"icon_url,omitempty"`

	// IconEmoji is the emoji to use as the icon for this message.
	// Overrides IconURL.
	// Must be used in conjunction with AsUser set to false, otherwise ignored.
	IconEmoji string `json:"icon_emoji,omitempty"`

	// ThreadTS is the timestamp (ts) of the parent message to reply to a thread.
	ThreadTS string `json:"thread_ts,omitempty"`

	// ReplyBroadcast used in conjunction with thread_ts and indicates whether reply
	// should be made visible to everyone in the channel or conversation.
	ReplyBroadcast bool `json:"reply_broadcast,omitempty"`

Message represents slack chat message.

func (*Message) AddAttachment

func (m *Message) AddAttachment(a *Attachment)

AddAttachment adds a to the message's attachments.

func (*Message) NewAttachment

func (m *Message) NewAttachment() *Attachment

NewAttachment creates a new empty attachment adds it to the message and returns it.

func (*Message) Send

func (m *Message) Send(c slack.Client) (*MessageResponse, error)

Send sends the msg to slack using the client c.

type MessageResponse

type MessageResponse struct {
	Timestamp string   `json:"ts,omitempty"`
	Channel   string   `json:"channel,omitempty"`
	Message   *Message `json:"message,omitempty"`

MessageResponse the response returned from the post message call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL