slack

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Canvas

type Canvas struct {
	ID    string `json:"id,omitempty"`
	Title string `json:"title,omitempty"`
}

Canvas represents minimal Slack canvas DTO.

type CanvasService

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

CanvasService provides Slack canvas operations.

func (*CanvasService) CreateCanvas

func (s *CanvasService) CreateCanvas(ctx context.Context, title, text string) (*Canvas, error)

CreateCanvas creates a canvas with initial markdown content.

func (*CanvasService) ShareCanvas

func (s *CanvasService) ShareCanvas(ctx context.Context, canvasID, channelID, accessLevel string) error

ShareCanvas shares canvas access with a channel.

type Client

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

Client is Slack Web API client.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates Slack Web API client.

func (*Client) Canvas

func (c *Client) Canvas() *CanvasService

Canvas returns canvas API service.

func (*Client) Conversations

func (c *Client) Conversations() *ConversationsService

Conversations returns conversations API service.

func (*Client) Messages

func (c *Client) Messages() *MessagesService

Messages returns messages API service.

func (*Client) UserGroups

func (c *Client) UserGroups() *UserGroupsService

UserGroups returns user groups API service.

func (*Client) Users

func (c *Client) Users() *UsersService

Users returns users API service.

func (*Client) Views

func (c *Client) Views() *ViewsService

Views returns views API service.

type Conversation

type Conversation struct {
	ID            string `json:"id"`
	Name          string `json:"name,omitempty"`
	IsChannel     bool   `json:"is_channel,omitempty"`
	IsGroup       bool   `json:"is_group,omitempty"`
	IsPrivate     bool   `json:"is_private,omitempty"`
	IsArchived    bool   `json:"is_archived,omitempty"`
	NumMembers    int    `json:"num_members,omitempty"`
	Creator       string `json:"creator,omitempty"`
	IsGeneral     bool   `json:"is_general,omitempty"`
	IsShared      bool   `json:"is_shared,omitempty"`
	IsExtShared   bool   `json:"is_ext_shared,omitempty"`
	IsOrgShared   bool   `json:"is_org_shared,omitempty"`
	ContextTeamID string `json:"context_team_id,omitempty"`
}

Conversation is a minimal Slack conversation DTO.

type ConversationsService

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

ConversationsService provides Slack conversation operations.

func (*ConversationsService) CreateConversation

func (s *ConversationsService) CreateConversation(ctx context.Context, name string, isPrivate bool) (*Conversation, error)

CreateConversation creates a Slack channel.

func (*ConversationsService) GetChannelByID

func (s *ConversationsService) GetChannelByID(ctx context.Context, channelID string) (*Conversation, error)

GetChannelByID returns conversation by channel ID.

func (*ConversationsService) GetConversationList

func (s *ConversationsService) GetConversationList(ctx context.Context, excludeArchived bool, channelTypes []string) ([]Conversation, error)

GetConversationList returns conversations and follows cursor pagination.

func (*ConversationsService) GetHistory added in v0.5.0

GetHistory fetches message history from a conversation. Uses conversations.history Slack API method.

func (*ConversationsService) GetReplies added in v0.5.0

GetReplies fetches replies (thread messages) for a given parent message. Uses conversations.replies Slack API method.

func (*ConversationsService) InviteUsersToChannel

func (s *ConversationsService) InviteUsersToChannel(ctx context.Context, userIDs []string, channelID string) (*Conversation, error)

InviteUsersToChannel invites users to a channel.

type EphemeralPostResult

type EphemeralPostResult struct {
	Channel   string `json:"channel,omitempty"`
	MessageTS string `json:"message_ts,omitempty"`
}

EphemeralPostResult contains fields returned by chat.postEphemeral.

type Error

type Error struct {
	Code     string
	Needed   string
	Provided string
	Warning  string
}

Error describes Slack API errors when JSON contains ok=false.

func (*Error) Error

func (e *Error) Error() string

Error formats Slack API error details.

type GetHistoryRequest added in v0.5.0

type GetHistoryRequest struct {
	Channel            string `json:"channel"`
	Cursor             string `json:"cursor,omitempty"`
	IncludeAllMetadata bool   `json:"include_all_metadata,omitempty"`
	Inclusive          bool   `json:"inclusive,omitempty"`
	Latest             string `json:"latest,omitempty"`
	Oldest             string `json:"oldest,omitempty"`
	Limit              int    `json:"limit,omitempty"`
}

