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 Adapter
- type AdapterStatus
- type Attachment
- type ChannelStore
- type ExternalChannel
- type FileSender
- type InboundMessage
- type Manager
- func (m *Manager) AdapterStatus(platform string) AdapterStatus
- func (m *Manager) ExternalChannels() []string
- func (m *Manager) IsGatewayChannel(name string) bool
- func (m *Manager) Register(adapter Adapter)
- func (m *Manager) SeedChannel(bcChannel string)
- 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))
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Stop(ctx context.Context)
- type PersistedChannel
- type StatusReporter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter interface {
// Name returns the platform identifier ("telegram", "discord", "slack").
Name() string
// Start connects to the platform and begins receiving messages.
// Calls onMessage for each inbound message. Blocks until ctx is canceled.
Start(ctx context.Context, onMessage func(InboundMessage)) error
// Stop gracefully disconnects from the platform.
Stop(ctx context.Context) error
// Send delivers a message to a platform channel.
Send(ctx context.Context, channelID, sender, content string) error
// Channels returns all channels/groups the bot is a member of.
Channels(ctx context.Context) ([]ExternalChannel, error)
// Health returns nil if the adapter is connected and operational.
Health(ctx context.Context) error
}
Adapter handles the platform connection lifecycle and message routing.
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"`
}
AdapterStatus reports connection state for the web UI.
type Attachment ¶
type Attachment struct {
URL string `json:"url"`
Name string `json:"name"`
MimeType string `json:"mime_type"`
Source string `json:"source"` // "slack", "telegram", "discord", "local"
FileID string `json:"file_id,omitempty"`
Size int64 `json:"size,omitempty"`
}
Attachment represents a file attached to a message.
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 ExternalChannel ¶
ExternalChannel represents a channel/group on an external platform.
type FileSender ¶
type FileSender interface {
// SendFile uploads a file to a platform channel.
SendFile(ctx context.Context, channelID, sender, filename string, data []byte, mimeType string) error
}
FileSender is optionally implemented by adapters that support file uploads.
type InboundMessage ¶
type InboundMessage struct {
Timestamp time.Time
ChannelID string
ChannelName string
Sender string
SenderID string
Content string
MessageID string
Attachments []Attachment
}
InboundMessage is a normalized message from an external platform.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates all gateway adapters and routes messages.
func (*Manager) AdapterStatus ¶
func (m *Manager) AdapterStatus(platform string) AdapterStatus
AdapterStatus returns the connection status for a specific adapter. If the adapter implements StatusReporter, uses that; otherwise infers from channels.
func (*Manager) ExternalChannels ¶
ExternalChannels returns all discovered external channels.
func (*Manager) IsGatewayChannel ¶
IsGatewayChannel returns true if the channel name belongs to an external gateway.
func (*Manager) SeedChannel ¶
SeedChannel adds a known gateway channel to the channel map. Used on startup to restore mappings for channels that were dynamically discovered in previous sessions. The channelID is set to the channel name suffix (e.g., "all-bc" for "slack:all-bc") since the platform adapter will resolve it.
Channel names follow the pattern "adapter_name:channel_name" where adapter_name may itself contain a colon (e.g. "telegram:foo:general").
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 ¶
SetInboundHandler sets the callback for inbound messages from external platforms.
type PersistedChannel ¶
PersistedChannel is a saved bc_channel → platform_id mapping.
type StatusReporter ¶
type StatusReporter interface {
// Status returns the current connection state for UI display.
Status() AdapterStatus
}
StatusReporter is optionally implemented by adapters that report connection state.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package discord implements the gateway.Adapter for Discord.
|
Package discord implements the gateway.Adapter for Discord. |
|
Package slackgw implements the gateway.Adapter for Slack.
|
Package slackgw implements the gateway.Adapter for Slack. |
|
Package telegram implements the gateway.Adapter for Telegram Bot API.
|
Package telegram implements the gateway.Adapter for Telegram Bot API. |