send

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 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 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.

Types

type Request

type Request struct {
	Target    string // permalink, #name, channel id, @handle, email or user id
	Text      string // Markdown
	Thread    *bool  // nil: true for a permalink, 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
}

type Sent

type Sent struct {
	Conversation string
	Parent       string
	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 slack.post_allowlist.
	PostAllowlist []string
	// 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) 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, 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.

Jump to

Keyboard shortcuts

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