slack

package module
v0.0.0-...-b4b4d35 Latest Latest
Warning

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

Go to latest
Published: May 28, 2018 License: MIT Imports: 13 Imported by: 73

README

Slack GoDoc

Golang client for the Slack API. Include the example code using each slack api.

Currently supports:

Method Description Example
channels.history Fetches history of messages and events from a channel. #link
channels.join Joins a channel, creating it if needed. #link
channels.list Lists all channels in a Slack team. #link
chat.postMessage Sends a message to a channel. #link
files.upload Upload an image/file #link
files.info Retrieves the information about an uploaded file #link
groups.invite Invites a user to a private group. #link
groups.create Creates a private group. #link
groups.list Lists private groups that the calling user has access to. #link
users.info Gets information about a channel. #link
users.list Lists all users in a Slack team. #link

Example

package main

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

const (
  token       = "your-api-token"
  channelName = "general"
)

func main() {
  api := slack.New(token)
  err := api.ChatPostMessage(channelName, "Hello, world!", nil)
  if err != nil {
    panic(err)
  }
}

Command line tool

If you are looking for slack commandline utility, vektorlab/slackcat probably suits you.

Author

Jun Kimura

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Color    string `json:"color,omitempty"`
	Fallback string `json:"fallback"`

	AuthorName    string `json:"author_name,omitempty"`
	AuthorSubname string `json:"author_subname,omitempty"`
	AuthorLink    string `json:"author_link,omitempty"`
	AuthorIcon    string `json:"author_icon,omitempty"`

	Title     string `json:"title,omitempty"`
	TitleLink string `json:"title_link,omitempty"`
	Pretext   string `json:"pretext,omitempty"`
	Text      string `json:"text"`

	ImageURL string `json:"image_url,omitempty"`
	ThumbURL string `json:"thumb_url,omitempty"`

	Footer     string `json:"footer,omitempty"`
	FooterIcon string `json:"footer_icon,omitempty"`
	TimeStamp  int64  `json:"ts,omitempty"`

	Fields     []*AttachmentField `json:"fields,omitempty"`
	MarkdownIn []string           `json:"mrkdwn_in,omitempty"`
}

type AttachmentField

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

https://api.slack.com/docs/attachments It is possible to create more richly-formatted messages using Attachments.

type AuthTestApiResponse

type AuthTestApiResponse struct {
	BaseAPIResponse
	Url    string `json:"url"`
	Team   string `json:"team"`
	User   string `json:"user"`
	TeamId string `json:"team_id"`
	UserId string `json:"user_id"`
}

response type for `auth.test` api

type BaseAPIResponse

type BaseAPIResponse struct {
	Ok    bool   `json:"ok"`
	Error string `json:"error"`
}

type Channel

type Channel struct {
	Id         string          `json:"id"`
	Name       string          `json:"name"`
	IsChannel  bool            `json:"is_channel"`
	Created    int             `json:"created"`
	Creator    string          `json:"creator"`
	IsArchived bool            `json:"is_archived"`
	IsGeneral  bool            `json:"is_general"`
	IsMember   bool            `json:"is_member"`
	Members    []string        `json:"members"`
	RawTopic   json.RawMessage `json:"topic"`
	RawPurpose json.RawMessage `json:"purpose"`
	NumMembers int             `json:"num_members"`
}

slack channel type

func (*Channel) Purpose

func (ch *Channel) Purpose() (*Purpose, error)

func (*Channel) Topic

func (ch *Channel) Topic() (*Topic, error)

type ChannelsHistoryOpt

type ChannelsHistoryOpt struct {
	Channel   string  `json:"channel"`
	Latest    float64 `json:"latest"`
	Oldest    float64 `json:"oldest"`
	Inclusive int     `json:"inclusive"`
	Count     int     `json:"count"`
	UnReads   int     `json:"unreads,omitempty"`
}

option type for `channels.history` api

func (*ChannelsHistoryOpt) Bind

func (opt *ChannelsHistoryOpt) Bind(uv *url.Values) error

type ChannelsHistoryResponse

