Documentation
¶
Overview ¶
Package send posts a message to Slack as the user.
Index ¶
- Variables
- func IsMessage(s string) bool
- func IsPermalink(s string) bool
- func Mrkdwn(markdown string) string
- func Ref(conversation, ts string) string
- func TypedMentions(markdown string, mention func(user string) string) string
- type Delete
- type Deleted
- type Edit
- type Edited
- type Known
- type KnownConversation
- type Message
- type Posted
- type Reacted
- type Reaction
- type Request
- type Resolved
- type Sent
- type Service
- func (s *Service) Allowed(res Resolved) error
- func (s *Service) Delete(ctx context.Context, d Delete) (Deleted, error)
- func (s *Service) Edit(ctx context.Context, e Edit) (Edited, error)
- func (s *Service) Mentions(ctx context.Context, markdown string, mention func(user string) string) (string, error)
- func (s *Service) Permalink(ctx context.Context, channel, ts string) string
- func (s *Service) React(ctx context.Context, r Reaction) (Reacted, error)
- func (s *Service) Read(ctx context.Context, ref string) (p Posted, ok bool, err error)
- func (s *Service) Resolve(ctx context.Context, r Request) (Resolved, error)
- func (s *Service) Send(ctx context.Context, r Request) (Sent, error)
- type Stored
- type StoredMessage
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotLoggedIn = errors.New("not logged in to Slack") ErrAmbiguous = errors.New("the target is ambiguous") ErrCannotPost = errors.New("cannot post to the target") ErrNotAllowed = errors.New("the target is not in the post allowlist") )
These are wrapped with the detail.
Functions ¶
func IsPermalink ¶
IsPermalink says whether s is a Slack message permalink.
func Mrkdwn ¶
Mrkdwn converts Markdown to Slack mrkdwn. Slack mentions and links written as <...> pass through; &, < and > are escaped everywhere else, code included, since Slack parses <...> inside code too.
Types ¶
type Delete ¶ added in v0.4.0
type Delete struct {
Message, User string
}
Delete names a message User posted, by its ref or its permalink.
type Deleted ¶ added in v0.4.0
type Deleted struct {
Conversation, Channel, TS string
// ThreadTS is the thread the message was in, "" when it was a top-level
// message without replies.
ThreadTS string
// Permalink is the message's, "" when Slack gave none.
Permalink string
Deleted string
}
Deleted is the message a deletion removed and Deleted, its text.
type Edit ¶
type Edit struct {
Message, Text, User string
}
Edit is new text, in Markdown, for a message User posted, named by its ref or its permalink.
type Edited ¶
type Edited struct {
Conversation, Channel, TS string
// Permalink is the message's, "" when Slack gives none.
Permalink string
Text, Replaced string
}
Edited is where an edit went: Text as posted, in mrkdwn, and Replaced, the text it replaced.
type Known ¶
type Known func(ctx context.Context, id string) (c KnownConversation, ok bool)
Known finds conversation id as the store holds it; ok is false when the store holds none, or not enough to place a post in it.
type KnownConversation ¶
KnownConversation is what placing a post needs of a conversation's stored copy. Kind is "channel", "private", "im" or "mpim"; DMUserName is the other party's handle of an im, "" when the store holds none.
type Message ¶
type Message struct{ Conversation, TS, ThreadTS string }
Message names one Slack message: by its ref, "<conversation>/<ts>", or by its permalink. ThreadTS is the thread it is in when the name says so (a permalink's thread_ts); a ref never does.
func ParseMessage ¶
ParseMessage reads s as a message ref or a message permalink.
type Posted ¶ added in v0.5.0
Posted is a message as Slack holds it, in the conversation Resolved names.
type Reacted ¶
type Reacted struct {
Conversation, Channel, TS, Name string
// Permalink is the message's, "" when Slack gives none.
Permalink string
Unchanged bool
}
Reacted is where a reaction went; Unchanged says the message already had it, or, on a removal, did not.
type Reaction ¶
Reaction is an emoji to add to, or remove from, a message, named by its ref or its permalink.
type Resolved ¶
type Resolved struct {
Channel, ThreadTS string // ThreadTS "" posts to the conversation
Conversation string // "#name", "@handle" or "group DM"
Parent string // first line of the thread parent, "" when not a reply
DMUser string // the other party when Channel is an im
Kind string // "im" or "mpim" for a direct message, "" for a channel
}
type Service ¶
type Service struct {
Client *slack.Client
Log func(format string, args ...any)
// PostAllowlist, when not empty, is the only set of conversations Send may post to:
// channel ids, or user ids naming the DM with that user. Config plugins.slack.post_allowlist.
PostAllowlist []string
// Stored finds the thread of a message without asking Slack; nil asks Slack.
Stored Stored
// Known finds a conversation without asking Slack; nil asks Slack.
Known Known
// contains filtered or unexported fields
}
func (*Service) Allowed ¶
Allowed is nil when PostAllowlist is empty or holds res.Channel or res.DMUser.
func (*Service) Delete ¶ added in v0.4.0
Delete removes d's message, under the post allowlist; it refuses a message another user posted.
func (*Service) Edit ¶
Edit replaces the text of e's message, under the post allowlist, with its mentions resolved as Send resolves them; it refuses a message another user posted.
func (*Service) Mentions ¶
func (s *Service) Mentions(ctx context.Context, markdown string, mention func(user string) string) (string, error)
Mentions replaces each @handle, @<user id> and email of markdown that names one live user, and each typed user mention, with mention(<user id>), outside code, Slack tokens, URLs and Markdown links. A name no user holds, or one a lookup fails on, stays text; one several users hold fails with ErrAmbiguous.
func (*Service) Permalink ¶
Permalink is the permalink of the message at ts in channel: the stored one, else Slack's; "" when Slack gives none.
func (*Service) Read ¶ added in v0.5.0
Read reads the message ref names, under the post allowlist; ok is false when Slack holds no such message.
type Stored ¶
type Stored func(ctx context.Context, conversation, ts string) (m StoredMessage, ok bool)
Stored finds the message at ts in conversation as the store holds it; ok is false when the store holds none, or cannot say which thread it is in.
type StoredMessage ¶
type StoredMessage struct{ TS, ThreadTS, Text, Permalink string }
StoredMessage is what placing a message needs of its stored copy. ThreadTS is "" or TS for a message that starts no thread or is its parent.