mockslack

package
v0.31.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const TokenCookieName = "slack_token"

TokenCookieName is the name of a cookie containing a token for a user session.

Variables

This section is empty.

Functions

func WithToken

func WithToken(ctx context.Context, tok *AuthToken) context.Context

WithToken will return a new context authorized for API calls with the given AuthToken.

Types

type API

type API state

API allows making calls to implemented Slack API methods.

API methods implement permission/scope checking.

func (*API) AuthRevoke

func (st *API) AuthRevoke(ctx context.Context, test bool) (bool, error)

AuthRevoke will revoke the auth token from the provided context.

func (*API) ChannelsCreate

func (st *API) ChannelsCreate(ctx context.Context, opts ConversationCreateOpts) (*Channel, error)

ChannelsCreate is used to create a channel.

func (*API) ChatPostMessage

func (st *API) ChatPostMessage(ctx context.Context, opts ChatPostMessageOptions) (*Message, error)

ChatPostMessage posts a message to a channel.

func (*API) ConversationsInfo

func (st *API) ConversationsInfo(ctx context.Context, id string) (*Channel, error)

ConversationsInfo returns information about a conversation.

func (*API) ConversationsList

func (st *API) ConversationsList(ctx context.Context, opts ConversationsListOpts) ([]Channel, string, error)

ConversationsList returns a list of channel-like conversations in a workspace.

func (*API) GroupsCreate

func (st *API) GroupsCreate(ctx context.Context, opts ConversationCreateOpts) (*Channel, error)

GroupsCreate is used to create a channel.

func (*API) OAuthAccess

func (st *API) OAuthAccess(ctx context.Context, opts OAuthAccessOpts) (*AuthToken, error)

OAuthAccess will exchange a temporary code for an access token.

func (*API) TeamInfo added in v0.31.0

func (st *API) TeamInfo(ctx context.Context, id string) (*Team, error)

func (*API) UserGroupList added in v0.31.0

func (st *API) UserGroupList(ctx context.Context) ([]UserGroup, error)

UserGroupList returns a list of User Groups in a workspace.

func (*API) UserGroupsUsersUpdate added in v0.31.0

func (st *API) UserGroupsUsersUpdate(ctx context.Context, opts UserGroupsUsersUpdateOptions) (*UserGroup, error)

UserGroupsUsersUpdate updates the list of users within a user group and returns the user group.

func (*API) UsersInfo added in v0.31.0

func (st *API) UsersInfo(ctx context.Context, id string) (*User, error)

type Action added in v0.29.0

type Action struct {
	ChannelID string
	AppID     string
	TeamID    string

	BlockID  string
	ActionID string
	Text     string
	Value    string
	URL      string
}

type App

type App struct {
	ID        string
	Name      string
	Secret    string
	AuthToken *AuthToken
	ActionURL string

	SigningSecret string
}

type AppInfo

type AppInfo struct {
	Name         string
	ClientID     string
	ClientSecret string
	AccessToken  string
	TeamID       string

	SigningSecret string

	ActionURL string
}

AppInfo contains information for an installed Slack app.

type AuthToken

type AuthToken struct {
	ID     string
	Scopes []string
	User   string
	IsBot  bool
}

AuthToken represents a state of authorization with the Slack server.

func ContextToken

func ContextToken(ctx context.Context) *AuthToken

ContextToken will return a copy of the AuthToken from the given context.

type Channel

type Channel struct {
	ID   string `json:"id"`
	Name string `json:"name"`

	IsChannel  bool `json:"is_channel"`
	IsGroup    bool `json:"is_group"`
	IsArchived bool `json:"is_archived"`
}

Channel represents a Slack channel or group.

type ChannelInfo

type ChannelInfo struct {
	ID, Name string
}

ChannelInfo contains information about a newly created Slack channel.

type ChatPostMessageOptions

type ChatPostMessageOptions struct {
	ChannelID string
	Text      string
	Color     string

	Actions []Action

	AsUser bool

	User string

	UpdateTS  string
	ThreadTS  string
	Broadcast bool
}

ChatPostMessageOptions are parameters for a `chat.postMessage` call.

type ConversationCreateOpts

type ConversationCreateOpts struct {
	Name     string
	Validate bool
}

ConversationCreateOpts is used to configure a new channel or group.

type ConversationsListOpts

type ConversationsListOpts struct {
	Cursor          string
	ExcludeArchived bool
	Limit           int
	Types           string
}

ConversationsListOpts contains parameters for the ConversationsList API call.

type Message

type Message struct {
	TS        string `json:"ts"`
	ThreadTS  string `json:"thread_ts"`
	UpdateTS  string `json:"update_ts"`
	Text      string `json:"text"`
	User      string `json:"user"`
	Broadcast bool   `json:"reply_broadcast"`
	Color     string `json:"color"`

	ChannelID string
	ToUserID  string

	Actions []Action
}

Message represents a Slack message.

type OAuthAccessOpts

type OAuthAccessOpts struct {
	ClientID     string
	ClientSecret string
	Code         string
}

OAuthAccessOpts contains parameters for an OAuthAccess API call.

type Server

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

Server implements a mock Slack API.

func NewServer

func NewServer() *Server

NewServer creates a new blank Server.

func (Server) API

func (st Server) API() *API

API returns an API instance.

func (Server) DeleteMessage added in v0.28.0

func (st Server) DeleteMessage(chanID, ts string) bool

DeleteMessage will delete a message from channel history.

func (Server) InstallApp

func (st Server) InstallApp(name string, scopes ...string) AppInfo

InstallApp will "install" a new app to this Slack server.

func (Server) InstallStaticApp

func (st Server) InstallStaticApp(app AppInfo, scopes ...string) (*AppInfo, error)

InstallApp will "install" a new app to this Slack server using pre-configured AppInfo.

func (Server) Messages

func (st Server) Messages(chanID string) []Message

Messages will return all messages from a given channel/group.

func (Server) NewChannel

func (st Server) NewChannel(name string) ChannelInfo

NewChannel will create a new Slack channel with the given name.

func (Server) NewUser

func (st Server) NewUser(name string) UserInfo

NewUser will create a new Slack user with the given name.

func (Server) NewUserGroup added in v0.31.0

func (st Server) NewUserGroup(name string) UserGroupInfo

NewUserGroup will create a new Slack user group with the given name.

func (*Server) PerformActionAs added in v0.29.0

func (s *Server) PerformActionAs(userID string, a Action) error

PerformActionAs will preform the action as the given user.

func (*Server) ServeActionResponse added in v0.29.0

func (s *Server) ServeActionResponse(w http.ResponseWriter, r *http.Request)

func (*Server) ServeAuthRevoke

func (s *Server) ServeAuthRevoke(w http.ResponseWriter, req *http.Request)

ServeAuthRevoke implements the auth.revoke API call.

https://api.slack.com/methods/auth.revoke

func (*Server) ServeAuthTest added in v0.27.0

func (s *Server) ServeAuthTest(w http.ResponseWriter, req *http.Request)

ServeAuthTest serves a request to the `auth.test` API call.

https://slack.com/api/auth.test

func (*Server) ServeChannelsCreate

func (s *Server) ServeChannelsCreate(w http.ResponseWriter, req *http.Request)

ServeChannelsCreate serves a request to the `channels.create` API call.

https://api.slack.com/methods/channels.create

func (*Server) ServeChatPostMessage

func (s *Server) ServeChatPostMessage(w http.ResponseWriter, req *http.Request)

ServeChatPostMessage serves a request to the `chat.postMessage` API call.

https://api.slack.com/methods/chat.postMessage

func (*Server) ServeChatUpdate added in v0.29.0

func (s *Server) ServeChatUpdate(w http.ResponseWriter, req *http.Request)

ServeChatUpdate serves a request to the `chat.update` API call.