type ChannelsHistoryResponse struct {
	BaseAPIResponse
	Latest             float64    `json:"latest"`
	Messages           []*Message `json:"messages"`
	HasMore            bool       `json:"has_more"`
	UnReadCountDisplay int        `json:"unread_count_display"`
}

response type for `channels.history` api

type ChannelsListAPIResponse

type ChannelsListAPIResponse struct {
	BaseAPIResponse
	RawChannels json.RawMessage `json:"channels"`
}

response type for `channels.list` api

func (*ChannelsListAPIResponse) Channels

func (res *ChannelsListAPIResponse) Channels() ([]*Channel, error)

Channels returns a slice of channel object from a response of `channels.list` api.

type ChatPostMessageAPIResponse

type ChatPostMessageAPIResponse struct {
	BaseAPIResponse
	Channel string `json:"channel"`
	Ts      string `json:"ts"`
}

response type for `chat.postMessage` api

type ChatPostMessageOpt

type ChatPostMessageOpt struct {
	AsUser      bool
	Username    string
	Parse       string
	LinkNames   string
	Attachments []*Attachment
	UnfurlLinks string
	UnfurlMedia string
	IconUrl     string
	IconEmoji   string
}

option type for `chat.postMessage` api

type FilesUploadAPIResponse

type FilesUploadAPIResponse struct {
	Ok    bool         `json:"ok"`
	Error string       `json:"error"`
	File  UploadedFile `json:"file"`
}

response of `files.upload` api

type FilesUploadOpt

type FilesUploadOpt struct {
	Content        string
	Filepath       string
	Filetype       string
	Filename       string
	Title          string
	InitialComment string
	Channels       []string
}

option type for `files.upload` api

type Group

type Group struct {
	Id         string          `json:"id"`
	Name       string          `json:"name"`
	Created    int             `json:"created"`
	Creator    string          `json:"creator"`
	IsArchived bool            `json:"is_archived"`
	Members    []string        `json:"members"`
	RawTopic   json.RawMessage `json:"topic"`
	RawPurpose json.RawMessage `json:"purpose"`
}

slack group type

type GroupsCreateAPIResponse

type GroupsCreateAPIResponse struct {
	BaseAPIResponse
	RawGroup json.RawMessage `json:"group"`
}

response type for `groups.create` api

func (*GroupsCreateAPIResponse) Group

func (res *GroupsCreateAPIResponse) Group() (*Group, error)

type GroupsListAPIResponse

type GroupsListAPIResponse struct {
	BaseAPIResponse
	RawGroups json.RawMessage `json:"groups"`
}

response type for `groups.list` api

func (*GroupsListAPIResponse) Groups

func (res *GroupsListAPIResponse) Groups() ([]*Group, error)

Groups returns a slice of group object from `groups.list` api.

type Icon

type Icon struct {
	Image34      string `json:"image_34"`
	Image44      string `json:"image_44"`
	Image68      string `json:"image_68"`
	Image88      string `json:"image_88"`
	Image102     string `json:"image_102"`
	Image132     string `json:"image_132"`
	ImageDefault bool   `json:"image_default"`
}

type Im

type Im struct {
	Id            string `json:"id"`
	Isim          bool   `json:"is_im"`
	User          string `json:"user"`
	Created       int    `json:"created"`
	IsUserDeleted bool   `json:"is_user_deleted"`
}

slack im type

type ImListAPIResponse

type ImListAPIResponse struct {
	BaseAPIResponse
	RawIms json.RawMessage `json:"ims"`
}

response type for `im.list` api

func (*ImListAPIResponse) Ims

func (res *ImListAPIResponse) Ims() ([]*Im, error)

Ims returns a slice of im object from `im.list` api.

type Message

type Message struct {
	Type    string `json:"type"`
	Ts      string `json:"ts"`
	UserId  string `json:"user"`
	Text    string `json:"text"`
	Subtype string `json:"subtype"`
}

func (*Message) Timestamp

func (msg *Message) Timestamp() *time.Time

type MpIm

