slack

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 42 Imported by: 1 module, 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.

Package slack is the Slack source plugin: it reads the conversations the user takes part in through Socket Mode, polling and search, keeps them in its own store, extracts their items through the host's agent, reports each thread and DM segment to the host as a snapshot, posts the drafts the user approves and serves the Slack tools of a session.

Index

Constants

View Source
const (
	// ActionSend posts a message as the user, or says where it would post.
	ActionSend = "send"
	// ActionThread names the thread unit of a message: the parent's thread
	// when it names a reply.
	ActionThread = "thread"
)

The actions the plugin runs for the host's CLI, with no unit.

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 (
	CommandLogin  = "login"
	CommandLogout = "logout"
	CommandStatus = "status"
)

The commands the plugin binary serves in CLI mode.

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 (
	JobIngest  = "ingest"
	JobExtract = "extract"
)

The jobs of the plugin's manifest, which the host runs through Ingest.

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 (
	ToolSend   = "slack_send_message"
	ToolRead   = "slack_read"
	ToolSearch = "slack_search"
	ToolDraft  = "slack_draft"
	ToolReact  = "slack_react"
	ToolEdit   = "slack_edit"
)

The tools of the plugin's manifest.

View Source
const CommandEval = "eval"

CommandEval is the command the running plugin serves, through the daemon: it reads the plugin's store and asks the host's agent.

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 plugins.slack.ingest.since.

View Source
const (
	// DropEvery spaces the catch-ups that recover what the inbox dropped.
	DropEvery = 5 * time.Minute
)
View Source
const EffectUnitClosed = "unit.closed"

EffectUnitClosed is the draft effect that marks a unit's closure, which no extraction pass clears.

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 RestartAfter = 30 * time.Second

RestartAfter is how long the plugin waits before it streams again after the socket failed.

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.

View Source
const ViewHealth = "health"

ViewHealth is the plugin's view of its own health.

Variables

This section is empty.

Functions

func Card

func Card(r slackrows.Row) (src.Card, error)

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

func DraftOf

func DraftOf(d src.Draft) draft.Draft

DraftOf is the plugin's draft of what the host carries.

func FollowUnit

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

FollowUnit is the thread unit a message ref or permalink names in team: the parent's thread when it names a reply. A name that does not say the thread (a ref, a permalink without thread_ts) costs one conversations.replies call to find the parent.

func KnownOver

func KnownOver(db *store.DB, log func(string, ...any)) send.Known

KnownOver finds a conversation as db holds it: a channel with its name and membership, a DM with the other party's handle; one db does not hold, or a channel it holds without a name, is left to Slack.

func StoredOver

func StoredOver(db *store.DB, log func(string, ...any)) send.Stored

StoredOver is the send.Stored over the messages the Slack module stores in db. A deleted message, or one search stored with no thread (its permalink may just not say it), is left to Slack; a store error is logged and left to Slack too.

func WireDraft

func WireDraft(d draft.Draft) src.Draft

WireDraft is d as the host carries it.

Types

type Clock

type Clock interface{ Now() time.Time }

Clock is the plugin's clock.

type Env

type Env struct {
	// Keychain nil is the login Keychain through security.
	Keychain auth.Keychain
	// BaseURL "" is slack.com.
	BaseURL string
	// LockPath "" is the token store's default.
	LockPath string
	// LoginPort nil is the config's plugins.slack.redirect_port.
	LoginPort *int
	// Open nil opens the URL in the default browser.
	Open func(ctx context.Context, url string) error
	// Now nil is the wall clock.
	Now func() time.Time
}

Env is how the plugin reaches the Keychain, Slack and the browser; tests replace each.

func (Env) Kit

func (e Env) Kit(cfg config.Config, logf func(string, ...any), meter func(src.Sample)) *Kit

Kit builds the kit of cfg; meter hears of each Keychain spawn, nil none.

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 Heat

type Heat int

Heat is how busy a unit's items keep it.

