notify

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package notify implements the notification gateway for delivering external platform events (Slack, Telegram, Discord, etc.) to subscribed bc agents via tmux send-keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentSender

type AgentSender interface {
	Send(ctx context.Context, name, message string) error
}

AgentSender is the interface for sending a message to an agent's tmux session. Implemented by *agent.AgentService (Send method).

type Attachment

type Attachment struct {
	Filename  string `json:"filename"`
	MimeType  string `json:"mime_type"`
	URL       string `json:"url,omitempty"`
	LocalPath string `json:"local_path,omitempty"`
	Size      int64  `json:"size"`
}

Attachment describes a file shared on a channel.

type Broadcaster

type Broadcaster interface {
	Publish(eventType string, data map[string]any)
}

Broadcaster pushes events to connected web clients via SSE/WebSocket. Implemented by *ws.Hub.

type ChannelKey

type ChannelKey = string

ChannelKey is the canonical identifier for an external channel. Format: "<platform>:<channel_name>", e.g., "slack:engineering".

type DeliveryEntry

type DeliveryEntry struct {
	LoggedAt time.Time      `json:"logged_at"`
	Channel  string         `json:"channel"`
	Agent    string         `json:"agent"`
	Status   DeliveryStatus `json:"status"`
	Error    string         `json:"error,omitempty"`
	Preview  string         `json:"preview"`
	ID       int64          `json:"id"`
}

DeliveryEntry records one delivery attempt in the activity log.

type DeliveryStatus

type DeliveryStatus string

DeliveryStatus is the outcome of a tmux send-keys attempt.

const (
	StatusDelivered DeliveryStatus = "delivered"
	StatusFailed    DeliveryStatus = "failed"
	StatusPending   DeliveryStatus = "pending"
)

type GatewayInfo

type GatewayInfo struct {
	LastSeenAt *time.Time `json:"last_seen_at,omitempty"`
	UpdatedAt  time.Time  `json:"updated_at"`
	Name       string     `json:"name"`
	Enabled    bool       `json:"enabled"`
	Connected  bool       `json:"connected"`
}

GatewayInfo holds gateway state from the database.

type MessageRecord

type MessageRecord struct {
	CreatedAt time.Time `json:"created_at"`
	Channel   string    `json:"channel"`
	Sender    string    `json:"sender"`
	Content   string    `json:"content"`
	ID        int64     `json:"id"`
}

MessageRecord is a stored inbound gateway message for the activity feed.

type Notification

type Notification struct {
	Timestamp   string       `json:"timestamp"`
	Channel     string       `json:"channel"`
	Platform    string       `json:"platform"`
	Sender      string       `json:"sender"`
	Content     string       `json:"content"`
	MessageID   string       `json:"message_id,omitempty"`
	Mentions    []string     `json:"mentions,omitempty"`
	Attachments []Attachment `json:"attachments,omitempty"`
}

Notification is the JSON payload sent to subscribed agents via tmux send-keys.

type PersistedChannel

type PersistedChannel struct {
	BCChannel  string
	Platform   string
	PlatformID string
}

PersistedChannel is a saved bc_channel → platform_id mapping.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the notification dispatch core. It receives inbound messages from gateway adapters and routes them to subscribed agents via tmux send-keys.

func NewService

func NewService(store *Store, agents AgentSender, hub Broadcaster) *Service

NewService creates a new notify service.

func (*Service) AllSubscriptions

func (s *Service) AllSubscriptions(ctx context.Context) ([]Subscription, error)

AllSubscriptions returns all subscriptions across all channels.

func (*Service) ChannelActivity

func (s *Service) ChannelActivity(ctx context.Context, channel string, limit int) ([]DeliveryEntry, error)

ChannelActivity returns recent delivery log entries for a channel.

func (*Service) ChannelMessages

func (s *Service) ChannelMessages(ctx context.Context, channel string, limit int, before int64) ([]MessageRecord, error)

ChannelMessages returns recent messages for a channel (newest first).

func (*Service) ChannelSubscriptions

func (s *Service) ChannelSubscriptions(ctx context.Context, channel string) ([]Subscription, error)

ChannelSubscriptions returns all subscriptions for a channel.

func (*Service) Dispatch

func (s *Service) Dispatch(channel, platform, sender, senderID, content, messageID string, attachments []Attachment)

Dispatch receives a normalized inbound message and delivers it to all subscribed agents. Runs in its own goroutine — never blocks the adapter.

func (*Service) PruneOldActivity

func (s *Service) PruneOldActivity(ctx context.Context, keepPerChannel int) error

