Documentation
¶
Overview ¶
Package channels defines the interfaces and types for DevClaw communication channels. Each channel (WhatsApp, Discord, Telegram) implements the Channel interface to receive and send messages in a unified way.
Package channels – manager.go orchestrates multiple communication channels, providing a single entry point to receive messages from all platforms and route responses to the correct channel.
Index ¶
- Variables
- type Channel
- type ChannelConfig
- type ContactInfo
- type HealthStatus
- type IncomingMessage
- type LocationInfo
- type Manager
- func (m *Manager) Channel(name string) (Channel, bool)
- func (m *Manager) ChannelStatus(name string) (HealthStatus, error)
- func (m *Manager) ConnectChannel(name string) error
- func (m *Manager) DisconnectChannel(name string) error
- func (m *Manager) HasChannels() bool
- func (m *Manager) HealthAll() map[string]HealthStatus
- func (m *Manager) ListChannels() []string
- func (m *Manager) MarkRead(ctx context.Context, channelName, chatID string, messageIDs []string)
- func (m *Manager) Messages() <-chan *IncomingMessage
- func (m *Manager) Register(ch Channel) error
- func (m *Manager) Send(ctx context.Context, channelName, to string, msg *OutgoingMessage) error
- func (m *Manager) SendMedia(ctx context.Context, channelName, to string, media *MediaMessage) error
- func (m *Manager) SendReaction(ctx context.Context, channelName, chatID, messageID, emoji string)
- func (m *Manager) SendTyping(ctx context.Context, channelName, to string)
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Stop()
- type MediaAttachment
- type MediaChannel
- type MediaInfo
- type MediaMessage
- type MessageType
- type OutgoingMessage
- type PresenceChannel
- type ReactionChannel
- type ReactionInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrChannelDisconnected = fmt.Errorf("channel is not connected") ErrSendFailed = fmt.Errorf("failed to send message") ErrConnectionFailed = fmt.Errorf("failed to connect to channel") ErrMediaNotSupported = fmt.Errorf("media not supported by this channel") ErrMediaDownloadFailed = fmt.Errorf("failed to download media") )
Errors.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel interface {
// Name returns the channel identifier (e.g. "whatsapp", "discord").
Name() string
// Connect establishes the connection to the messaging platform.
Connect(ctx context.Context) error
// Disconnect gracefully closes the connection.
Disconnect() error
// Send sends a message to the specified recipient.
Send(ctx context.Context, to string, message *OutgoingMessage) error
// Receive returns a Go channel that emits incoming messages.
Receive() <-chan *IncomingMessage
// IsConnected returns true if the channel is connected.
IsConnected() bool
// Health returns the channel health status.
Health() HealthStatus
}
Channel defines the interface that every communication channel must implement.
type ChannelConfig ¶
type ChannelConfig struct {
Enabled bool `yaml:"enabled"`
Trigger string `yaml:"trigger"`
MaxRetries int `yaml:"max_retries"`
RetryBackoffMs int `yaml:"retry_backoff_ms"`
}
ChannelConfig contains common configuration for all channels.
type ContactInfo ¶
ContactInfo contains shared contact data.
type HealthStatus ¶
type HealthStatus struct {
Connected bool
LastMessageAt time.Time
ErrorCount int
LatencyMs int64
Details map[string]any
}
HealthStatus represents the health state of a channel.
type IncomingMessage ¶
type IncomingMessage struct {
// ID is the unique message identifier in the source channel.
ID string
// Channel identifies the source channel (e.g. "whatsapp").
Channel string
// From is the sender identifier on the platform.
From string
// FromName is the sender display name (if available).
FromName string
// ChatID is the group or DM identifier.
ChatID string
// IsGroup indicates whether the message is from a group chat.
IsGroup bool
// Type is the message content type.
Type MessageType
// Content is the text content of the message.
Content string
// Timestamp is when the message was sent.
Timestamp time.Time
// ReplyTo contains the ID of the message being replied to.
ReplyTo string
// QuotedContent is the text of the quoted message (if replying).
QuotedContent string
// Media contains media attachment details (if any).
Media *MediaInfo
// Location contains location data (if MessageLocation).
Location *LocationInfo
// Contact contains contact data (if MessageContact).
Contact *ContactInfo
// Reaction contains reaction data (if MessageReaction).
Reaction *ReactionInfo
// Metadata contains additional channel-specific data.
Metadata map[string]any
}
IncomingMessage represents a message received from any channel.
type LocationInfo ¶
type LocationInfo struct {
Latitude float64
Longitude float64
Name string
Address string
URL string
AccuracyM uint32
}
LocationInfo contains location coordinates.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates multiple communication channels, aggregating incoming messages into a single stream and routing responses.
func NewManager ¶
NewManager creates a new channel manager.
func (*Manager) ChannelStatus ¶
func (m *Manager) ChannelStatus(name string) (HealthStatus, error)
ChannelStatus returns health status for a specific channel.
func (*Manager) ConnectChannel ¶
ConnectChannel connects a specific channel by name. Returns error if channel not found or connection fails.
func (*Manager) DisconnectChannel ¶
DisconnectChannel disconnects a specific channel by name.
func (*Manager) HasChannels ¶
HasChannels returns true if at least one channel is registered.
func (*Manager) HealthAll ¶
func (m *Manager) HealthAll() map[string]HealthStatus
HealthAll returns health status for all registered channels.
func (*Manager) ListChannels ¶
ListChannels returns the names of all registered channels.
func (*Manager) MarkRead ¶
MarkRead marks messages as read on the specified channel. Silently does nothing if the channel doesn't support presence.
func (*Manager) Messages ¶
func (m *Manager) Messages() <-chan *IncomingMessage
Messages returns the aggregated message stream from all channels.
func (*Manager) SendMedia ¶
SendMedia sends a media message through the specified channel. Returns ErrMediaNotSupported if the channel doesn't support media.
func (*Manager) SendReaction ¶
SendReaction sends an emoji reaction to a message on the specified channel. Silently does nothing if the channel doesn't support reactions.
func (*Manager) SendTyping ¶
SendTyping sends a typing indicator on the specified channel. Silently does nothing if the channel doesn't support presence.
type MediaAttachment ¶ added in v1.8.0
type MediaAttachment struct {
// MediaID is the stored media identifier.
MediaID string
// Type is the media type (for convenience).
Type MessageType
// Caption is the text accompanying the media.
Caption string
}
MediaAttachment references stored media for sending.
type MediaChannel ¶
type MediaChannel interface {
Channel
// SendMedia sends a media message (image, audio, video, document).
SendMedia(ctx context.Context, to string, media *MediaMessage) error
// DownloadMedia downloads media from an incoming message.
// Returns the raw bytes and MIME type.
DownloadMedia(ctx context.Context, msg *IncomingMessage) ([]byte, string, error)
}
MediaChannel extends Channel with media capabilities. Channels that support media (images, audio, video, documents) should implement this interface.
type MediaInfo ¶
type MediaInfo struct {
// Type is the media type.
Type MessageType
// MimeType is the MIME type of the media.
MimeType string
// Filename is the original filename (for documents).
Filename string
// FileSize is the size in bytes.
FileSize uint64
// Caption is the media caption text.
Caption string
// Duration is the duration in seconds (audio/video).
Duration uint32
// Width is the width in pixels (images/video).
Width uint32
// Height is the height in pixels (images/video).
Height uint32
// URL is a direct download URL (if available).
URL string
// DirectPath is the platform-specific media path (for whatsapp).
DirectPath string
// MediaKey is the encryption key for the media (for whatsapp).
MediaKey []byte
// FileSHA256 is the SHA256 hash of the file.
FileSHA256 []byte
// FileEncSHA256 is the SHA256 hash of the encrypted file.
FileEncSHA256 []byte
}
MediaInfo describes media attached to an incoming message.
type MediaMessage ¶
type MediaMessage struct {
// Type is the media type (image, audio, video, document, sticker).
Type MessageType
// Data is the raw media bytes. Either Data or URL must be set.
Data []byte
// URL is a URL to the media file. Either Data or URL must be set.
URL string
// MimeType is the MIME type (e.g. "image/jpeg", "audio/ogg").
MimeType string
// Filename is the original filename (for documents).
Filename string
// Caption is the text caption accompanying the media.
Caption string
// Duration is the duration in seconds (for audio/video).
Duration uint32
// Width is the media width in pixels (for images/video).
Width uint32
// Height is the media height in pixels (for images/video).
Height uint32
// ReplyTo contains the ID of the message to reply to.
ReplyTo string
}
MediaMessage represents a media file to be sent.
type MessageType ¶
type MessageType string
MessageType identifies the kind of message content.
const ( MessageText MessageType = "text" MessageImage MessageType = "image" MessageAudio MessageType = "audio" MessageVideo MessageType = "video" MessageDocument MessageType = "document" MessageSticker MessageType = "sticker" MessageLocation MessageType = "location" MessageContact MessageType = "contact" MessageReaction MessageType = "reaction" )
type OutgoingMessage ¶
type OutgoingMessage struct {
// Content is the text content of the message.
Content string
// ReplyTo contains the ID of the message to reply to.
ReplyTo string
// Attachments contains media attachments to send with the message.
Attachments []*MediaAttachment
// Metadata contains additional channel-specific data.
Metadata map[string]any
}
OutgoingMessage represents a message to be sent through a channel.
type PresenceChannel ¶
type PresenceChannel interface {
Channel
// SendTyping sends a "typing..." indicator to the recipient.
SendTyping(ctx context.Context, to string) error
// SendPresence updates the bot's presence status.
SendPresence(ctx context.Context, available bool) error
// MarkRead marks a message as read.
MarkRead(ctx context.Context, chatID string, messageIDs []string) error
}
PresenceChannel extends Channel with typing/presence indicators.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package discord - components.go provides reusable interactive component handling for Discord (buttons, select menus) with registration, TTL-based cleanup, AllowedUsers restriction, and Reusable behavior.
|
Package discord - components.go provides reusable interactive component handling for Discord (buttons, select menus) with registration, TTL-based cleanup, AllowedUsers restriction, and Reusable behavior. |
|
Package slack implements the Slack channel for DevClaw using the Slack Web API and Socket Mode for real-time events — no external dependencies beyond HTTP.
|
Package slack implements the Slack channel for DevClaw using the Slack Web API and Socket Mode for real-time events — no external dependencies beyond HTTP. |
|
Package telegram implements the Telegram channel for DevClaw using the Telegram Bot API directly via HTTP — no external dependencies.
|
Package telegram implements the Telegram channel for DevClaw using the Telegram Bot API directly via HTTP — no external dependencies. |
|
Package whatsapp – events.go processes incoming WhatsApp events from whatsmeow and converts them into unified DevClaw IncomingMessage types.
|
Package whatsapp – events.go processes incoming WhatsApp events from whatsmeow and converts them into unified DevClaw IncomingMessage types. |