slack

package
v0.1.19 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelDeleteHandler

type ChannelDeleteHandler = func(ctx context.Context, channelID string, isThread bool)

ChannelDeleteHandler is a callback for channel deletion events.

type IncomingMessage

type IncomingMessage = orchestrator.IncomingMessage

IncomingMessage is an alias for orchestrator.IncomingMessage.

type InteractionHandler

type InteractionHandler = func(ctx context.Context, i any)

InteractionHandler is a callback for slash command interactions.

type MessageHandler

type MessageHandler = func(ctx context.Context, msg *IncomingMessage)

MessageHandler is a callback for incoming messages.

type OutgoingMessage

type OutgoingMessage = orchestrator.OutgoingMessage

OutgoingMessage is an alias for orchestrator.OutgoingMessage.

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) 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 its parent message.

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) InviteUserToChannel

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

InviteUserToChannel invites a user to a Slack channel.

func (*SlackBot) OnChannelDelete

func (b *SlackBot) OnChannelDelete(handler ChannelDeleteHandler)

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

func (*SlackBot) OnInteraction

func (b *SlackBot) OnInteraction(handler InteractionHandler)

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

func (*SlackBot) OnMessage

func (b *SlackBot) OnMessage(handler 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) SendMessage

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

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

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) 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)
	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)
}

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