slack

package module
v0.0.0-...-61655e2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2016 License: MIT Imports: 7 Imported by: 0

README

slack api

CircleCI GoDoc Usage

attachments := slack.NewAttachments(1)
attachments[0].SetFallback("Required plain-text summary of the attachment.").SetTitle("タイトル")

json, err := slack.JSON(attachments)
if err != nil {
	log.Println(err)
}

c := slack.NewClient()
c.SetToken("YOUR TOKEN").SetChannel("#general").SetText("こんにちは").SetAttachments(json).PostMessage()

You can check the token for test from here.

Install

go get github.com/kwmt/slack

Documentation

Overview

Example
package main

import (
	"github.com/kwmt/slack"
)

func main() {
	c := slack.NewClient()
	c.SetToken("YOUR TOKEN").SetChannel("#general").SetText("こんにちは").PostMessage()
}
Output:

Index

Examples

Constants

View Source
const (
	COLOR_GOOD    = "good"
	COLOR_WARNING = "warning"
	COLOR_DANGER  = "danger"
)

Variables

This section is empty.

Functions

func JSON

func JSON(attachments []Attachment) (string, error)

Types

type Attachment

type Attachment struct {
	Fallback string `json:"fallback"`
	Color    string `json:"color,omitempty"`
	Pretext  string `json:"pretext,omitempty"`
	Author
	Title
	Text     string  `json:"text,omitempty"`
	Fields   []Field `json:"fields,omitempty"`
	ImageUrl string  `json:"image_url,omitempty"`
	ThumbUrl string  `json:"thumb_url,omitempty"`
	Footer
}
Example
package main

import (
	"log"

	"github.com/kwmt/slack"
)

func main() {
	// https://api.slack.com/docs/message-attachments
	//    [
	//        {
	//            "fallback": "Required plain-text summary of the attachment.",
	//            "color": "good",
	//            "pretext": "Optional text that appears above the attachment block",
	//            "author_name": "Bobby Tables",
	//            "author_link": "http://flickr.com/bobby/",
	//            "author_icon": "http://flickr.com/icons/bobby.jpg",
	//            "title": "Slack API Documentation",
	//            "title_link": "https://api.slack.com/",
	//            "text": "Optional text that appears within the attachment",
	//            "fields": [
	//                {
	//                    "title": "Priority",
	//                    "value": "High",
	//                    "short": false
	//                }
	//            ],
	//            "image_url": "http://my-website.com/path/to/image.jpg",
	//            "thumb_url": "http://example.com/path/to/thumb.png",
	//            "footer": "Slack API",
	//            "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
	//            "ts": 123456789
	//        }
	//    ]

	fields := slack.NewFields(1)
	fields[0].SetTitle("Priority").SetValue("High").SetShort(false)

	attachments := slack.NewAttachments(1)
	attachments[0].SetFallback("Required plain-text summary of the attachment.").SetColor(slack.COLOR_GOOD).SetPretext(
		"Optional text that appears above the attachment block",
	).SetAuthorName("Bobby Tables").SetAuthorLink("http://flickr.com/bobby/").SetAuthorIcon("http://flickr.com/icons/bobby.jpg").SetTitle(
		"Slack API Documentatio",
	).SetTitleLink("https://api.slack.com/").SetText("Optional text that appears within the attachment").SetFields(fields).SetImageURL(
		"http://my-website.com/path/to/image.jpg",
	).SetThumbURL("http://example.com/path/to/thumb.png").SetFooterText("Slack API").SetFooterIcon(
		"https://platform.slack-edge.com/img/default_application_icon.png",
	).SetFooterTs(123456789)

	json, err := slack.JSON(attachments)
	if err != nil {
		log.Println(err)
	}

	c := slack.NewClient()
	c.SetToken("YOUR TOKEN").SetChannel("#general").SetText("こんにちは").SetAttachments(json).PostMessage()
}
Output:

func NewAttachments

func NewAttachments(count int) []Attachment

func (*Attachment) SetAuthorIcon

func (attachment *Attachment) SetAuthorIcon(authorIcon string) *Attachment
func (attachment *Attachment) SetAuthorLink(authorLink string) *Attachment

func (*Attachment) SetAuthorName

func (attachment *Attachment) SetAuthorName(authorName string) *Attachment