GetHistoryRequest contains parameters for conversations.history.

type GetRepliesRequest added in v0.5.0

type GetRepliesRequest struct {
	Channel            string `json:"channel"`
	TS                 string `json:"ts"`
	Cursor             string `json:"cursor,omitempty"`
	IncludeAllMetadata bool   `json:"include_all_metadata,omitempty"`
	Inclusive          bool   `json:"inclusive,omitempty"`
	Latest             string `json:"latest,omitempty"`
	Oldest             string `json:"oldest,omitempty"`
	Limit              int    `json:"limit,omitempty"`
}

GetRepliesRequest contains parameters for conversations.replies.

type HistoryResponse added in v0.5.0

type HistoryResponse struct {
	Messages         []Message        `json:"messages"`
	HasMore          bool             `json:"has_more"`
	PinCount         int              `json:"pin_count,omitempty"`
	ResponseMetadata ResponseMetadata `json:"response_metadata"`
}

HistoryResponse is the response from conversations.history and conversations.replies.

type ListUserGroupUsersRequest added in v0.8.2

type ListUserGroupUsersRequest struct {
	UserGroup       string `json:"usergroup"`
	IncludeDisabled bool   `json:"include_disabled,omitempty"`
	TeamID          string `json:"team_id,omitempty"`
}

ListUserGroupUsersRequest contains parameters for usergroups.users.list.

type ListUsersRequest added in v0.8.2

type ListUsersRequest struct {
	Cursor        string `json:"cursor,omitempty"`
	IncludeLocale bool   `json:"include_locale,omitempty"`
	Limit         int    `json:"limit,omitempty"`
	TeamID        string
	FetchAll      bool
	// FetchAllThrottle defines pause between page requests when FetchAll=true.
	// If <=0, a safe default of 1 second is used.
	FetchAllThrottle time.Duration
}

ListUsersRequest contains parameters for users.list.

type ListUsersResponse added in v0.8.2

type ListUsersResponse struct {
	Members          []User           `json:"members"`
	CacheTS          int64            `json:"cache_ts,omitempty"`
	ResponseMetadata ResponseMetadata `json:"response_metadata"`
}

ListUsersResponse is the response from users.list.

type Message

type Message struct {
	Type       string `json:"type,omitempty"`
	SubType    string `json:"subtype,omitempty"`
	User       string `json:"user,omitempty"`
	Text       string `json:"text,omitempty"`
	TS         string `json:"ts,omitempty"`
	ThreadTS   string `json:"thread_ts,omitempty"`
	ReplyCount int    `json:"reply_count,omitempty"`
}

Message is a minimal Slack message DTO.

type MessagesService

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

MessagesService provides Slack messaging operations.

func (*MessagesService) PostEphemeralMessage

func (s *MessagesService) PostEphemeralMessage(ctx context.Context, req *PostEphemeralRequest) (*EphemeralPostResult, error)

PostEphemeralMessage posts an ephemeral message visible only to a specific user.

func (*MessagesService) PostMessage

func (s *MessagesService) PostMessage(ctx context.Context, req *PostMessageRequest) (*PostedMessage, error)

PostMessage posts a message to a channel.

func (*MessagesService) UpdateMessage

func (s *MessagesService) UpdateMessage(ctx context.Context, req *UpdateMessageRequest) (*PostedMessage, error)

UpdateMessage updates an existing message.

type ModalViewRequest

type ModalViewRequest struct {
	Type            string           `json:"type,omitempty"`
	CallbackID      string           `json:"callback_id,omitempty"`
	Title           *ViewText        `json:"title,omitempty"`
	Close           *ViewText        `json:"close,omitempty"`
	Submit          *ViewText        `json:"submit,omitempty"`
	Blocks          []map[string]any `json:"blocks,omitempty"`
	PrivateMetadata string           `json:"private_metadata,omitempty"`
	ExternalID      string           `json:"external_id,omitempty"`
}

ModalViewRequest describes modal/home view payload for views.open/views.update.

type OpenViewResult

type OpenViewResult struct {
	View View `json:"view"`
}

OpenViewResult contains fields returned by views.open/views.update.

type Option