const (
	HeatCold Heat = iota
	HeatWarm
	HeatActive
)

type HeatReader

type HeatReader interface {
	Heat(ctx context.Context, units []unit.Unit) (map[unit.Unit]Heat, error)
}

HeatReader reads the heat of units; a unit absent is cold.

type HeatScheduler

type HeatScheduler struct {
	DB       *store.SlackStore
	Heat     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 Kit

type Kit struct {
	Store  *auth.Store
	Client *slackapi.Client
	Send   *send.Service
}

Kit is one process's Slack client, token store and sender over one configuration.

type Landing

type Landing struct {
	Facts    dslack.FactsReader
	Segments dslack.Segments
	// Messages finds the thread of a stored message; nil asks Slack.
	Messages send.Stored
}

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

func LandingOver

func LandingOver(db *store.DB, log func(string, ...any)) Landing

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

func (Landing) MessageUnit

func (l Landing) MessageUnit(ctx context.Context, c *slackapi.Client, team, message string) (unit.Unit, error)

MessageUnit is the unit holding the message a ref or permalink names in team: the tracked DM segment or thread it lands in, else its thread, which the store says when it holds the message and Slack otherwise.

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 LedgerHeat

type LedgerHeat struct {
	Items   func(ctx context.Context, units []unit.Unit) (map[unit.Unit][]items.Item, error)
	WarmFor func() time.Duration
	Now     func() time.Time
}

LedgerHeat reads heat from the host's items: active while a unit has an open item, warm for WarmFor after its last item resolved, cold otherwise.

func (LedgerHeat) Heat

func (h LedgerHeat) Heat(ctx context.Context, units []unit.Unit) (map[unit.Unit]Heat, error)

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) BackfillDraining

func (m *Metrics) BackfillDraining(objects int)

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 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

Payload is a Slack unit as a turn reads it: its argument, its wording and its messages.

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() []config.PlacementRule
}

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) (src.Placement, bool, error)

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

func (Places) Placement

func (p Places) Placement(ctx context.Context, u unit.Unit, item string) (src.Placements, error)

Placement is where u's work runs: the plugin's default and the extraction's suggestion for item.

func (Places) Suggested

