platforms

package
v0.4.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatURLForDiscord

func FormatURLForDiscord(rawURL string) string

FormatURLForDiscord creates a Discord-friendly URL

Types

type DiscordEmbed

type DiscordEmbed struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Image       *struct {
		URL string `json:"url,omitempty"`
	} `json:"image,omitempty"`
	Thumbnail *struct {
		URL string `json:"url,omitempty"`
	} `json:"thumbnail,omitempty"`
}

DiscordEmbed represents a Discord embed

type DiscordMessage

type DiscordMessage struct {
	Content  string          `json:"content,omitempty"`
	Embeds   []DiscordEmbed  `json:"embeds,omitempty"`
	File     *multipart.File `json:"-"`
	Filename string          `json:"-"`
}

DiscordMessage represents a Discord message payload

type DiscordPlatform

type DiscordPlatform struct {
	// contains filtered or unexported fields
}

DiscordPlatform implements Discord messaging

func NewDiscordPlatform

func NewDiscordPlatform(token string) *DiscordPlatform

NewDiscordPlatform creates a new Discord platform

func (*DiscordPlatform) Connect

func (d *DiscordPlatform) Connect(ctx context.Context) error

Connect establishes connection to Discord

func (*DiscordPlatform) CreateDM

func (d *DiscordPlatform) CreateDM(ctx context.Context, userID string) (string, error)

CreateDM creates a direct message channel with a user

func (*DiscordPlatform) Disconnect

func (d *DiscordPlatform) Disconnect() error

Disconnect closes the connection

func (*DiscordPlatform) GetBotInfo

func (d *DiscordPlatform) GetBotInfo() (string, string)

GetBotInfo returns bot information

func (*DiscordPlatform) GetChannelMessages

func (d *DiscordPlatform) GetChannelMessages(ctx context.Context, channelID string, limit int) ([]Message, error)

GetChannelMessages gets messages from a channel

func (*DiscordPlatform) IsConnected

func (d *DiscordPlatform) IsConnected() bool

IsConnected returns connection status

func (*DiscordPlatform) JoinVoiceChannel

func (d *DiscordPlatform) JoinVoiceChannel(ctx context.Context, guildID, channelID string) error

JoinVoiceChannel joins a voice channel

func (*DiscordPlatform) LeaveVoiceChannel

func (d *DiscordPlatform) LeaveVoiceChannel(ctx context.Context) error

LeaveVoiceChannel leaves the current voice channel

func (*DiscordPlatform) Name

func (d *DiscordPlatform) Name() string

Name returns the platform name

func (*DiscordPlatform) Receive

func (d *DiscordPlatform) Receive(ctx context.Context) (<-chan Message, error)

Receive receives messages (polling - for webhook mode)

func (*DiscordPlatform) Send

func (d *DiscordPlatform) Send(ctx context.Context, channelID string, message Message) error

Send sends a message

func (*DiscordPlatform) SendWebhook

func (d *DiscordPlatform) SendWebhook(ctx context.Context, webhookURL string, message Message) error

SendWebhook sends a message via webhook

func (*DiscordPlatform) SetWebhook

func (d *DiscordPlatform) SetWebhook(ctx context.Context, webhookURL string) error

SetWebhook sets up webhook for this platform

type DiscordWebhookPayload

type DiscordWebhookPayload struct {
	Content string         `json:"content,omitempty"`
	Embeds  []DiscordEmbed `json:"embeds,omitempty"`
}

DiscordWebhookPayload represents a Discord webhook payload

type EmailPlatform

type EmailPlatform struct {
	// contains filtered or unexported fields
}

EmailPlatform implements Email messaging

func NewEmailPlatform

func NewEmailPlatform(smtpHost string, smtpPort int, username, password, fromAddr string) *EmailPlatform

NewEmailPlatform creates a new Email platform

func (*EmailPlatform) Connect

func (e *EmailPlatform) Connect(ctx context.Context) error

Connect establishes connection to SMTP server

func (*EmailPlatform) Disconnect

func (e *EmailPlatform) Disconnect() error

Disconnect closes the connection

func (*EmailPlatform) IsConnected

func (e *EmailPlatform) IsConnected() bool

IsConnected returns connection status

func (*EmailPlatform) Name