PruneOldActivity removes old delivery log entries for every channel, keeping the most recent keepPerChannel entries in each.

func (*Service) SetMentionOnly

func (s *Service) SetMentionOnly(ctx context.Context, channel, agent string, mentionOnly bool) error

SetMentionOnly updates the @mention-only toggle for a subscription.

func (*Service) Store

func (s *Service) Store() *Store

Store returns the underlying store for direct access by handlers.

func (*Service) Subscribe

func (s *Service) Subscribe(ctx context.Context, channel, agent string, mentionOnly bool) error

Subscribe adds an agent to a channel.

func (*Service) Unsubscribe

func (s *Service) Unsubscribe(ctx context.Context, channel, agent string) error

Unsubscribe removes an agent from a channel.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the SQLite/Postgres-backed persistence layer for subscriptions and the delivery log. Uses the shared workspace database.

func OpenStore

func OpenStore(workspacePath string) (*Store, error)

OpenStore opens the notify store using the shared workspace database.

func (*Store) AllSubscriptions

func (s *Store) AllSubscriptions(ctx context.Context) ([]Subscription, error)

AllSubscriptions returns all subscriptions across all channels.

func (*Store) Close

func (s *Store) Close() error

Close is a no-op — the shared DB is owned by the caller.

func (*Store) DeliveryChannels

func (s *Store) DeliveryChannels(ctx context.Context) ([]string, error)

DeliveryChannels returns the distinct channel names in the delivery log.

func (*Store) GetMessages

func (s *Store) GetMessages(ctx context.Context, channel string, limit int, before int64) ([]MessageRecord, error)

GetMessages returns recent messages for a channel (newest first).

func (*Store) ListGateways

func (s *Store) ListGateways(ctx context.Context) ([]GatewayInfo, error)

ListGateways returns all registered gateways.

func (*Store) LoadChannels

func (s *Store) LoadChannels(ctx context.Context) ([]PersistedChannel, error)

LoadChannels returns all persisted channel mappings.

func (*Store) LogDelivery

func (s *Store) LogDelivery(ctx context.Context, e DeliveryEntry) error

LogDelivery records a delivery attempt.

func (*Store) PruneActivity

func (s *Store) PruneActivity(ctx context.Context, channel string, keepLast int) error

PruneActivity deletes old delivery log entries, keeping the most recent keepLast per channel.

func (*Store) RecentActivity

func (s *Store) RecentActivity(ctx context.Context, channel string, limit int) ([]DeliveryEntry, error)

RecentActivity returns the most recent delivery log entries for a channel.

func (*Store) SaveChannel

func (s *Store) SaveChannel(ctx context.Context, bcChannel, platform, platformID string) error

SaveChannel persists a channel mapping so it survives server restarts.

func (*Store) SaveMessage

func (s *Store) SaveMessage(ctx context.Context, channel, sender, content string) error

SaveMessage stores an inbound gateway message for the activity feed.

func (*Store) SetGatewayConnected

func (s *Store) SetGatewayConnected(ctx context.Context, name string, connected bool) error

SetGatewayConnected updates the connected status and last_seen_at.

func (*Store) SetMentionOnly

func (s *Store) SetMentionOnly(ctx context.Context, channel, agent string, mentionOnly bool) error

SetMentionOnly updates the mention_only flag for a subscription.

func (*Store) Subscribe

func (s *Store) Subscribe(ctx context.Context, channel, agent string, mentionOnly bool) error

Subscribe adds an agent to a channel. If already subscribed, this is a no-op.

func (*Store) Subscribers

func (s *Store) Subscribers(ctx context.Context, channel string) ([]Subscription, error)

Subscribers returns all subscriptions for a channel.

func (*Store) TotalMessageCount

func (s *Store) TotalMessageCount(ctx context.Context) (int, error)

TotalMessageCount returns the total number of stored messages across all channels.

func (*Store) Unsubscribe

func (s *Store) Unsubscribe(ctx context.Context, channel, agent string) error

Unsubscribe removes an agent from a channel.

func (*Store) UpsertGateway

func (s *Store) UpsertGateway(ctx context.Context, name string, enabled, connected bool) error

UpsertGateway inserts or updates a gateway record.

type Subscription

type Subscription struct {
	CreatedAt   time.Time `json:"created_at"`
	Channel     string    `json:"channel"`
	Agent       string    `json:"agent"`
	ID          int64     `json:"id"`
	MentionOnly bool      `json:"mention_only"`
}

Subscription ties an agent to a channel with delivery settings.

Jump to

Keyboard shortcuts

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