slack

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthTestResult

type AuthTestResult struct {
	UserID string `json:"user_id"`
	User   string `json:"user"`
	TeamID string `json:"team_id"`
	Team   string `json:"team"`
	URL    string `json:"url"`
}

type Channel

type Channel struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Topic      string `json:"topic,omitempty"`
	Purpose    string `json:"purpose,omitempty"`
	NumMembers int    `json:"num_members"`
	IsArchived bool   `json:"is_archived"`
	IsPrivate  bool   `json:"is_private"`
	IsMember   bool   `json:"is_member"`
	Created    int    `json:"created"`
}

type Client

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

func NewClient

func NewClient(token string, opts ...Option) *Client

func (*Client) AddReaction

func (c *Client) AddReaction(channelID, timestamp, name string) error

func (*Client) ArchiveChannel

func (c *Client) ArchiveChannel(channelID string) error

func (*Client) AuthTest

func (c *Client) AuthTest() (*AuthTestResult, error)

func (*Client) CreateChannel

func (c *Client) CreateChannel(name string, isPrivate bool) (*Channel, error)

func (*Client) DeleteFile

func (c *Client) DeleteFile(fileID string) error

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(channelID, timestamp string) error

func (*Client) DownloadFile

func (c *Client) DownloadFile(url, destPath string) error

func (*Client) EditMessage

func (c *Client) EditMessage(channelID, timestamp, text string) (*Message, error)

func (*Client) GetChannelInfo

func (c *Client) GetChannelInfo(channelID string) (*Channel, error)

func (*Client) GetFileInfo

func (c *Client) GetFileInfo(fileID string) (*File, error)

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(userID string) (*User, error)

func (*Client) GetUserPresence

func (c *Client) GetUserPresence(userID string) (string, error)

func (*Client) InviteToChannel

func (c *Client) InviteToChannel(channelID string, userIDs ...string) error

func (*Client) KickFromChannel

func (c *Client) KickFromChannel(channelID, userID string) error

func (*Client) ListChannels

func (c *Client) ListChannels(params PaginationParams) (*PaginatedResult[Channel], error)

func (*Client) ListFiles

func (c *Client) ListFiles(params PaginationParams, channelID, userID string) (*PaginatedResult[File], error)

func (*Client) ListMessages

func (c *Client) ListMessages(params ListMessagesParams) (*PaginatedResult[Message], error)

func (*Client) ListReactions

func (c *Client) ListReactions(userID string, params PaginationParams) (*PaginatedResult[ReactedItem], error)

func (*Client) ListUsers

func (c *Client) ListUsers(params PaginationParams) (*PaginatedResult[User], error)

func (*Client) RemoveReaction

func (c *Client) RemoveReaction(channelID, timestamp, name string) error

func (*Client) SearchMessages

func (c *Client) SearchMessages(params SearchParams) (*SearchResult, error)

func (*Client) SendMessage

func (c *Client) SendMessage(params SendMessageParams) (*Message, error)

func (*Client) SetChannelPurpose

func (c *Client) SetChannelPurpose(channelID, purpose string) error

func (*Client) SetChannelTopic

func (c *Client) SetChannelTopic(channelID, topic string) error

func (*Client) UploadFile

func (c *Client) UploadFile(channelID, filename, title string, reader io.Reader) (*File, error)

type ErrorCode

type ErrorCode string
const (
	ErrAuth       ErrorCode = "auth_error"
	ErrRateLimit  ErrorCode = "rate_limited"
	ErrNotFound   ErrorCode = "not_found"
	ErrPermission ErrorCode = "permission_denied"
	ErrValidation ErrorCode = "validation_error"
	ErrAPI        ErrorCode = "api_error"
	ErrNetwork    ErrorCode = "network_error"
)

type File

type File struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Title      string `json:"title"`
	Mimetype   string `json:"mimetype"`
	Filetype   string `json:"filetype"`
	Size       int    `json:"size"`
	User       string `json:"user"`
	Created    int64  `json:"created"`
	URLPrivate string `json:"url_private"`
	Permalink  string `json:"permalink"`
}

