slack

package module
v0.0.0-...-9a199e3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2015 License: MIT Imports: 14 Imported by: 0

README

Slack

This library implements the Slack API Web and Real Time Messaging parts. A simple example utilizing most of the functionality can be seen under examples/scli which implements a full featured CLI client for Slack - either interactive or for batch usage.

##Implemented Methods

Method Description Support
api.test Checks API calling code false
auth.test Checks authentication & identity true
channels.archive Archives a channel true
channels.create Creates a channel true
channels.history Fetches history of messages and events from a channel true
channels.info Gets information about a channel true
channels.invite Invites a user to a channel true
channels.join Joins a channel, creating it if needed true
channels.kick Removes a user from a channel true
channels.leave Leaves a channel true
channels.list Lists all channels in a Slack team true
channels.mark Sets the read cursor in a channel true
channels.rename Renames a channel true
channels.setPurpose Sets the purpose for a channel true
channels.setTopic Sets the topic for a channel true
channels.unarchive Unarchives a channel true
chat.delete Deletes a message true
chat.postMessage Sends a message to a channel true
chat.update Updates a message false
emoji.list Lists custom emoji for a team true
files.delete Deletes a file true
files.info Gets information about a team file true
files.list Lists & filters team files true
files.upload Uploads or creates a file true
groups.archive Archives a private group true
groups.close Closes a private group true
groups.create Creates a private group true
groups.createChild Clones and archives a private group true
groups.history Fetches history of messages and events from a private group true
groups.info Gets information about a private group true
groups.invite Invites a user to a private group true
groups.kick Removes a user from a private group true
groups.leave Leaves a private group true
groups.list Lists private groups that the calling user has access to true
groups.mark Sets the read cursor in a private group true
groups.open Opens a private group true
groups.rename Renames a private group true
groups.setPurpose Sets the purpose for a private group true
groups.setTopic Sets the topic for a private group true
groups.unarchive Unarchives a private group true
im.close Close a direct message channel true
im.history Fetches history of messages and events from direct message channel true
im.list Lists direct message channels for the calling user true
im.mark Sets the read cursor in a direct message channel true
im.open Opens a direct message channel true
rtm.start Starts a Real Time Messaging session true
search.all Searches for messages and files matching a query false
search.files Searches for files matching a query false
search.messages Searches for messages matching a query false
stars.list Lists stars for a user false
team.accessLogs Gets the access logs for the current team false
team.info Gets information about the current team true
users.getPresence Gets user presence information false
users.info Gets information about a user true
users.list Lists all users in a Slack team true
users.setActive Marks a user as active false
users.setPresence Manually sets user presence false

##Missing Features

  • All of the above with a false in the support column.
  • Testing

##Install

If you have a go workplace setup and working you can simply do:

go get -u -t -v github.com/demisto/slack

##Usage

There are 2 ways to initiate the library, both using the various configuration functions slack.Set*:

  • Either using a test token retrieved from Slack and then setting the token
s, err = slack.New(slack.SetToken("test token retrieved from Slack"))
  • Using OAuth - see a simple example using uuid for random state. For this to work, you need to register your application with Slack.
// Start the OAuth process

// First, generate a random state
uuid, err := random.New()
if err != nil {
  panic(err)
}
conf := &oauth2.Config{
  ClientID:     "Your client ID",
  ClientSecret: "Your client secret",
  Scopes:       []string{"client"}, // the widest scope - can be others depending on requirement
  Endpoint: oauth2.Endpoint{
    AuthURL:  "https://slack.com/oauth/authorize",
    TokenURL: "https://slack.com/api/oauth.access",
  },
}
// Store state somewhere you can use later with timestamp
// ...
url := conf.AuthCodeURL(uuid.String())
// Redirect user to the OAuth Slack page
http.Redirect(w, r, url, http.StatusFound)
// Now, handle the redirected URL after the successful authentication

state := r.FormValue("state")
code := r.FormValue("code")
errStr := r.FormValue("error")
if errStr != "" {
  WriteError(w, &Error{"oauth_err", 401, "Slack OAuth Error", errStr})
  return
}
if state == "" || code == "" {
  WriteError(w, ErrBadContentRequest)
  return
}
// Retrieve the state you saved in the first step and make sure it is not too old
// ...
token, err := slack.OAuthAccess("Your client ID", "Your client secret", code, "")
if err != nil {
  WriteError(w, &Error{"oauth_err", 401, "Slack OAuth Error", err.Error()})
  return
}
// Done - you have the token - you can save it for later use
s, err := slack.New(slack.SetToken(token.AccessToken))
if err != nil {
  panic(err)
}
// Get our own user id
test, err := s.AuthTest()
if err != nil {
  panic(err)
}

