slack

package module
v0.0.0-...-4a78045 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2015 License: BSD-2-Clause Imports: 18 Imported by: 0

README

Slack API in Go

Installing

go get

$ go get github.com/nlopes/slack

Example

Getting all groups

import (
	"fmt"

	"github.com/nlopes/slack"
)

func main() {
	api := slack.New("YOUR_TOKEN_HERE")
	// If you set debugging, it will log all requests to the console
	// Useful when encountering issues
	// api.SetDebug(true)
	groups, err := api.GetGroups(false)
	if err != nil {
		fmt.Printf("%s\n", err)
		return
	}
	for _, group := range groups {
		fmt.Printf("Id: %s, Name: %s\n", group.Id, group.Name)
	}
}

Getting User Information

import (
    "fmt"

    "github.com/nlopes/slack"
)

func main() {
    api := slack.New("YOUR_TOKEN_HERE")
    user, err := api.GetUserInfo("U023BECGF")
    if err != nil {
	    fmt.Printf("%s\n", err)
	    return
    }
    fmt.Printf("Id: %s, Fullname: %s, Email: %s\n", user.Id, user.Profile.RealName, user.Profile.Email)
}

Why?

I am currently learning Go and this seemed like a good idea.

Stability

As with any other piece of software expect bugs. Also, the design isn't finalized yet because I am not happy with how I laid out some things. Especially the websocket stuff. It is functional but very incomplete and buggy.

Help

Anyone is welcome to contribute. Either open a PR or create an issue.

License

BSD 2 Clause license

Documentation

Index

Constants

View Source
const (
	DEFAULT_MESSAGE_USERNAME     = ""
	DEFAULT_MESSAGE_PARSE        = ""
	DEFAULT_MESSAGE_LINK_NAMES   = 0
	DEFAULT_MESSAGE_UNFURL_LINKS = true
	DEFAULT_MESSAGE_UNFURL_MEDIA = false
	DEFAULT_MESSAGE_ICON_URL     = ""
	DEFAULT_MESSAGE_ICON_EMOJI   = ""
)
View Source
const (
	// Add here the defaults in the siten
	DEFAULT_FILES_USERID  = ""
	DEFAULT_FILES_TS_FROM = 0
	DEFAULT_FILES_TS_TO   = -1
	DEFAULT_FILES_TYPES   = "all"
	DEFAULT_FILES_COUNT   = 100
	DEFAULT_FILES_PAGE    = 1
)
View Source
const (
	DEFAULT_HISTORY_LATEST    = ""
	DEFAULT_HISTORY_OLDEST    = "0"
	DEFAULT_HISTORY_COUNT     = 100
	DEFAULT_HISTORY_INCLUSIVE = false
)
View Source
const (
	DEFAULT_SEARCH_SORT      = "score"
	DEFAULT_SEARCH_SORT_DIR  = "desc"
	DEFAULT_SEARCH_HIGHLIGHT = false
	DEFAULT_SEARCH_COUNT     = 100
	DEFAULT_SEARCH_PAGE      = 1
)
View Source
const (
	DEFAULT_STARS_USERID = ""
	DEFAULT_STARS_COUNT  = 100
	DEFAULT_STARS_PAGE   = 1
)

Variables

View Source
var SLACK_API string = "https://slack.com/api/"

Added as a var so that we can change this for testing purposes

Functions

func GetOAuthToken

func GetOAuthToken(clientId, clientSecret, code, redirectURI string, debug bool) (accessToken string, scope string, err error)

GetOAuthToken retrieves an AccessToken

Types

type AccountsChangedEvent

type AccountsChangedEvent struct {
	Type string `json:"type"`
}

type AckMessage

type AckMessage struct {
	ReplyTo   int    `json:"reply_to"`
	Timestamp string `json:"ts"`
	Text      string `json:"text"`
	SlackResponse
}

AckMessage is used for messages received in reply to other messages

type Attachment

type Attachment struct {
	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"`

	Fields []AttachmentField `json:"fields,omitempty"`
}

Attachment contains all the information for an attachment

type AttachmentField

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

AttachmentField contains information for an attachment field An Attachment can contain multiple of these

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"`
}

type Bot

type Bot struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	Deleted bool   `json:"deleted"`
	Icons   Icons  `json:"icons"`
}

Bot contains information about a bot

type BotAddedEvent

