butterrobot/internal/model/platform.go
Felipe M. 8801c43f92
All checks were successful
CI / goreleaser-lint (push) Successful in 10s
CI / format (push) Successful in 1m52s
Release / release (push) Successful in 5m40s
CI / lint (push) Successful in 2m31s
CI / test (push) Successful in 1m0s
CI / build (push) Successful in 4m6s
feat: add !gallerydl command to download media from links
Reply to a message containing a link with !gallerydl (or send it with a
link inline) to download the media via the gallery-dl CLI and have the
files posted back as a reply. Restricted to an allowed_users allowlist
(comma-separated, per-channel/global config); no one is allowed by
default.

- Add media support to the platform layer: model.Message.Files,
  ActionSendMedia, and Platform.SendMedia. Telegram uploads via
  multipart (sendPhoto/sendVideo/sendDocument, 50MB cap); Slack returns
  unsupported for now.
- Add internal/shell (os/exec wrapper) and internal/urlutil (URL
  extraction) helpers with tests.
- Dispatch ActionSendMedia in app and clean up the temp download dir.
- Admin config UI for allowed_users / gallery_dl_path; docs entry.
- Containerfile: base on alpine and install gallery-dl + ffmpeg (was
  scratch); release workflow sets up QEMU + Buildx for cross-arch image
  builds.
2026-07-05 20:05:57 +02:00

53 lines
1.6 KiB
Go

package model
import (
"errors"
"net/http"
"git.nakama.town/fmartingr/butterrobot/internal/config"
)
var (
// ErrPlatform is a general platform error
ErrPlatform = errors.New("platform error")
// ErrPlatformInit is an error during platform initialization
ErrPlatformInit = errors.New("platform initialization error")
// ErrPlatformAuth is an authentication error
ErrPlatformAuth = errors.New("platform authentication error")
// ErrPlatformNotFound is returned when a requested platform doesn't exist
ErrPlatformNotFound = errors.New("platform not found")
)
// AuthResponse represents a platform authentication response
type AuthResponse struct {
Data map[string]any
StatusCode int
}
// Platform defines the interface all chat platforms must implement
type Platform interface {
// Init initializes the platform
Init(cfg *config.Config) error
// ParseIncomingMessage parses the incoming HTTP request into a Message
ParseIncomingMessage(r *http.Request) (*Message, error)
// ParseChannelNameFromRaw extracts a human-readable channel name from raw data
ParseChannelNameFromRaw(channelRaw map[string]any) string
// ParseChannelFromMessage extracts channel data from a message
ParseChannelFromMessage(body []byte) (map[string]any, error)
// SendMessage sends a message through the platform
SendMessage(msg *Message) error
// SendMedia uploads the local files in msg.Files through the platform,
// replying to msg.ReplyTo when set
SendMedia(msg *Message) error
// DeleteMessage deletes a message from the platform
DeleteMessage(channel string, messageID string) error
}