Documentation
¶
Overview ¶
Package gateway provides external messaging platform integrations. It bridges bc channels to platforms like Telegram, Discord, and Slack.
Index ¶
- func Truncate(s string, n int) string
- type AdapterStatus
- type AdapterType
- type ChannelInfo
- type ChannelStore
- type Manager
- func (m *Manager) AdapterNames() []string
- func (m *Manager) AdapterStatus(platform string) AdapterStatus
- func (m *Manager) DiscoveredSources() []string
- func (m *Manager) GetAdapter(name string) NotificationAdapter
- func (m *Manager) HandleNotification(platform string, n Notification)
- func (m *Manager) IsGatewayChannel(name string) bool
- func (m *Manager) Register(adapter NotificationAdapter)
- func (m *Manager) Send(ctx context.Context, bcChannel, sender, content string) (bool, error)
- func (m *Manager) SendFile(ctx context.Context, bcChannel, sender, filename string, data []byte, ...) (bool, error)
- func (m *Manager) SetChannelStore(store ChannelStore)
- func (m *Manager) SetInboundHandler(fn func(bcChannel, sender, content string, raw json.RawMessage))
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Stop(_ context.Context)
- func (m *Manager) WebhookHandlers() map[string]http.Handler
- type Notification
- type NotificationAdapter
- type PersistedChannel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AdapterStatus ¶
type AdapterStatus struct {
LastMessageAt time.Time `json:"last_message_at,omitempty"`
Error string `json:"error,omitempty"`
BotName string `json:"bot_name,omitempty"`
Connected bool `json:"connected"`
MessageCount int64 `json:"message_count"`
}
AdapterStatus reports connection state for the web UI.
type AdapterType ¶ added in v0.2.1
type AdapterType string
AdapterType identifies the connection pattern for a NotificationAdapter.
const ( // AdapterSocket is a long-lived connection (WebSocket, polling loop). AdapterSocket AdapterType = "socket" // AdapterWebhook is an HTTP endpoint where the platform POSTs events to bc. AdapterWebhook AdapterType = "webhook" // AdapterPoll is timer-based polling where bc fetches new events. AdapterPoll AdapterType = "poll" )
type ChannelInfo ¶ added in v0.2.1
type ChannelInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Platform string `json:"platform"`
}
ChannelInfo represents a discovered channel on a platform.
type ChannelStore ¶
type ChannelStore interface {
SaveChannel(ctx context.Context, bcChannel, platform, platformID string) error
LoadChannels(ctx context.Context) ([]PersistedChannel, error)
}
ChannelStore persists channel mappings so they survive server restarts. Implemented by notify.Store via a wrapper.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates all gateway adapters and routes messages.
func (*Manager) AdapterNames ¶ added in v0.2.1
AdapterNames returns the names of all registered adapters.
func (*Manager) AdapterStatus ¶
func (m *Manager) AdapterStatus(platform string) AdapterStatus
AdapterStatus returns the connection status for a specific adapter.
func (*Manager) DiscoveredSources ¶ added in v0.2.1
DiscoveredSources returns all discovered external channels.
func (*Manager) GetAdapter ¶ added in v0.2.1
func (m *Manager) GetAdapter(name string) NotificationAdapter
GetAdapter returns a registered adapter by name, or nil if not found.
func (*Manager) HandleNotification ¶ added in v0.2.1
func (m *Manager) HandleNotification(platform string, n Notification)
HandleNotification processes an inbound notification from a specific platform.
func (*Manager) IsGatewayChannel ¶
IsGatewayChannel returns true if the channel name belongs to an external gateway.
func (*Manager) Register ¶
func (m *Manager) Register(adapter NotificationAdapter)
Register adds a NotificationAdapter to the manager.
func (*Manager) Send ¶
Send routes a message from a bc channel to the appropriate external platform. Returns true if the channel is an external gateway channel and was handled.
func (*Manager) SendFile ¶
func (m *Manager) SendFile(ctx context.Context, bcChannel, sender, filename string, data []byte, mimeType string) (bool, error)
SendFile uploads a file to a gateway channel. Returns false if the channel is not a gateway channel or the adapter doesn't support file uploads.
func (*Manager) SetChannelStore ¶
func (m *Manager) SetChannelStore(store ChannelStore)
SetChannelStore sets the persistence store for channel mappings.
func (*Manager) SetInboundHandler ¶
func (m *Manager) SetInboundHandler(fn func(bcChannel, sender, content string, raw json.RawMessage))
SetInboundHandler sets the callback for inbound messages from external platforms.
type Notification ¶ added in v0.2.1
type Notification struct {
Timestamp time.Time `json:"timestamp"`
Raw json.RawMessage `json:"raw"`
Channel string `json:"channel"`
Platform string `json:"platform"`
Sender string `json:"sender"`
Content string `json:"content"` // human-readable text for display/storage
Mentions []string `json:"mentions"`
}
Notification is a normalized inbound event from an external platform. The Raw field contains the complete platform payload as JSON.
type NotificationAdapter ¶ added in v0.2.1
type NotificationAdapter interface {
// Name returns the adapter identifier ("slack", "github", "telegram").
Name() string
// Type returns the connection pattern (socket, webhook, or poll).
Type() AdapterType
// Start connects to the platform and begins receiving notifications.
// Calls handler for each inbound event with raw JSON payload.
// Blocks until ctx is canceled. For webhook adapters, this is a no-op.
Start(ctx context.Context, handler func(Notification)) error
// Stop gracefully disconnects from the platform.
Stop() error
// HTTPHandler returns an http.Handler for webhook-based adapters.
// Socket and poll adapters return nil.
HTTPHandler() http.Handler
// Channels returns discovered channels/groups the bot has access to.
Channels() []ChannelInfo
// Status returns the adapter's connection state for the web UI.
Status() AdapterStatus
}
NotificationAdapter handles the platform connection lifecycle. This is the new interface that all adapters should implement.
type PersistedChannel ¶
PersistedChannel is a saved bc_channel → platform_id mapping.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package discord implements the gateway.NotificationAdapter for Discord.
|
Package discord implements the gateway.NotificationAdapter for Discord. |
|
Package github implements the gateway.NotificationAdapter for GitHub webhooks.
|
Package github implements the gateway.NotificationAdapter for GitHub webhooks. |
|
Package imessage implements a gateway.NotificationAdapter that polls the BlueBubbles API for new iMessage messages.
|
Package imessage implements a gateway.NotificationAdapter that polls the BlueBubbles API for new iMessage messages. |
|
Package irc implements a gateway.NotificationAdapter for IRC channels using the ergochat/irc-go library.
|
Package irc implements a gateway.NotificationAdapter for IRC channels using the ergochat/irc-go library. |
|
Package matrix implements a gateway.NotificationAdapter that polls the Matrix client-server API /sync endpoint for new events.
|
Package matrix implements a gateway.NotificationAdapter that polls the Matrix client-server API /sync endpoint for new events. |
|
Package mattermost implements a gateway.NotificationAdapter using the Mattermost WebSocket API for real-time message events.
|
Package mattermost implements a gateway.NotificationAdapter using the Mattermost WebSocket API for real-time message events. |
|
Package mqtt implements a gateway.NotificationAdapter for MQTT topics using the Eclipse Paho MQTT client.
|
Package mqtt implements a gateway.NotificationAdapter for MQTT topics using the Eclipse Paho MQTT client. |
|
Package notion implements a gateway.NotificationAdapter that polls the Notion API for recently updated pages and databases.
|
Package notion implements a gateway.NotificationAdapter that polls the Notion API for recently updated pages and databases. |
|
Package reddit implements a gateway.NotificationAdapter that polls the Reddit API for new posts and comments in a subreddit.
|
Package reddit implements a gateway.NotificationAdapter that polls the Reddit API for new posts and comments in a subreddit. |
|
Package rss implements a gateway.NotificationAdapter that polls RSS 2.0 and Atom feeds on a configurable interval.
|
Package rss implements a gateway.NotificationAdapter that polls RSS 2.0 and Atom feeds on a configurable interval. |
|
Package signal implements a gateway.NotificationAdapter that polls a signal-cli REST API for new messages.
|
Package signal implements a gateway.NotificationAdapter that polls a signal-cli REST API for new messages. |
|
Package slackgw implements the gateway.NotificationAdapter for Slack.
|
Package slackgw implements the gateway.NotificationAdapter for Slack. |
|
Package telegram implements the gateway.NotificationAdapter for Telegram Bot API.
|
Package telegram implements the gateway.NotificationAdapter for Telegram Bot API. |
|
Package twitter implements a gateway.NotificationAdapter that polls the Twitter API v2 mentions endpoint for new mentions.
|
Package twitter implements a gateway.NotificationAdapter that polls the Twitter API v2 mentions endpoint for new mentions. |
|
Package webhook implements a generic gateway.NotificationAdapter that receives arbitrary JSON payloads via HTTP POST.
|
Package webhook implements a generic gateway.NotificationAdapter that receives arbitrary JSON payloads via HTTP POST. |
|
Package whatsapp implements a gateway.NotificationAdapter using whatsmeow (WhatsApp Web multi-device protocol).
|
Package whatsapp implements a gateway.NotificationAdapter using whatsmeow (WhatsApp Web multi-device protocol). |