func (p Places) Suggested(ctx context.Context, u unit.Unit, item string) (src.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 Plugin

type Plugin struct {
	Env Env
	// Slack, when set, replaces the handles Start builds over the
	// configuration: tests give a fake Slack.
	Slack func(cfg config.Config, kit *Kit) Slack
	// Logger nil is the SDK's.
	Logger hclog.Logger
	// contains filtered or unexported fields
}

Plugin is the Slack source plugin as the SDK serves it.

func (*Plugin) Action

func (s *Plugin) Action(ctx context.Context, req src.ActionRequest) (json.RawMessage, error)

Action runs one of the plugin's actions.

func (*Plugin) ApplyEffect

func (s *Plugin) ApplyEffect(ctx context.Context, req src.EffectRequest) error

func (*Plugin) BriefDescribe

func (s *Plugin) BriefDescribe(ctx context.Context, in src.BriefInput) (string, error)

func (*Plugin) BriefInput

func (s *Plugin) BriefInput(ctx context.Context, u sdk.Unit) (src.BriefInput, error)

func (*Plugin) BriefRevision

func (s *Plugin) BriefRevision(ctx context.Context, u sdk.Unit) (src.BriefRevision, error)

func (*Plugin) BriefStale

func (s *Plugin) BriefStale(ctx context.Context, req src.BriefStaleRequest) (bool, error)

func (*Plugin) BriefWant

func (s *Plugin) BriefWant(_ context.Context, u sdk.Unit) (bool, error)

BriefWant asks the extraction to read u now, past its quiet time: true when u has changes left to read, so a brief of u is coming through Recorder.PutBrief.

func (*Plugin) CallTool

func (s *Plugin) CallTool(ctx context.Context, call src.ToolCall) (src.ToolResult, error)

CallTool runs one of the manifest's tools for the session call.Session.

func (*Plugin) Checkout

func (s *Plugin) Checkout(context.Context, sdk.Unit) (src.Checkout, bool, error)

Checkout is none: a Slack unit's work checks out no repository.

func (*Plugin) Health

func (s *Plugin) Health(ctx context.Context) (sdk.Health, error)

Health is loading until every unit was reported once.

func (*Plugin) Identity

func (s *Plugin) Identity(ctx context.Context) (src.Identity, error)

func (*Plugin) Ingest

func (s *Plugin) Ingest(ctx context.Context, req src.IngestRequest) (src.IngestResult, error)

Ingest runs a job of the manifest.

func (*Plugin) Landed

func (s *Plugin) Landed(ctx context.Context, d src.Draft) (sdk.Unit, bool, error)

func (*Plugin) Locate

func (s *Plugin) Locate(context.Context, string) (sdk.Unit, bool, error)

Locate finds no unit in a checkout: Slack units have none.

func (*Plugin) Notify

func (s *Plugin) Notify(_ context.Context, units []sdk.Unit, _ []sdk.Topic) error

Notify reports units again: their tasks, gates or turns moved.

func (*Plugin) Payload

func (s *Plugin) Payload(ctx context.Context, req src.PayloadRequest) (src.PayloadResult, error)

func (*Plugin) Place

func (s *Plugin) Place(ctx context.Context, d src.Draft) (string, error)

func (*Plugin) Placement

func (s *Plugin) Placement(ctx context.Context, u sdk.Unit, item string) (src.Placements, error)

func (*Plugin) Plan

Plan plans no round: Slack units have no automatic rounds.

func (*Plugin) Proposals

func (s *Plugin) Proposals(context.Context, time.Time) ([]src.Draft, error)

Proposals are none: the plugin's drafts come from the profile's workflows.

func (*Plugin) Publish

func (s *Plugin) Publish(ctx context.Context, d src.Draft) (src.Evidence, error)

func (*Plugin) Resolve

func (s *Plugin) Resolve(ctx context.Context, address string) (sdk.Unit, bool, error)

func (*Plugin) RunCLI

func (s *Plugin) RunCLI(ctx context.Context, req src.CLIRequest, stdout, stderr io.Writer) (int, error)

RunCLI runs login, logout or status with no daemon and no store: they read and write only the Keychain and call Slack. The running plugin runs eval instead, and only it.

func (*Plugin) Start

func (s *Plugin) Start(ctx context.Context, req src.StartRequest) error

Start opens the plugin's store in its state directory, importing what the host exported once, and starts the socket stream and the reports.

func (*Plugin) Stop

func (s *Plugin) Stop(context.Context) error

Stop ends the stream and the reports and closes the store.

func (*Plugin) Track

func (s *Plugin) Track(ctx context.Context, req src.TrackRequest) (src.Tracked, error)

func (*Plugin) Untrack

func (s *Plugin) Untrack(ctx context.Context, w sdk.Unit) error

func (*Plugin) Validate

func (s *Plugin) Validate(ctx context.Context, d src.Draft) error

func (*Plugin) Verify

func (s *Plugin) Verify(ctx context.Context, d src.Draft, startedAt time.Time) (src.Evidence, bool, error)

func (*Plugin) View

func (s *Plugin) View(ctx context.Context, req src.ViewRequest) (json.RawMessage, error)

func (*Plugin) Where

func (s *Plugin) Where(ctx context.Context, d src.Draft) (string, error)

func (*Plugin) WriteState

func (s *Plugin) WriteState(context.Context, src.StateWrite) (src.Evidence, error)

type Problem

type Problem struct {
	Answer string `json:"answer"`
	Fields fields `json:"fields,omitempty"`
}

Problem is one problem of a fix_these answer: an answer of the tool, which the host words, and its fields.

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)
	// Items are the unit's items, whose anchors place a draft on a DM segment.
	Items func(ctx context.Context, u unit.Unit) ([]items.Item, 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 *store.DB, s *send.Service, token func() (auth.Token, error), load func(ctx context.Context, u unit.Unit) ([]items.Item, error),
	now func() time.Time, log func(string, ...any)) *Publisher

