slack

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 41 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package slack is the Slack source: ingestion, rows, cards and the plugin's capabilities.

Index

Constants

View Source
const (
	RuleMention   = "mention"
	RuleTerm      = "term"
	RuleRepliedTo = "replied-to-viewer"
	RuleWroteIn   = "viewer-in-thread"
	RuleDM        = "dm"
	RuleFollowed  = "followed"
	RuleWatched   = "watched"
)

Admission rules (Slack spec 5.1), named in logs and tests.

View Source
const (
	// StartOverlap is how far before the high-water mark the start's
	// catch-up reads: a stop drops envelopes acked but still queued and
	// deltas still in the inbox, while later messages moved the mark.
	StartOverlap = 10 * time.Minute
	// DMSearch is the search.messages modifier for direct and group messages.
	DMSearch = "is:dm"
	// DMThreadWindow is how far before a DM's high-water mark the catch-up
	// probes stored threads for replies: history carries no replies.
	DMThreadWindow = 7 * 24 * time.Hour
)
View Source
const (
	ReasonStart     = "start"
	ReasonReconnect = "reconnect"
	ReasonOverflow  = "overflow"
	ReasonClockJump = "clock_jump"
	ReasonDown      = "down_5m"
	ReasonDropped   = "touch_failed"
)

Catch-up reasons, as health reports them in last_catchup.

View Source
const (
	// GapTick is how often the gap detector compares the clocks.
	GapTick = 30 * time.Second
	// ClockJump is how far the wall clock must outrun the monotonic one to
	// count as a wake from sleep: on macOS the monotonic clock stops asleep.
	ClockJump = 20 * time.Minute
	// DownGap is how long the socket may stay down before a catch-up runs
	// without waiting for the reconnect; Slack redelivers for about 6 min.
	DownGap = 5 * time.Minute
)
View Source
const (
	SocketDownWarnAfter = 5 * time.Minute
	MissedWarnAt        = 5
	GrantWarnDays       = 25
	// LoginRecheck is how long a found login is trusted before the Keychain
	// is read again; a call that finds the login gone forgets it at once.
	LoginRecheck = 5 * time.Minute
)

