channels

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package channels is the channel model shared by the ways ReputeCast reaches people (design expansion phase 8): email, SMS, push and WhatsApp.

It holds what every channel after email has in common, so push and WhatsApp (X22) slot in next to SMS without reworking it:

  • the channel switch of Sending providers, from a registry of channels and whether each is set up in a workspace;
  • quiet hours in the recipient's time zone (quiet.go);
  • consent per list and per channel, with its evidence;
  • the message log of texts, notifications and WhatsApp messages, kept 90 days in its own tables, never in the audit log.

Email keeps its own model (list memberships, consent events, messages); this package never changes it.

Index

Constants

View Source
const (
	HardFrom = 8 * 60
	HardTo   = 21 * 60
)

Hard limits, in minutes after local midnight.

Variables

View Source
var (
	ErrWindowEmpty    = errors.New("channels: the window ends before it starts")
	ErrWindowTooEarly = errors.New("channels: texts can't go out before 08:00 local time")
	ErrWindowTooLate  = errors.New("channels: texts can't go out after 21:00 local time")
)

Errors from Validate. The app words them; the API names the limit.

All lists the channels in the order the app shows them.

View Source
var DefaultWindow = Window{From: 9 * 60, To: 20 * 60}

DefaultWindow is 09:00–20:00.

Functions

func Clock

func Clock(m int) string

Clock writes minutes after midnight as 24-hour time: 540 → "09:00".

func Register

func Register(i Info)

Register adds a channel; each channel's domain calls it from its wiring. A channel without an entry is shown as not built yet.

func SwitchShown

func SwitchShown(statuses []ChannelStatus) bool

SwitchShown is the rule for the channel switch: it appears once a second channel is set up. Until then the header offers "Add a channel".

func Valid

func Valid(c Channel) bool

Valid reports whether c is a known channel.

Types

type Channel

type Channel string

Channel is a way to reach people.

const (
	Email    Channel = "email"
	SMS      Channel = "sms"
	Push     Channel = "push"
	WhatsApp Channel = "whatsapp"
)

Channels, in the switch's order.

type ChannelStatus

type ChannelStatus struct {
	Channel Channel `json:"channel" enum:"email,sms,push,whatsapp"`
	// Available is false for a channel this build doesn't have yet.
	Available bool `json:"available"`
	// SetUp is true once the workspace can send on it.
	SetUp bool `json:"setUp"`
}

ChannelStatus is one channel in the switch.

func Statuses

func Statuses(ctx context.Context, workspaceID uuid.UUID) []ChannelStatus

Statuses returns every channel's state in a workspace. A channel whose check fails counts as not set up, so the switch still renders.

type Hold

type Hold struct {
	Held  bool      `json:"held"`
	Until time.Time `json:"until"`
}

Hold is what quiet hours do to a text due at t: send it then, or hold it until the window opens.

type Info

type Info struct {
	Channel Channel
	// SetUp reports whether the workspace can send on the channel: a
	// connected provider for email, SMS and WhatsApp, keys and a site for
	// push.
	SetUp func(ctx context.Context, workspaceID uuid.UUID) (bool, error)
}

Info registers a channel's setup state for the switch.

func Lookup

func Lookup(c Channel) (Info, bool)

Lookup returns a channel's entry.

type Window

type Window struct {
	From int `json:"from" minimum:"0" maximum:"1440"`
	To   int `json:"to" minimum:"0" maximum:"1440"`
}

Window is a daily sending window, in minutes after local midnight: From is the first minute texts may leave, To the first one they may not.

func (Window) Check

func (w Window) Check(t time.Time, loc *time.Location) Hold

Check applies the window to a text due at t for a recipient in loc.

func (Window) Clamp

func (w Window) Clamp() Window

Clamp narrows the window to the hard limits. Stored windows are always valid; Clamp guards a window read from older data.

func (Window) Closes

func (w Window) Closes(t time.Time, loc *time.Location) time.Time

Closes is when the window that contains t closes, in loc.

func (Window) Inside

func (w Window) Inside(t time.Time, loc *time.Location) bool

Inside reports whether t is inside the window in loc.

func (Window) LocalSend

func (w Window) LocalSend(date time.Time, minute int, loc *time.Location) (time.Time, bool)

LocalSend is the moment a text scheduled "at a time in each recipient's time zone" goes out: the date and minute in loc. It reports false when the minute is outside the window, which the app never offers.

func (Window) NextOpen

func (w Window) NextOpen(t time.Time, loc *time.Location) time.Time

NextOpen is the earliest moment at or after t inside the window in loc: t itself when the window is open, else the next opening.

func (Window) String

func (w Window) String() string

String is "09:00–20:00".

func (Window) Validate

func (w Window) Validate() error

Validate checks the window against the hard limits.

Jump to

Keyboard shortcuts

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