PublisherOver publishes through s, with the segments db stores and the host's items of a unit, load.

func (*Publisher) Landed

func (p *Publisher) Landed(_ context.Context, d draft.Draft) (unit.Unit, bool, error)

Landed is the thread the post of d, a draft on a unit of another provider sent to a Slack target, started or replied in, read from its permalink.

func (*Publisher) Place

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

Place names where a draft with no target posts. A thread unit's draft posts in that thread (""). A DM segment has no thread of its own: a message answers the newest message its items anchor on, in that message's thread, which a top-level message starts; a reaction goes on the newest message an item started at, the counterpart's request. A message the user writes with no items goes to the conversation, as typing in the DM does.

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) Takes

func (p *Publisher) Takes(target string) bool

Takes says whether target names a place a draft posts to in Slack: a message permalink, a conversation or a person.

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, or, for a recorded edit, the conversation of the message it replaced.

type Reader

type Reader struct {
	Facts    dslack.FactsReader
	Segments interface {
		UnitsFor(ctx context.Context, conv, ts string) ([]unit.Unit, error)
	}
	// Messages finds the thread of a stored message a ref names; nil asks Slack.
	Messages send.Stored
	Client   *slackapi.Client
	// Location is the time zone Search shows times in; nil is the local one.
	Location *time.Location
	// Log takes what a read leaves out on a Slack error; nil drops it.
	Log func(format string, args ...any)
}

Reader renders the messages of a unit, or of the thread a message ref or permalink names, 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 *store.DB, c *slackapi.Client, log func(string, ...any)) *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 the thread of a message ref or permalink, keeping the first message and the newest up to limit in all.

func (*Reader) Search

func (r *Reader) Search(ctx context.Context, q SearchQuery) (string, error)

Search renders the newest messages the user can read that match q, one line each: permalink, author, time in r.Location and first line. A direct message is shown only when tracked, as slack_read reads it.

type SearchQuery

type SearchQuery struct {
	Query string
	// Channel is a #name or a channel id.
	Channel string
	// From is an @handle, a user id or an email.
	From string
	// After and Before are dates, YYYY-MM-DD, both exclusive.
	After, Before string
	Limit         int
}

SearchQuery is what slack_search looks for: Query as Slack's search reads it, narrowed by the filters set.

type Segments

type Segments struct {
	Store *store.SegmentStore
	Clock 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 SendArgs

type SendArgs struct {
	Target    string `json:"target"`
	Text      string `json:"text"`
	Thread    *bool  `json:"thread,omitempty"`
	Broadcast bool   `json:"broadcast,omitempty"`
	DryRun    bool   `json:"dry_run,omitempty"`
}

SendArgs are ActionSend's arguments; DryRun posts nothing and says where the message would go and what it would say.

type SendResult

type SendResult struct {
	Conversation string `json:"conversation"`
	Parent       string `json:"parent,omitempty"`
	Text         string `json:"text"`
	Permalink    string `json:"permalink,omitempty"`
}

SendResult is where a message went, or would go, and its text as Slack shows it.

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 wall 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 plugin builds over its configuration: 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 ingest.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) ([]ingest.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) (ingest.Facts, error)

func (*Source) Stubs

