slacktest

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: BSD-2-Clause Imports: 13 Imported by: 0

README

slacktest

code in this package was shamelessly copied from https://github.com/lusis/slack-test. since we were unable to get a response from the maintainer and its lack of license have left us in an odd state. but wanted to move it here for maintenance purposes.

Documentation

Index

Constants

View Source
const (
	// ErrEmptyServerToHub is the error when attempting an empty server address to the hub
	ErrEmptyServerToHub = errorsx.String("Unable to add an empty server address to hub")
	// ErrPassedEmptyServerAddr is the error when being passed an empty server address
	ErrPassedEmptyServerAddr = errorsx.String("Passed an empty server address")
	// ErrNoQueuesRegisteredForServer is the error when there are no queues for a server in the hub
	ErrNoQueuesRegisteredForServer = errorsx.String("No queues registered for server")
)
View Source
const ServerBotChannelsContextKey contextKey = "__SERVER_CHANNELS__"

ServerBotChannelsContextKey is the list of channels associated with the fake server

View Source
const ServerBotGroupsContextKey contextKey = "__SERVER_GROUPS__"

ServerBotGroupsContextKey is the list of channels associated with the fake server

View Source
const ServerBotHubNameContextKey contextKey = "__SERVER_HUBNAME__"

ServerBotHubNameContextKey is the context key for passing along the server name registered in the hub

View Source
const ServerBotIDContextKey contextKey = "__SERVER_BOTID__"

ServerBotIDContextKey is the bot userid

View Source
const ServerBotNameContextKey contextKey = "__SERVER_BOTNAME__"

ServerBotNameContextKey is the bot name

View Source
const ServerURLContextKey contextKey = "__SERVER_URL__"

ServerURLContextKey is the context key to store the server's url

View Source
const ServerWSContextKey contextKey = "__SERVER_WS_URL__"

ServerWSContextKey is the context key to store the server's ws url

Variables

This section is empty.

Functions

func BotIDFromContext

func BotIDFromContext(ctx context.Context) string

BotIDFromContext returns the bot userid from a provided context

func BotNameFromContext

func BotNameFromContext(ctx context.Context) string

BotNameFromContext returns the botname from a provided context

func RTMConnectHandler

func RTMConnectHandler(w http.ResponseWriter, r *http.Request)

RTMConnectHandler generates a valid connection

func RTMRespEventType

func RTMRespEventType(c *websocket.Conn) (t string, m json.RawMessage, err error)

RTMRespEventType retrieve the event type from the next message

func RTMRespPong

func RTMRespPong(c *websocket.Conn, m json.RawMessage) (err error)

RTMRespPong decode a ping and respond with a pong event.

func RTMServerSendGoodbye

func RTMServerSendGoodbye(c *websocket.Conn) error

RTMServerSendGoodbye send a goodbye event

func Websocket

func Websocket(delegate func(c *websocket.Conn)) func(w http.ResponseWriter, r *http.Request)

Websocket handler

Types

type Customize

type Customize interface {
	Handle(pattern string, handler http.HandlerFunc)
}

Customize the server's responses.

type GroupConversationResponse

type GroupConversationResponse struct {
	Ok      bool                    `json:"ok"`
	Channel slack.GroupConversation `json:"channel"`
}

type Server

type Server struct {
	Logger     *log.Logger
	BotName    string
	BotID      string
	ServerAddr string
	SeenFeed   chan (string)
	// contains filtered or unexported fields
}

Server represents a Slack Test server

func NewTestServer

func NewTestServer(custom ...binder) *Server

NewTestServer returns a slacktest.Server ready to be started

func (*Server) GetAPIURL

func (sts *Server) GetAPIURL() string

GetAPIURL returns the api url you can pass to slack.SLACK_API

func (*Server) GetChannels

func (sts *Server) GetChannels() []slack.Channel

GetChannels returns all the fake channels registered

func (*Server) GetGroups

func (sts *Server) GetGroups() []slack.Group

GetGroups returns all the fake groups registered

func (*Server) GetSeenInboundMessages

func (sts *Server) GetSeenInboundMessages() []string

GetSeenInboundMessages returns all messages seen via websocket excluding pings

func (*Server) GetSeenOutboundMessages

func (sts *Server) GetSeenOutboundMessages() []string

GetSeenOutboundMessages returns all messages seen via websocket excluding pings

func (*Server) GetTestRTMInstance

func (sts *Server) GetTestRTMInstance() *slack.RTM

GetTestRTMInstance will give you an RTM instance in the context of the current fake server

func (*Server) GetWSURL

func (sts *Server) GetWSURL() string

GetWSURL returns the websocket url

func (*Server) Handle

func (sts *Server) Handle(pattern string, handler http.HandlerFunc)

Handle allow for customizing endpoints

func (*Server) SawMessage

func (sts *Server) SawMessage(msg string) bool

SawMessage checks if an incoming message was seen

func (*Server) SawOutgoingMessage

func (sts *Server) SawOutgoingMessage(msg string) bool

SawOutgoingMessage checks if a message was sent to connected websocket clients

func (*Server) SendBotChannelInvite

func (sts *Server) SendBotChannelInvite()

SendBotChannelInvite invites the bot to a channel

func (*Server) SendBotGroupInvite

func (sts *Server) SendBotGroupInvite()

SendBotGroupInvite invites the bot to a channel

func (*Server) SendDirectMessageToBot

func (sts *Server) SendDirectMessageToBot(msg string)

SendDirectMessageToBot sends a direct message to the bot

func (*Server) SendMessageToBot

func (sts *Server) SendMessageToBot(channel, msg string)

SendMessageToBot sends a message addressed to the Bot

func (*Server) SendMessageToChannel

func (sts *Server) SendMessageToChannel(channel, msg string)

SendMessageToChannel sends a message to a channel

func (*Server) SendToWebsocket

func (sts *Server) SendToWebsocket(s string)

SendToWebsocket send `s` as is to connected clients. This is useful for sending your own custom json to the websocket

func (*Server) SetBotName

func (sts *Server) SetBotName(b string)

SetBotName sets a custom botname

func (*Server) Start

func (sts *Server) Start()

Start starts the test server

func (*Server) Stop

func (sts *Server) Stop()

Stop stops the test server

Jump to

Keyboard shortcuts

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