slack

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SlackBot

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

SlackBot implements orchestrator.Bot using the Slack API with Socket Mode.

func NewBot

func NewBot(session SlackSession, socketClient SocketModeClient, logger *slog.Logger) *SlackBot

NewBot creates a new SlackBot with the given session, socket mode client, and logger.

func (*SlackBot) BotUserID

func (b *SlackBot) BotUserID() string

BotUserID returns the bot's Slack user ID.

func (*SlackBot) CreateChannel

func (b *SlackBot) CreateChannel(ctx context.Context, name string) (string, error)

CreateChannel creates a new public Slack channel. If the channel name is already taken, it looks up the existing channel and returns its ID.

func (*SlackBot) CreateSimpleThread added in v0.1.31

func (b *SlackBot) CreateSimpleThread(ctx context.Context, channelID, name, initialMessage string) (string, error)

CreateSimpleThread creates a new thread with a plain initial message (no bot mention). The name is posted as the parent message (the thread "title" in Slack), and the initialMessage is posted as the first reply inside the thread. Returns a composite "channelID:messageTS" thread ID.

func (*SlackBot) CreateThread

func (b *SlackBot) CreateThread(ctx context.Context, channelID, name, mentionUserID, message string) (string, error)

CreateThread creates a new thread by posting an initial message in the channel. Returns a composite ID "channelID:messageTS" that represents the thread.

func (*SlackBot) DeleteThread

func (b *SlackBot) DeleteThread(ctx context.Context, threadID string) error

DeleteThread deletes a thread by deleting all its messages (replies and parent).

func (*SlackBot) GetChannelName added in v0.1.22

func (b *SlackBot) GetChannelName(_ context.Context, channelID string) (string, error)

GetChannelName returns the name of a Slack channel by its ID.

func (*SlackBot) GetChannelParentID

func (b *SlackBot) GetChannelParentID(_ context.Context, channelID string) (string, error)

GetChannelParentID returns the parent channel ID for a thread (composite ID), or empty string if not a thread.

func (*SlackBot) GetMemberRoles added in v0.1.41

func (b *SlackBot) GetMemberRoles(_ context.Context, _, _ string) ([]string, error)

GetMemberRoles returns nil for Slack — Slack has no role equivalent. Slack-based access control relies on allow_users only.

func (*SlackBot) GetOwnerUserID added in v0.1.20

func (b *SlackBot) GetOwnerUserID(ctx context.Context) (string, error)

GetOwnerUserID returns the Slack workspace owner's user ID.

func (*SlackBot) HandleIncomingMessage added in v0.2.0

func (b *SlackBot) HandleIncomingMessage(_ context.Context, _, _, _, _ string)

func (*SlackBot) HandleThreadCreated added in v0.2.0

func (b *SlackBot) HandleThreadCreated(ctx context.Context, threadID, _, message string)

HandleThreadCreated posts the initial message (with a bot mention) to the thread so that the normal message event handler picks it up and triggers a new agent run.

func (*SlackBot) InviteUserToChannel

func (b *SlackBot) InviteUserToChannel(ctx context.Context, channelID, userID string) error

InviteUserToChannel invites a user to a Slack channel.

func (*SlackBot) IsBotUser added in v0.2.0

func (b *SlackBot) IsBotUser(userID string) bool

IsBotUser returns true if the given userID matches the bot's user ID.

func (*SlackBot) OnChannelDelete

func (b *SlackBot) OnChannelDelete(handler bot.ChannelDeleteHandler)

OnChannelDelete registers a handler to be called when a channel is deleted.

func (*SlackBot) OnChannelJoin added in v0.1.22

func (b *SlackBot) OnChannelJoin(handler bot.ChannelJoinHandler)

OnChannelJoin registers a handler to be called when the bot joins a channel.

func (*SlackBot) OnInteraction

func (b *SlackBot) OnInteraction(handler bot.InteractionHandler)

OnInteraction registers a handler to be called for slash command interactions.

func (*SlackBot) OnMessage

func (b *SlackBot) OnMessage(handler bot.MessageHandler)