func (s *Source) Stubs(ctx context.Context, objects []string) ([]ingest.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 SourceHealth

type SourceHealth struct {
	Warnings []string        `json:"warnings"`
	Detail   json.RawMessage `json:"detail,omitempty"`
}

SourceHealth is the plugin's health as the host's health shows it: its warnings and the detail of its socket, catch-up and login.

type Store

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

Store is the Slack source's ingest.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 []ingest.Facts, read ingest.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) ([]ingest.Stub, error)

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

type ThreadArgs

type ThreadArgs struct {
	Message string `json:"message"`
}

ThreadArgs are ActionThread's arguments.

type Watches

type Watches struct{ DB *store.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 auth keeps the Slack tokens: login, refresh and the Keychain.
Package auth keeps the Slack tokens: login, refresh and the Keychain.
cmd
wloop-plugin-slack command
Command wloop-plugin-slack is the Slack source plugin's binary, which the host runs as a child process.
Command wloop-plugin-slack is the Slack source plugin's binary, which the host runs as a child process.
Package config is the configuration the Slack plugin reads: its [plugins.slack] table and the host keys its manifest's config_reads names, as the host passes them.
Package config is the configuration the Slack plugin reads: its [plugins.slack] table and the host keys its manifest's config_reads names, as the host passes them.
Package slack is the Slack plugin's domain: messages, deltas and the facts the source stores.
Package slack is the Slack plugin's domain: messages, deltas and the facts the source stores.
Package draft holds the Outbox drafts: posts the loop proposes and the user approves before they reach a provider.
Package draft holds the Outbox drafts: posts the loop proposes and the user approves before they reach a provider.
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 host is the host's broker as the Slack plugin calls it, in the plugin's own types: the items ledger, the agent and the profile layer.
Package host is the host's broker as the Slack plugin calls it, in the plugin's own types: the items ledger, the agent and the profile layer.
hosttest
Package hosttest is an in-memory host broker for the Slack plugin's tests: it records what the plugin reports, proposes and writes, applies item ops with the host ledger's rules, and answers asks from a script.
Package hosttest is an in-memory host broker for the Slack plugin's tests: it records what the plugin reports, proposes and writes, applies item ops with the host ledger's rules, and answers asks from a script.
Package ingest drives the Slack source: discovery, change detection by object version, detail reads of what moved, and saves through the source's store.
Package ingest drives the Slack source: discovery, change detection by object version, detail reads of what moved, and saves through the source's store.
Package items holds the cross-source items ledger's types.
Package items holds the cross-source items ledger's types.
Package jsonschema validates structured agent answers against the subset of JSON Schema the profile's schemas may use: type, properties, required, additionalProperties, enum, minLength, maxLength, minItems, maxItems, items, pattern (RE2) and description.
Package jsonschema validates structured agent answers against the subset of JSON Schema the profile's schemas may use: type, properties, required, additionalProperties, enum, minLength, maxLength, minItems, maxItems, items, pattern (RE2) and description.
Package link holds the cross-source links between units.
Package link holds the cross-source links between units.
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.
Package send posts a message to Slack as the user.
Package send posts a message to Slack as the user.
Package slack is a thin client for the Slack Web API.
Package slack is a thin client for the Slack Web API.
Package slacktest is a fake Slack Web API for tests.
Package slacktest is a fake Slack Web API for tests.
Package socket keeps a Slack Socket Mode connection.
Package socket keeps a Slack Socket Mode connection.
sockettest
Package sockettest is a fake Slack Socket Mode server for tests.
Package sockettest is a fake Slack Socket Mode server for tests.
Package store is the Slack plugin's own database, in the state directory the host gives it: the conversations, threads, messages and users it read, the DM segment map and what the extraction keeps per unit.
Package store is the Slack plugin's own database, in the state directory the host gives it: the conversations, threads, messages and users it read, the DM segment map and what the extraction keeps per unit.
Package tag names what a pull request touches with key:value tags, a matching system and nothing more: nine fixed keys, each value normalized to one spelling.
Package tag names what a pull request touches with key:value tags, a matching system and nothing more: nine fixed keys, each value normalized to one spelling.
Package unit names the units of work the Slack plugin and the host share: a provider and the provider's key, as the host's units are.
Package unit names the units of work the Slack plugin and the host share: a provider and the provider's key, as the host's units are.

Jump to

Keyboard shortcuts

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