Documentation
¶
Overview ¶
Package files provides file processing utilities for Telegram messages.
Index ¶
- func IsFileSizeAllowed(size int64) bool
- func IsGeminiSupported(mimeType string) bool
- func MaxFileSize() int64
- func RecordFileDownload(userID int64, fileType FileType, durationSeconds float64, sizeBytes int64, ...)
- type FileSaver
- type FileStorage
- type FileTooLargeError
- type FileType
- type ProcessedFile
- type Processor
- type SavedFile
- type UnsupportedFormatError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsFileSizeAllowed ¶ added in v0.6.0
IsFileSizeAllowed checks if a file size is within Telegram Bot API limits.
func IsGeminiSupported ¶ added in v0.6.0
IsGeminiSupported checks if a MIME type is supported by Gemini API.
func MaxFileSize ¶ added in v0.6.0
func MaxFileSize() int64
MaxFileSize returns the maximum file size allowed for download.
Types ¶
type FileSaver ¶ added in v0.6.0
type FileSaver interface {
// SaveFile saves a file and returns the artifact ID (existing on dedup, new on creation).
// messageText is the text content of the message (msg.Text or msg.Caption) for context (v0.6.0).
SaveFile(ctx context.Context, userID int64, messageID int64, fileType string, originalName string, mimeType string, reader io.Reader, messageText string) (*int64, error)
}
FileSaver is the interface for saving artifacts (to avoid circular dependency).
type FileStorage ¶ added in v0.6.0
type FileStorage struct {
// contains filtered or unexported fields
}
FileStorage handles saving files to disk with SHA256 calculation.
func NewFileStorage ¶ added in v0.6.0
func NewFileStorage(basePath string, logger *slog.Logger) *FileStorage
NewFileStorage creates a new file storage service.
func (*FileStorage) DeleteFile ¶ added in v0.6.0
func (fs *FileStorage) DeleteFile(relativePath string) error
DeleteFile deletes a file from disk.
func (*FileStorage) GetFullPath ¶ added in v0.6.0
func (fs *FileStorage) GetFullPath(relativePath string) string
GetFullPath returns the absolute path for a relative artifact path.
type FileTooLargeError ¶ added in v0.6.0
FileTooLargeError is returned when a file exceeds the size limit.
func (*FileTooLargeError) Error ¶ added in v0.6.0
func (e *FileTooLargeError) Error() string
type FileType ¶
type FileType string
FileType represents the type of file being processed.
const ( FileTypePhoto FileType = "photo" FileTypeImage FileType = "image" // image sent as document FileTypePDF FileType = "pdf" FileTypeVoice FileType = "voice" FileTypeAudio FileType = "audio" // audio files (MP3, etc.) FileTypeVideo FileType = "video" // video files (MP4, etc.) FileTypeVideoNote FileType = "video_note" // video messages (circles) FileTypeDocument FileType = "document" // text files )
type ProcessedFile ¶
type ProcessedFile struct {
// LLMParts contains the file data formatted for OpenRouter API
// (FilePart, TextPart from openrouter package) (v0.6.0: unified on FilePart)
LLMParts []interface{}
// Instruction is the localized LLM instruction for this file type
// (e.g., "Quote the transcription..." for voice messages)
Instruction string
// FileType indicates the type of file
FileType FileType
// FileID is the Telegram file ID
FileID string
// FileName is the original file name (if available)
FileName string
// MimeType is the MIME type of the file
MimeType string
// Size is the file size in bytes
Size int64
// Duration is the download time (for metrics)
Duration time.Duration
// ArtifactID is the ID of the saved artifact (nil if not saved or disabled)
ArtifactID *int64
}
ProcessedFile represents a processed file ready for LLM consumption.
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor handles file downloads and processing from Telegram messages.
func NewProcessor ¶
func NewProcessor( downloader telegram.FileDownloader, translator *i18n.Translator, language string, logger *slog.Logger, ) *Processor
NewProcessor creates a new file processor.
func (*Processor) ProcessMessage ¶
func (p *Processor) ProcessMessage(ctx context.Context, msg *telegram.Message, userID int64, groupText string) ([]*ProcessedFile, error)
ProcessMessage extracts and processes the file from a message. A Telegram message contains at most one file (photo OR document OR voice OR audio). Individual file errors are logged as warnings and nil is returned for that file. Returns a slice with 0 or 1 successfully processed files. groupText is the full text of all messages in the current MessageGroup (v0.6.0).
func (*Processor) SetFileHandler ¶ added in v0.6.0
SetFileHandler sets the optional file handler for saving artifacts.
func (*Processor) SetMinVoiceDurationSec ¶ added in v0.6.0
SetMinVoiceDurationSec sets the minimum voice duration for saving as artifact. 0 = save all voices, -1 = disable voice artifacts, N = only save voices >= N seconds.
type SavedFile ¶ added in v0.6.0
type SavedFile struct {
Path string // Relative path from base
ContentHash string // SHA256 hex
Size int64 // Bytes
}
SavedFile contains metadata about a saved file.
type UnsupportedFormatError ¶ added in v0.6.0
UnsupportedFormatError is returned when a file format is not supported by Gemini.
func (*UnsupportedFormatError) Error ¶ added in v0.6.0
func (e *UnsupportedFormatError) Error() string