slack

package
v0.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package slack is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Listen starts the client running forever and is intended to be called from
	// a dedicated goroutine - it will not return. Real time events for messages
	// and reactions are dispatched to the provided channels.
	Listen(msgChan chan<- *Message, reactionChan chan<- *Reaction)
	// SendMessage sends the provided text to the provided slack channel ID.
	SendMessage(text, channelID string)
	// AddReaction adds the provided reaction (no ":" delimiters) to the given
	// message.
	AddReaction(reaction string, message *Message) error
	// ParseTimestamp parses a Slack-style timestamp and returns a time.Time
	// instance.
	ParseTimestamp(ts string) (time.Time, error)
	// BotName returns the friendly name of the bot.
	BotName() string
	// BotID returns the user ID of the bot.
	BotID() string
	// TeamName returns the friendly name of the slack team/workspace.
	TeamName() string
	// TeamID returns the team ID the bot is connected to.
	TeamID() string
	// ConversationName translates a slack channel/conversation ID to a friendly name.
	ConversationName(id string) string
	// ConversationID is the reverse of ConversationName and returns the ID for
	// a friendly channel/conversation name.
	ConversationID(name string) string
	// UserName returns the friendly user name for the given slack user ID.
	UserName(id string) string
	// UserID is the reverse of Username and returns the ID for a friendly user
	// name.
	UserID(username string) string
}

Client is an interface that abstracts away the slack client from the rest of the codebase. It contains all of the operations the bot needs to be able to do with Slack.

func New

func New(log *logrus.Logger, c *config.Config) (Client, error)

New Constructs Client instance from the given config or returns an error. After calling New a managed RTM instance for a Websocket with slack will have been created and spawned on a goroutine and Listen() may be called to read events.

type Conversation

type Conversation struct {
	// Conversation ID.
	ID string
	// Conversation name (no "#" prefix for channel names).
	Name string
}

Conversation is a structure describing a channel/conversation. It has both an ID and a friendly name. Note: typically a Conversation is a channel but it may also be a DM exchange!

type Message

type Message struct {
	// ChannelID is the ID of the channel that the message was seen in.
	ChannelID string
	// UserID is the ID of the user that spoke the message.
	UserID string
	// Text is the raw text of the message.
	Text string
	// Timestamp is the raw slack timestamp of the message.
	Timestamp string
}

Message is a structure describing a slack message from a user in a channel.

func (Message) String

func (m Message) String() string

String is a simple debugging representation of a message.

type MockSlackAPI

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

MockSlackAPI is a mock of SlackAPI interface

func NewMockSlackAPI

func NewMockSlackAPI(ctrl *gomock.Controller) *MockSlackAPI

NewMockSlackAPI creates a new mock instance

func (*MockSlackAPI) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockSlackAPI) GetConversations

func (m *MockSlackAPI) GetConversations(arg0 *slack.GetConversationsParameters) ([]slack.Channel, string, error)

GetConversations mocks base method

func (*MockSlackAPI) GetUsers

func (m *MockSlackAPI) GetUsers() ([]slack.User, error)

GetUsers mocks base method

type MockSlackAPIMockRecorder

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

MockSlackAPIMockRecorder is the mock recorder for MockSlackAPI

func (*MockSlackAPIMockRecorder) GetConversations

func (mr *MockSlackAPIMockRecorder) GetConversations(arg0 interface{}) *gomock.Call

GetConversations indicates an expected call of GetConversations

func (*MockSlackAPIMockRecorder) GetUsers

func (mr *MockSlackAPIMockRecorder) GetUsers() *gomock.Call

GetUsers indicates an expected call of GetUsers

type Reaction

type Reaction struct {
	// The user ID that added/removed the reactji.
	User string
	// The reactji (no ":" delimiters).
	Reaction string
	// The slack timestamp that the reaction event occurred.
	Timestamp string
	// Whether the reactji was removed or added.
	Removed bool
}

Reaction is a structure describing a reaction event.

type SlackAPI

type SlackAPI interface {
	GetConversations(opts *slack.GetConversationsParameters) ([]slack.Channel, string, error)
	GetUsers() ([]slack.User, error)
}

SlackAPI is an interface that abstracts away the slack API from this package's code. It is 100% to facilitate unit testing/mocking and shouldn't be used outside of this package. It must be exported to have mockgen work :-(

NB: Generate this mock in the same package so we avoid a cyclic import - it's most useful in slack_test.go.

type User

type User struct {
	// User ID.
	ID string
	// User's friendly name (no leading "@" prefix).
	Name string
}

User is a structure describing a slack user. It has both an ID and a friendly name.

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