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 Known
- type KnownConversation
- type Message
- type Posted
- type Request
- type Resolved
- type Sent
- type Service
- func (s *Service) Allowed(res Resolved) 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) 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 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 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) 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.