slack

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const SlackTextLimit = 4000

SlackTextLimit is the maximum character limit for a single Slack message

View Source
const SocketModeURL = "wss://wss.slack.com/ws"

SocketModeURL is the Slack Socket Mode WebSocket endpoint

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	*base.Adapter
	// contains filtered or unexported fields
}

func NewAdapter

func NewAdapter(config Config, logger *slog.Logger, opts ...base.AdapterOption) *Adapter

func (*Adapter) AddReaction added in v0.11.1

func (a *Adapter) AddReaction(ctx context.Context, reaction base.Reaction) error

AddReaction adds a reaction to a message

func (*Adapter) SendAttachment

func (a *Adapter) SendAttachment(ctx context.Context, channelID, threadTS string, attachment base.Attachment) error

SendAttachment sends an attachment to a Slack channel

func (*Adapter) SendMessage

func (a *Adapter) SendMessage(ctx context.Context, sessionID string, msg *base.ChatMessage) error

func (*Adapter) SendMessageWithOptions

func (a *Adapter) SendMessageWithOptions(ctx context.Context, sessionID string, msg *MessageContent, opts SendMessageOptions) error

SendMessageWithOptions sends a message with full options support This includes: message chunking, thread support, rate limiting

func (*Adapter) SendToChannel

func (a *Adapter) SendToChannel(ctx context.Context, channelID, text, threadTS string) error

func (*Adapter) SetSender

func (a *Adapter) SetSender(fn func(ctx context.Context, sessionID string, msg *base.ChatMessage) error)

func (*Adapter) SetSlashCommandHandler added in v0.11.1

func (a *Adapter) SetSlashCommandHandler(fn func(cmd SlashCommand))

SetSlashCommandHandler sets the handler for slash commands

func (*Adapter) Start

func (a *Adapter) Start(ctx context.Context) error

Start starts the adapter (overrides base.Adapter.Start to support Socket Mode)

func (*Adapter) Stop

func (a *Adapter) Stop() error

Stop waits for pending webhook goroutines to complete

type Config

type Config struct {
	BotToken      string
	AppToken      string
	SigningSecret string
	SystemPrompt  string
	// Mode: "http" (default) or "socket" for WebSocket connection
	Mode string
	// ServerAddr: HTTP server address (e.g., ":8080")
	ServerAddr string
}

func (*Config) IsSocketMode

func (c *Config) IsSocketMode() bool

IsSocketMode returns true if Socket Mode is enabled

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration based on the selected mode

type Event

type Event struct {
	Token     string          `json:"token"`
	TeamID    string          `json:"team_id"`
	APIAppID  string          `json:"api_app_id"`
	Type      string          `json:"type"`
	EventID   string          `json:"event_id"`
	EventTime int64           `json:"event_time"`
	Event     json.RawMessage `json:"event"`
	Challenge string          `json:"challenge"`
}

type EventHandler

type EventHandler func(eventType string, data json.RawMessage)

EventHandler handles incoming Slack events

type MessageContent

type MessageContent struct {
	Content string
}

MessageContent represents the content of a message to send

type MessageEvent

type MessageEvent struct {
	Type        string `json:"type"`
	Channel     string `json:"channel"`
	ChannelType string `json:"channel_type"`
	User        string `json:"user"`
	Text        string `json:"text"`
	TS          string `json:"ts"`
	EventTS     string `json:"event_ts"`
	BotID       string `json:"bot_id,omitempty"`
	SubType     string `json:"subtype,omitempty"`
	ThreadTS    string `json:"thread_ts,omitempty"`      // Thread identifier
	ParentUser  string `json:"parent_user_id,omitempty"` // Parent message user
}

type RetryConfig

type RetryConfig struct {
	MaxAttempts int
	BaseDelay   time.Duration
	MaxDelay    time.Duration
}

RetryConfig configures the retry behavior

type SendMessageOptions

type SendMessageOptions struct {
	ChannelID string
	ThreadTS  string
	Markdown  bool // Whether to convert markdown to mrkdwn
}

SendMessageOptions contains options for sending messages

type SlashCommand added in v0.11.1

type SlashCommand struct {
	Command     string
	Text        string
	UserID      string
	ChannelID   string
	ResponseURL string
}

SlashCommand represents a Slack slash command

type SocketModeConfig

type SocketModeConfig struct {
	AppToken string // xapp-* token
	BotToken string // xoxb-* token
}

SocketModeConfig holds configuration for Socket Mode connection

type SocketModeConnection

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

SocketModeConnection manages a WebSocket connection to Slack's Socket Mode

func NewSocketModeConnection

func NewSocketModeConnection(config SocketModeConfig, logger *slog.Logger) *SocketModeConnection

NewSocketModeConnection creates a new Socket Mode connection

func (*SocketModeConnection) IsConnected

func (s *SocketModeConnection) IsConnected() bool

IsConnected returns true if the connection is active

func (*SocketModeConnection) RegisterHandler

func (s *SocketModeConnection) RegisterHandler(eventType string, handler EventHandler)

RegisterHandler registers an event handler for a specific event type

func (*SocketModeConnection) Send

func (s *SocketModeConnection) Send(data map[string]any) error

Send sends a message over the WebSocket connection

func (*SocketModeConnection) SetReconnectCallbacks added in v0.11.2

func (s *SocketModeConnection) SetReconnectCallbacks(onReconnect func(), onReconnectFail func(error))

SetReconnectCallbacks sets callbacks for reconnection events

func (*SocketModeConnection) Start

func (s *SocketModeConnection) Start(ctx context.Context) error

Start begins the Socket Mode connection

func (*SocketModeConnection) Stop

func (s *SocketModeConnection) Stop() error

Stop closes the Socket Mode connection

Jump to

Keyboard shortcuts

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