type MpIm struct {
	Id         string          `json:"id"`
	Name       string          `json:"name"`
	Created    int64           `json:"created"`
	Creator    string          `json:"creator"`
	IsArchived bool            `json:"is_archived"`
	IsMpim     bool            `json:"is_mpim"`
	Members    []string        `json:"members"`
	RawTopic   json.RawMessage `json:"topic"`
	RawPurpose json.RawMessage `json:"purpose"`
}

slack mpim type

type MpImListAPIResponse

type MpImListAPIResponse struct {
	BaseAPIResponse
	RawMpIms json.RawMessage `json:"groups"`
}

response type for `im.list` api

func (*MpImListAPIResponse) MpIms

func (res *MpImListAPIResponse) MpIms() ([]*MpIm, error)

MpIms returns a slice of mpim object from `mpim.list` api.

type ProfileInfo

type ProfileInfo struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	RealName  string `json:"real_name"`
	Email     string `json:"email"`
	Skype     string `json:"skype"`
	Phone     string `json:"phone"`
	Image24   string `json:"image_24"`
	Image32   string `json:"image_32"`
	Image48   string `json:"image_48"`
	Image72   string `json:"image_72"`
	Image192  string `json:"image_192"`
}

slack user profile type

type Purpose

type Purpose struct {
	Value   string `json:"value"`
	Creator string `json:"creator"`
	LastSet int    `json:"last_set"`
}

type Slack

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

func New

func New(token string) *Slack

Create a slack client with an API token.

func (*Slack) AuthTest

func (sl *Slack) AuthTest() (*AuthTestApiResponse, error)

API auth.test: Checks authentication and tells you who you are.

func (*Slack) ChannelsHistory

func (sl *Slack) ChannelsHistory(opt *ChannelsHistoryOpt) (*ChannelsHistoryResponse, error)

API channels.history: Fetches history of messages and events from a channel.

func (*Slack) ChannelsHistoryMessages

func (sl *Slack) ChannelsHistoryMessages(opt *ChannelsHistoryOpt) ([]*Message, error)

func (*Slack) ChannelsList

func (sl *Slack) ChannelsList() ([]*Channel, error)

API channels.list: Lists all channels in a Slack team.

func (*Slack) ChatPostMessage

func (sl *Slack) ChatPostMessage(channelId string, text string, opt *ChatPostMessageOpt) error

API chat.postMessage: Sends a message to a channel.

func (*Slack) CreateGroup

func (sl *Slack) CreateGroup(name string) error

API groups.create: Creates a private group.

func (*Slack) DoRequest

func (sl *Slack) DoRequest(req *http.Request) ([]byte, error)

func (*Slack) FilesUpload

func (sl *Slack) FilesUpload(opt *FilesUploadOpt) (file *UploadedFile, err error)

API files.upload: Uploads or creates a file.

func (*Slack) FindChannel

func (sl *Slack) FindChannel(cb func(*Channel) bool) (*Channel, error)

FindChannel returns a channel object that satisfy conditions specified.

func (*Slack) FindChannelByName

func (sl *Slack) FindChannelByName(name string) (*Channel, error)

FindChannelByName returns a channel object that matches name specified.

func (*Slack) FindFile

func (sl *Slack) FindFile(id string) (file *UploadedFile, err error)

API files.info: Retrieves information about a specified uploaded file.

func (*Slack) FindGroup

func (sl *Slack) FindGroup(cb func(*Group) bool) (*Group, error)

FindGroup returns a group object that satisfy conditions specified.

func (*Slack) FindGroupByName

func (sl *Slack) FindGroupByName(name string) (*Group, error)

FindGroupByName returns a group object that matches name specified.

func (*Slack) FindIm

func (sl *Slack) FindIm(cb func(*Im) bool) (*Im, error)

FindIm returns a im object that satisfy conditions specified.

func (*Slack) FindImByName

func (sl *Slack) FindImByName(name string) (*Im, error)

FindImByName returns a im object that matches name specified.

func (*Slack) FindMpIm

func (sl *Slack) FindMpIm(cb func(*MpIm) bool) (*MpIm, error)

FindMpIm returns a mpim object that satisfy conditions specified.

func (*Slack) FindUser

func (sl *Slack) FindUser(cb func(*User) bool) (*User, error)