##Authors

The library was written by slavikm as a side project to play with Slack API for demisto.

Documentation

Overview

Package slack is a library implementing the Slack Web and RTM API.

Written by Slavik Markovich at Demisto

Index

Constants

View Source
const (
	// DefaultURL points to the default Slack API
	DefaultURL = "https://slack.com/api/"
)

Variables

View Source
var (
	// ErrBadToken is returned when a bad token is passed to the API
	ErrBadToken = &Error{"bad_token", "Bad token was provided to the API"}
	// ErrNoToken is returned when the token is missing
	ErrNoToken = &Error{"no_token", "You must provide a Slack token to use the API"}
	// ErrBadOAuth is returned when OAuth credentials are bad
	ErrBadOAuth = &Error{"bad_oauth", "Bad OAuth credentials provided"}
)

Functions

func SetErrorLog

func SetErrorLog(logger *log.Logger) func(*Slack) error

SetErrorLog sets the logger for critical messages. It is nil by default.

func SetTraceLog

func SetTraceLog(logger *log.Logger) func(*Slack) error

SetTraceLog specifies the logger to use for output of trace messages like HTTP requests and responses. It is nil by default.

func TimestampToTime

func TimestampToTime(timestamp string) (time.Time, error)

TimestampToTime converter

Types

type Attachment

type Attachment struct {
	ServiceName string            `json:"service_name"`
	Fallback    string            `json:"fallback"`
	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"`
	ImageURL    string            `json:"image_url,omitempty"`
	ThumbURL    string            `json:"thumb_url,omitempty"`
	ThumbWidth  int               `json:"thumb_width"`
	ThumbHeight int               `json:"thumb_height"`
	FromURL     string            `json:"from_url"`
	Fields      []AttachmentField `json:"fields,omitempty"`
	MarkdownIn  []string          `json:"mrkdwn_in,omitempty"`
}

Attachment holds information about an attachment

type AttachmentField

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

AttachmentField holds information about an attachment field

type AuthTestResponse

type AuthTestResponse struct {
	URL    string `json:"url"`
	Team   string `json:"team"`
	User   string `json:"user"`
	TeamID string `json:"team_id"`
	UserID string `json:"user_id"`
	// contains filtered or unexported fields
}

AuthTestResponse is response to auth.test - see https://api.slack.com/methods/auth.test

func (*AuthTestResponse) Error

func (r *AuthTestResponse) Error() string

func (*AuthTestResponse) IsOK

func (r *AuthTestResponse) IsOK() bool

type BaseChannel

type BaseChannel struct {
	ID                 string              `json:"id"`
	Name               string              `json:"name"`
	Created            int64               `json:"created"`
	Creator            string              `json:"creator"`
	IsArchived         bool                `json:"is_archived"`
	IsOpen             bool                `json:"is_open"`
	Members            []string            `json:"members"`
	Topic              ChannelTopicPurpose `json:"topic"`
	Purpose            ChannelTopicPurpose `json:"purpose"`
	LastRead           string              `json:"last_read,omitempty"`
	Latest             Message             `json:"latest,omitempty"`
	UnreadCount        int                 `json:"unread_count,omitempty"`
	UnreadCountDisplay int                 `json:"unread_count_display,omitempty"`
	NumMembers         int                 `json:"num_members,omitempty"`
}

BaseChannel holds information about channel / group / IM

type Bot

type Bot struct {
	ID      string            `json:"id"`
	Name    string            `json:"name"`
	Deleted bool              `json:"deleted"`
	Icons   map[string]string `json:"icons"`
}

Bot holds the info about a bot

type Channel

type Channel struct {
	BaseChannel
	IsGeneral bool `json:"is_general"`
	IsChannel bool `json:"is_channel"`
	IsMember  bool `json:"is_member"`
}

Channel holds information about the channel

type ChannelCommonResponse

