slack

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package slack provides a DataSource connector that enumerates Slack channel messages for vectorization. It uses the Slack Web API (conversations.history) and requires a bot token with channels:history and channels:read.

Package slack provides a Messenger adapter for the Slack platform.

This file implements the HTTP Events API handler (eventsHTTPHandler), enabling Slack to receive events via HTTP push instead of Socket Mode. This allows the adapter to be mounted on a shared HTTP mux at a context path (e.g., /agents/{name}/slack/events) rather than requiring its own WebSocket connection or dedicated port.

The Events API is Slack's recommended approach for production apps that have a publicly accessible endpoint. It delivers events as signed HTTP POST requests. See: https://api.slack.com/events-api

Package slack provides a Messenger adapter for the Slack platform using Socket Mode for bi-directional communication without a public endpoint.

The adapter wraps github.com/slack-go/slack and its Socket Mode client. Incoming events are received over a WebSocket connection, and outgoing messages are sent via the Slack Web API.

Transport: Socket Mode (WebSocket — no public endpoint required).

Authentication

Two tokens are required:

  • An app-level token (xapp-…) with the connections:write scope for Socket Mode.
  • A bot user OAuth token (xoxb-…) with chat:write and other desired scopes.

Usage

m := slack.New(slack.Config{
	AppToken: os.Getenv("SLACK_APP_TOKEN"),
	BotToken: os.Getenv("SLACK_BOT_TOKEN"),
})
if err := m.Connect(ctx); err != nil { /* handle */ }
defer m.Disconnect(ctx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AppToken is the Slack app-level token (xapp-...) required for Socket Mode.
	// Not needed when using HTTP Events API mode (SigningSecret + SharedMux).
	AppToken string
	// BotToken is the Slack bot user OAuth token (xoxb-...).
	BotToken string
	// SigningSecret is used to verify incoming HTTP Events API requests.
	// When set together with WithSharedMux(), the adapter operates in HTTP
	// push mode instead of Socket Mode: incoming events arrive as signed
	// HTTP POST requests rather than over a WebSocket connection.
	// See: https://api.slack.com/authentication/verifying-requests-from-slack
	SigningSecret string
}

Config holds Slack-specific configuration.

type Messenger

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

Messenger implements the messenger.Messenger interface for Slack. It supports two transport modes:

  • Socket Mode (default): outbound WebSocket, no public endpoint required.
  • HTTP Events API: inbound HTTP push, requires SigningSecret + SharedMux.

It manages the event routing, incoming message buffer, and connection state through an internal mutex.

func New

func New(cfg Config, opts ...messenger.Option) *Messenger

New creates a new Slack Messenger with the given config and options.

func (*Messenger) Connect

func (m *Messenger) Connect(ctx context.Context) (http.Handler, error)

Connect establishes a connection to Slack and returns an optional http.Handler.

In HTTP Events API mode (SigningSecret set): returns a non-nil handler that the caller mounts at a context path. Events arrive as signed HTTP POST requests.

In Socket Mode (default): returns nil handler and opens an outbound WebSocket connection. No inbound HTTP required.

func (*Messenger) ConnectionInfo

func (m *Messenger) ConnectionInfo() string

ConnectionInfo returns connection instructions for the Slack adapter.

func (*Messenger) Disconnect

func (m *Messenger) Disconnect(ctx context.Context) error

Disconnect gracefully shuts down the Slack connection.

func (*Messenger) FormatApproval

FormatApproval builds a Slack Block Kit message for an approval notification. This satisfies the messenger.ApprovalFormatter interface, keeping all Slack-specific formatting inside the Slack adapter.

func (*Messenger) FormatClarification

FormatClarification builds a Slack Block Kit message for a clarification question.

func (*Messenger) Platform

func (m *Messenger) Platform() messenger.Platform

Platform returns the Slack platform identifier.

func (*Messenger) Receive

func (m *Messenger) Receive(_ context.Context) (<-chan messenger.IncomingMessage, error)

Receive returns a channel of incoming messages from Slack.

func (*Messenger) Send

Send delivers a message to a Slack channel or thread. If req.Type is SendTypeReaction, adds an emoji reaction to the message identified by ReplyToMessageID (format "channelID:ts"). If req.Metadata["blocks"] contains a []slack.Block, the message is sent with Block Kit formatting.

func (*Messenger) UpdateMessage

func (m *Messenger) UpdateMessage(ctx context.Context, req messenger.UpdateRequest) error

UpdateMessage replaces the content of a previously sent Slack message using the chat.update API. Used to disarm approval/clarification buttons after resolution (e.g. replacing buttons with "✅ Approved by @user").

The MessageID must be in the "channelID:timestamp" format returned by Send. If Metadata["blocks"] is set, the blocks are used for the update.

type SlackConnector

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

SlackConnector implements datasource.DataSource for Slack channels. It fetches conversation history for each channel in scope and returns normalized items (one per message) for the sync pipeline to vectorize.

func NewSlackConnector

func NewSlackConnector(api *slack.Client) *SlackConnector

NewSlackConnector returns a DataSource that lists messages from Slack channels. The caller must provide an authenticated slack.Client (e.g. from slack.New(botToken)); the connector uses conversations.history and does not connect via Socket Mode.

func (*SlackConnector) ListItems

ListItems fetches messages from each channel in scope.SlackChannelIDs and returns them as NormalizedItems. Each message becomes one item with ID "slack:channelID:timestamp" and content equal to the message text.

func (*SlackConnector) Name

func (c *SlackConnector) Name() string

Name returns the source identifier for Slack.

Jump to

Keyboard shortcuts

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