type ListMessagesParams

type ListMessagesParams struct {
	ChannelID  string
	Pagination PaginationParams
	Oldest     time.Time
	Latest     time.Time
}

type Message

type Message struct {
	Timestamp string `json:"timestamp"`
	User      string `json:"user"`
	Text      string `json:"text"`
	ThreadTS  string `json:"thread_ts,omitempty"`
	Channel   string `json:"channel,omitempty"`
	Type      string `json:"type"`
	Permalink string `json:"permalink,omitempty"`
}

type Option

type Option func(*Client)

func WithDebug

func WithDebug() Option

type PaginatedResult

type PaginatedResult[T any] struct {
	Items      []T    `json:"items"`
	NextCursor string `json:"next_cursor,omitempty"`
	HasMore    bool   `json:"has_more"`
}

type PaginationParams

type PaginationParams struct {
	Cursor string
	Limit  int
	All    bool
}

func (PaginationParams) EffectiveLimit

func (p PaginationParams) EffectiveLimit() int

type ReactedItem

type ReactedItem struct {
	Type      string     `json:"type"`
	Channel   string     `json:"channel,omitempty"`
	Timestamp string     `json:"timestamp,omitempty"`
	Reactions []Reaction `json:"reactions"`
}

type Reaction

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

type SearchFilesResult

type SearchFilesResult struct {
	Matches []File `json:"matches"`
	Total   int    `json:"total"`
}

type SearchParams

type SearchParams struct {
	Query      string
	Sort       string
	SortDir    string
	Pagination PaginationParams
}

type SearchResult

type SearchResult struct {
	Matches []Message `json:"matches"`
	Total   int       `json:"total"`
}

type SendMessageParams

type SendMessageParams struct {
	ChannelID      string
	Text           string
	ThreadTS       string
	ReplyBroadcast bool
}

type Service

type Service interface {
	AuthTest() (*AuthTestResult, error)

	ListChannels(params PaginationParams) (*PaginatedResult[Channel], error)
	GetChannelInfo(channelID string) (*Channel, error)
	CreateChannel(name string, isPrivate bool) (*Channel, error)
	ArchiveChannel(channelID string) error
	InviteToChannel(channelID string, userIDs ...string) error
	KickFromChannel(channelID, userID string) error
	SetChannelTopic(channelID, topic string) error
	SetChannelPurpose(channelID, purpose string) error

	ListMessages(params ListMessagesParams) (*PaginatedResult[Message], error)
	SendMessage(params SendMessageParams) (*Message, error)
	EditMessage(channelID, timestamp, text string) (*Message, error)
	DeleteMessage(channelID, timestamp string) error
	SearchMessages(params SearchParams) (*SearchResult, error)

	ListUsers(params PaginationParams) (*PaginatedResult[User], error)
	GetUserInfo(userID string) (*User, error)
	GetUserPresence(userID string) (string, error)

	AddReaction(channelID, timestamp, name string) error
	RemoveReaction(channelID, timestamp, name string) error
	ListReactions(userID string, params PaginationParams) (*PaginatedResult[ReactedItem], error)

	ListFiles(params PaginationParams, channelID, userID string) (*PaginatedResult[File], error)
	GetFileInfo(fileID string) (*File, error)
	UploadFile(channelID, filename, title string, reader io.Reader) (*File, error)
	DownloadFile(url, destPath string) error
	DeleteFile(fileID string) error
}

Service defines the interface for all Slack API operations. *Client satisfies this interface.

type SlackError

type SlackError struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
	Detail  string    `json:"detail,omitempty"`
	Err     error     `json:"-"`
}

func (*SlackError) Error

func (e *SlackError) Error() string

func (*SlackError) Unwrap

func (e *SlackError) Unwrap() error

type User

type User struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	RealName string `json:"real_name"`
	Email    string `json:"email,omitempty"`
	IsAdmin  bool   `json:"is_admin"`
	IsBot    bool   `json:"is_bot"`
	Deleted  bool   `json:"deleted"`
	TZ       string `json:"tz,omitempty"`
	Presence string `json:"presence,omitempty"`
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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