type ChannelCommonResponse struct {
	Channel struct {
		ID        string `json:"id"`
		Name      string `json:"name"`
		Created   int64  `json:"created"`
		IsChannel bool   `json:"is_channel"`
		IsGroup   bool   `json:"is_group"`
	} `json:"channel"`
	// contains filtered or unexported fields
}

ChannelCommonResponse holds response to rename request

func (*ChannelCommonResponse) Error

func (r *ChannelCommonResponse) Error() string

func (*ChannelCommonResponse) IsOK

func (r *ChannelCommonResponse) IsOK() bool

type ChannelListResponse

type ChannelListResponse struct {
	Channels []Channel `json:"channels"`
	// contains filtered or unexported fields
}

ChannelListResponse holds a response to a channel list request

func (*ChannelListResponse) Error

func (r *ChannelListResponse) Error() string

func (*ChannelListResponse) IsOK

func (r *ChannelListResponse) IsOK() bool

type ChannelResponse

type ChannelResponse struct {
	Channel Channel `json:"channel"`
	// contains filtered or unexported fields
}

ChannelResponse holds a response to a channel request

func (*ChannelResponse) Error

func (r *ChannelResponse) Error() string

func (*ChannelResponse) IsOK

func (r *ChannelResponse) IsOK() bool

type ChannelTopicPurpose

type ChannelTopicPurpose struct {
	Value   string `json:"value"`
	Creator string `json:"creator"`
	LastSet int64  `json:"last_set"`
}

ChannelTopicPurpose holds the topic or purpose of a channel

type CloseResponse

type CloseResponse struct {
	NoOp          bool `json:"no_op"`
	AlreadyClosed bool `json:"already_closed"`
	// contains filtered or unexported fields
}

CloseResponse is returned for close requests

func (*CloseResponse) Error

func (r *CloseResponse) Error() string

func (*CloseResponse) IsOK

func (r *CloseResponse) IsOK() bool

type Comment

type Comment struct {
	ID        string     `json:"id"`
	Timestamp int64      `json:"timestamp"`
	User      string     `json:"user"`
	Comment   string     `json:"comment"`
	Created   int64      `json:"created,omitempty"`
	Reactions []Reaction `json:"reactions,omitempty"`
}

Comment holds information about a file comment

type CommentResponse

type CommentResponse struct {
	Comment Comment `json:"comment"`
	// contains filtered or unexported fields
}

CommentResponse is returned for comment actions

func (*CommentResponse) Error

func (r *CommentResponse) Error() string

func (*CommentResponse) IsOK

func (r *CommentResponse) IsOK() bool

type EmojiListResponse

type EmojiListResponse struct {
	Emoji map[string]string `json:"emoji"`
	// contains filtered or unexported fields
}

EmojiListResponse is returned for the emoji list request

func (*EmojiListResponse) Error

func (r *EmojiListResponse) Error() string

func (*EmojiListResponse) IsOK

func (r *EmojiListResponse) IsOK() bool

type Error

type Error struct {
	ID     string `json:"id"`
	Detail string `json:"detail"`
}

Error is returned when there is a known condition error in the API

func (*Error) Error

func (e *Error) Error() string

type File

type File struct {
	ID      string `json:"id"`
	Created int64  `json:"created"`

	Name       string `json:"name"`
	Title      string `json:"title,omitempty"`
	Mimetype   string `json:"mimetype"`
	Filetype   string `json:"filetype"`
	PrettyType string `json:"pretty_type"`
	UserID     string `json:"user"`

	Mode         string `json:"mode,omitempty"`
	Editable     bool   `json:"editable"`
	IsExternal   bool   `json:"is_external"`
	ExternalType string `json:"external_type,omitempty"`

	Size int `json:"size"`

	URL                string `json:"url,omitempty"`
	URLDownload        string `json:"url_download,omitempty"`
	URLPrivate         string `json:"url_private,omitempty"`
	URLPrivateDownload string `json:"url_private_download,omitempty"`

	Thumb64     string `json:"thumb_64,omitempty"`
	Thumb80     string `json:"thumb_80,omitempty"`
	Thumb360    string `json:"thumb_360,omitempty"`
	Thumb360Gif string `json:"thumb_360_gif,omitempty"`
	Thumb360W   int    `json:"thumb_360_w"`
	Thumb360H   int    `json:"thumb_360_h"`

	Permalink        string `json:"permalink,omitempty"`
	EditLink         string `json:"edit_link,omitempty"`
	Preview          string `json:"preview,omitempty"`
	PreviewHighlight string `json:"preview_highlight,omitempty"`
	Lines            int    `json:"lines"`
	LinesMore        int    `json:"lines_more"`

	IsPublic        bool     `json:"is_public"`
	PublicURLShared bool     `json:"public_url_shared"`
	Channels        []string `json:"channels,omitempty"`
	Groups          []string `json:"groups,omitempty"`
	InitialComment  Comment  `json:"initial_comment,omitempty"`
	NumStars        int      `json:"num_stars"`
	IsStarred       bool     `json:"is_starred"`

	Reactions []Reaction `json:"reactions,omitempty"`
}