type BotAddedEvent struct {
	Type string `json:"type"`
	Bot  Bot    `json:"bot"`
}

type BotChangedEvent

type BotChangedEvent struct {
	Type string `json:"type"`
	Bot  Bot    `json:"bot"`
}

type Channel

type Channel struct {
	Id                 string         `json:"id"`
	Name               string         `json:"name"`
	IsChannel          bool           `json:"is_channel"`
	Created            JSONTime       `json:"created"`
	Creator            string         `json:"creator"`
	IsArchived         bool           `json:"is_archived"`
	IsGeneral          bool           `json:"is_general"`
	IsGroup            bool           `json:"is_group"`
	IsStarred          bool           `json:"is_starred"`
	Members            []string       `json:"members"`
	Topic              ChannelTopic   `json:"topic"`
	Purpose            ChannelPurpose `json:"purpose"`
	IsMember           bool           `json:"is_member"`
	LastRead           string         `json:"last_read,omitempty"`
	Latest             Message        `json:"latest,omitempty"`
	UnreadCount        int            `json:"unread_count,omitempty"`
	NumMembers         int            `json:"num_members,omitempty"`
	UnreadCountDisplay int            `json:"unread_count_display,omitempty"`
}

Channel contains information about the channel

type ChannelArchiveEvent

type ChannelArchiveEvent ChannelInfoEvent

type ChannelCreatedEvent

type ChannelCreatedEvent struct {
	Type           string             `json:"type"`
	Channel        ChannelCreatedInfo `json:"channel"`
	EventTimestamp JSONTimeString     `json:"event_ts"`
}

type ChannelCreatedInfo

type ChannelCreatedInfo struct {
	Id        string         `json:"id"`
	IsChannel bool           `json:"is_channel"`
	Name      string         `json:"name"`
	Created   JSONTimeString `json:"created"`
	Creator   string         `json:"creator"`
}

type ChannelDeletedEvent

type ChannelDeletedEvent ChannelInfoEvent

type ChannelHistoryChangedEvent

type ChannelHistoryChangedEvent struct {
	Type           string         `json:"type"`
	Latest         JSONTimeString `json:"latest"`
	Timestamp      JSONTimeString `json:"ts"`
	EventTimestamp JSONTimeString `json:"event_ts"`
}

type ChannelInfoEvent

type ChannelInfoEvent struct {
	// channel_left
	// channel_deleted
	// channel_archive
	// channel_unarchive
	Type      string         `json:"type"`
	ChannelId string         `json:"channel"`
	UserId    string         `json:"user,omitempty"`
	Timestamp JSONTimeString `json:"ts,omitempty"`
}

type ChannelJoinedEvent

type ChannelJoinedEvent struct {
	Type    string  `json:"type"`
	Channel Channel `json:"channel"`
}

type ChannelLeftEvent

type ChannelLeftEvent ChannelInfoEvent

type ChannelMarkedEvent

type ChannelMarkedEvent ChannelInfoEvent

type ChannelPurpose

type ChannelPurpose struct {
	Value   string   `json:"value"`
	Creator string   `json:"creator"`
	LastSet JSONTime `json:"last_set"`
}

ChannelPurpose contains information about the channel purpose

type ChannelRenameEvent

type ChannelRenameEvent struct {
	Type    string            `json:"type"`
	Channel ChannelRenameInfo `json:"channel"`
}

type ChannelRenameInfo

type ChannelRenameInfo struct {
	Id      string   `json:"id"`
	Name    string   `json:"name"`
	Created JSONTime `json:"created"`
}

type ChannelTopic

type ChannelTopic struct {
	Value   string   `json:"value"`
	Creator string   `json:"creator"`
	LastSet JSONTime `json:"last_set"`
}

ChannelTopic contains information about the channel topic

type ChannelUnarchiveEvent

type ChannelUnarchiveEvent ChannelInfoEvent

type CommandsChangedEvent

type CommandsChangedEvent struct {
	Type           string         `json:"type"`
	EventTimestamp JSONTimeString `json:"event_ts"`
}

type Comment

type Comment struct {
	Id        string   `json:"id"`
	Timestamp JSONTime `json:"timestamp"`
	UserId    string   `json:"user"`
	Comment   string   `json:"comment"`
	Created   JSONTime `json:"created,omitempty"`
}

Comment contains all the information relative to a comment

type Config

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

Config contains some config parameters needed Token always needs to be set for the api to function Origin and Protocol are optional and only needed for websocket

