Documentation
¶
Overview ¶
Package channels provides the ChatChannel interface for all chat platform integrations.
Index ¶
- Variables
- type ChannelError
- type ChannelRouter
- func (r *ChannelRouter) Close() error
- func (r *ChannelRouter) GetChannel(platform chat_apps.Platform) ChatChannel
- func (r *ChannelRouter) HandleWebhook(ctx context.Context, platform chat_apps.Platform, headers map[string]string, ...) (*chat_apps.IncomingMessage, error)
- func (r *ChannelRouter) Register(channel ChatChannel)
- func (r *ChannelRouter) SendChunkedResponse(ctx context.Context, platform chat_apps.Platform, chatID string, ...) error
- func (r *ChannelRouter) SendResponse(ctx context.Context, platform chat_apps.Platform, ...) error
- type ChatChannel
- type MediaHandler
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoChannelForPlatform = &ChannelError{Code: "NO_CHANNEL", Message: "no channel registered for platform"} ErrInvalidSignature = &ChannelError{Code: "INVALID_SIGNATURE", Message: "webhook signature validation failed"} ErrInvalidPayload = &ChannelError{Code: "INVALID_PAYLOAD", Message: "could not parse webhook payload"} ErrMediaDownloadFailed = &ChannelError{Code: "MEDIA_FAILED", Message: "failed to download media"} )
Errors
Functions ¶
This section is empty.
Types ¶
type ChannelError ¶
ChannelError represents an error in channel operations.
func (*ChannelError) Error ¶
func (e *ChannelError) Error() string
func (*ChannelError) IsRetryable ¶
func (e *ChannelError) IsRetryable() bool
IsRetryable returns true if the error is transient and the operation can be retried.
func (*ChannelError) Unwrap ¶
func (e *ChannelError) Unwrap() error
type ChannelRouter ¶
type ChannelRouter struct {
// contains filtered or unexported fields
}
ChannelRouter routes incoming messages to the appropriate handler. It verifies user credentials and forwards messages to the AI agent system. Concurrent-safe for Register and GetChannel operations.
func NewChannelRouter ¶
func NewChannelRouter(media MediaHandler) *ChannelRouter
NewChannelRouter creates a new channel router.
func (*ChannelRouter) Close ¶
func (r *ChannelRouter) Close() error
Close closes all registered channels. Concurrent-safe: uses write lock.
func (*ChannelRouter) GetChannel ¶
func (r *ChannelRouter) GetChannel(platform chat_apps.Platform) ChatChannel
GetChannel returns the channel for a platform, or nil if not registered. Concurrent-safe: uses read lock.
func (*ChannelRouter) HandleWebhook ¶
func (r *ChannelRouter) HandleWebhook(ctx context.Context, platform chat_apps.Platform, headers map[string]string, body []byte) (*chat_apps.IncomingMessage, error)
HandleWebhook handles an incoming webhook request.
func (*ChannelRouter) Register ¶
func (r *ChannelRouter) Register(channel ChatChannel)
Register registers a chat channel for a platform. Concurrent-safe: uses write lock.
func (*ChannelRouter) SendChunkedResponse ¶
func (r *ChannelRouter) SendChunkedResponse(ctx context.Context, platform chat_apps.Platform, chatID string, chunks <-chan string) error
SendChunkedResponse sends a streaming AI response to a chat platform.
func (*ChannelRouter) SendResponse ¶
func (r *ChannelRouter) SendResponse(ctx context.Context, platform chat_apps.Platform, msg *chat_apps.OutgoingMessage) error
SendResponse sends a single response message to a chat platform.
type ChatChannel ¶
type ChatChannel interface {
// Name returns the platform name (e.g., "telegram", "whatsapp", "dingtalk").
Name() chat_apps.Platform
// ValidateWebhook verifies the incoming webhook request.
// Returns an error if the request signature is invalid or the request is malformed.
ValidateWebhook(ctx context.Context, headers map[string]string, body []byte) error
// ParseMessage parses the incoming webhook payload into an IncomingMessage.
// The payload format is platform-specific (JSON for most platforms).
ParseMessage(ctx context.Context, payload []byte) (*chat_apps.IncomingMessage, error)
// SendMessage sends a single message to the chat platform.
SendMessage(ctx context.Context, msg *chat_apps.OutgoingMessage) error
// SendChunkedMessage sends streaming content chunks.
// The channels function closes when all chunks are sent or an error occurs.
// This is used for streaming AI responses.
SendChunkedMessage(ctx context.Context, chatID string, chunks <-chan string) error
// DownloadMedia downloads media from the platform's CDN.
// Returns the media data, MIME type, and an error if any.
DownloadMedia(ctx context.Context, url string) ([]byte, string, error)
// Close closes any open connections and releases resources.
Close() error
}
ChatChannel defines the interface for all chat platform integrations. Each platform (Telegram, WhatsApp, DingTalk) implements this interface.
type MediaHandler ¶
type MediaHandler interface {
// ProcessAudio converts audio data to text using Whisper.
ProcessAudio(ctx context.Context, data []byte, mimeType string) (string, error)
// ProcessImage extracts text from images using OCR.
ProcessImage(ctx context.Context, data []byte) (string, error)
}
MediaHandler processes multimedia messages (audio, images).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dingtalk provides cryptographic utilities for DingTalk.
|
Package dingtalk provides cryptographic utilities for DingTalk. |
|
Package telegram implements the Telegram Bot channel.
|
Package telegram implements the Telegram Bot channel. |
|
Package whatsapp implements WhatsApp integration via Baileys Node.js bridge.
|
Package whatsapp implements WhatsApp integration via Baileys Node.js bridge. |