slack

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatMrkdwn

func FormatMrkdwn(text string) string

FormatMrkdwn converts standard Markdown to Slack mrkdwn format.

Conversions:

  • **bold** → *bold*
  • ~~strike~~ → ~strike~
  • [text](url) → <url|text>
  • # Heading → *Heading*

Content inside code blocks (```) is preserved without transformation.

Types

type ApprovalProvider

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

ApprovalProvider implements approval.Provider for Slack using Block Kit action buttons.

func NewApprovalProvider

func NewApprovalProvider(api Client, timeout time.Duration) *ApprovalProvider

NewApprovalProvider creates a Slack approval provider.

func (*ApprovalProvider) CanHandle

func (p *ApprovalProvider) CanHandle(sessionKey string) bool

CanHandle returns true for session keys starting with "slack:".

func (*ApprovalProvider) HandleInteractive

func (p *ApprovalProvider) HandleInteractive(actionID string)

HandleInteractive processes a Slack interactive callback (block_actions) for approval.

func (*ApprovalProvider) RequestApproval

RequestApproval posts a message with approve/deny/always-allow action buttons and waits for interaction.

type Block

type Block struct {
	Type string
	Text *TextBlock
}

Block represents a Slack Block Kit block

type Channel

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

Channel implements Slack bot

func New

func New(cfg Config) (*Channel, error)

New creates a new Slack channel

func (*Channel) GetApprovalProvider

func (c *Channel) GetApprovalProvider() *ApprovalProvider

GetApprovalProvider returns the channel's approval provider for composite registration.

func (*Channel) Send

func (c *Channel) Send(channelID string, msg *OutgoingMessage) error

Send sends a message. Standard Markdown in msg.Text is auto-converted to Slack mrkdwn before sending.

func (*Channel) SetHandler

func (c *Channel) SetHandler(handler MessageHandler)

SetHandler sets the message handler

func (*Channel) Start

func (c *Channel) Start(ctx context.Context) error

Start starts the Slack bot

func (*Channel) StartTyping

func (c *Channel) StartTyping(channelID string) func()

StartTyping posts a "_Processing..._ " placeholder message. The returned stop function deletes the placeholder on call. If posting fails, a no-op stop function is returned.

func (*Channel) Stop

func (c *Channel) Stop()

Stop stops the Slack bot

type Client

type Client interface {
	AuthTest() (*slack.AuthTestResponse, error)
	PostMessage(channelID string, options ...slack.MsgOption) (string, string, error)
	UpdateMessage(channelID, timestamp string, options ...slack.MsgOption) (string, string, string, error)
	DeleteMessage(channelID, messageTimestamp string) (string, string, error)
}

Client defines the interface for Slack REST API operations.

type Config

type Config struct {
	BotToken           string // xoxb-...
	AppToken           string // xapp-... (for Socket Mode)
	SigningSecret      string
	ApprovalTimeoutSec int          // 0 = default 30s
	APIURL             string       // optional, for testing
	HTTPClient         *http.Client // optional, for testing
	Client             Client       // optional, for testing
	Socket             Socket       // optional, for testing
}

Config holds Slack channel configuration

type IncomingMessage

type IncomingMessage struct {
	EventType string // app_mention, message
	ChannelID string
	UserID    string
	Text      string
	ThreadTS  string
	IsThread  bool
}

IncomingMessage represents a message from Slack

type MessageHandler

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

MessageHandler handles incoming messages

type OutgoingMessage

type OutgoingMessage struct {
	Text     string
	ThreadTS string
	Blocks   []Block
}

OutgoingMessage represents a message to send

type SlackClient

type SlackClient struct {
	*slack.Client
}

SlackClient is an adapter for *slack.Client.

func NewSlackClient

func NewSlackClient(c *slack.Client) *SlackClient

NewSlackClient creates a new SlackClient adapter.

type SlackSocket

type SlackSocket struct {
	*socketmode.Client
}

SlackSocket is an adapter for *socketmode.Client.

func NewSlackSocket

func NewSlackSocket(c *socketmode.Client) *SlackSocket

NewSlackSocket creates a new SlackSocket adapter.

func (*SlackSocket) Events

func (s *SlackSocket) Events() <-chan socketmode.Event

Events returns the events channel.

type Socket

type Socket interface {
	Run() error
	Ack(req socketmode.Request, payload ...interface{})
	Events() <-chan socketmode.Event
}

Socket defines the interface for Slack Socket Mode operations.

type TextBlock

type TextBlock struct {
	Type string // mrkdwn, plain_text
	Text string
}

TextBlock represents text in a block

Jump to

Keyboard shortcuts

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