type CtxChannel

type CtxChannel struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

type CtxMessage

type CtxMessage struct {
	UserId    string `json:"user"`
	Username  string `json:"username"`
	Text      string `json:"text"`
	Timestamp string `json:"ts"`
	Type      string `json:"type"`
}

type EmailDomainChangedEvent

type EmailDomainChangedEvent struct {
	Type           string         `json:"type"`
	EventTimestamp JSONTimeString `json:"event_ts"`
	EmailDomain    string         `json:"email_domain"`
}

type EmojiChangedEvent

type EmojiChangedEvent struct {
	Type           string         `json:"type"`
	EventTimestamp JSONTimeString `json:"event_ts"`
}

type Event

type Event struct {
	Type string `json:"type,omitempty"`
}

Event contains the event type

type File

type File struct {
	Id        string   `json:"id"`
	Created   JSONTime `json:"created"`
	Timestamp JSONTime `json:"timestamp"`

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

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

	Size int `json:"size"`

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

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

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

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

File contains all the information for a file

type FileChangeEvent

type FileChangeEvent fileActionEvent

type FileCommentAddedEvent

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

type FileCommentDeletedEvent

type FileCommentDeletedEvent struct {
	CommentId string `json:"comment"`
	// contains filtered or unexported fields
}

type FileCommentEditedEvent

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

type FileCreatedEvent

type FileCreatedEvent fileActionEvent

type FileDeletedEvent

type FileDeletedEvent fileActionEvent

type FilePrivateEvent

type FilePrivateEvent fileActionEvent

type FilePublicEvent

type FilePublicEvent fileActionEvent

type FileSharedEvent

type FileSharedEvent fileActionEvent

type FileUnsharedEvent

type FileUnsharedEvent fileActionEvent

type FileUploadParameters

type FileUploadParameters struct {
	File           string
	Content        string
	Filetype       string
	Filename       string
	Title          string
	InitialComment string
	Channels       []string
}

FileUploadParameters contains all the parameters necessary (including the optional ones) for an UploadFile() request

type GetFilesParameters

type GetFilesParameters struct {
	UserId        string
	TimestampFrom JSONTime
	TimestampTo   JSONTime
	Types         string
	Count         int
	Page          int
}

GetFilesParameters contains all the parameters necessary (including the optional ones) for a GetFiles() request

func NewGetFilesParameters

func NewGetFilesParameters() GetFilesParameters

NewGetFilesParameters provides an instance of GetFilesParameters with all the sane default values set

type Group

type Group struct {
	Id                 string         `json:"id"`
	Name               string         `json:"name"`
	IsGroup            bool           `json:"is_group"`
	Created            JSONTime       `json:"created"`
	Creator            string         `json:"creator"`
	IsArchived         bool           `json:"is_archived"`
	IsGeneral          bool           `json:"is_general"`
	IsOpen             bool           `json:"is_open,omitempty"`
	Members            []string       `json:"members"`
	Topic              ChannelTopic   `json:"topic"`
	Purpose            ChannelPurpose `json:"purpose"`
	LastRead           string         `json:"last_read,omitempty"`
	Latest             Message        `json:"latest,omitempty"`
	UnreadCount        int            `json:"unread_count,omitempty"`
	NumMembers         int            `json:"num_members,omitempty"`
	UnreadCountDisplay int            `json:"unread_count_display,omitempty"`

	// XXX: does this exist for a group too?
	IsMember bool `json:"is_member"`
}

Group contains all the information for a group

type GroupArchiveEvent

type GroupArchiveEvent ChannelInfoEvent

type GroupCloseEvent

type GroupCloseEvent ChannelInfoEvent

type GroupCreatedEvent

type GroupCreatedEvent struct {
	Type    string             `json:"type"`
	UserId  string             `json:"user"`
	Channel ChannelCreatedInfo `json:"channel"`
}

type GroupHistoryChangedEvent

type GroupHistoryChangedEvent ChannelHistoryChangedEvent

type GroupJoinedEvent

type GroupJoinedEvent ChannelJoinedEvent

type GroupLeftEvent

type GroupLeftEvent ChannelInfoEvent

type GroupMarkedEvent

type GroupMarkedEvent ChannelInfoEvent

XXX: Should we really do this? event.Group is probably nicer than event.Channel even though the api returns "channel"

type GroupOpenEvent

type GroupOpenEvent ChannelInfoEvent

type GroupRenameEvent

type GroupRenameEvent ChannelRenameEvent

type GroupUnarchiveEvent

type GroupUnarchiveEvent ChannelInfoEvent

type HelloEvent

type HelloEvent struct{}

type History

type History struct {
	Latest   string    `json:"latest"`
	Messages []Message `json:"messages"`
	HasMore  bool      `json:"has_more"`
}

History contains message history information needed to navigate a Channel / Group / DM history

type HistoryParameters

type HistoryParameters struct {
	Latest    string
	Oldest    string
	Count     int
	Inclusive bool
}

HistoryParameters contains all the necessary information to help in the retrieval of history for Channels/Groups/DMs

func NewHistoryParameters

func NewHistoryParameters() HistoryParameters

NewHistoryParameters provides an instance of HistoryParameters with all the sane default values set

type IM

type IM struct {
	Id                 string   `json:"id"`
	IsIM               bool     `json:"is_im"`
	UserId             string   `json:"user"`
	Created            JSONTime `json:"created"`
	IsUserDeleted      bool     `json:"is_user_deleted"`
	UnreadCount        int      `json:"unread_count,omitempty"`
	UnreadCountDisplay int      `json:"unread_count_display,omitempty"`
}

IM contains information related to the Direct Message channel

type IMCloseEvent

type IMCloseEvent ChannelInfoEvent

type IMCreatedEvent

type IMCreatedEvent struct {
	Type    string             `json:"type"`
	UserId  string             `json:"user"`
	Channel ChannelCreatedInfo `json:"channel"`
}

type IMHistoryChangedEvent

type IMHistoryChangedEvent ChannelHistoryChangedEvent

type IMMarkedEvent

type IMMarkedEvent ChannelInfoEvent

type IMMarkedHistoryChanged

type IMMarkedHistoryChanged ChannelInfoEvent

type IMOpenEvent

type IMOpenEvent ChannelInfoEvent

type Icons

type Icons struct {
	Image48 string `json:"image_48"`
}

Icons XXX: needs further investigation

type Info

type Info struct {
	Url      string      `json:"url,omitempty"`
	User     UserDetails `json:"self,omitempty"`
	Team     Team        `json:"team,omitempty"`
	Users    []User      `json:"users,omitempty"`
	Channels []Channel   `json:"channels,omitempty"`
	Bots     []Bot       `json:"bots,omitempty"`
	IMs      []IM        `json:"ims,omitempty"`
}

Info contains various details about Users, Channels, Bots and the authenticated user It is returned by StartRTM

func (Info) GetBotById

func (info Info) GetBotById(botId string) *Bot

GetBotById returns a bot given a bot id

func (Info) GetChannelById

func (info Info) GetChannelById(channelId string) *Channel

GetChannelById returns a channel given a channel id

func (Info) GetUserById

func (info Info) GetUserById(userId string) *User

GetUserById returns a user given a user id

type JSONTime

type JSONTime int64

JSONTime exists so that we can have a String method converting the date

func (JSONTime) String

func (t JSONTime) String() string

String converts the unix timestamp into a string

type JSONTimeString

type JSONTimeString string

func (JSONTimeString) String

func (t JSONTimeString) String() string

String converts the unix timestamp into a string

type LatencyReport

type LatencyReport struct {
	Value time.Duration
}

type ManualPresenceChangeEvent

type ManualPresenceChangeEvent struct {
	Type     string `json:"type"`
	Presence string `json:"presence"`
}

type Message

type Message struct {
	Msg
	SubMessage Msg `json:"message,omitempty"`
}

Message is an auxiliary type to allow us to have a message containing sub messages

type MessageEvent

type MessageEvent Message

type Msg

type Msg struct {
	Id        string `json:"id"`
	BotId     string `json:"bot_id,omitempty"`
	UserId    string `json:"user,omitempty"`
	Username  string `json:"username,omitempty"`
	ChannelId string `json:"channel,omitempty"`
	Timestamp string `json:"ts,omitempty"`
	Text      string `json:"text,omitempty"`
	Team      string `json:"team,omitempty"`
	File      File   `json:"file,omitempty"`
	// Type may come if it's part of a message list
	// e.g.: channel.history
	Type      string `json:"type,omitempty"`
	IsStarred bool   `json:"is_starred,omitempty"`
	// Submessage
	SubType          string       `json:"subtype,omitempty"`
	Hidden           bool         `json:"bool,omitempty"`
	DeletedTimestamp string       `json:"deleted_ts,omitempty"`
	Attachments      []Attachment `json:"attachments,omitempty"`
	ReplyTo          int          `json:"reply_to,omitempty"`
	Upload           bool         `json:"upload,omitempty"`
}

Msg contains information about a slack message

type OutgoingMessage

type OutgoingMessage struct {
	Id        int    `json:"id"`
	ChannelId string `json:"channel,omitempty"`
	Text      string `json:"text,omitempty"`
	Type      string `json:"type,omitempty"`
}

type Pagination

type Pagination struct {
	TotalCount int `json:"total_count"`
	Page       int `json:"page"`
	PerPage    int `json:"per_page"`
	PageCount  int `json:"page_count"`
	First      int `json:"first"`
	Last       int `json:"last"`
}

Pagination contains pagination information This is different from Paging in that it contains additional details

type Paging

type Paging struct {
	Count int `json:"count"`
	Total int `json:"total"`
	Page  int `json:"page"`
	Pages int `json:"pages"`
}

Paging contains paging information

type Ping

type Ping struct {
	Id   int    `json:"id"`
	Type string `json:"type"`
}

Ping contains information about a Ping Event

type Pong

type Pong struct {
	Type    string `json:"type"`
	ReplyTo int    `json:"reply_to"`
}

Pong contains information about a Pong Event

type PostMessageParameters

type PostMessageParameters struct {
	Text        string
	Username    string
	AsUser      bool `json:"as_user,omitempty"`
	Parse       string
	LinkNames   int
	Attachments []Attachment
	UnfurlLinks bool
	UnfurlMedia bool
	IconURL     string
	IconEmoji   string
}

PostMessageParameters contains all the parameters necessary (including the optional ones) for a PostMessage() request

func NewPostMessageParameters

func NewPostMessageParameters() PostMessageParameters

NewPostMessageParameters provides an instance of PostMessageParameters with all the sane default values set

type PrefChangeEvent

type PrefChangeEvent struct {
	Type  string          `json:"type"`
	Name  string          `json:"name"`
	Value json.RawMessage `json:"value"`
}

type Presence

type Presence struct {
	Presence string `json:"presence"`
	UserId   string `json:"user"`
}

Presence XXX: not used yet

type PresenceChangeEvent

type PresenceChangeEvent struct {
	Type     string `json:"type"`
	Presence string `json:"presence"`
	UserId   string `json:"user"`
}

type SearchFiles

type SearchFiles struct {
	Matches    []File `json:"matches"`
	Paging     `json:"paging"`
	Pagination `json:"pagination"`
	Total      int `json:"total"`
}

type SearchMessage

type SearchMessage struct {
	Type      string     `json:"type"`
	Channel   CtxChannel `json:"channel"`
	UserId    string     `json:"user"`
	Username  string     `json:"username"`
	Timestamp string     `json:"ts"`
	Text      string     `json:"text"`
	Permalink string     `json:"permalink"`
	Previous  CtxMessage `json:"previous"`
	Previous2 CtxMessage `json:"previous_2"`
	Next      CtxMessage `json:"next"`
	Next2     CtxMessage `json:"next_2"`
}

type SearchMessages

type SearchMessages struct {
	Matches    []SearchMessage `json:"matches"`
	Paging     `json:"paging"`
	Pagination `json:"pagination"`
	Total      int `json:"total"`
}

type SearchParameters

type SearchParameters struct {
	Sort          string
	SortDirection string
	Highlight     bool
	Count         int
	Page          int
}

func NewSearchParameters

func NewSearchParameters() SearchParameters

type Slack

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

func New

func New(token string) *Slack

func (*Slack) ArchiveChannel

func (api *Slack) ArchiveChannel(channelId string) error

ArchiveChannel archives the given channel

func (*Slack) ArchiveGroup

func (api *Slack) ArchiveGroup(groupId string) error

ArchiveGroup archives a private group

func (*Slack) AuthTest

func (api *Slack) AuthTest() (response *AuthTestResponse, error error)

AuthTest tests if the user is able to do authenticated requests or not

func (*Slack) CloseGroup

func (api *Slack) CloseGroup(groupId string) (bool, bool, error)

CloseGroup closes a private group

func (*Slack) CloseIMChannel

func (api *Slack) CloseIMChannel(channelId string) (bool, bool, error)

CloseIMChannel closes the direct message channel

func (*Slack) CreateChannel

func (api *Slack) CreateChannel(channel string) (*Channel, error)

CreateChannel creates a channel with the given name and returns a *Channel

func (*Slack) CreateChildGroup

func (api *Slack) CreateChildGroup(groupId string) (*Group, error)

CreateChildGroup creates a new private group archiving the old one This method takes an existing private group and performs the following steps:

  1. Renames the existing group (from "example" to "example-archived").
  2. Archives the existing group.
  3. Creates a new group with the name of the existing group.
  4. Adds all members of the existing group to the new group.

func (*Slack) CreateGroup

func (api *Slack) CreateGroup(group string) (*Group, error)

CreateGroup creates a private group

func (*Slack) DeleteFile

func (api *Slack) DeleteFile(fileId string) error

DeleteFile deletes a file

func (*Slack) DeleteMessage

func (api *Slack) DeleteMessage(channelId, messageTimestamp string) (string, string, error)

DeleteMessage deletes a message in a channel

func (*Slack) GetChannelHistory

func (api *Slack) GetChannelHistory(channelId string, params HistoryParameters) (*History, error)

GetChannelHistory retrieves the channel history

func (*Slack) GetChannelInfo

func (api *Slack) GetChannelInfo(channelId string) (*Channel, error)

GetChannelInfo retrieves the given channel

func (*Slack) GetChannels

func (api *Slack) GetChannels(excludeArchived bool) ([]Channel, error)

GetChannels retrieves all the channels

func (*Slack) GetEmoji

func (api *Slack) GetEmoji() (map[string]string, error)

GetEmoji retrieves all the emojis

func (*Slack) GetFileInfo

func (api *Slack) GetFileInfo(fileId string, count, page int) (*File, []Comment, *Paging, error)

GetFileInfo retrieves a file and related comments

func (*Slack) GetFiles

func (api *Slack) GetFiles(params GetFilesParameters) ([]File, *Paging, error)

GetFiles retrieves all files according to the parameters given

func (*Slack) GetGroupHistory

func (api *Slack) GetGroupHistory(groupId string, params HistoryParameters) (*History, error)

GetGroupHistory retrieves message history for a give group

func (*Slack) GetGroups

func (api *Slack) GetGroups(excludeArchived bool) ([]Group, error)

GetGroups retrieves all groups

func (*Slack) GetIMChannels

func (api *Slack) GetIMChannels() ([]IM, error)

GetIMChannels returns the list of direct message channels

func (*Slack) GetIMHistory

func (api *Slack) GetIMHistory(channelId string, params HistoryParameters) (*History, error)

GetIMHistory retrieves the direct message channel history

func (*Slack) GetInfo

func (api *Slack) GetInfo() Info

func (*Slack) GetStarred

func (api *Slack) GetStarred(params StarsParameters) ([]StarredItem, *Paging, error)

GetStarred returns a list of StarredItem items. The user then has to iterate over them and figure out what they should be looking at according to what is in the Type.

for _, item := range items {
    switch c.Type {
    case "file_comment":
        log.Println(c.Comment)
    case "file":
         ...
    }
}

func (*Slack) GetUserInfo

func (api *Slack) GetUserInfo(userId string) (*User, error)

GetUserInfo will retrive the complete user information

func (*Slack) GetUserPresence

func (api *Slack) GetUserPresence(userId string) (*UserPresence, error)

GetUserPresence will retrieve the current presence status of given user.

func (*Slack) GetUsers

func (api *Slack) GetUsers() ([]User, error)

GetUsers returns the list of users (with their detailed information)

func (*Slack) InviteUserToChannel

func (api *Slack) InviteUserToChannel(channelId, userId string) (*Channel, error)

InviteUserToChannel invites a user to a given channel and returns a *Channel

func (*Slack) InviteUserToGroup

func (api *Slack) InviteUserToGroup(groupId, userId string) (*Group, bool, error)

InviteUserToGroup invites a user to a group

func (*Slack) JoinChannel

func (api *Slack) JoinChannel(channel string) (*Channel, error)

JoinChannel joins the currently authenticated user to a channel

func (*Slack) KickUserFromChannel

func (api *Slack) KickUserFromChannel(channelId, userId string) error

KickUserFromChannel kicks a user from a given channel

func (*Slack) KickUserFromGroup

func (api *Slack) KickUserFromGroup(groupId, userId string) error

KickUserFromGroup kicks a user from a group

func (*Slack) LeaveChannel

func (api *Slack) LeaveChannel(channelId string) (bool, error)

LeaveChannel makes the authenticated user leave the given channel

func (*Slack) LeaveGroup

func (api *Slack) LeaveGroup(groupId string) error

LeaveGroup makes authenticated user leave the group

func (*Slack) MarkIMChannel

func (api *Slack) MarkIMChannel(channelId, ts string) (err error)

MarkIMChannel sets the read mark of a direct message channel to a specific point

func (*Slack) OpenGroup

func (api *Slack) OpenGroup(groupId string) (bool, bool, error)

OpenGroup opens a private group

func (*Slack) OpenIMChannel

func (api *Slack) OpenIMChannel(userId string) (bool, bool, string, error)

OpenIMChannel opens a direct message channel to the user provided as argument Returns some status and the channelId

func (*Slack) PostMessage

func (api *Slack) PostMessage(channelId string, text string, params PostMessageParameters) (channel string, timestamp string, err error)

PostMessage sends a message to a channel Message is automatically escaped according to https://api.slack.com/docs/formatting

func (*Slack) RenameChannel

func (api *Slack) RenameChannel(channelId, name string) (*Channel, error)

RenameChannel renames a given channel

func (*Slack) RenameGroup

func (api *Slack) RenameGroup(groupId, name string) (*Channel, error)

RenameGroup renames a group XXX: They return a channel, not a group. What is this crap? :( Inconsistent api it seems.

func (*Slack) Search

func (api *Slack) Search(query string, params SearchParameters) (*SearchMessages, *SearchFiles, error)

func (*Slack) SearchFiles

func (api *Slack) SearchFiles(query string, params SearchParameters) (*SearchFiles, error)

func (*Slack) SearchMessages

func (api *Slack) SearchMessages(query string, params SearchParameters) (*SearchMessages, error)

func (*Slack) SetChannelPurpose

func (api *Slack) SetChannelPurpose(channelId, purpose string) (string, error)

SetChannelPurpose sets the channel purpose and returns the purpose that was successfully set

func (*Slack) SetChannelReadMark

func (api *Slack) SetChannelReadMark(channelId, ts string) error

SetChannelReadMark sets the read mark of a given channel to a specific point Clients should try to avoid making this call too often. When needing to mark a read position, a client should set a timer before making the call. In this way, any further updates needed during the timeout will not generate extra calls (just one per channel). This is useful for when reading scroll-back history, or following a busy live channel. A timeout of 5 seconds is a good starting point. Be sure to flush these calls on shutdown/logout.

func (*Slack) SetChannelTopic

func (api *Slack) SetChannelTopic(channelId, topic string) (string, error)

SetChannelTopic sets the channel topic and returns the topic that was successfully set

func (*Slack) SetDebug

func (api *Slack) SetDebug(debug bool)

SetDebug switches the api into debug mode When in debug mode, it logs various info about what its doing If you ever use this in production, don't call SetDebug(true)

func (*Slack) SetGroupPurpose

func (api *Slack) SetGroupPurpose(groupId, purpose string) (string, error)

SetGroupPurpose sets the group purpose

func (*Slack) SetGroupReadMark

func (api *Slack) SetGroupReadMark(groupId, ts string) error

SetGroupReadMark sets the read mark on a private group Clients should try to avoid making this call too often. When needing to mark a read position, a client should set a timer before making the call. In this way, any further updates needed during the timeout will not generate extra calls (just one per channel). This is useful for when reading scroll-back history, or following a busy live channel. A timeout of 5 seconds is a good starting point. Be sure to flush these calls on shutdown/logout.

func (*Slack) SetGroupTopic

func (api *Slack) SetGroupTopic(groupId, topic string) (string, error)

SetGroupTopic sets the group topic

func (*Slack) SetUserAsActive

func (api *Slack) SetUserAsActive() error

SetUserAsActive marks the currently authenticated user as active

func (*Slack) SetUserPresence

func (api *Slack) SetUserPresence(presence string) error

SetUserPresence changes the currently authenticated user presence

func (*Slack) StartRTM

func (api *Slack) StartRTM(protocol, origin string) (*SlackWS, error)

func (*Slack) UnarchiveChannel

func (api *Slack) UnarchiveChannel(channelId string) error

UnarchiveChannel unarchives the given channel

func (*Slack) UnarchiveGroup

func (api *Slack) UnarchiveGroup(groupId string) error

UnarchiveGroup unarchives a private group

func (*Slack) UpdateMessage

func (api *Slack) UpdateMessage(channelId, timestamp, text string) (string, string, string, error)

UpdateMessage updates a message in a channel

func (*Slack) UploadFile

func (api *Slack) UploadFile(params FileUploadParameters) (file *File, err error)

UploadFile uploads a file

type SlackEvent

type SlackEvent struct {
	Type uint64
	Data interface{}
}

type SlackResponse

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

type SlackWS

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

func (*SlackWS) HandleIncomingEvents

func (api *SlackWS) HandleIncomingEvents(ch chan SlackEvent)

func (*SlackWS) Keepalive

func (api *SlackWS) Keepalive(interval time.Duration)

func (*SlackWS) NewOutgoingMessage

func (api *SlackWS) NewOutgoingMessage(text string, channel string) *OutgoingMessage

NewOutGoingMessage prepares an OutgoingMessage that the user can use to send a message

func (*SlackWS) Ping

func (api *SlackWS) Ping() error

func (*SlackWS) SendMessage

func (api *SlackWS) SendMessage(msg *OutgoingMessage) error

type SlackWSError

type SlackWSError struct {
	Code int
	Msg  string
}

func (SlackWSError) Error

func (s SlackWSError) Error() string

type SlackWSResponse

type SlackWSResponse struct {
	Ok    bool          `json:"ok"`
	Error *SlackWSError `json:"error"`
}

type StarAddedEvent

type StarAddedEvent starEvent

type StarRemovedEvent

type StarRemovedEvent starEvent

type StarredItem

type StarredItem struct {
	Type      string `json:"type"`
	ChannelId string `json:"channel"`
	Message   `json:"message,omitempty"`
	File      `json:"file,omitempty"`
	Comment   `json:"comment,omitempty"`
}

TODO: Verify this. The whole thing is complicated. I don't like the way they mixed things It also appears to be a bug in parsing the message

type StarsParameters

type StarsParameters struct {
	User  string
	Count int
	Page  int
}

func NewStarsParameters

func NewStarsParameters() StarsParameters

type Team

type Team struct {
	Id     string `json:"id"`
	Name   string `json:"name"`
	Domain string `json:"name"`
}

Team contains details about a team

type TeamDomainChangeEvent

type TeamDomainChangeEvent struct {
	Type   string `json:"type"`
	Url    string `json:"url"`
	Domain string `json:"domain"`
}

type TeamJoinEvent

type TeamJoinEvent struct {
	Type string `json:"type"`
	User User   `json:"user,omitempty"`
}

type TeamMigrationStartedEvent

type TeamMigrationStartedEvent struct {
	Type string `json:"type"`
}

type TeamPrefChangeEvent

type TeamPrefChangeEvent struct {
	Type  string   `json:"type"`
	Name  string   `json:"name,omitempty"`
	Value []string `json:"value,omitempty"`
}

type TeamRenameEvent

type TeamRenameEvent struct {
	Type           string         `json:"type"`
	Name           string         `json:"name,omitempty"`
	EventTimestamp JSONTimeString `json:"event_ts,omitempty"`
}

type User

type User struct {
	Id                string      `json:"id"`
	Name              string      `json:"name"`
	Deleted           bool        `json:"deleted"`
	Color             string      `json:"color"`
	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"`
	HasFiles          bool        `json:"has_files"`
	Presence          string      `json:"presence"`
}

User contains all the information of a user

type UserChangeEvent

type UserChangeEvent struct {
	Type string `json:"type"`
	User User   `json:"user"`
}

type UserDetails

type UserDetails struct {
	Id             string    `json:"id"`
	Name           string    `json:"name"`
	Created        JSONTime  `json:"created"`
	ManualPresence string    `json:"manual_presence"`
	Prefs          UserPrefs `json:"prefs"`
}

UserDetails contains user details coming in the initial response from StartRTM

type UserPrefs

type UserPrefs struct {
}

XXX: Need to implement

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    JSONTime `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 UserTypingEvent

type UserTypingEvent struct {
	Type      string `json:"type"`
	UserId    string `json:"user"`
	ChannelId string `json:"channel"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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