Health thresholds (#slack-health).

View Source
const (
	SkipNotConfigured = "slack: not configured"
	SkipNotLoggedIn   = "slack: not logged in"
	SkipNoStore       = "slack: no store"
)

Skip texts of the ingestion job.

View Source
const (
	PollActive = 5 * time.Minute
	PollWarm   = 30 * time.Minute
	PollCold   = 60 * time.Minute
	// RecentFor keeps an object active after its last activity.
	RecentFor = 24 * time.Hour
)

Poll intervals by heat; polling never stops.

View Source
const (
	CursorViewerTeam = "viewer_team"
	CursorViewerUser = "viewer_user"
)

Cursor names of slack_cursors.

View Source
const CursorBackfill = "backfill"

CursorBackfill is set once the first start's backfill finished.

View Source
const Debounce = 2 * time.Second

Debounce is how long the inbox gathers an object's deltas before one Touch.

View Source
const DefaultPoll = 5 * time.Minute

DefaultPoll is the default Scheduler's interval.

View Source
const DefaultSince = 7 * 24 * time.Hour

DefaultSince is how far back the backfill reads without slack.ingest.since.

View Source
const (
	// DropEvery spaces the catch-ups that recover what the inbox dropped.
	DropEvery = 5 * time.Minute
)
View Source
const EventWindow = 10 * time.Minute

EventWindow is how long the stream remembers an event_id: Slack redelivers events whose ack it missed, even on a live connection.

View Source
const IngestEvery = time.Minute

IngestEvery is the Slack ingestion job's interval.

View Source
const SearchEvery = 5 * time.Minute

SearchEvery is how often Discover runs the mention search; a catch-up runs it whatever its age.

View Source
const SkipBudget = "slack: budget low for "

SkipBudget prefixes the job's skip text while a probe method's budget is spent.

View Source
const SkipSearchLimited = "slack: search.messages budget is low"

SkipSearchLimited is why a search did not run: search.messages is inside its Retry-After window or spent its budget for the minute.

View Source
const UserTTL = 24 * time.Hour

UserTTL is how long a user read from Slack is served from slack_users.

Variables

This section is empty.

Functions

func Card

func Card(_ context.Context, r api.Row) (card.Card, error)

Card is a Slack unit's card, read from its row alone.

func FollowUnit

func FollowUnit(ctx context.Context, c *slackapi.Client, team, permalink string) (unit.Unit, error)

FollowUnit is the thread unit a permalink names in team: the parent's thread when it names a reply. A permalink without thread_ts costs one conversations.replies call to find the parent.

func IsPermalink(s string) bool

IsPermalink says whether s is a Slack message permalink.

func Module

func Module(cfg config.Config, d sourcereg.Deps, s Slack) (sourcereg.Module, error)

Module is the Slack source: an ingestion job every minute, the socket stream and follows. Without a store, a login or an app token it stays idle.

func ThreadOf

func ThreadOf(permalink string) string

ThreadOf is the thread_ts a message permalink carries, "" when none.

Types

type Every

type Every time.Duration

Every is a Scheduler that checks every object again after a fixed interval.

func (Every) Next

func (e Every) Next(_ context.Context, objects []string, now time.Time) (map[string]time.Time, error)

type HeatScheduler

type HeatScheduler struct {
	DB       *sqlite.SlackStore
	Heat     port.HeatReader
	Segments dslack.Segments
	Log      func(format string, args ...any)
}

HeatScheduler is the dslack.Scheduler that checks an object again by the heat of its units and its last activity: active or active in the last RecentFor every PollActive, warm every PollWarm, cold every PollCold. An object the store lacks yet is active, and so is every object when the heat cannot be read.

func (HeatScheduler) Next

func (h HeatScheduler) Next(ctx context.Context, objects []string, now time.Time) (map[string]time.Time, error)

type Landing

type Landing struct {
	Facts    dslack.FactsReader
	Segments dslack.Segments
}

Landing finds the tracked unit a post outside the outbox landed in.

func LandingOver

func LandingOver(db *sqlite.DB) Landing

LandingOver reads the facts and segments the Slack module stores in db.

func (Landing) UnitOf

func (l Landing) UnitOf(ctx context.Context, team, channel, ts, threadTS string) (unit.Unit, bool, error)

UnitOf is the unit of a post in team at ts in channel, in the thread threadTS ("" when none): the DM segment covering its anchor, or its channel thread when the facts store it. It reads only the store; false when untracked.

type Metrics

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

Metrics are the Slack source's in-memory counters, safe for concurrent use; the zero value is ready.

func (*Metrics) Admitted

func (m *Metrics) Admitted(v dslack.Via)

func (*Metrics) Backfill

func (m *Metrics) Backfill(conversations, threads, deltas int, done bool)

func (*Metrics) CatchUp

func (m *Metrics) CatchUp(reason string, deltas, missedWhileConnected int)

func (*Metrics) RateLimited

func (m *Metrics) RateLimited(method string)

RateLimited is wired to slack.Client.OnRateLimited.

func (*Metrics) Received

func (m *Metrics) Received()

func (*Metrics) Socket

func (m *Metrics) Socket(s socket.State)

func (*Metrics) Warn

func (m *Metrics) Warn(source string, fn func() []string)

Warn registers fn as the warnings of source, e.g. the extraction breaker; a second call replaces it.

type Payload

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

Payload is a Slack unit as a turn reads it.

func (Payload) Arg

func (p Payload) Arg() string

func (Payload) Contents

func (p Payload) Contents() string

func (Payload) Fact

func (p Payload) Fact(string) (any, bool)

func (Payload) Unit

func (p Payload) Unit() unit.Unit

func (Payload) Wording

func (p Payload) Wording() turn.Wording

type Payloads

type Payloads struct {
	Facts dslack.FactsReader
	// MaxChars zero is the config's default.
	MaxChars int
}

Payloads reads a Slack unit's turn payload from the stored facts: its messages rendered as slack_read renders them, within MaxChars.

func (Payloads) Payload

func (r Payloads) Payload(ctx context.Context, req turn.Request) (turn.Payload, error)

type Places

type Places struct {
	Hints interface {
		Hints(ctx context.Context, u unit.Unit) (map[string]extract.Hint, error)
	}
	// Conversation fails with dslack.ErrUnknownUnit for a conversation not stored.
	Conversation func(ctx context.Context, id string) (dslack.Conversation, error)
	Contexts     func() placement.Map
}

Places are Slack's placement hints and defaults. The hint is the contexts rule the extraction suggested for the unit's items; the default is the first "slack:#<channel name>" rule that matches the unit's channel.

func (Places) Default

func (p Places) Default(ctx context.Context, u unit.Unit, _ string) (placement.Placement, bool, error)

Default is the first "slack:#<name>" rule matching the unit's channel; a direct message has none.

func (Places) Suggested

func (p Places) Suggested(ctx context.Context, u unit.Unit, item string) (placement.Placement, bool, error)

Suggested is the rule the extraction named for item; for no item, the one rule every hinted item of the unit names.

type Publisher

type Publisher struct {
	Send *send.Service
	// Token is the stored user token: its user and granted scopes.
	Token    func() (auth.Token, error)
	Segments interface {
		Range(ctx context.Context, u unit.Unit) (conv, fromTS, toTS string, err error)
	}
	// People are the persons the unit's items name, for mentions of other providers.
	People func(ctx context.Context, u unit.Unit) ([]items.Person, error)
	Now    func() time.Time
	Log    func(format string, args ...any)
}

Publisher posts Slack drafts as the user: messages through send's resolution and post allowlist, reactions with reactions.add.

func PublisherOver

func PublisherOver(db *sqlite.DB, s *send.Service, token func() (auth.Token, error), now func() time.Time, log func(string, ...any)) *Publisher

PublisherOver publishes through s, with the segments and the items' persons db stores.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, d draft.Draft) (draft.Evidence, error)

Publish posts d once. An error after the request may have reached Slack starts "may have been posted".

func (*Publisher) Validate

func (p *Publisher) Validate(ctx context.Context, d draft.Draft) error

Validate refuses, without posting, a draft Slack would not take.

func (*Publisher) Verify

func (p *Publisher) Verify(ctx context.Context, d draft.Draft, startedAt time.Time) (draft.Evidence, bool, error)

Verify looks for d posted by the user at or after startedAt, minus the clock skew. A failed read says where to check.

func (*Publisher) Where

func (p *Publisher) Where(ctx context.Context, d draft.Draft) (string, error)

Where names the conversation d would post to.

type Reader

type Reader struct {
	Facts    dslack.FactsReader
	Segments interface {
		UnitsFor(ctx context.Context, conv, ts string) ([]unit.Unit, error)
	}
	Client *slackapi.Client
}

Reader renders a unit's or a permalink's messages for slack_read. It reads the stored facts and calls Slack only for a channel thread that is not stored; a direct message is read from its stored segments only. It never stores or admits what it reads.

func ReaderOver

func ReaderOver(db *sqlite.DB, c *slackapi.Client) *Reader

ReaderOver reads the facts the Slack module stores in db.

func (*Reader) Read

func (r *Reader) Read(ctx context.Context, target string, limit int) (string, error)

Read renders target, a unit ("slack:<key>") or a message permalink, keeping the first message and the newest up to limit in all.

type Segments

type Segments struct {
	Store *sqlite.SegmentStore
	Clock port.Clock
}

Segments is the DM segment map in the store, as units.

func (Segments) Apply

func (s Segments) Apply(ctx context.Context, team, conv string, spans []dslack.Span) ([]unit.Unit, error)

func (Segments) Range

func (s Segments) Range(ctx context.Context, u unit.Unit) (conv, fromTS, toTS string, err error)

func (Segments) UnitsFor

func (s Segments) UnitsFor(ctx context.Context, conv, ts string) ([]unit.Unit, error)

type Slack

type Slack struct {
	Tokens *auth.Store
	Client *slackapi.Client
	// Open is apps.connections.open; nil calls Client.ConnectionsOpen with the app token.
	Open func(ctx context.Context) (string, error)
	// Dial nil is coder/websocket.
	Dial    func(ctx context.Context, url string) (socket.Socket, error)
	Metrics *Metrics
	// Now nil is the daemon's clock.
	Now func() time.Time
	// Debounce zero is Debounce.
	Debounce time.Duration
	// Recheck is how often an idle Run looks for a login; zero is IngestEvery.
	Recheck time.Duration
}

Slack are the handles the CLI builds for the plugin: the token store and the client that calls Slack with the user token. Tests set the others.

type Source

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

Source is the Slack port.Source. Read builds facts from the inbox and calls Slack only for an object the store cannot complete: a thread whose parent is unknown, or an object with no waiting delta.

func (*Source) Discover

func (s *Source) Discover(ctx context.Context, cursor string) ([]port.Stub, string, error)

Discover runs the mention search every SearchEvery and returns the objects of the matches it admits; the next cursor is the newest match's ts, saved with the pass's facts. A failed search is logged and the pass goes on with the watched objects.

func (*Source) Provider

func (s *Source) Provider() unit.ProviderID

func (*Source) Read

func (s *Source) Read(ctx context.Context, objects []string) (port.Facts, error)

func (*Source) Stubs

func (s *Source) Stubs(ctx context.Context, objects []string) ([]port.Stub, error)

Stubs are the objects at their stored versions, so only an object never read (version "") moves.

func (*Source) Viewer

func (s *Source) Viewer(context.Context) (string, error)

type Store

type Store struct {
	DB        *sqlite.SlackStore
	Segments  dslack.Segments
	Scheduler dslack.Scheduler
	Now       func() time.Time
}

Store is the Slack source's port.SourceStore and FactsReader over the slack_* tables. Segments may be nil until the segment map exists; a nil Scheduler is Every(DefaultPoll), a nil Now is time.Now.

func (*Store) Changes

func (s *Store) Changes(ctx context.Context, afterSeq int64, limit int) ([]dslack.Change, error)

func (*Store) Conversation

func (s *Store) Conversation(ctx context.Context, id string) (dslack.Conversation, error)

func (*Store) Cursor

func (s *Store) Cursor(ctx context.Context) (string, error)

func (*Store) Messages

func (s *Store) Messages(ctx context.Context, u unit.Unit, after string, limit int) ([]dslack.Message, error)

Messages are u's messages after the ts after, ascending, at most limit.

func (*Store) MessagesBefore

func (s *Store) MessagesBefore(ctx context.Context, conv, before string, n int) ([]dslack.Message, error)

MessagesBefore are the newest n messages of conv anchored before ts, ascending.

func (*Store) Save

func (s *Store) Save(ctx context.Context, light []port.Facts, read port.Facts, cursor string, at time.Time) error

Save stores the light facts, then the read facts (the read wins for one object), then the cursor; every stored object gets its next check from the Scheduler.

func (*Store) See

func (s *Store) See(ctx context.Context, objects []string, at time.Time) error

See stamps every object the pass returned and moves each to the Scheduler's next check, changed or not.

func (*Store) UserByEmail

func (s *Store) UserByEmail(ctx context.Context, email string) (dslack.User, bool, error)

func (*Store) Users

func (s *Store) Users(ctx context.Context, ids []string) (map[string]dslack.User, error)

func (*Store) Versions

func (s *Store) Versions(ctx context.Context, objects []string) (map[string]string, error)

func (*Store) Viewer

func (s *Store) Viewer(ctx context.Context) (team, user string, err error)

Viewer is the team and user of the stored login, from the viewer cursors.

func (*Store) Watched

func (s *Store) Watched(ctx context.Context) ([]port.Stub, error)

Watched are the watched objects due now, with their stored versions.

type Watches

type Watches struct{ DB *sqlite.SlackStore }

Watches is the dslack.Watcher over slack_objects: a watched object the store lacks is read on the next pass.

func (Watches) Unwatch

func (w Watches) Unwatch(ctx context.Context, obj dslack.ObjectRef) error

func (Watches) Watch

func (w Watches) Watch(ctx context.Context, obj dslack.ObjectRef, reason dslack.WatchReason) error

Directories

Path Synopsis
Package eval measures the Slack extractor: an oracle reads a conversation and writes the viewer's briefing, a blind reader writes the same briefing from the extractor's ledger alone, and a judge with the conversation compares them.
Package eval measures the Slack extractor: an oracle reads a conversation and writes the viewer's briefing, a blind reader writes the same briefing from the extractor's ledger alone, and a judge with the conversation compares them.
Package extract turns a Slack conversation window into items ledger ops through one agent call.
Package extract turns a Slack conversation window into items ledger ops through one agent call.
Package slackrows serves Slack units as read model rows: threads and DM segments with their extraction verdict and open items.
Package slackrows serves Slack units as read model rows: threads and DM segments with their extraction verdict and open items.

Jump to

Keyboard shortcuts

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