https://api.slack.com/methods/chat.update

func (*Server) ServeConversationsInfo

func (s *Server) ServeConversationsInfo(w http.ResponseWriter, req *http.Request)

ServeConversationsInfo serves a request to the `conversations.info` API call.

https://api.slack.com/methods/conversations.info

func (*Server) ServeConversationsList

func (s *Server) ServeConversationsList(w http.ResponseWriter, req *http.Request)

ServeConversationsList serves a request to the `conversations.list` API call.

https://api.slack.com/methods/conversations.list

func (*Server) ServeGroupsCreate

func (s *Server) ServeGroupsCreate(w http.ResponseWriter, req *http.Request)

ServeGroupsCreate serves a request to the `Groups.create` API call.

https://api.slack.com/methods/Groups.create

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP serves the Slack API.

func (*Server) ServeOAuthAccess

func (s *Server) ServeOAuthAccess(w http.ResponseWriter, req *http.Request)

ServeOAuthAccess serves a request to the `oauth.access` API call.

https://api.slack.com/methods/oauth.access

func (*Server) ServeTeamInfo added in v0.31.0

func (s *Server) ServeTeamInfo(w http.ResponseWriter, req *http.Request)

ServeTeamInfo serves a request to the `team.info` API call.

https://api.slack.com/methods/team.info

func (*Server) ServeUserGroupList added in v0.31.0

func (s *Server) ServeUserGroupList(w http.ResponseWriter, req *http.Request)

ServeUserGroupList serves a request to the `usergroups.list` API call.

https://api.slack.com/methods/usergroups.list

func (*Server) ServeUserGroupsUsersUpdate added in v0.31.0

func (s *Server) ServeUserGroupsUsersUpdate(w http.ResponseWriter, req *http.Request)

ServeUserGroupsUsersUpdate serves a request to the `usergroups.users.update` API call.

https://api.slack.com/methods/usergroups.users.update

func (*Server) ServeUsersInfo added in v0.31.0

func (s *Server) ServeUsersInfo(w http.ResponseWriter, req *http.Request)

ServeUsersInfo serves a request to the `users.info` API call.

https://api.slack.com/methods/users.info

func (*Server) SetActionURL added in v0.29.0

func (s *Server) SetActionURL(appID string, actionURL string)

func (Server) SetAutoCreateChannel

func (st Server) SetAutoCreateChannel(value bool)

SetAutoCreateChannel, if set to true, will cause messages sent to non-existent channels to succeed by creating the channel automatically.

func (*Server) SetURLPrefix added in v0.29.0

func (s *Server) SetURLPrefix(prefix string)

SetURLPrefix will update the URL prefix for this server.

func (Server) UserGroupUserIDs added in v0.31.0

func (st Server) UserGroupUserIDs(ugID string) []string

UserGroupUserIDs will return all users from a given user group.

type Team added in v0.31.0

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

type TeamInfoOpts added in v0.31.0

type TeamInfoOpts struct {
	Team string
}

TeamInfoOpts contains parameters for the TeamInfo API call.

type User

type User struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	TeamID string `json:"team_id"`
}

type UserGroup added in v0.31.0

type UserGroup struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Handle string `json:"handle"`

	IsUserGroup bool `json:"is_usergroup"`

	Users []string `json:"users"`
}

UserGroup represents a Slack user group.

type UserGroupInfo added in v0.31.0

type UserGroupInfo struct {
	ID, Name, Handle string
}

UserGroupInfo contains information about a newly created Slack user group.

type UserGroupsUsersUpdateOptions added in v0.31.0

type UserGroupsUsersUpdateOptions struct {
	Usergroup string
	Users     []string
}

type UserInfo

type UserInfo struct {
	ID        string
	Name      string
	AuthToken string
}

UserInfo contains information for a newly created user.

type UsersInfoOpts added in v0.31.0

type UsersInfoOpts struct {
	User string
}

UsersInfoOpts contains parameters for the UsersInfo API call.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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