send

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 15 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 send posts a message to Slack as the user.

Index

Constants

This section is empty.

Variables

View Source
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 IsMessage

func IsMessage(s string) bool

IsMessage says whether s names one message: a ref or a permalink.

func IsPermalink(s string) bool

IsPermalink says whether s is a Slack message permalink.

func Mrkdwn

func Mrkdwn(markdown string) string

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.

func Ref

func Ref(conversation, ts string) string

Ref is the ref of the message at ts in conversation.

func TypedMentions

func TypedMentions(markdown string, mention func(user string) string) string

TypedMentions replaces each Slack user mention markdown spells as a token, <@<user id>> or <@<user id>|label>, with mention(<user id>), outside code and Markdown links.

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

type KnownConversation struct {
	ID, Name, Kind, DMUser, DMUserName string
	IsMember, Archived                 bool
}

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

func ParseMessage(s string) (Message, bool)

ParseMessage reads s as a message ref or a message permalink.

func (Message) Ref

func (m Message) Ref() string

Ref is the message's ref, "<conversation>/<ts>".

type Posted added in v0.5.0

type Posted struct {
	Resolved
	TS, ThreadTS, User, Text string
}

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

type Reaction struct {
	Message, Name string
	Remove        bool
}

Reaction is an emoji to add to, or remove from, a message, named by its ref or its permalink.

type Request

type Request struct {
	Target    string // message ref or permalink, #name, channel id, @handle, email or user id
	Text      string // Markdown
	Thread    *bool  // nil: true for a message, false otherwise
	Broadcast bool
	Source    string // "session", "cli" or "draft"; logged
}

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 Sent

type Sent struct {
	Conversation string
	Parent       string
	ThreadTS     string // the thread replied in, "" when not a reply
	Text         string // as posted, mrkdwn
	Permalink    string
	Channel, TS  string
}

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

func (s *Service) Allowed(res Resolved) error

Allowed is nil when PostAllowlist is empty or holds res.Channel or res.DMUser.

func (*Service) Delete added in v0.4.0

func (s *Service) Delete(ctx context.Context, d Delete) (Deleted, error)

Delete removes d's message, under the post allowlist; it refuses a message another user posted.

func (*Service) Edit

func (s *Service) Edit(ctx context.Context, e Edit) (Edited, error)

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 (s *Service) Permalink(ctx context.Context, channel, ts string) string

Permalink is the permalink of the message at ts in channel: the stored one, else Slack's; "" when Slack gives none.

func (*Service) React

func (s *Service) React(ctx context.Context, r Reaction) (Reacted, error)

React adds or removes r on its message, under the post allowlist.

func (*Service) Read added in v0.5.0

func (s *Service) Read(ctx context.Context, ref string) (p Posted, ok bool, err error)

Read reads the message ref names, under the post allowlist; ok is false when Slack holds no such message.

func (*Service) Resolve

func (s *Service) Resolve(ctx context.Context, r Request) (Resolved, error)

Resolve finds the conversation and thread of r without posting.

func (*Service) Send

func (s *Service) Send(ctx context.Context, r Request) (Sent, error)

Send resolves r and the mentions of its text, checks the allowlist and posts. Once chat.postMessage succeeded it never fails: a permalink it cannot read is left empty, so a caller never retries a message that went out.

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.

func (Stored) InThread

func (s Stored) InThread(ctx context.Context, m Message) Message

InThread is m with the thread the store holds it in, its own TS when it is in none; m as named when its name says the thread or the store does not.

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.

Jump to

Keyboard shortcuts

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