func (e *EmailPlatform) Name() string

Name returns the platform name

func (*EmailPlatform) Receive

func (e *EmailPlatform) Receive(ctx context.Context) (<-chan Message, error)

Receive is not supported for Email (uses webhooks)

func (*EmailPlatform) Send

func (e *EmailPlatform) Send(ctx context.Context, to string, msg Message) error

Send sends an email

type Gateway

type Gateway struct {
	// contains filtered or unexported fields
}

Gateway manages multiple platforms

func NewGateway

func NewGateway(config *GatewayConfig) *Gateway

NewGateway creates a new gateway

func (*Gateway) GetPlatform

func (g *Gateway) GetPlatform(name string) (Platform, bool)

GetPlatform returns a platform by name

func (*Gateway) ListPlatforms

func (g *Gateway) ListPlatforms() []string

ListPlatforms returns all registered platforms

func (*Gateway) Register

func (g *Gateway) Register(name string, platform Platform)

Register adds a platform to the gateway

func (*Gateway) Start

func (g *Gateway) Start(ctx context.Context) error

Start initializes all platforms

func (*Gateway) Stop

func (g *Gateway) Stop() error

Stop closes all platform connections

type GatewayConfig

type GatewayConfig struct {
	Port         int              `json:"port"`
	Platforms    []PlatformConfig `json:"platforms"`
	AllowedUsers []string         `json:"allowed_users"`
	AutoReply    bool             `json:"auto_reply"`
	VoiceReply   bool             `json:"voice_reply"`
}

GatewayConfig holds gateway configuration

type MatrixPlatform

type MatrixPlatform struct {
	// contains filtered or unexported fields
}

MatrixPlatform implements Matrix messaging

func NewMatrixPlatform

func NewMatrixPlatform(homeserver, userID, accessToken string) *MatrixPlatform

NewMatrixPlatform creates a new Matrix platform

func (*MatrixPlatform) Connect

func (m *MatrixPlatform) Connect(ctx context.Context) error

Connect establishes connection to Matrix

func (*MatrixPlatform) Disconnect

func (m *MatrixPlatform) Disconnect() error

Disconnect closes the connection

func (*MatrixPlatform) IsConnected

func (m *MatrixPlatform) IsConnected() bool

IsConnected returns connection status

func (*MatrixPlatform) JoinRoom

func (m *MatrixPlatform) JoinRoom(ctx context.Context, roomID string) error

JoinRoom joins a Matrix room

func (*MatrixPlatform) Name

func (m *MatrixPlatform) Name() string

Name returns the platform name

func (*MatrixPlatform) Receive

func (m *MatrixPlatform) Receive(ctx context.Context) (<-chan Message, error)

Receive is not supported for Matrix (uses webhooks)

func (*MatrixPlatform) Send

func (m *MatrixPlatform) Send(ctx context.Context, roomID string, msg Message) error

Send sends a message

type Media

type Media struct {
	Type     string `json:"type"` // voice, photo, video, document, image
	URL      string `json:"url"`
	FileID   string `json:"file_id,omitempty"`
	MimeType string `json:"mime_type,omitempty"`
	Size     int64  `json:"size,omitempty"`
	Width    int    `json:"width,omitempty"`
	Height   int    `json:"height,omitempty"`
	Duration int    `json:"duration,omitempty"`
	Caption  string `json:"caption,omitempty"`
}

Media represents attached media

type Message

