format

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package format renders slio's normalized Message model as either AI-readable Markdown or JSON, onto a writer the caller supplies. It reaches nothing else — no network, no disk: display names and mention resolution arrive through Resolver, which is typically backed by internal/cache and users.info.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTs

func ParseTs(ts string) (time.Time, error)

ParseTs converts a Slack message ts (e.g. "1234567890.123456") to a time.Time.

func Ts added in v1.0.4

func Ts(t time.Time) string

Ts converts a time.Time to a Slack ts string, for use as the oldest/latest API parameters.

func WriteChannels added in v1.0.4

func WriteChannels(w io.Writer, f Format, channels []Channel) error

WriteChannels renders channels in the requested format and writes them to w.

func WriteMessages added in v1.0.4

func WriteMessages(w io.Writer, f Format, messages []Message, resolveUser Resolver, notice string, placement NoticePlacement) error

WriteMessages renders messages in the requested format and writes them to w. A notice (may be "") reports that the list was truncated, and placement says which side of the messages it belongs on.

In JSON mode the placement is ignored: object field order doesn't matter to a consumer, so the notice is one field either way.

Types

type Channel added in v1.0.4

type Channel struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Channel is one channel in `channel list` output. Unlike Message it needs no rendering pass, so it doubles as the JSON shape rather than having a separate wire type.

type FileInfo

type FileInfo struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Size int64  `json:"size"`
	// LocalPath is set only when --download saved the file locally.
	LocalPath string `json:"local_path,omitempty"`
}

FileInfo describes a message attachment.

type Format

type Format string

Format is the output format selected by --format. It implements pflag.Value, so a typo is rejected while cobra parses the flags — before the command runs and issues any Slack request.

const (
	Markdown Format = "md"
	JSON     Format = "json"
)

Formats accepted by --format.

func (*Format) Set

func (f *Format) Set(s string) error

Set assigns only on success, so a rejected value leaves the receiver — the flag's default — intact.

func (Format) String

func (f Format) String() string

func (Format) Type

func (Format) Type() string

Type names the value shown in the --format help line. It reports "string" rather than "format" because that help text is part of the agent-facing contract kept in sync across README.md, skills/slio/SKILL.md and the help strings; see CLAUDE.md.

type Message

type Message struct {
	// Ts is the raw Slack timestamp (e.g. "1234567890.123456"), always
	// included in JSON output alongside the formatted time so agents can
	// build permalinks and follow-up calls.
	Ts   string
	Time time.Time

	// Author is a resolved user display name or a bot's
	// username/bot_profile.name; formatting treats both the same.
	Author string

	// Text is the raw mrkdwn message body, transformed by renderText.
	Text string

	Edited bool
	// IsSystem marks a join/leave/etc. message, rendered as a single line.
	IsSystem bool

	Reactions []Reaction
	Files     []FileInfo

	// ReplyCount and ThreadPermalink are set only for `history` output, on
	// messages that have replies.
	ReplyCount      int
	ThreadPermalink string

	// Permalink is set only for `search` output, taken directly from the
	// API response.
	Permalink string

	// QuotedBlocks holds bot attachment/block text extracted for
	// rendering as blockquotes.
	QuotedBlocks []string

	// Linked marks the one message a permalink pointed at, set only by
	// `thread` (the only command taking a single message's URL).
	Linked bool
}

Message is slio's normalized representation of a single Slack message, assembled by the command layer from either conversations.replies/history (which populate ReplyCount/ThreadPermalink) or search.messages (which populates Permalink instead — search.messages reports neither reaction nor reply-count data).

type NoticePlacement added in v1.0.4

type NoticePlacement int

NoticePlacement says which side of the message list a truncation notice goes on. `history` leads with "older messages omitted" so it is read before the messages it qualifies; `search` trails with "N more results", which only means anything after the results it counts past.

const (
	NoticeBeforeMessages NoticePlacement = iota
	NoticeAfterMessages
)

Placements accepted by WriteMessages.

type Reaction

type Reaction struct {
	Name  string `json:"name"`
	Count int    `json:"count"`
}

Reaction is one aggregated reaction on a message.

type Resolver

type Resolver func(userID string) string

Resolver maps a Slack user ID to its display name, used to expand <@U…> mentions in message text. An empty return means "unknown" and falls back to any inline display text Slack included, or the raw ID.

Jump to

Keyboard shortcuts

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