File holds information about a file

type FileListResponse

type FileListResponse struct {
	Files  []File `json:"files"`
	Paging paging `json:"paging"`
	// contains filtered or unexported fields
}

FileListResponse is the response to the file list command

func (*FileListResponse) Error

func (r *FileListResponse) Error() string

func (*FileListResponse) IsOK

func (r *FileListResponse) IsOK() bool

type FileResponse

type FileResponse struct {
	File     File      `json:"file"`
	Comments []Comment `json:"comments"`
	Paging   paging    `json:"paging"`
	// contains filtered or unexported fields
}

FileResponse for file info command

func (*FileResponse) Error

func (r *FileResponse) Error() string

func (*FileResponse) IsOK

func (r *FileResponse) IsOK() bool

type FileUploadResponse

type FileUploadResponse struct {
	File File `json:"file"`
	// contains filtered or unexported fields
}

FileUploadResponse is the response to the file upload command

func (*FileUploadResponse) Error

func (r *FileUploadResponse) Error() string

func (*FileUploadResponse) IsOK

func (r *FileUploadResponse) IsOK() bool

type Group

type Group struct {
	BaseChannel
	IsGroup bool `json:"is_group"`
}

Group holds information about the group

type GroupListResponse

type GroupListResponse struct {
	Groups []Group `json:"groups"`
	// contains filtered or unexported fields
}

GroupListResponse holds a response to a group list request

func (*GroupListResponse) Error

func (r *GroupListResponse) Error() string

func (*GroupListResponse) IsOK

func (r *GroupListResponse) IsOK() bool

type GroupResponse

type GroupResponse struct {
	Group Group `json:"group"`
	// contains filtered or unexported fields
}

GroupResponse holds a response to a group request

func (*GroupResponse) Error

func (r *GroupResponse) Error() string

func (*GroupResponse) IsOK

func (r *GroupResponse) IsOK() bool

type HistoryResponse

type HistoryResponse struct {
	Latest   string    `json:"latest"`
	HasMore  bool      `json:"has_more"`
	Messages []Message `json:"messages"`
	// contains filtered or unexported fields
}

HistoryResponse holds a response to a history request

func (*HistoryResponse) Error

func (r *HistoryResponse) Error() string

func (*HistoryResponse) IsOK

func (r *HistoryResponse) IsOK() bool

type IM

type IM struct {
	BaseChannel
	IsIM          bool   `json:"is_im"`
	User          string `json:"user"`
	IsUserDeleted bool   `json:"is_user_deleted"`
}

IM holds information about IM

type IMListResponse

type IMListResponse struct {
	IMs []IM `json:"ims"`
	// contains filtered or unexported fields
}

IMListResponse holds a response to an IM list request

func (*IMListResponse) Error

func (r *IMListResponse) Error() string

func (*IMListResponse) IsOK

func (r *IMListResponse) IsOK() bool

type InviteeType

type InviteeType int

InviteeType for the invite

const (
	// InviteeRegular without any restrictions
	InviteeRegular InviteeType = iota
	// InviteeRestricted to certain channels and groups
	InviteeRestricted
	// InviteeUltraRestricted to a single channel or group
	InviteeUltraRestricted
)

type Message