type Message struct {
	ID        string                 `json:"id"`
	ChatID    string                 `json:"chat_id"`
	Text      string                 `json:"text"`
	Timestamp time.Time              `json:"timestamp"`
	From      User                   `json:"from"`
	Media     *Media                 `json:"media,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

Message represents a platform-agnostic message

func (*Message) FromJSON

func (m *Message) FromJSON(data []byte) error

FromJSON parses a message from JSON

func (*Message) ToJSON

func (m *Message) ToJSON() ([]byte, error)

ToJSON converts a message to JSON

type Platform

type Platform interface {
	Name() string
	Connect(ctx context.Context) error
	Disconnect() error
	IsConnected() bool
	Send(ctx context.Context, chatID string, message Message) error
	Receive(ctx context.Context) (<-chan Message, error)
}

Platform defines the interface for messaging platforms

type PlatformConfig

type PlatformConfig struct {
	Type   string                 `json:"type"` // telegram, discord, slack, etc.
	Token  string                 `json:"token,omitempty"`
	Config map[string]interface{} `json:"config,omitempty"`
}

PlatformConfig holds individual platform configuration

type SMSPlatform

type SMSPlatform struct {
	// contains filtered or unexported fields
}

SMSPlatform implements SMS messaging

func NewSMSPlatform

func NewSMSPlatform(apiKey, apiURL, from string) *SMSPlatform

NewSMSPlatform creates a new SMS platform

func (*SMSPlatform) Connect

func (s *SMSPlatform) Connect(ctx context.Context) error

Connect establishes connection to SMS gateway

func (*SMSPlatform) Disconnect

func (s *SMSPlatform) Disconnect() error

Disconnect closes the connection

func (*SMSPlatform) IsConnected

func (s *SMSPlatform) IsConnected() bool

IsConnected returns connection status

func (*SMSPlatform) Name

func (s *SMSPlatform) Name() string

Name returns the platform name

func (*SMSPlatform) Receive

func (s *SMSPlatform) Receive(ctx context.Context) (<-chan Message, error)

Receive is not supported for SMS

func (*SMSPlatform) Send

func (s *SMSPlatform) Send(ctx context.Context, to string, msg Message) error

Send sends an SMS

type SignalPlatform

type SignalPlatform struct {
	// contains filtered or unexported fields
}

SignalPlatform implements Signal messaging

func NewSignalPlatform

func NewSignalPlatform(serviceURL, username, password string) *SignalPlatform

NewSignalPlatform creates a new Signal platform

func (*SignalPlatform) Connect

func (s *SignalPlatform) Connect(ctx context.Context) error

Connect establishes connection to Signal

func (*SignalPlatform) Disconnect

func (s *SignalPlatform) Disconnect() error

Disconnect closes the connection

func (*SignalPlatform) IsConnected

func (s *SignalPlatform) IsConnected() bool

IsConnected returns connection status

func (*SignalPlatform) Name

func (s *SignalPlatform) Name() string

Name returns the platform name

func (*SignalPlatform) Receive

func (s *SignalPlatform) Receive(ctx context.Context) (<-chan Message, error)

Receive is not supported for Signal (uses external service)

func (*SignalPlatform) Send

func (s *SignalPlatform) Send(ctx context.Context, recipient string, msg Message) error

Send sends a message

type TelegramChat

type TelegramChat struct {
	ID       int64  `json:"id"`
	Type     string `json:"type"`
	Username string `json:"username"`
	Title    string `json:"title"`
}

TelegramChat represents a Telegram chat

type TelegramMessage

type TelegramMessage struct {
	ChatID              int64  `json:"chat_id"`
	Text                string `json:"text"`
	ParseMode           string `json:"parse_mode,omitempty"`
	DisableNotification bool   `json:"disable_notification,omitempty"`
}

TelegramMessage represents a Telegram message payload

type TelegramPlatform

type TelegramPlatform struct {
	// contains filtered or unexported fields
}

TelegramPlatform implements Telegram messaging

func NewTelegramPlatform

func NewTelegramPlatform(token string) *TelegramPlatform

NewTelegramPlatform creates a new Telegram platform

func (*TelegramPlatform) Connect

func (t *TelegramPlatform) Connect(ctx context.Context) error

Connect establishes connection to Telegram

func (*TelegramPlatform) Disconnect

func (t *TelegramPlatform) Disconnect() error

Disconnect closes the connection

func (*TelegramPlatform) GetFileURL

func (t *TelegramPlatform) GetFileURL(fileID string) (string, error)

GetFileURL gets the URL for a file

func (*TelegramPlatform) IsConnected

func (t *TelegramPlatform) IsConnected() bool

IsConnected returns connection status

func (*TelegramPlatform) Name

func (t *TelegramPlatform) Name() string

Name returns the platform name

func (*TelegramPlatform) Receive

func (t *TelegramPlatform) Receive(ctx context.Context) (<-chan Message, error)

Receive receives messages (polling)

func (*TelegramPlatform) Send

func (t *TelegramPlatform) Send(ctx context.Context, chatID string, message Message) error

Send sends a message

func (*TelegramPlatform) SetWebhook

func (t *TelegramPlatform) SetWebhook(ctx context.Context, webhookURL string) error

SetWebhook sets up webhook for this platform

type TelegramUpdate

type TelegramUpdate struct {
	UpdateID int64 `json:"update_id"`
	Message  *struct {
		MessageID int64        `json:"message_id"`
		From      TelegramUser `json:"from"`
		Chat      TelegramChat `json:"chat"`
		Text      string       `json:"text"`
		Date      int64        `json:"date"`
		Voice     *struct {
			FileID   string `json:"file_id"`
			Duration int    `json:"duration"`
			MimeType string `json:"mime_type"`
			FileSize int    `json:"file_size"`
		} `json:"voice"`
		Photo []struct {
			FileID string `json:"file_id"`
			Width  int    `json:"width"`
			Height int    `json:"height"`
		} `json:"photo"`
		Video *struct {
			FileID   string `json:"file_id"`
			Width    int    `json:"width"`
			Height   int    `json:"height"`
			Duration int    `json:"duration"`
		} `json:"video"`
		Document *struct {
			FileID   string `json:"file_id"`
			FileName string `json:"file_name"`
			MimeType string `json:"mime_type"`
			FileSize int    `json:"file_size"`
		} `json:"document"`
		Caption string `json:"caption"`
	} `json:"message"`
}

TelegramUpdate represents a Telegram update

type TelegramUser

type TelegramUser struct {
	ID        int64  `json:"id"`
	Username  string `json:"username"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Language  string `json:"language_code"`
}

