Documentation
¶
Overview ¶
Package slack is the Slack source: ingestion, rows, cards and the plugin's capabilities.
Index ¶
- Constants
- func Card(_ context.Context, r api.Row) (card.Card, error)
- func FollowUnit(ctx context.Context, c *slackapi.Client, team, permalink string) (unit.Unit, error)
- func IsPermalink(s string) bool
- func Module(cfg config.Config, d sourcereg.Deps, s Slack) (sourcereg.Module, error)
- func ThreadOf(permalink string) string
- type Every
- type HeatScheduler
- type Landing
- type Metrics
- func (m *Metrics) Admitted(v dslack.Via)
- func (m *Metrics) Backfill(conversations, threads, deltas int, done bool)
- func (m *Metrics) CatchUp(reason string, deltas, missedWhileConnected int)
- func (m *Metrics) RateLimited(method string)
- func (m *Metrics) Received()
- func (m *Metrics) Socket(s socket.State)
- func (m *Metrics) Warn(source string, fn func() []string)
- type Payload
- type Payloads
- type Places
- type Publisher
- func (p *Publisher) Publish(ctx context.Context, d draft.Draft) (draft.Evidence, error)
- func (p *Publisher) Validate(ctx context.Context, d draft.Draft) error
- func (p *Publisher) Verify(ctx context.Context, d draft.Draft, startedAt time.Time) (draft.Evidence, bool, error)
- func (p *Publisher) Where(ctx context.Context, d draft.Draft) (string, error)
- type Reader
- type Segments
- type Slack
- type Source
- func (s *Source) Discover(ctx context.Context, cursor string) ([]port.Stub, string, error)
- func (s *Source) Provider() unit.ProviderID
- func (s *Source) Read(ctx context.Context, objects []string) (port.Facts, error)
- func (s *Source) Stubs(ctx context.Context, objects []string) ([]port.Stub, error)
- func (s *Source) Viewer(context.Context) (string, error)
- type Store
- func (s *Store) Changes(ctx context.Context, afterSeq int64, limit int) ([]dslack.Change, error)
- func (s *Store) Conversation(ctx context.Context, id string) (dslack.Conversation, error)
- func (s *Store) Cursor(ctx context.Context) (string, error)
- func (s *Store) Messages(ctx context.Context, u unit.Unit, after string, limit int) ([]dslack.Message, error)
- func (s *Store) MessagesBefore(ctx context.Context, conv, before string, n int) ([]dslack.Message, error)
- func (s *Store) Save(ctx context.Context, light []port.Facts, read port.Facts, cursor string, ...) error
- func (s *Store) See(ctx context.Context, objects []string, at time.Time) error
- func (s *Store) UserByEmail(ctx context.Context, email string) (dslack.User, bool, error)
- func (s *Store) Users(ctx context.Context, ids []string) (map[string]dslack.User, error)
- func (s *Store) Versions(ctx context.Context, objects []string) (map[string]string, error)
- func (s *Store) Viewer(ctx context.Context) (team, user string, err error)
- func (s *Store) Watched(ctx context.Context) ([]port.Stub, error)
- type Watches
Constants ¶
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.
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 )
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.
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 )
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).
const ( SkipNotConfigured = "slack: not configured" SkipNotLoggedIn = "slack: not logged in" SkipNoStore = "slack: no store" )
Skip texts of the ingestion job.
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.
const ( CursorViewerTeam = "viewer_team" CursorViewerUser = "viewer_user" )
Cursor names of slack_cursors.
const CursorBackfill = "backfill"
CursorBackfill is set once the first start's backfill finished.
const Debounce = 2 * time.Second
Debounce is how long the inbox gathers an object's deltas before one Touch.
const DefaultPoll = 5 * time.Minute
DefaultPoll is the default Scheduler's interval.
const DefaultSince = 7 * 24 * time.Hour
DefaultSince is how far back the backfill reads without slack.ingest.since.
const ( // DropEvery spaces the catch-ups that recover what the inbox dropped. DropEvery = 5 * time.Minute )
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.
const IngestEvery = time.Minute
IngestEvery is the Slack ingestion job's interval.
const SearchEvery = 5 * time.Minute
SearchEvery is how often Discover runs the mention search; a catch-up runs it whatever its age.
const SkipBudget = "slack: budget low for "
SkipBudget prefixes the job's skip text while a probe method's budget is spent.
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.
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 FollowUnit ¶
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 ¶
IsPermalink says whether s is a Slack message permalink.
Types ¶
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.
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 ¶
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) RateLimited ¶
RateLimited is wired to slack.Client.OnRateLimited.
type Payload ¶
type Payload struct {
// contains filtered or unexported fields
}
Payload is a Slack unit as a turn reads it.
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.
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.
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 ¶
Publish posts d once. An error after the request may have reached Slack starts "may have been posted".
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 ¶
ReaderOver reads the facts the Slack module stores in db.
type Segments ¶
type Segments struct {
Store *sqlite.SegmentStore
Clock port.Clock
}
Segments is the DM segment map in the store, as units.
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 ¶
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
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) Conversation ¶
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 ¶
See stamps every object the pass returned and moves each to the Scheduler's next check, changed or not.
func (*Store) UserByEmail ¶
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.
Source Files
¶
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. |