FindUser returns a user object that satisfy conditions specified.

func (*Slack) FindUserByName

func (sl *Slack) FindUserByName(name string) (*User, error)

FindUserByName returns a user object that matches name specified.

func (*Slack) GetRequest

func (sl *Slack) GetRequest(endpoint string, uv *url.Values) ([]byte, error)

func (*Slack) GroupsList

func (sl *Slack) GroupsList() ([]*Group, error)

API groups.list: Lists private groups that the calling user has access to.

func (*Slack) ImList

func (sl *Slack) ImList() ([]*Im, error)

API im.list: Lists direct message channels for the calling user.

func (*Slack) InviteGroup

func (sl *Slack) InviteGroup(channelId, userId string) error

API groups.invite: Invites a user to a private group.

func (*Slack) JoinChannel

func (sl *Slack) JoinChannel(name string) error

API channels.join: Joins a channel, creating it if needed.

func (*Slack) MpImList

func (sl *Slack) MpImList() ([]*MpIm, error)

API mpim.list: Lists multiparty direct message channels for the calling user.

func (*Slack) PostRequest

func (sl *Slack) PostRequest(endpoint string, uv *url.Values, body *bytes.Buffer) ([]byte, error)

func (*Slack) TeamInfo

func (sl *Slack) TeamInfo() (*TeamInfo, error)

func (*Slack) UsersInfo

func (sl *Slack) UsersInfo(userId string) (*User, error)

API users.info: Gets information about a user.

func (*Slack) UsersList

func (sl *Slack) UsersList() ([]*User, error)

API users.list: Lists all users in a Slack team.

type TeamInfo

type TeamInfo struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Domain      string `json:"domain"`
	EmailDomain string `json:"email_domain"`
	Icon        *Icon  `json:"icon"`
}

type TeamInfoResponse

type TeamInfoResponse struct {
	BaseAPIResponse
	*TeamInfo `json:"team"`
}

type Topic

type Topic struct {
	Value   string `json:"value"`
	Creator string `json:"creator"`
	LastSet int    `json:"last_set"`
}

type UploadedFile

type UploadedFile struct {
	ID                 string `json:"id"`
	Title              string `json:"title"`
	Name               string `json:"name"`
	MimeType           string `json:"mimetype"`
	FileType           string `json:"filetype"`
	User               string `json:"user"`
	PrivateUrl         string `json:"url_private"`
	PrivateDownloadUrl string `json:"url_private_download"`
	Permalink          string `json:"permalink"`
	PublicPermalink    string `json:"permalink_public"`
}

type User

type User struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Deleted  bool   `json:"deleted"`
	Color    string `json:"color"`
	Profile  *ProfileInfo
	IsAdmin  bool `json:"is_admin"`
	IsOwner  bool `json:"is_owner"`
	Has2fa   bool `json:"has_2fa"`
	HasFiles bool `json:"has_files"`
}

slack user type

type UsersInfoAPIResponse

type UsersInfoAPIResponse struct {
	BaseAPIResponse
	User *User `json:"user"`
}

response type of `users.info` api

type UsersListAPIResponse

type UsersListAPIResponse struct {
	BaseAPIResponse
	RawMembers json.RawMessage `json:"members"`
}

response type of `users.list` api

func (*UsersListAPIResponse) Members

func (res *UsersListAPIResponse) Members() ([]*User, error)

type WebHook

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

func NewWebHook

func NewWebHook(hookURL string) *WebHook

func (*WebHook) PostMessage

func (hk *WebHook) PostMessage(payload *WebHookPostPayload) error

type WebHookPostPayload

type WebHookPostPayload struct {
	Text        string        `json:"text,omitempty"`
	Channel     string        `json:"channel,omitempty"`
	Username    string        `json:"username,omitempty"`
	IconUrl     string        `json:"icon_url,omitempty"`
	IconEmoji   string        `json:"icon_emoji,omitempty"`
	UnfurlLinks bool          `json:"unfurl_links,omitempty"`
	LinkNames   string        `json:"link_names,omitempty"`
	Attachments []*Attachment `json:"attachments,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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