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
- Variables
- func Clock(m int) string
- func Register(i Info)
- func SwitchShown(statuses []ChannelStatus) bool
- func Valid(c Channel) bool
- type Channel
- type ChannelStatus
- type Hold
- type Info
- type Window
- func (w Window) Check(t time.Time, loc *time.Location) Hold
- func (w Window) Clamp() Window
- func (w Window) Closes(t time.Time, loc *time.Location) time.Time
- func (w Window) Inside(t time.Time, loc *time.Location) bool
- func (w Window) LocalSend(date time.Time, minute int, loc *time.Location) (time.Time, bool)
- func (w Window) NextOpen(t time.Time, loc *time.Location) time.Time
- func (w Window) String() string
- func (w Window) Validate() error
Constants ¶
const ( HardFrom = 8 * 60 HardTo = 21 * 60 )
Hard limits, in minutes after local midnight.
Variables ¶
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.
var DefaultWindow = Window{From: 9 * 60, To: 20 * 60}
DefaultWindow is 09:00–20:00.
Functions ¶
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".
Types ¶
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.
type Hold ¶
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.
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) Clamp ¶
Clamp narrows the window to the hard limits. Stored windows are always valid; Clamp guards a window read from older data.
func (Window) LocalSend ¶
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.