type Message struct {
	Type      string `json:"type"`
	Channel   string `json:"channel"`
	User      string `json:"user"`
	Text      string `json:"text"`
	Timestamp string `json:"ts"`
	Hidden    bool   `json:"hidden,omitempty"`
	Subtype   string `json:"subtype,omitempty"`
	Edited    struct {
		User      string `json:"user"`
		Timestamp string `json:"ts"`
	} `json:"edited,omitempty"`
	Message struct {
		Type      string `json:"type"`
		User      string `json:"user"`
		Text      string `json:"text"`
		Timestamp string `json:"ts"`
		Edited    struct {
			User      string `json:"user"`
			Timestamp string `json:"ts"`
		} `json:"edited,omitempty"`
	} `json:"message,omitempty"`
	DeletedTS string     `json:"deleted_ts,omitempty"`
	Topic     string     `json:"topic,omitempty"`
	Purpose   string     `json:"purpose,omitempty"`
	Name      string     `json:"name,omitempty"`
	OldName   string     `json:"old_name,omitempty"`
	Members   []string   `json:"members,omitempty"`
	Upload    bool       `json:"upload,omitempty"`
	File      File       `json:"file,omitempty"`
	Comment   Comment    `json:"comment,omitempty"`
	Reactions []Reaction `json:"reactions,omitempty"`
	Error     struct {
		Code int    `json:"code"`
		Msg  string `json:"msg"`
	} `json:"error,omitempty"`
	Context interface{} `json:"context,omitempty"` // A piece of data that will be passed with every message from RTMStart
}

Message holds the information about incoming messages in the RTM

type OAuthAccessResponse

type OAuthAccessResponse struct {
	AccessToken string `json:"access_token"`
	Scope       string `json:"scope"`
	// contains filtered or unexported fields
}

OAuthAccessResponse - See https://api.slack.com/methods/oauth.access

func OAuthAccess

func OAuthAccess(clientID, clientSecret, code, redirectURI string) (*OAuthAccessResponse, error)

OAuthAccess returns the token for OAuth

func (*OAuthAccessResponse) Error

func (r *OAuthAccessResponse) Error() string

func (*OAuthAccessResponse) IsOK

func (r *OAuthAccessResponse) IsOK() bool

type OptionFunc

type OptionFunc func(*Slack) error

OptionFunc is a function that configures a Client. It is used in New

func SetHTTPClient

func SetHTTPClient(httpClient *http.Client) OptionFunc

SetHTTPClient can be used to specify the http.Client to use when making requests to Slack.

func SetToken

func SetToken(token string) OptionFunc

SetToken sets the Slack API token to use

func SetURL

func SetURL(rawurl string) OptionFunc

SetURL defines the URL endpoint for Slack

type PostMessageReply

type PostMessageReply struct {
	Channel   string             `json:"channel"`
	Timestamp string             `json:"ts"`
	Message   PostMessageRequest `json:"message"`
	// contains filtered or unexported fields
}

PostMessageReply is the reply to the post message request - see https://api.slack.com/methods/chat.postMessage

func (*PostMessageReply) Error

func (r *PostMessageReply) Error() string

func (*PostMessageReply) IsOK

func (r *PostMessageReply) IsOK() bool

type PostMessageRequest

type PostMessageRequest struct {
	Channel     string       `json:"channel"`
	Text        string       `json:"text"`
	Username    string       `json:"username"`
	AsUser      bool         `json:"as_user"`
	Parse       string       `json:"parse"`
	LinkNames   int          `json:"link_names"`
	Attachments []Attachment `json:"attachments"`
	UnfurlLinks bool         `json:"unfurl_links"`
	UnfurlMedia bool         `json:"unfurl_media"`
	IconURL     string       `json:"icon_url"`
	IconEmoji   string       `json:"icon_emoji"`
}

PostMessageRequest includes all the fields in the post message request - see https://api.slack.com/methods/chat.postMessage

type PurposeResponse

type PurposeResponse struct {
	Purpose string `json:"purpose"`
	// contains filtered or unexported fields
}

PurposeResponse is the response to setPurpose request

func (*PurposeResponse) Error

func (r *PurposeResponse) Error() string

func (*PurposeResponse) IsOK

func (r *PurposeResponse) IsOK() bool

type RTMMessage

type RTMMessage struct {
	ID      int    `json:"id"`
	Type    string `json:"type"`
	Channel string `json:"channel"`
	Text    string `json:"text"`
}

RTMMessage is sent on the channel for simple text

type RTMStartReply

type RTMStartReply struct {
	URL  string `json:"url"`
	Self struct {
		ID             string                 `json:"id"`
		Name           string                 `json:"name"`
		Prefs          map[string]interface{} `json:"prefs"`
		Created        int64                  `json:"created"`
		ManualPresence string                 `json:"manual_presence"`
	} `json:"self"`
	Team          Team      `json:"team"`
	LatestEventTS string    `json:"latest_event_ts"`
	Channels      []Channel `json:"channels"`
	Groups        []Group   `json:"groups"`
	IMS           []IM      `json:"ims"`
	Users         []User    `json:"users"`
	Bots          []Bot     `json:"bots"`
	// contains filtered or unexported fields
}

