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 ¶
- type AgentSender
- type Attachment
- type Broadcaster
- type ChannelKey
- type DeliveryEntry
- type DeliveryStatus
- type GatewayInfo
- type MessageRecord
- type Notification
- type PersistedChannel
- type Service
- func (s *Service) AllSubscriptions(ctx context.Context) ([]Subscription, error)
- func (s *Service) ChannelActivity(ctx context.Context, channel string, limit int) ([]DeliveryEntry, error)
- func (s *Service) ChannelMessages(ctx context.Context, channel string, limit int, before int64) ([]MessageRecord, error)
- func (s *Service) ChannelSubscriptions(ctx context.Context, channel string) ([]Subscription, error)
- func (s *Service) Dispatch(channel, platform, sender, senderID, content, messageID string, ...)
- func (s *Service) PruneOldActivity(ctx context.Context, keepPerChannel int) error
- func (s *Service) SetMentionOnly(ctx context.Context, channel, agent string, mentionOnly bool) error
- func (s *Service) Store() *Store
- func (s *Service) Subscribe(ctx context.Context, channel, agent string, mentionOnly bool) error
- func (s *Service) Unsubscribe(ctx context.Context, channel, agent string) error
- type Store
- func (s *Store) AllSubscriptions(ctx context.Context) ([]Subscription, error)
- func (s *Store) Close() error
- func (s *Store) DeliveryChannels(ctx context.Context) ([]string, error)
- func (s *Store) GetMessages(ctx context.Context, channel string, limit int, before int64) ([]MessageRecord, error)
- func (s *Store) ListGateways(ctx context.Context) ([]GatewayInfo, error)
- func (s *Store) LoadChannels(ctx context.Context) ([]PersistedChannel, error)
- func (s *Store) LogDelivery(ctx context.Context, e DeliveryEntry) error
- func (s *Store) PruneActivity(ctx context.Context, channel string, keepLast int) error
- func (s *Store) RecentActivity(ctx context.Context, channel string, limit int) ([]DeliveryEntry, error)
- func (s *Store) SaveChannel(ctx context.Context, bcChannel, platform, platformID string) error
- func (s *Store) SaveMessage(ctx context.Context, channel, sender, content string) error
- func (s *Store) SetGatewayConnected(ctx context.Context, name string, connected bool) error
- func (s *Store) SetMentionOnly(ctx context.Context, channel, agent string, mentionOnly bool) error
- func (s *Store) Subscribe(ctx context.Context, channel, agent string, mentionOnly bool) error
- func (s *Store) Subscribers(ctx context.Context, channel string) ([]Subscription, error)
- func (s *Store) TotalMessageCount(ctx context.Context) (int, error)
- func (s *Store) Unsubscribe(ctx context.Context, channel, agent string) error
- func (s *Store) UpsertGateway(ctx context.Context, name string, enabled, connected bool) error
- type Subscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentSender ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 (*Store) AllSubscriptions ¶
func (s *Store) AllSubscriptions(ctx context.Context) ([]Subscription, error)
AllSubscriptions returns all subscriptions across all channels.
func (*Store) DeliveryChannels ¶
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 ¶
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 ¶
SaveChannel persists a channel mapping so it survives server restarts.
func (*Store) SaveMessage ¶
SaveMessage stores an inbound gateway message for the activity feed.
func (*Store) SetGatewayConnected ¶
SetGatewayConnected updates the connected status and last_seen_at.
func (*Store) SetMentionOnly ¶
SetMentionOnly updates the mention_only flag for a subscription.
func (*Store) Subscribe ¶
Subscribe adds an agent to a channel. If already subscribed, this is a no-op.
func (*Store) Subscribers ¶
Subscribers returns all subscriptions for a channel.
func (*Store) TotalMessageCount ¶
TotalMessageCount returns the total number of stored messages across all channels.
func (*Store) Unsubscribe ¶
Unsubscribe removes an agent from a channel.