slack

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(processor func(synthetic.Message), catch string) func(synthetic.Message)

Contains returns a processor that runs the `processor` if the message contains the `catch` string.

func Exactly

func Exactly(processor func(synthetic.Message), catch string) func(synthetic.Message)

Exactly returns a processot that runs the `processor` if the message is exactly like the `catch` string.

func LogMessage

func LogMessage(msg synthetic.Message)

LogMessage is a message processor to log the message received.

func Mentioned

func Mentioned(processor func(synthetic.Message)) func(synthetic.Message)

Mentioned returns a processor that runs the `processor` if the message is mentioning the bot.

func NotMentioned

func NotMentioned(processor func(synthetic.Message)) func(synthetic.Message)

NotMentioned returns a processor that runs the `processor` if the message is not mentioning the bot.

func RemoveWord

func RemoveWord(text string, word string) string

RemoveWord removes `word` from `text` and returns the result. Note this uses a single space to split the words in `text`.

func ReplaceSpace

func ReplaceSpace(s string) string

ReplaceSpace ...

Types

type Chat

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

Chat represents the whole chat connection providing methods to interact with the chat system.

func NewChat

func NewChat(token string, defaultReplyInThread bool, debug bool) (chat *Chat)

NewChat is the constructor for the Chat object.

func (*Chat) IncomingEvents

func (c *Chat) IncomingEvents() chan slack.RTMEvent

IncomingEvents returns the channel to the chat system events.

func (*Chat) Process

func (c *Chat) Process(msg slack.RTMEvent)

Process runs the message processing for the chat system.

func (*Chat) RegisterMessageProcessor

func (c *Chat) RegisterMessageProcessor(processor IMessageProcessor)

RegisterMessageProcessor allows to add more message processors.

func (*Chat) Start

func (c *Chat) Start()

Start initializes the chat connection.

type Conversation

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

Conversation is a wrapper over slack-go's Channel object. It provides an abstraction layer over channels, group conversations and direct chats.

func NewConversationFromID

func NewConversationFromID(id string, api IClient) (conversation *Conversation, err error)

NewConversationFromID returns a Conversation object wrapping the channel, group conversation, or direct chat identified by `id`.

func (*Conversation) Name

func (c *Conversation) Name() string

Name returns the name of the conversation.

type IClient

type IClient interface {
	GetConversationInfo(string, bool) (*slack.Channel, error)
	GetUserInfo(string) (*slack.User, error)
	NewRTM(...slack.RTMOption) *slack.RTM
	AddReaction(string, slack.ItemRef) error
	RemoveReaction(string, slack.ItemRef) error
}

IClient is an interface for the chat system's client.

type IMessageProcessor

type IMessageProcessor interface {
	Name() string
	Run(synthetic.Message)
}

IMessageProcessor is an interface to represent message processor functions.

type IRTM

type IRTM interface {
	ManageConnection()
	NewOutgoingMessage(string, string, ...slack.RTMsgOption) *slack.OutgoingMessage
	SendMessage(*slack.OutgoingMessage)
}

IRTM is an interface for the chat system RTM interface.

type Message

type Message struct {
	Completed bool
	// contains filtered or unexported fields
}

Message contains all the information about a message the bot was notified about.

func ReadMessage

func ReadMessage(event *slack.MessageEvent, chat *Chat) (msg *Message, err error)

ReadMessage generates the `Message` from a message event.

func (*Message) ClearMention

func (m *Message) ClearMention() string

ClearMention returns the message text without the bot's username.

func (*Message) Conversation

func (m *Message) Conversation() synthetic.Conversation

Conversation is an accessor for Conversation.

func (*Message) Mention

func (m *Message) Mention() bool

Mention is an accessor for Mention.

func (*Message) React

func (m *Message) React(reaction string)

React adds the `reaction` reaction to the message.

func (*Message) Reply

func (m *Message) Reply(msg string, inThread bool)

Reply send the `msg` string as a reply to the message, in a thread if `inThread` is true.

func (*Message) Text

func (m *Message) Text() string

Text is an accessor for text.

func (*Message) Thread

func (m *Message) Thread() bool

Thread is an accessor for Thread.

func (*Message) Unreact

func (m *Message) Unreact(reaction string)

Unreact removes the `reaction` reaction from the message.

func (*Message) User

func (m *Message) User() synthetic.User

User is an accessor for User.

type MessageProcessor

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

MessageProcessor is an implementation of IMessageProcessor.

func NewMessageProcessor

func NewMessageProcessor(name string, processorFunc func(synthetic.Message)) *MessageProcessor

NewMessageProcessor is the constructor for MessageProcessor.

func (*MessageProcessor) Name

func (mp *MessageProcessor) Name() string

Name returns the name of the MessageProcessor.

func (*MessageProcessor) Run

func (mp *MessageProcessor) Run(msg synthetic.Message)

Run executes the MessageProcessor function.

type MockClient

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

MockClient is a mocking client for testing.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new MockClient.

func (*MockClient) AddReaction

func (c *MockClient) AddReaction(reaction string, item slack.ItemRef) error

AddReaction registers `reaction` on `item` for validation.

func (*MockClient) GetConversationInfo

func (c *MockClient) GetConversationInfo(id string, includeLocale bool) (channel *slack.Channel, err error)

GetConversationInfo returns the channel information for `id`.

func (*MockClient) GetUserInfo

func (c *MockClient) GetUserInfo(id string) (*slack.User, error)

GetUserInfo returns the user information for `id`.

func (*MockClient) NewRTM

func (c *MockClient) NewRTM(options ...slack.RTMOption) *slack.RTM

NewRTM returns a null Slack RTM.

func (*MockClient) RemoveReaction

func (c *MockClient) RemoveReaction(reaction string, item slack.ItemRef) error

RemoveReaction registers `reaction` removal on `item` for validation.

type MockRTM

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

MockRTM is a mocking RTM.

func NewMockRTM

func NewMockRTM() *MockRTM

NewMockRTM creates a new MockRTM.

func (*MockRTM) ManageConnection

func (rtm *MockRTM) ManageConnection()

ManageConnection fakes the real Slack RTM connection manager.

func (*MockRTM) NewOutgoingMessage

func (rtm *MockRTM) NewOutgoingMessage(text string, channelID string, options ...slack.RTMsgOption) *slack.OutgoingMessage

NewOutgoingMessage creates a fake message object to send.

func (*MockRTM) SendMessage

func (rtm *MockRTM) SendMessage(msg *slack.OutgoingMessage)

SendMessage fakes sending a message.

type User

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

User is a weapper over slack-go's User object. It provides some utility methods over the User information.

func NewUserFromID

func NewUserFromID(id string, api IClient) (user *User, err error)

NewUserFromID returns a User object wrapping the user identified by `id`.

func (*User) Name

func (u *User) Name() string

Name returns the name of the user.

Jump to

Keyboard shortcuts

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