RTMStartReply holds the reply to the RTM start message with info about everything

func (*RTMStartReply) Error

func (r *RTMStartReply) Error() string

func (*RTMStartReply) IsOK

func (r *RTMStartReply) IsOK() bool

type Reaction

type Reaction struct {
	Name  string   `json:"name"`
	Count int      `json:"count"`
	Uesrs []string `json:"users"`
}

Reaction contains the reaction details

type ReactionsGetResponse

type ReactionsGetResponse struct {
	Type    string  `json:"type"`
	Channel string  `json:"channel,omitempty"`
	Message Message `json:"message,omitempty"`
	File    File    `json:"file,omitempty"`
	Comment Comment `json:"comment,omitempty"`
	// contains filtered or unexported fields
}

ReactionsGetResponse is the response to the ReactionsGet request

func (*ReactionsGetResponse) Error

func (r *ReactionsGetResponse) Error() string

func (*ReactionsGetResponse) IsOK

func (r *ReactionsGetResponse) IsOK() bool

type ReactionsListResponse

type ReactionsListResponse struct {
	Items  ReactionsGetResponse `json:"items"`
	Paging paging               `json:"paging"`
	// contains filtered or unexported fields
}

ReactionsListResponse is the response to the ReactionsList request

func (*ReactionsListResponse) Error

func (r *ReactionsListResponse) Error() string

func (*ReactionsListResponse) IsOK

func (r *ReactionsListResponse) IsOK() bool

type Response

type Response interface {
	IsOK() bool
	Error() string
}

Response interface represents any reply from Slack with the basic ok, error methods

type Slack

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

Slack is the client to the Slack API.

func New

func New(options ...OptionFunc) (*Slack, error)

New creates a new Slack client.

The caller can configure the new client by passing configuration options to the func.

Example:

s, err := slack.New(
  slack.SetURL("https://some.url.com:port/"),
  slack.SetErrorLog(log.New(os.Stderr, "Slack: ", log.Lshortfile),
  slack.SetToken("Your-Token"))

You must provide either a token or the OAuth parameters to retrieve the token. If no URL is configured, Slack uses DefaultURL by default.

If no HttpClient is configured, then http.DefaultClient is used. You can use your own http.Client with some http.Transport for advanced scenarios.

An error is also returned when some configuration option is invalid.

func (*Slack) Archive

func (s *Slack) Archive(channel string) (Response, error)

Archive a channel or a group

func (*Slack) AuthTest

func (s *Slack) AuthTest() (*AuthTestResponse, error)

AuthTest tests if the authentication is in place - see https://api.slack.com/methods/auth.test

func (*Slack) ChannelCreate

func (s *Slack) ChannelCreate(name string) (*ChannelResponse, error)

ChannelCreate creates a channel

func (*Slack) ChannelInfo

func (s *Slack) ChannelInfo(channel string) (*ChannelResponse, error)

ChannelInfo returns info about the channel

func (*Slack) ChannelInvite

func (s *Slack) ChannelInvite(channel, user string) (*ChannelResponse, error)

ChannelInvite invites a user to a group

func (*Slack) ChannelJoin

func (s *Slack) ChannelJoin(channel string) (*ChannelResponse, error)

ChannelJoin joins a channel - notice that this expects channel name and not id

func (*Slack) ChannelList

func (s *Slack) ChannelList(excludeArchived bool) (*ChannelListResponse, error)

ChannelList returns the list of channels

func (*Slack) CloseGroupOrIM

func (s *Slack) CloseGroupOrIM(id string) (*CloseResponse, error)

CloseGroupOrIM closes the given id

func (*Slack) EmojiList

func (s *Slack) EmojiList() (*EmojiListResponse, error)

EmojiList returns the list of emoji

func (*Slack) FileAddComment

func (s *Slack) FileAddComment(file, comment string, setActive bool) (*CommentResponse, error)

FileAddComment to a given file

func (*Slack) FileInfo

func (s *Slack) FileInfo(file string, count, page int) (*FileResponse, error)

FileInfo command

func (*Slack) FileList

func (s *Slack) FileList(user, tsFrom, tsTo string, types []string, count, page int) (*FileListResponse, error)

FileList the files for the team

func (*Slack) GroupCreate

func (s *Slack) GroupCreate(name string) (*GroupResponse, error)

GroupCreate creates a new group with the given name

func (*Slack) GroupCreateChild

func (s *Slack) GroupCreateChild(group string) (*GroupResponse, error)

GroupCreateChild archives existing group and creates a new group with the given name

func (*Slack) GroupInfo

func (s *Slack) GroupInfo(group string) (*GroupResponse, error)

GroupInfo returns info about the group

func (*Slack) GroupInvite

func (s *Slack) GroupInvite(channel, user string) (*GroupResponse, error)

GroupInvite invites a user to a group

func (*Slack) GroupList

func (s *Slack) GroupList(excludeArchived bool) (*GroupListResponse, error)

GroupList returns the list of groups

func (*Slack) History

func (s *Slack) History(channel, latest, oldest string, inclusive bool, count int) (*HistoryResponse, error)

History retrieves history of channel, group and IM

func (*Slack) IMList

func (s *Slack) IMList() (*IMListResponse, error)

IMList returns the list of IMs

func (*Slack) InviteToSlack

func (s *Slack) InviteToSlack(invitee UserInviteDetails, channels []string, inviteType InviteeType) error

InviteToSlack invites the given user to your team. You can use inviteType (0 - regular, 1 - restricted with a list of channels, 2 - single channel user)

func (*Slack) Kick

func (s *Slack) Kick(channel, user string) (Response, error)

Kick a user from a channel or group

func (*Slack) Leave

func (s *Slack) Leave(channel string) (Response, error)

Leave a channel or a group

func (*Slack) Mark

func (s *Slack) Mark(channel, ts string) error

Mark marks the given channel as read. Automatically detects channel/group/im

func (*Slack) OpenGroupOrIM

func (s *Slack) OpenGroupOrIM(id string) (*CloseResponse, error)

OpenGroupOrIM closes the given id

func (*Slack) PostMessage

func (s *Slack) PostMessage(m *PostMessageRequest, escape bool) (*PostMessageReply, error)

PostMessage posts a message to a channel

func (*Slack) RTMSend

func (s *Slack) RTMSend(channel, text string) (int, error)

RTMSend a simple text message to a channel/group/dm

func (*Slack) RTMStart

func (s *Slack) RTMStart(origin string, in chan *Message, context interface{}) (*RTMStartReply, error)

RTMStart starts the websocket

func (*Slack) RTMStop

func (s *Slack) RTMStop() error

RTMStop closes the WebSocket which in turn closes the in channel passed in RTMStart

func (*Slack) ReactionsAdd

func (s *Slack) ReactionsAdd(name, file, fileComment, channel, timestamp string) (Response, error)

ReactionsAdd to either file, fileComment or a combination of channel and timestamp

func (*Slack) ReactionsGet

func (s *Slack) ReactionsGet(file, fileComment, channel, timestamp string, full bool) (*ReactionsGetResponse, error)

ReactionsGet for either file, fileComment or a combination of channel and timestamp

func (*Slack) ReactionsList

func (s *Slack) ReactionsList(user string, full bool, count, page int) (*ReactionsListResponse, error)

ReactionsList filtered by user (optional and defaults to current)

func (*Slack) ReactionsRemove

func (s *Slack) ReactionsRemove(name, file, fileComment, channel, timestamp string) (Response, error)

ReactionsRemove from either file, fileComment or a combination of channel and timestamp

func (*Slack) Rename

func (s *Slack) Rename(channel, name string) (*ChannelCommonResponse, error)

Rename a channel or a group

func (*Slack) SetPurpose

func (s *Slack) SetPurpose(channel, purpose string) (*PurposeResponse, error)

SetPurpose of the channel / group

func (*Slack) SetTopic

func (s *Slack) SetTopic(channel, purpose string) (*TopicResponse, error)

SetTopic of the channel / group

func (*Slack) TeamInfo

func (s *Slack) TeamInfo() (*TeamInfoResponse, error)

TeamInfo returns info about the team

func (*Slack) Unarchive

func (s *Slack) Unarchive(channel string) (Response, error)

Unarchive a channel or a group

func (*Slack) Upload

func (s *Slack) Upload(title, filetype, filename, initialComment string, channels []string, data io.Reader) (*FileUploadResponse, error)

Upload a file to Slack optionally sharing it on given channels

func (*Slack) UserInfo

func (s *Slack) UserInfo(user string) (*UserInfoResponse, error)

UserInfo returns info about the requested user

func (*Slack) UserList

func (s *Slack) UserList() (*UserListResponse, error)

UserList returns the list of users

type Team

type Team struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	EmailDomain string                 `json:"email_domain"`
	Domain      string                 `json:"domain"`
	Prefs       map[string]interface{} `json:"prefs"`
	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"`
	} `json:"icon"`
	OverStorageLimit bool   `json:"over_storage_limit"`
	Plan             string `json:"plan"`
}