OnMessage registers a handler to be called for incoming messages.

func (*SlackBot) PostMessage

func (b *SlackBot) PostMessage(ctx context.Context, channelID, content string) error

PostMessage sends a simple message to the given channel or thread. Text mentions of the bot (e.g. @BotName) are converted to proper Slack mentions.

func (*SlackBot) RegisterCommands

func (b *SlackBot) RegisterCommands(_ context.Context) error

RegisterCommands is a no-op for Slack. Commands are registered via the Slack app manifest.

func (*SlackBot) RemoveCommands

func (b *SlackBot) RemoveCommands(_ context.Context) error

RemoveCommands is a no-op for Slack.

func (*SlackBot) RemoveStopButton added in v0.1.42

func (b *SlackBot) RemoveStopButton(_ context.Context, channelID, messageID string) error

RemoveStopButton removes the stop button message by deleting it.

func (*SlackBot) RenameThread added in v0.1.49

func (b *SlackBot) RenameThread(ctx context.Context, threadID, name string) error

RenameThread renames a Slack thread by updating the parent message text. The parent message acts as the thread "title" — response content lives in replies.

func (*SlackBot) SendMessage

func (b *SlackBot) SendMessage(ctx context.Context, msg *bot.OutgoingMessage) error

SendMessage sends one or more messages to Slack, splitting at 4000 chars.

func (*SlackBot) SendStopButton added in v0.1.42

func (b *SlackBot) SendStopButton(_ context.Context, channelID, runID string) (string, error)

SendStopButton sends a message with a Block Kit "Stop" button.

func (*SlackBot) SendTyping

func (b *SlackBot) SendTyping(ctx context.Context, channelID string) error

SendTyping adds an "eyes" emoji reaction to the last received message in the channel and removes it when the context is cancelled.

func (*SlackBot) SetChannelTopic added in v0.1.21

func (b *SlackBot) SetChannelTopic(ctx context.Context, channelID, topic string) error

SetChannelTopic sets the topic/description of a Slack channel.

func (*SlackBot) Start

func (b *SlackBot) Start(ctx context.Context) error

Start authenticates with Slack and begins listening for Socket Mode events.

func (*SlackBot) Stop

func (b *SlackBot) Stop() error

Stop cancels the Socket Mode connection.

type SlackSession

type SlackSession interface {
	PostMessage(channelID string, options ...goslack.MsgOption) (string, string, error)
	DeleteMessage(channel, messageTimestamp string) (string, string, error)
	UpdateMessage(channelID, timestamp string, options ...goslack.MsgOption) (string, string, string, error)
	AuthTest() (*goslack.AuthTestResponse, error)
	CreateConversation(params goslack.CreateConversationParams) (*goslack.Channel, error)
	AddReaction(name string, item goslack.ItemRef) error
	RemoveReaction(name string, item goslack.ItemRef) error
	GetConversationReplies(params *goslack.GetConversationRepliesParameters) ([]goslack.Message, bool, string, error)
	InviteUsersToConversation(channelID string, users ...string) (*goslack.Channel, error)
	GetConversations(params *goslack.GetConversationsParameters) ([]goslack.Channel, string, error)
	GetUsers(options ...goslack.GetUsersOption) ([]goslack.User, error)
	SetTopicOfConversation(channelID, topic string) (*goslack.Channel, error)
	SetUserPresence(presence string) error
	GetConversationInfo(input *goslack.GetConversationInfoInput) (*goslack.Channel, error)
}

SlackSession abstracts the slack.Client methods used by the bot, enabling test mocking.

type SocketModeClient

type SocketModeClient interface {
	RunContext(ctx context.Context) error
	Ack(req socketmode.Request, payload ...any)
	Events() <-chan socketmode.Event
}

SocketModeClient abstracts the socketmode.Client for testability.

func NewSocketModeAdapter

func NewSocketModeAdapter(client *socketmode.Client) SocketModeClient

NewSocketModeAdapter wraps a socketmode.Client as a SocketModeClient.

Jump to

Keyboard shortcuts

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