TelegramUser represents a Telegram user

type User

type User struct {
	ID        string `json:"id"`
	Username  string `json:"username,omitempty"`
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
	Language  string `json:"language,omitempty"`
	IsBot     bool   `json:"is_bot,omitempty"`
}

User represents a platform-agnostic user

type WhatsAppMedia

type WhatsAppMedia struct {
	Link     string `json:"link,omitempty"`
	Caption  string `json:"caption,omitempty"`
	ID       string `json:"id,omitempty"`
	Provider string `json:"provider,omitempty"`
}

WhatsAppMedia represents WhatsApp media message

type WhatsAppMessage

type WhatsAppMessage struct {
	MessagingProduct string         `json:"messaging_product"`
	To               string         `json:"to"`
	Type             string         `json:"type"`
	Text             *WhatsAppText  `json:"text,omitempty"`
	Image            *WhatsAppMedia `json:"image,omitempty"`
	Audio            *WhatsAppMedia `json:"audio,omitempty"`
	Video            *WhatsAppMedia `json:"video,omitempty"`
	Document         *WhatsAppMedia `json:"document,omitempty"`
}

WhatsAppMessage represents a WhatsApp message payload

type WhatsAppPlatform

type WhatsAppPlatform struct {
	// contains filtered or unexported fields
}

WhatsAppPlatform implements WhatsApp messaging

func NewWhatsAppPlatform

func NewWhatsAppPlatform(phoneID, apiKey string) *WhatsAppPlatform

NewWhatsAppPlatform creates a new WhatsApp platform

func (*WhatsAppPlatform) Connect

func (w *WhatsAppPlatform) Connect(ctx context.Context) error

Connect establishes connection to WhatsApp

func (*WhatsAppPlatform) Disconnect

func (w *WhatsAppPlatform) Disconnect() error

Disconnect closes the connection

func (*WhatsAppPlatform) IsConnected

func (w *WhatsAppPlatform) IsConnected() bool

IsConnected returns connection status

func (*WhatsAppPlatform) Name

func (w *WhatsAppPlatform) Name() string

Name returns the platform name

func (*WhatsAppPlatform) Receive

func (w *WhatsAppPlatform) Receive(ctx context.Context) (<-chan Message, error)

Receive is not supported for WhatsApp (uses webhooks)

func (*WhatsAppPlatform) Send

func (w *WhatsAppPlatform) Send(ctx context.Context, to string, msg Message) error

Send sends a message

type WhatsAppText

type WhatsAppText struct {
	PreviewURL bool   `json:"preview_url,omitempty"`
	Body       string `json:"body"`
}

WhatsAppText represents WhatsApp text message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL