README ¶
slacktest
This package was copied from https://github.com/lusis/slack-test for historical reasons.
This package's license is the following.
Copyright 2018 @lusis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Documentation ¶
Index ¶
- Constants
- func BotIDFromContext(ctx context.Context) string
- func BotNameFromContext(ctx context.Context) string
- func RTMConnectHandler(w http.ResponseWriter, r *http.Request)
- func RTMRespEventType(c *websocket.Conn) (t string, m json.RawMessage, err error)
- func RTMRespPong(c *websocket.Conn, m json.RawMessage) (err error)
- func RTMServerSendGoodbye(c *websocket.Conn) error
- func Websocket(delegate func(c *websocket.Conn)) func(w http.ResponseWriter, r *http.Request)
- type Customize
- type GroupConversationResponse
- type Server
- func (sts *Server) GetAPIURL() string
- func (sts *Server) GetChannels() []slack.Channel
- func (sts *Server) GetGroups() []slack.Group
- func (sts *Server) GetSeenInboundMessages() []string
- func (sts *Server) GetSeenOutboundMessages() []string
- func (sts *Server) GetTestRTMInstance() *slack.RTM
- func (sts *Server) GetWSURL() string
- func (sts *Server) Handle(pattern string, handler http.HandlerFunc)
- func (sts *Server) SawMessage(msg string) bool
- func (sts *Server) SawOutgoingMessage(msg string) bool
- func (sts *Server) SendBotChannelInvite()
- func (sts *Server) SendBotGroupInvite()
- func (sts *Server) SendDirectMessageToBot(msg string)
- func (sts *Server) SendMessageToBot(channel, msg string)
- func (sts *Server) SendMessageToChannel(channel, msg string)
- func (sts *Server) SendToWebsocket(s string)
- func (sts *Server) SetBotName(b string)
- func (sts *Server) Start()
- func (sts *Server) Stop()
Constants ¶
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") )
const ServerBotChannelsContextKey contextKey = "__SERVER_CHANNELS__"
ServerBotChannelsContextKey is the list of channels associated with the fake server
const ServerBotGroupsContextKey contextKey = "__SERVER_GROUPS__"
ServerBotGroupsContextKey is the list of channels associated with the fake server
const ServerBotHubNameContextKey contextKey = "__SERVER_HUBNAME__"
ServerBotHubNameContextKey is the context key for passing along the server name registered in the hub
const ServerBotIDContextKey contextKey = "__SERVER_BOTID__"
ServerBotIDContextKey is the bot userid
const ServerBotNameContextKey contextKey = "__SERVER_BOTNAME__"
ServerBotNameContextKey is the bot name
const ServerURLContextKey contextKey = "__SERVER_URL__"
ServerURLContextKey is the context key to store the server's url
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 ¶
BotIDFromContext returns the bot userid from a provided context
func BotNameFromContext ¶
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 ¶
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 ¶
RTMServerSendGoodbye send a goodbye event
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) GetChannels ¶
GetChannels returns all the fake channels registered
func (*Server) GetSeenInboundMessages ¶
GetSeenInboundMessages returns all messages seen via websocket excluding pings
func (*Server) GetSeenOutboundMessages ¶
GetSeenOutboundMessages returns all messages seen via websocket excluding pings
func (*Server) GetTestRTMInstance ¶
GetTestRTMInstance will give you an RTM instance in the context of the current fake server
func (*Server) Handle ¶
func (sts *Server) Handle(pattern string, handler http.HandlerFunc)
Handle allow for customizing endpoints
func (*Server) SawMessage ¶
SawMessage checks if an incoming message was seen
func (*Server) SawOutgoingMessage ¶
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 ¶
SendDirectMessageToBot sends a direct message to the bot
func (*Server) SendMessageToBot ¶
SendMessageToBot sends a message addressed to the Bot
func (*Server) SendMessageToChannel ¶
SendMessageToChannel sends a message to a channel
func (*Server) SendToWebsocket ¶
SendToWebsocket send `s` as is to connected clients. This is useful for sending your own custom json to the websocket
func (*Server) SetBotName ¶
SetBotName sets a custom botname