Documentation
¶
Overview ¶
Package slack is the Slack plugin's domain: messages, deltas and the facts the source stores. The core never imports it.
Index ¶
- Constants
- Variables
- func CompareTS(a, b string) int
- func DMObject(conv string) string
- func GroupHandles(into map[string]string, texts ...string)
- func GroupKey(id string) string
- func GroupName(id string, handles map[string]string) string
- func IsGroupID(s string) bool
- func IsUserID(s string) bool
- func ObjectOf(conv string, kind ConversationKind, m Message) string
- func ParseObject(s string) (conv, ts string, err error)
- func TSTime(ts string) time.Time
- func TeamKey(name string) string
- func ThreadObject(conv, ts string) string
- func ThreadUnit(team, conv, ts string) unit.Unit
- func UserKey(id string) string
- func ValidKey(key string) error
- func ValidPersonKey(key string) error
- type Change
- type ChangeKind
- type Conversation
- type ConversationKind
- type DMWindow
- type Delta
- type Facts
- type FactsReader
- type File
- type Key
- type Kind
- type Message
- type ObjectRef
- type Reaction
- type Scheduler
- type SegmentWriter
- type Segments
- type Span
- type Thread
- type User
- type Via
- type WatchReason
- type Watcher
Constants ¶
const ( UserIDPattern = `[UW][A-Z0-9]{8,}` GroupIDPattern = `S[A-Z0-9]{8,}` )
Slack ids: a user's starts with U or W, a user group's with S, each followed by at least eight letters or digits. The patterns are for regular expressions that embed an id.
const Provider unit.ProviderID = "slack"
const UnknownGroup = "a user group"
UnknownGroup names a user group whose handle no message gave.
Variables ¶
var ErrUnknownUnit = errors.New("slack: unknown unit")
var HiddenSubtypes = []string{"message_replied", "channel_join", "channel_leave", "group_join",
"group_leave", "channel_topic", "channel_purpose", "channel_name", "pinned_item", "unpinned_item"}
Functions ¶
func GroupHandles ¶
GroupHandles adds to into the handle of each user group texts mention as <!subteam^ID|@handle>.
func ObjectOf ¶
func ObjectOf(conv string, kind ConversationKind, m Message) string
ObjectOf: in an im or mpim every message, thread replies included, belongs to DMObject(conv); elsewhere a message belongs to ThreadObject(conv, ThreadTS or TS).
func ParseObject ¶
ParseObject splits an object id; ts is "" for a DM object.
func TSTime ¶
TSTime is the instant a Slack ts names, to the microsecond; zero for a ts that names none.
func ThreadObject ¶
ThreadObject is "<conv>/<ts>": a thread, or a lone channel message keyed by its own ts.
func ThreadUnit ¶
ThreadUnit has the key "<team>/<conv>/<ts>", valid for ValidKey.
func ValidKey ¶
ValidKey says why key is not a Slack unit key: "<team>/<conv>/<ts>" for a thread, "<team>/<dm>/seg/<id>" for a DM segment.
func ValidPersonKey ¶
ValidPersonKey says why key is not a person key the plugin writes: "slack:<user id>", "group:<user group id>" or "group:<name>", where a name is one line of text that is no id and carries no key prefix or mention of its own.
Types ¶
type Change ¶
type Change struct {
Seq int64
Conversation, TS, ThreadTS string
Kind ChangeKind
At time.Time
}
type ChangeKind ¶
type ChangeKind string // "new", "edited", "deleted", "reaction"
const ( ChangeNew ChangeKind = "new" ChangeEdited ChangeKind = "edited" ChangeDeleted ChangeKind = "deleted" ChangeReaction ChangeKind = "reaction" )
type Conversation ¶
type Conversation struct {
ID, Name string // Name "" for an im
Kind ConversationKind
IsMember, Archived bool
DMUser string // the other party of an im
}
type ConversationKind ¶
type ConversationKind string // "channel", "private", "im", "mpim"
const ( KindChannel ConversationKind = "channel" KindPrivate ConversationKind = "private" KindIM ConversationKind = "im" KindMPIM ConversationKind = "mpim" )
func (ConversationKind) DM ¶
func (k ConversationKind) DM() bool
DM says whether the conversation is an im or an mpim.
type DMWindow ¶
type Delta ¶
type Delta struct {
Conversation, ChannelType, TS, ThreadTS string
EventID string
Kind Kind
Message *Message // nil for reactions
Reaction *struct{ Name, User string }
Via Via
ReceivedAt time.Time
}
type Facts ¶
type Facts struct {
Team string
Conversations []Conversation
Threads []Thread
DMs []DMWindow
Users []User
}
type FactsReader ¶
type FactsReader interface {
// Messages of u with ts > after, ascending, at most limit (0: all). A segment unit
// is sliced by Segments.Range, replies in the DM included by their parent's ts.
Messages(ctx context.Context, u unit.Unit, after string, limit int) ([]Message, error)
Conversation(ctx context.Context, id string) (Conversation, error)
Users(ctx context.Context, ids []string) (map[string]User, error) // cached only, never calls Slack
UserByEmail(ctx context.Context, email string) (User, bool, error)
Changes(ctx context.Context, afterSeq int64, limit int) ([]Change, error) // ascending Seq
Viewer(ctx context.Context) (team, user string, err error)
}
type Key ¶
type Key struct{ Team, Conversation, TS, Segment string }
Key is a Slack unit key: a thread when TS is set, a DM segment when Segment is.
type Message ¶
type Message struct {
TS, ThreadTS, ParentUser string // ThreadTS "" or == TS for a parent or a lone message
User, BotID, AppID, Username string // User is the human when set, whatever BotID holds
Subtype, Text, EditedTS string
Deleted bool
Files []File
Links []string // URLs in text and attachments
Mentions []string // user ids mentioned
Reactions []Reaction
ReplyCount int
LatestReply string
Permalink string
}
func MessageFrom ¶
func MessageFrom(raw json.RawMessage) (Message, error)
MessageFrom decodes one message of a Web API page (history, replies, search).
type ObjectRef ¶
type ObjectRef struct{ Conversation, TS string }
ObjectRef names a watched object; TS "" names a DM conversation.
type Scheduler ¶
type Scheduler interface {
Next(ctx context.Context, objects []string, now time.Time) (map[string]time.Time, error)
}
Scheduler gives the next poll time of watched objects. The default is now+5 min; the module replaces it with a heat scheduler.
type SegmentWriter ¶
type Segments ¶
type Segments interface {
// UnitsFor returns the segments covering ts; empty until segmented. Callers pass a
// reply's thread_ts, so a reply follows its parent's segment.
UnitsFor(ctx context.Context, conv, ts string) ([]unit.Unit, error)
Range(ctx context.Context, u unit.Unit) (conv, fromTS, toTS string, err error) // toTS "" while open
}
type Span ¶
type Span struct{ ID, FromTS, ToTS string }
Span is a DM segment's range; ID "" asks for a new segment; ToTS "" is open.
type Thread ¶
type Via ¶
type Via string
Via is how a message arrived. A message search stored with no thread is not trusted to place a post: search may not say the thread.
type WatchReason ¶
type WatchReason string // "admission", "extraction", "user-follow", "turn"
const ( ReasonAdmission WatchReason = "admission" ReasonExtraction WatchReason = "extraction" ReasonUserFollow WatchReason = "user-follow" ReasonTurn WatchReason = "turn" )