writes

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package writes implements the shared safety pipeline every Telegram-side write command goes through, mirroring the Python flow in tgcli.commands.messages._run_write_command and the gates in tgcli.safety.

The pipeline order is fixed (changing it changes the contract):

  1. Write gate (--allow-write or TG_ALLOW_WRITE=1, --read-only blocks even with allow)
  2. Idempotency lookup (cached envelope replay short-circuits before resolve)
  3. Fuzzy gate (--fuzzy required for non-int / non-@username selectors)
  4. Resolver (DB-only int / @username / fuzzy title)
  5. Dry-run (returns payload preview before any client call or rate limiter)
  6. Local rate limiter (sliding 20 / 60s)
  7. Audit pre (NDJSON line, shared request_id)
  8. Telegram call
  9. Idempotency record (so a replay returns the same envelope data)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, db *sql.DB, in PipelineInput) (any, error)

Run executes the full pipeline. It returns the runner's `data` map (or an error mapped to the standard exit codes by dispatch). Callers wire this inside dispatch.Run so audit/envelope/exit code handling is uniform.

Types

type Args

type Args struct {
	safety.Args
	DryRun         bool
	IdempotencyKey string
}

Args is the flag bundle the pipeline reads.

type PipelineInput

type PipelineInput struct {
	Cmd            string
	RawSelector    string
	Args           Args
	DBPath         string
	AuditPath      string
	TelethonMethod string
	// PayloadPreview is what the dry-run envelope returns and what shows up in audit_pre.
	PayloadPreview map[string]any
	// Run is the Telegram-side action. It receives the resolved chat id/title
	// and returns the success-envelope `data` map.
	Run func(ctx context.Context, chatID int64, chatTitle string) (map[string]any, error)
}

PipelineInput is what the caller hands the pipeline.

Jump to

Keyboard shortcuts

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