func (*Attachment) SetColor

func (attachment *Attachment) SetColor(color string) *Attachment

This is able to set value either be one of good, warning, danger, or any hex color code (eg. #439FE0).

func (*Attachment) SetFallback

func (attachment *Attachment) SetFallback(fallback string) *Attachment

func (*Attachment) SetFields

func (attachment *Attachment) SetFields(fields []Field) *Attachment

func (*Attachment) SetFooterIcon

func (attachment *Attachment) SetFooterIcon(icon string) *Attachment

func (*Attachment) SetFooterText

func (attachment *Attachment) SetFooterText(text string) *Attachment

func (*Attachment) SetFooterTs

func (attachment *Attachment) SetFooterTs(ts int64) *Attachment

timestamp

func (*Attachment) SetImageURL

func (attachment *Attachment) SetImageURL(imageUrl string) *Attachment

func (*Attachment) SetPretext

func (attachment *Attachment) SetPretext(pretext string) *Attachment

func (*Attachment) SetText

func (attachment *Attachment) SetText(text string) *Attachment

func (*Attachment) SetThumbURL

func (attachment *Attachment) SetThumbURL(thumbUrl string) *Attachment

func (*Attachment) SetTitle

func (attachment *Attachment) SetTitle(title string) *Attachment
func (attachment *Attachment) SetTitleLink(titleLink string) *Attachment

type Author

type Author struct {
	Name string `json:"author_name,omitempty"`
	Link string `json:"author_link,omitempty"`
	Icon string `json:"author_icon,omitempty"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) PostMessage

func (c *Client) PostMessage() (*Response, error)

func (*Client) SetAsUser

func (c *Client) SetAsUser(asUser bool) *Client

func (*Client) SetAttachments

func (c *Client) SetAttachments(attachmentsJSON string) *Client

func (*Client) SetChannel

func (c *Client) SetChannel(channel string) *Client

func (*Client) SetIconEmoji

func (c *Client) SetIconEmoji(iconEmoji string) *Client

func (*Client) SetIconURL

func (c *Client) SetIconURL(iconURL string) *Client

func (*Client) SetLinkNames

func (c *Client) SetLinkNames(linkNames int) *Client

func (*Client) SetParse

func (c *Client) SetParse(parse string) *Client

func (*Client) SetText

func (c *Client) SetText(text string) *Client

func (*Client) SetToken

func (c *Client) SetToken(token string) *Client
func (c *Client) SetUnfurlLinks(unfurlLinks bool) *Client

func (*Client) SetUnfurlMedia

func (c *Client) SetUnfurlMedia(unfurlMedia bool) *Client

func (*Client) SetUserName

func (c *Client) SetUserName(name string) *Client

type Field

type Field struct {
	Title string `json:"title,omitempty"`
	Value string `json:"value,omitempty"`
	Short bool   `json:"short,omitempty"`
}

func NewFields

func NewFields(count int) []Field

func (*Field) SetShort

func (field *Field) SetShort(short bool) *Field

func (*Field) SetTitle

func (field *Field) SetTitle(title string) *Field

func (*Field) SetValue

func (field *Field) SetValue(value string) *Field
type Footer struct {
	// brief text
	Footer string `json:"footer,omitempty"`
	Icon   string `json:"footer_icon,omitempty"`
	Ts     int64  `json:"ts,omitempty"`
}

type Message

type Message struct {
	Text     string `json:"text,omitempty"`
	Username string `json:"username,omitempty"`
	BotID    string `json:"bot_id,omitempty"`
	Type     string `json:"type,omitempty"`
	Subtype  string `json:"subtype,omitempty"`
	Ts       string `json:"ts,omitempty"`
}

type Response

type Response struct {
	Ok      bool    `json:"ok,omitempty"`
	Channel string  `json:"channel,omitempty"`
	Ts      string  `json:"ts,omitempty"`
	Message Message `json:"message,omitempty"`
	Error   string  `json:"error,omitempty"`
	// contains filtered or unexported fields
}

func (*Response) GetRequest

func (resp *Response) GetRequest() *http.Request

type Title

type Title struct {
	Title string `json:"title,omitempty"`
	Link  string `json:"title_link,omitempty"`
}

Jump to

Keyboard shortcuts

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