type Option func(*config)

Option configures Slack client.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL overrides Slack API base URL.

func WithTeamID

func WithTeamID(teamID string) Option

WithTeamID sets optional team_id for grid/org tokens.

func WithToken

func WithToken(token string) Option

WithToken sets Bot/User token used in Authorization header.

func WithTransport

func WithTransport(tr *transport.Client) Option

WithTransport injects shared transport client.

type PostEphemeralRequest added in v0.4.0

type PostEphemeralRequest struct {
	Channel     string `json:"channel"`
	User        string `json:"user"`
	Text        string `json:"text,omitempty"`
	Blocks      []any  `json:"blocks,omitempty"`
	Attachments []any  `json:"attachments,omitempty"`
	ThreadTS    string `json:"thread_ts,omitempty"`
}

PostEphemeralRequest is the payload for chat.postEphemeral.

type PostMessageRequest added in v0.4.0

type PostMessageRequest struct {
	Channel     string         `json:"channel"`
	Text        string         `json:"text,omitempty"`
	Blocks      []any          `json:"blocks,omitempty"`
	Attachments []any          `json:"attachments,omitempty"`
	ThreadTS    string         `json:"thread_ts,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
	UnfurlLinks *bool          `json:"unfurl_links,omitempty"`
	UnfurlMedia *bool          `json:"unfurl_media,omitempty"`
}

PostMessageRequest is the payload for chat.postMessage. Blocks and Attachments accept any JSON-serializable structs (e.g. slack-go block types, maps, or custom structs).

type PostedMessage

type PostedMessage struct {
	Channel string  `json:"channel,omitempty"`
	TS      string  `json:"ts,omitempty"`
	Message Message `json:"message,omitempty"`
}

PostedMessage contains main fields returned by chat post/update methods.

type ResponseMetadata

type ResponseMetadata struct {
	NextCursor string `json:"next_cursor"`
}

ResponseMetadata is Slack cursor pagination metadata.

type SocketModeClient

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

SocketModeClient manages Slack socket mode lifecycle.

func NewSocketModeClient

func NewSocketModeClient(opts ...SocketModeOption) *SocketModeClient

NewSocketModeClient creates a socket mode client.

func (*SocketModeClient) Run

func (c *SocketModeClient) Run(ctx context.Context) error

Run starts socket mode processing loop.

func (*SocketModeClient) RunWithHandler

func (c *SocketModeClient) RunWithHandler(ctx context.Context, handler SocketModeHandler) error

RunWithHandler starts socket mode loop and dispatches events to handler.

type SocketModeConn

type SocketModeConn interface {
	ReadJSON(v any) error
	WriteJSON(v any) error
	Close() error
}

SocketModeConn abstracts websocket connection used by socket mode client.

type SocketModeDialer

type SocketModeDialer interface {
	Dial(ctx context.Context, wsURL string) (SocketModeConn, error)
}

SocketModeDialer opens websocket connection to provided URL.

type SocketModeEvent

type SocketModeEvent struct {
	Type                   string          `json:"type,omitempty"`
	EnvelopeID             string          `json:"envelope_id,omitempty"`
	AcceptsResponsePayload bool            `json:"accepts_response_payload,omitempty"`
	Payload                json.RawMessage `json:"payload,omitempty"`
	RetryAttempt           int             `json:"retry_attempt,omitempty"`
	RetryReason            string          `json:"retry_reason,omitempty"`
	Reason                 string          `json:"reason,omitempty"`
}

SocketModeEvent is a single event envelope delivered over socket mode.

type SocketModeHandler

type SocketModeHandler interface {
	HandleEvent(ctx context.Context, event SocketModeEvent) (*SocketModeResponse, error)
}

SocketModeHandler processes socket mode events.

type SocketModeHandlerFunc

type SocketModeHandlerFunc func(ctx context.Context, event SocketModeEvent) (*SocketModeResponse, error)

SocketModeHandlerFunc adapts function to SocketModeHandler.

func (SocketModeHandlerFunc) HandleEvent

HandleEvent calls f(ctx, event).

type SocketModeOption

type SocketModeOption func(*socketModeConfig)

SocketModeOption configures SocketModeClient.

func WithAppLevelToken

func WithAppLevelToken(appToken string) SocketModeOption

WithAppLevelToken sets app-level token for socket mode.

func WithSocketModeBaseURL

func WithSocketModeBaseURL(baseURL string) SocketModeOption

WithSocketModeBaseURL overrides Slack API base URL for apps.connections.open.

func WithSocketModeDialer

func WithSocketModeDialer(dialer SocketModeDialer) SocketModeOption

WithSocketModeDialer overrides websocket dialer implementation.

func WithSocketModeLogger

func WithSocketModeLogger(logger transport.Logger) SocketModeOption

WithSocketModeLogger sets optional logger for socket mode runtime diagnostics.

func WithSocketModeReconnectDelay

func WithSocketModeReconnectDelay(delay time.Duration) SocketModeOption

WithSocketModeReconnectDelay sets reconnect delay after connection errors.

func WithSocketModeTransport

func WithSocketModeTransport(tr *transport.Client) SocketModeOption

WithSocketModeTransport injects transport used by apps.connections.open calls.

type SocketModeResponse

type SocketModeResponse struct {
	Payload any `json:"payload,omitempty"`
}

SocketModeResponse contains optional payload sent in envelope ACK.

type UpdateMessageRequest added in v0.4.0

type UpdateMessageRequest struct {
	Channel     string         `json:"channel"`
	TS          string         `json:"ts"`
	Text        string         `json:"text,omitempty"`
	Blocks      []any          `json:"blocks,omitempty"`
	Attachments []any          `json:"attachments,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

UpdateMessageRequest is the payload for chat.update.

type UpdateUserGroupUsersRequest added in v0.8.2

type UpdateUserGroupUsersRequest struct {
	UserGroup          string   `json:"usergroup"`
	Users              []string `json:"users"`
	IncludeCount       bool     `json:"include_count,omitempty"`
	TeamID             string   `json:"team_id,omitempty"`
	AdditionalChannels []string `json:"additional_channels,omitempty"`
	IsShared           bool     `json:"is_shared,omitempty"`
}

UpdateUserGroupUsersRequest contains parameters for usergroups.users.update.

type User

type User struct {
	ID                     string      `json:"id"`
	Name                   string      `json:"name,omitempty"`
	IsBot                  bool        `json:"is_bot,omitempty"`
	Updated                int64       `json:"updated,omitempty"`
	IsAppUser              bool        `json:"is_app_user,omitempty"`
	TeamID                 string      `json:"team_id,omitempty"`
	Deleted                bool        `json:"deleted,omitempty"`
	Color                  string      `json:"color,omitempty"`
	IsEmailConfirmed       bool        `json:"is_email_confirmed,omitempty"`
	RealName               string      `json:"real_name,omitempty"`
	TZ                     string      `json:"tz,omitempty"`
	TZLabel                string      `json:"tz_label,omitempty"`
	TZOffset               int         `json:"tz_offset,omitempty"`
	IsAdmin                bool        `json:"is_admin,omitempty"`
	IsOwner                bool        `json:"is_owner,omitempty"`
	IsPrimaryOwner         bool        `json:"is_primary_owner,omitempty"`
	IsRestricted           bool        `json:"is_restricted,omitempty"`
	IsUltraRestricted      bool        `json:"is_ultra_restricted,omitempty"`
	WhoCanShareContactCard string      `json:"who_can_share_contact_card,omitempty"`
	Profile                UserProfile `json:"profile,omitempty"`
}

User is Slack user DTO.

type UserGroup

type UserGroup struct {
	ID          string `json:"id"`
	TeamID      string `json:"team_id,omitempty"`
	Name        string `json:"name,omitempty"`
	Handle      string `json:"handle,omitempty"`
	Description string `json:"description,omitempty"`
}

UserGroup is a minimal Slack user group DTO.

type UserGroupsService

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

UserGroupsService provides Slack user groups operations.

func (*UserGroupsService) CreateUserGroup

func (s *UserGroupsService) CreateUserGroup(ctx context.Context, name, tag string) (*UserGroup, error)

CreateUserGroup creates a user group in Slack.

func (*UserGroupsService) ListUserGroupUsers added in v0.8.2

func (s *UserGroupsService) ListUserGroupUsers(ctx context.Context, req *ListUserGroupUsersRequest) ([]string, error)

ListUserGroupUsers lists members of a user group using usergroups.users.list.

func (*UserGroupsService) ListUserGroups

func (s *UserGroupsService) ListUserGroups(ctx context.Context) ([]UserGroup, error)

ListUserGroups lists user groups.

func (*UserGroupsService) UpdateUserGroupUsers added in v0.8.2

func (s *UserGroupsService) UpdateUserGroupUsers(ctx context.Context, req *UpdateUserGroupUsersRequest) (*UserGroup, error)

UpdateUserGroupUsers updates members of a user group using usergroups.users.update.

type UserProfile added in v0.8.2

type UserProfile struct {
	RealName               string `json:"real_name,omitempty"`
	DisplayName            string `json:"display_name,omitempty"`
	AvatarHash             string `json:"avatar_hash,omitempty"`
	RealNameNormalized     string `json:"real_name_normalized,omitempty"`
	DisplayNameNormalized  string `json:"display_name_normalized,omitempty"`
	Image24                string `json:"image_24,omitempty"`
	Image32                string `json:"image_32,omitempty"`
	Image48                string `json:"image_48,omitempty"`
	Image72                string `json:"image_72,omitempty"`
	Image192               string `json:"image_192,omitempty"`
	Image512               string `json:"image_512,omitempty"`
	Image1024              string `json:"image_1024,omitempty"`
	ImageOriginal          string `json:"image_original,omitempty"`
	IsCustomImage          bool   `json:"is_custom_image,omitempty"`
	FirstName              string `json:"first_name,omitempty"`
	LastName               string `json:"last_name,omitempty"`
	Team                   string `json:"team,omitempty"`
	Email                  string `json:"email,omitempty"`
	Title                  string `json:"title,omitempty"`
	Phone                  string `json:"phone,omitempty"`
	Skype                  string `json:"skype,omitempty"`
	StatusText             string `json:"status_text,omitempty"`
	StatusTextCanonical    string `json:"status_text_canonical,omitempty"`
	StatusEmoji            string `json:"status_emoji,omitempty"`
	StatusEmojiDisplayInfo []any  `json:"status_emoji_display_info,omitempty"`
	StatusExpiration       int    `json:"status_expiration,omitempty"`
	BotID                  string `json:"bot_id,omitempty"`
	APIAppID               string `json:"api_app_id,omitempty"`
	AlwaysActive           bool   `json:"always_active,omitempty"`
}

UserProfile is Slack user profile payload.

type UsersService

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

UsersService provides Slack users operations.

func (*UsersService) GetUserByEmail

func (s *UsersService) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail returns user by email.

func (*UsersService) GetUserByID

func (s *UsersService) GetUserByID(ctx context.Context, userID string) (*User, error)

GetUserByID returns user by ID.

func (*UsersService) GetUsersByGroupID

func (s *UsersService) GetUsersByGroupID(ctx context.Context, userGroupID string) ([]User, error)

GetUsersByGroupID returns users belonging to a user group.

func (*UsersService) GetUsersByID

func (s *UsersService) GetUsersByID(ctx context.Context, userIDs []string) ([]User, error)

GetUsersByID returns users for provided IDs.

func (*UsersService) ListUsers added in v0.8.2

ListUsers returns users from users.list and optionally fetches all pages.

type View

type View struct {
	ID         string `json:"id,omitempty"`
	ExternalID string `json:"external_id,omitempty"`
	Type       string `json:"type,omitempty"`
	CallbackID string `json:"callback_id,omitempty"`
	Hash       string `json:"hash,omitempty"`
}

View is a minimal Slack view response DTO.

type ViewText

type ViewText struct {
	Type  string `json:"type"`
	Text  string `json:"text"`
	Emoji bool   `json:"emoji,omitempty"`
}

ViewText represents Slack plain_text/markdown text object.

type ViewsService

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

ViewsService provides Slack modal/home views operations.

func (*ViewsService) OpenView

func (s *ViewsService) OpenView(ctx context.Context, triggerID string, req *ModalViewRequest) (*OpenViewResult, error)

OpenView opens a view for the provided trigger.

func (*ViewsService) UpdateView

func (s *ViewsService) UpdateView(ctx context.Context, view ModalViewRequest, externalID, hash, viewID string) (*OpenViewResult, error)

UpdateView updates an existing view by viewID or externalID.

Jump to

Keyboard shortcuts

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