Team holds information about the team

type TeamInfoResponse

type TeamInfoResponse struct {
	Team Team `json:"team"`
	// contains filtered or unexported fields
}

TeamInfoResponse holds thre response to the team info request

func (*TeamInfoResponse) Error

func (r *TeamInfoResponse) Error() string

func (*TeamInfoResponse) IsOK

func (r *TeamInfoResponse) IsOK() bool

type TopicResponse

type TopicResponse struct {
	Topic string `json:"topic"`
	// contains filtered or unexported fields
}

TopicResponse is the response to setTopic request

func (*TopicResponse) Error

func (r *TopicResponse) Error() string

func (*TopicResponse) IsOK

func (r *TopicResponse) IsOK() bool

type User

type User struct {
	ID                string      `json:"id"`
	Name              string      `json:"name"`
	Deleted           bool        `json:"deleted"`
	Color             string      `json:"color"`
	RealName          string      `json:"real_name"`
	TZ                string      `json:"tz,omitempty"`
	TZLabel           string      `json:"tz_label"`
	TZOffset          int         `json:"tz_offset"`
	Profile           UserProfile `json:"profile"`
	IsBot             bool        `json:"is_bot"`
	IsAdmin           bool        `json:"is_admin"`
	IsOwner           bool        `json:"is_owner"`
	IsPrimaryOwner    bool        `json:"is_primary_owner"`
	IsRestricted      bool        `json:"is_restricted"`
	IsUltraRestricted bool        `json:"is_ultra_restricted"`
	Has2FA            bool        `json:"has_2fa"`
	HasFiles          bool        `json:"has_files"`
	Presence          string      `json:"presence"`
}

User contains all the information of a user

type UserInfoResponse

type UserInfoResponse struct {
	User User `json:"user"`
	// contains filtered or unexported fields
}

UserInfoResponse holds the response to a user info request

func (*UserInfoResponse) Error

func (r *UserInfoResponse) Error() string

func (*UserInfoResponse) IsOK

func (r *UserInfoResponse) IsOK() bool

type UserInviteDetails

type UserInviteDetails struct {
	Email     string `json:"email"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
}

UserInviteDetails with first and last name optional

type UserListResponse

type UserListResponse struct {
	Members []User `json:"members"`
	// contains filtered or unexported fields
}

UserListResponse holds the response for the user list request

func (*UserListResponse) Error

func (r *UserListResponse) Error() string

func (*UserListResponse) IsOK

func (r *UserListResponse) IsOK() bool

type UserPresence

type UserPresence struct {
	Presence        string `json:"presence,omitempty"`
	Online          bool   `json:"online,omitempty"`
	AutoAway        bool   `json:"auto_away,omitempty"`
	ManualAway      bool   `json:"manual_away,omitempty"`
	ConnectionCount int    `json:"connection_count,omitempty"`
	LastActivity    int64  `json:"last_activity,omitempty"`
}

UserPresence contains details about a user online status

type UserProfile

type UserProfile struct {
	FirstName          string `json:"first_name"`
	LastName           string `json:"last_name"`
	RealName           string `json:"real_name"`
	RealNameNormalized string `json:"real_name_normalized"`
	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"`
	ImageOriginal      string `json:"image_original"`
	Title              string `json:"title"`
}

UserProfile contains all the information details of a given user

type WSMessageResponse

type WSMessageResponse struct {
	OK      bool `json:"ok"`
	ReplyTo int  `json:"reply_to"`
	Error   struct {
		Code int    `json:"code"`
		Msg  string `json:"msg"`
	} `json:"error"`
}

WSMessageResponse holds a response to a WS request

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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